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

Accuracy is 0 when negative sampling is disabled #2778

Closed
ChristianAngel opened this issue Mar 30, 2020 · 1 comment
Closed

Accuracy is 0 when negative sampling is disabled #2778

ChristianAngel opened this issue Mar 30, 2020 · 1 comment

Comments

@ChristianAngel
Copy link

Problem description

When Word2Vec is trained on the text8 dataset with negative=0 (negative sampling disabled), the accuracy drops to 0 when evaluated on questions-words.txt.

Steps/code/corpus to reproduce

Minimal reproducible example:

import gensim.downloader
from gensim.models import Word2Vec

def evaluate(model):
    globalStats = model.wv.accuracy("questions-words.txt") 
    numberCorrect = len(globalStats[-1]['correct'])
    return numberCorrect

dataset = gensim.downloader.load("text8")
model1 = Word2Vec(dataset, size=300, workers=1, negative=5)
model2 = Word2Vec(dataset, size=300, workers=1, negative=0)

print("Number correct with negative sampling:", evaluate(model1))
print("Number correct without negative sampling:", evaluate(model2))

Output:

Number correct with negative sampling: 4031
Number correct without negative sampling: 0

questions-words.txt was downloaded from https://github.com/nicholas-leonard/word2vec/blob/master/questions-words.txt

Versions

Linux-3.10.0-862.2.3.el7.x86_64-x86_64-with-centos-7.5.1804-Core
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0]
NumPy 1.16.4
SciPy 1.3.0
gensim 3.8.1
FAST_VERSION 1

@gojomo
Copy link
Collaborator

gojomo commented Apr 3, 2020

Duplicate of #1983 - but the only thing missing is a warning/error. This is a nonsensical configuration: if you disable negative without also enabling hs, then the model has no output-layer & source of backprop-training. (Either negative must be nonzero, or hs must be enabled, for anything useful to happen - as with the original word2vec.c code released by Google, there's no non-sparse training mode.) Training will complete instantly, logging output will be nonsense.

@gojomo gojomo closed this as completed Apr 3, 2020
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

2 participants