如何使用 word2vec 进行准确的食物相似性以及我应该如何为此任务设计 word2vec 参数?
How to do an accurate food similarity using word2vec and how should i design the word2vec parameters for this task?
我正在处理食物相似性问题,我需要为给定的印度菜找到相似的印度食物。那么,任何人都可以帮助我有效地处理这个问题吗?使用 word2vec 可以解决这个问题吗?
对于这项任务,我从寻找成分的向量开始,然后对成分应用 tf-idf 加权平均以获得菜肴的向量。我抓取了不同菜肴的成分数据,然后我应用了 wor2vec,但我没有找到满意的结果。
#Setting values for NN parameters
num_features = 300 # Word vector dimensionality
min_word_count = 3
num_workers = 4 # Number of CPUs
context = 10 # Context window size ie. avg recipe size
downsampling = 1e-3 # threshold for configuring which
# higher-frequency words are randomly downsampled
#Initializing and training the model
model = word2vec.Word2Vec(sentences, workers=num_workers, \
size=num_features, min_count = min_word_count, \
window = context, sample = downsampling) '''
#using init_sims to make the model much more memory-efficient.
model.init_sims(replace=True)
model.most_similar('ginger')
输出:
[('salt', 0.9999704957008362),
('cloves garlic', 0.9999628067016602),
('garam masala', 0.9999610781669617),
('turmeric', 0.9999603033065796),
('onions', 0.999959409236908),
('vegetable oil', 0.9999580383300781),
('coriander', 0.9999570250511169),
('black pepper', 0.9999487400054932),
('cumin seeds', 0.999948263168335),
('green chile pepper', 0.9999480247497559)]
Word2vec 对于这个任务可能是合理的。您可能需要更多数据或参数调整才能获得最佳结果。
我看不出你的示例结果有什么问题,所以你应该在你的问题中添加更多细节,以及更多 examples/explanation,说明你为什么对结果不满意。
如果您有某些 ideal-results,您可以将其收集到可重复的模型测试中,这将有助于您调整模型。例如,如果您知道 "cinnamon" 应该比 "salt" 更适合 "ginger",您可以将其(以及数十、数百或数千个其他 "preferred answers")编码为一种可以对模型进行评分的自动评估方法。
然后,您可以调整 ("meta-optimize") 个模型参数以找到在您的评估中得分最高的模型。
- 更少或更多维度 (
size
) 可能有所帮助,具体取决于数据的丰富程度
- 更小或更大的
window
可能会有帮助
- 更多培训
epochs
可能会有帮助
- 更大的
min_count
(丢弃更多 low-frequency 词)通常会有帮助,尤其是对于更大的数据集
- a more-aggressive
sample
值(较小,例如 1e-04
或 1e-05
)可以提供帮助,数据集非常大
- non-default
ns_exponent
值可能有帮助,尤其是 recommendation-applications
我正在处理食物相似性问题,我需要为给定的印度菜找到相似的印度食物。那么,任何人都可以帮助我有效地处理这个问题吗?使用 word2vec 可以解决这个问题吗?
对于这项任务,我从寻找成分的向量开始,然后对成分应用 tf-idf 加权平均以获得菜肴的向量。我抓取了不同菜肴的成分数据,然后我应用了 wor2vec,但我没有找到满意的结果。
#Setting values for NN parameters
num_features = 300 # Word vector dimensionality
min_word_count = 3
num_workers = 4 # Number of CPUs
context = 10 # Context window size ie. avg recipe size
downsampling = 1e-3 # threshold for configuring which
# higher-frequency words are randomly downsampled
#Initializing and training the model
model = word2vec.Word2Vec(sentences, workers=num_workers, \
size=num_features, min_count = min_word_count, \
window = context, sample = downsampling) '''
#using init_sims to make the model much more memory-efficient.
model.init_sims(replace=True)
model.most_similar('ginger')
输出:
[('salt', 0.9999704957008362),
('cloves garlic', 0.9999628067016602),
('garam masala', 0.9999610781669617),
('turmeric', 0.9999603033065796),
('onions', 0.999959409236908),
('vegetable oil', 0.9999580383300781),
('coriander', 0.9999570250511169),
('black pepper', 0.9999487400054932),
('cumin seeds', 0.999948263168335),
('green chile pepper', 0.9999480247497559)]
Word2vec 对于这个任务可能是合理的。您可能需要更多数据或参数调整才能获得最佳结果。
我看不出你的示例结果有什么问题,所以你应该在你的问题中添加更多细节,以及更多 examples/explanation,说明你为什么对结果不满意。
如果您有某些 ideal-results,您可以将其收集到可重复的模型测试中,这将有助于您调整模型。例如,如果您知道 "cinnamon" 应该比 "salt" 更适合 "ginger",您可以将其(以及数十、数百或数千个其他 "preferred answers")编码为一种可以对模型进行评分的自动评估方法。
然后,您可以调整 ("meta-optimize") 个模型参数以找到在您的评估中得分最高的模型。
- 更少或更多维度 (
size
) 可能有所帮助,具体取决于数据的丰富程度 - 更小或更大的
window
可能会有帮助 - 更多培训
epochs
可能会有帮助 - 更大的
min_count
(丢弃更多 low-frequency 词)通常会有帮助,尤其是对于更大的数据集 - a more-aggressive
sample
值(较小,例如1e-04
或1e-05
)可以提供帮助,数据集非常大 - non-default
ns_exponent
值可能有帮助,尤其是 recommendation-applications