我在做情绪分析。我正在使用elmo方法来获取单词嵌入。但我对这个方法给出的输出结果感到困惑。考虑张量流网站中给出的代码:
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=True)
embeddings = elmo(["the cat is on the mat", "dogs are in the fog"],
signature="default",as_dict=True)["elmo"]特定句子的嵌入向量根据给出的字符串数而不同。详细解释
x = "the cat is on the mat"
y = "dogs are in the fog"
x1 = elmo([x],signature="default",as_dict=True)["elmo"]
z1 = elmo([x,y] ,signature="default",as_dict=True)["elmo"] 因此,x1[0]将不等于z1[0]。当您更改字符串的输入列表时,情况会发生变化。为什么一个句子的输出取决于另一个句子。我不是在训练数据。我只使用现有的预先训练过的模型。在这种情况下,我很困惑如何将我的评论文本转换为嵌入并用于情感分析。请解释一下。
注意事项:为了获得嵌入向量,我使用以下代码:
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(tf.tables_initializer())
# return average of ELMo features
return sess.run(tf.reduce_mean(x1,1))发布于 2019-03-26 10:02:05
当我运行您的代码时,x1和z1是相同的。但是,z11与
y1 = elmo([y],signature="default",as_dict=True)["elmo"]
return sess.run(tf.reduce_mean(y1,1))因为y比x有更少的记号,并且盲目地减少超过-结束的输出会捡到垃圾。
我建议使用“默认”输出,而不是"elmo",它可以完成预期的缩减。请参阅模块文档。
https://stackoverflow.com/questions/55334020
复制相似问题