Skip to content

Commit

Permalink
Final fix for word2vec + svm input formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
advaithsrao committed Nov 8, 2023
1 parent 97b471a commit 33eb1e9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion utils/util_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ def fit_transform(
np.ndarray: Word2Vec embeddings for the input text.
"""

embedding = []

# Initialize an array to store Word2Vec embeddings for the input text
words = self.tokenizer.tokenize(text) # Tokenize the document
word_vectors = [self.model[word] if word in self.model else np.zeros(self.model.vector_size) for word in words]
document_embedding = np.mean(word_vectors, axis=0) # Calculate the mean of word embeddings for the document
embedding.append(document_embedding)

return document_embedding
return np.array(embedding)


class TPSampler:
Expand Down

0 comments on commit 33eb1e9

Please sign in to comment.