elmo预训练模型的输出

问题描述 投票:0回答:1

我正在研究情绪分析。我正在使用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))
tensorflow sentiment-analysis word-embedding tensorflow-hub elmo
1个回答
0
投票

当我运行你的代码时,x1 [0]和z1 [0]是相同的。然而,z1 [1]与结果不同

y1 = elmo([y],signature="default",as_dict=True)["elmo"]
return sess.run(tf.reduce_mean(y1,1))

因为y的代币数比x少,而且盲目地减少过去的输出会收拾垃圾。

我建议使用“默认”输出而不是“elmo”,它可以实现预期的缩减。请参阅模块文档。

© www.soinside.com 2019 - 2024. All rights reserved.