lpq29743 / IAN

A TensorFlow implementation for "Interactive Attention Networks for Aspect-Level Sentiment Classification"
MIT License
99 stars 40 forks source link

关于代码的小问题 #9

Closed marvelousgirl closed 5 years ago

marvelousgirl commented 5 years ago

您好, 问题一:这句是什么意思? aspect_att_temp = tf.concat([tf.nn.softmax(tf.slice(aspect_score, [0, 0], [1, l])), tf.zeros([1, self.max_aspect_len - l])], 1) 我理解的是如果aspect_score=[12,4,3,6], 那么tf.slice的结果是12,然后tf.nn.softmax的结果是1, 最终tf.concat结果是[1,0,0,0]。 请问理解对吗? 问题二: 在utils.py文件里,对context的长度,您都进行了减1,请问是为什么呢?

lpq29743 commented 5 years ago

问题1: 这个地方是为了保证求 attention score 的时候只在句子长度范围内做。如原本分数是 [12, 4, 3, 6, ...],由于此时序列长度仅为 4,所以只算此序列长度范围内的 attention score。 当然,还有一种做法是将其余部分减去一个较大的数,使得其接近负无穷,从而保证 softmax 后序列外得到的值接近于 0 问题2: 这里是去掉 aspect_term 所占的长度,只理会上下文

marvelousgirl commented 5 years ago

明白了,谢谢,原来是[1,l] 以为后面是1