def get_word2vec_sim(context_seq, gen_seq):
'''return the word2vec cosine similarity between the context and each generated sequence
(where the word2vec representation for a sequence is just the average of its word vectors)'''
word_pairs = get_word_pairs(context_seq, gen_seq)
if word_pairs:
pair_scores = [similarity.word2vec(encoder(word1),encoder(word2)) for word1,word2 in word_pairs]
else: #no word pairs between context and generated sequences (e.g. generated sequence might be punctuation only)
pair_scores = [0]
# assert(len(word_pairs) == len(pair_scores))
word2vec_sim = numpy.mean(pair_scores)
return word2vec_sim
generation_metrics.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录