Skip to content

word2vec Issues #3

Description

@manohardev

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions