Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

word2vec Issues #3

Open
manohardev opened this issue Nov 17, 2022 · 0 comments
Open

word2vec Issues #3

manohardev opened this issue Nov 17, 2022 · 0 comments

Comments

@manohardev
Copy link

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 ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant