【发布时间】:2020-01-30 20:33:45
【问题描述】:
我正在构建一个 Word2Vec 模型,用于在包含约 35.000 个句子的数据集上进行类别推荐,总共约 500.000 个词,但只有约 3.000 个不同的词。 我基本上是这样构建模型的:
def train_w2v_model(df, epochs):
w2v_model = Word2Vec(min_count=5,
window=100,
size=230,
sample=0,
workers=cores-1,
batch_words=100)
vocab = df['sentences'].apply(list)
w2v_model.build_vocab(vocab)
w2v_model.train(vocab, total_examples=w2v_model.corpus_count, total_words=w2v_model.corpus_total_words, epochs=epochs, compute_loss=True)
return w2v_model.get_latest_training_loss()
我试图为这样的模型找到合适的时期数:
print(train_w2v_model(1))
=>> 86898.2109375
print(train_w2v_model(100))
=>> 5025273.0
我发现结果非常违反直觉。
我不明白增加 epoch 的数量会如何导致性能下降。
这似乎不是对函数 get_latest_training_loss 的误解,因为我观察到函数 most_similar 的结果更好,只有 1 个 epoch:
100 个时代:
w2v_model.wv.most_similar(['machine_learning'])
=>> [('salesforce', 0.3464601933956146),
('marketing_relationnel', 0.3125850558280945),
('batiment', 0.30903393030166626),
('go', 0.29414454102516174),
('simulation', 0.2930642068386078),
('data_management', 0.28968319296836853),
('scraping', 0.28260597586631775),
('virtualisation', 0.27560457587242126),
('dataviz', 0.26913416385650635),
('pandas', 0.2685554623603821)]
1 个纪元:
w2v_model.wv.most_similar(['machine_learning'])
=>> [('data_science', 0.9953729510307312),
('data_mining', 0.9930223822593689),
('big_data', 0.9894922375679016),
('spark', 0.9881765842437744),
('nlp', 0.9879133701324463),
('hadoop', 0.9834049344062805),
('deep_learning', 0.9831978678703308),
('r', 0.9827396273612976),
('data_visualisation', 0.9805369973182678),
('nltk', 0.9800992012023926)]
对它为什么会这样表现有任何见解吗?我会认为增加 epoch 的数量肯定会对 training loss 产生积极影响。
【问题讨论】:
标签: python machine-learning nlp gensim word2vec