0

我正在做情绪分析。我正在使用 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))

如果(比如说)z = [1000 个字符串的列表],则值会从第一个小数点本身发生变化。我做了很多检查。我在重复'我们为每个句子得到不同的向量',为什么会这样?权重是否得到训练(但我没有训练模型,只是从预训练模型中提取向量)

4

0 回答 0