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

testTrainingSgNegative is possibly incorrect #1233

Closed
shubhvachher opened this issue Mar 22, 2017 · 6 comments
Closed

testTrainingSgNegative is possibly incorrect #1233

shubhvachher opened this issue Mar 22, 2017 · 6 comments

Comments

@shubhvachher
Copy link
Contributor

File : gensim/test/test_word2vec.py
Method : testTrainingSgNegative

    def testTrainingSgNegative(self):
        """Test skip-gram (negative sampling) word2vec training."""
        # to test training, make the corpus larger by repeating its sentences over and over
        # build vocabulary, don't train yet
        model = word2vec.Word2Vec(size=2, min_count=1, hs=0, negative=2)
        model.build_vocab(sentences)
        self.assertTrue(model.wv.syn0.shape == (len(model.wv.vocab), 2))
        self.assertTrue(model.syn1neg.shape == (len(model.wv.vocab), 2))

        model.train(sentences)
        sims = model.most_similar('graph', topn=10)
        # self.assertTrue(sims[0][0] == 'trees', sims)  # most similar

        # test querying for "most similar" by vector
        graph_vector = model.wv.syn0norm[model.wv.vocab['graph'].index]
        sims2 = model.most_similar(positive=[graph_vector], topn=11)
        sims2 = [(w, sim) for w, sim in sims2 if w != 'graph']  # ignore 'graph' itself
        self.assertEqual(sims, sims2)

        # build vocab and train in one step; must be the same as above
        model2 = word2vec.Word2Vec(sentences, size=2, min_count=1, hs=0, negative=2)
        self.models_equal(model, model2)

Lines that read : model = word2vec.Word2Vec(size=2, min_count=1, hs=0, negative=2)
Should read : model = word2vec.Word2Vec(size=2, min_count=1, sg=1, hs=0, negative=2)

New testMethod does pass unittests.

Is my assumption correct? If so, should I go ahead correcting this line and submitting?

@gojomo
Copy link
Collaborator

gojomo commented Mar 22, 2017

Yes - it should be teting sg=1, both for model and model2, thanks! Do you see any similar mismatches between intent-of-method, and what's actually tested?

@shubhvachher
Copy link
Contributor Author

Well, I'm trying to familiarize myself with your codebase for GSoC! I'm going through it all anyway :D
Meanwhile, adding fix to PR #1229.

@gojomo
Copy link
Collaborator

gojomo commented Mar 23, 2017

Thanks! Note both sets of changes can be easier to review in separate PRs.

@tmylk
Copy link
Contributor

tmylk commented Mar 23, 2017

@shubhvachher Thanks for your contribution. Please email me/chat on gitter about GSOC.

@shubhvachher
Copy link
Contributor Author

Doing that now @tmylk. I actually do have things to ask! Thanks

@shubhvachher
Copy link
Contributor Author

Fixed above.

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

3 participants