piskvorky/gensim

model.trainables.update_weights executes even when no new vocabulary is added

Open

#2.025 aberto em 10 de abr. de 2018

Ver no GitHub
 (4 comments) (0 reactions) (1 assignee)Python (4.349 forks)batch import
Hacktoberfestbugdifficulty easyimpact LOW

Métricas do repositório

Stars
 (15.144 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

This one is not a major issue, but I think it is important to fix in order to avoid confusion.

Even when there is no new vocabulary, model.trainables.update_weights takes a while to execute (with no effect on the model) because it doesn't check whether gained_vocab is greater than zero or not.

https://github.com/RaRe-Technologies/gensim/blob/06f5f5c4fa9fb54a169e53034a3bf3fa035cbc3c/gensim/models/word2vec.py#L1467

should be replaced by:

gained_vocab = len(wv.vocab) - len(wv.vectors)
if gained_vocab <= 0:
	raise RuntimeError(
	    "There is no new vocabulary added.  "
	    "If you want to update the weights with a new vocabulary, please first update model.vocab"
	)

Guia do colaborador