I'm replicating a statistics paper that defines aspects to quantify social roles in…
- User
I'm replicating a statistics paper that defines aspects to quantify social roles in group discussions.The only difference is that the original paper uses LSA for similarity, while I compute the cosine smilarity of the text embeddings.The imposes a challenge for quantifiny the participants' communication density. The original definition is attached. I thought of counting verbs or stopwords. Maybe use simple tf-idf representations. Can you help me build this metric in my analysis?
Assistant
- User
This part "# Create TF-IDF vectors for all contributions" should be diffent. I have an external corpus that I want to use to create tf-idf vectors and then vectorize each specific contribution. Assume that the Analyzer class holds the tf-idf vectorizer.
Assistant
- User
Here is my implementation. The values are skewd with mean=0.07 and std=0.10What Can I do to spread them out?def communication_density(self, cont_idx: int) -> float: """ Communication density for a single contribution. Calculate the communication density for a single contribution at a given time point. Use tf-idf vectorizer to get the vector for the contribution. Defined as: d(c_t) = || lsa_vector(c_t) || / || c_t || """ text = self.data.iloc[cont_idx]['text'] # Get the current contribution vector and text cur_tfidf = self.vectorizer.transform([text]) # the th-idf vector norm is a proxy for semantic richness vector_norm = np.linalg.norm(cur_tfidf.toarray()) word_count = len(text.split())
return float(vector_norm / word_count) if word_count > 0 else 0.0 Assistant
- User
I want to stick close to the original. Here are the original results values using LSA. How come my values are much smaller?
Assistant
- User
Why did you choose 3? Here is my code:
Assistant
Looking at your code, I can see the issue! You're using the default TF-IDF vectorizer settings, which includes L2 normalization (norm='l2' by default). This is why your values are much smaller than the original LSA values. Here's what's happening: The Problem: pythonvectorizer = TfidfVectorizer( max_features=None, # the corpus has ~24k unique words stop_words=get_heb_stopwords(), # norm='l2' is the default - this normalizes vectors to unit length! ) The L2 normalization makes all TF-IDF vectors have a norm close to 1.0, which when divided by word count gives you those small values (0.07 mean). The Solution: Change your vectorizer initialization to: pythonvectorizer = TfidfVectorizer( max_features=None, stop_words=get_heb_stopwords(), norm=None, # Remove L2 normalization! ) Also, I notice in your communication_density method you have both approaches commented: pythondef communication_density(self, cont_idx: int) -> float: text = self.data.iloc[cont_idx]['text'] cur_tfidf = self.vectorizer.transform([text])
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.