computationalanalysissocial_roles.pdfPDFI'm creating a replicant of this paper on my own…
- User
computational_analysis_social_roles.pdfPDFI'm creating a replicant of this paper on my own data. Which Python library can I use to calculate the cosine similarity of two contributions? Is this simple tf-idf?
- Assistant
Yes — for replicating the method in that paper, you can use cosine similarity on tf-idf vectors of contributions. Here’s how it fits together:
The paper uses Latent Semantic Analysis (LSA), which is built on tf-idf.
Each contribution is represented as a vector (from tf-idf, or after dimensionality reduction with SVD in LSA).
Cosine similarity is then calculated between these vectors to measure the semantic similarity of contributions .
In Python, you have a couple of standard library choices:
scikit-learn
TfidfVectorizer to get tf-idf vectors.
cosine_similarity from sklearn.metrics.pairwise to compute similarity.
TruncatedSVD if you want to replicate the LSA step used in the paper.
pythonCopyEditfrom sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity from sklearn.decomposition import TruncatedSVD
- User
Yes
- Assistant
Perfect 👍 — let’s build a step-by-step Python workflow that follows the approach in the paper:
🔹 Workflow: Replicating Contribution Similarity (like in the paper) We’ll go through:
Preprocessing text
TF-IDF vectorization
LSA (dimensionality reduction with SVD)
- User
Should I use Gensym or the above implementation?
- Assistant
Good question 👍 It depends on how close you want to stick to the original paper’s pipeline versus convenience for experimentation:
🔹 scikit-learn (the implementation I gave above) ✅ Pros
Directly mirrors the LSA (TF-IDF + SVD + cosine similarity) that the paper used.
Very explicit → you see each step (TF-IDF, SVD, similarity).
Easier to tweak (e.g., number of dimensions, stopwords, preprocessing).
Good for research replication, since reviewers often expect sklearn.
⚠️ Cons
You manage each step yourself (vectorizer, SVD, etc.).
Less convenient if you want streaming / large corpora.
🔹 gensim ✅ Pros
Designed for large corpora (can handle streaming from disk).
Has built-in models for TF-IDF, LSA, LDA, Word2Vec, Doc2Vec.
More memory-efficient than sklearn for big data.
Cosine similarity can be computed directly between vectors.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.