Document_Classification icon indicating copy to clipboard operation
Document_Classification copied to clipboard

word2vec Issues

Open manohardev opened this issue 2 years ago • 0 comments

Current code is not working, and it is giving issues in the below code. Could you please update the code?

def word_averaging(wv, words): all_words, mean = set(), []

for word in words:
    if isinstance(word, np.ndarray):
        mean.append(word)
    elif word in wv.vocab:
        mean.append(wv.syn0norm[wv.vocab[word].index])
        all_words.add(wv.vocab[word].index)

if not mean:
    return np.zeros(wv.vector_size,)

mean = gensim.matutils.unitvec(np.array(mean).mean(axis=0)).astype(np.float32)
return mean

def word_averaging_list(wv, text_list): return np.vstack([word_averaging(wv, post) for post in text_list ])

manohardev avatar Nov 17 '22 22:11 manohardev