Closed caoxu915683474 closed 5 years ago
What does the atten_sum doesn't change
mean? Can you provide more details? It seems that you want to add an extra term to the sequence loss, an important hint I guess might be helpful is that a variable using in the __call__
is not fetchable, due to the limitation of TensorFlow.
谢谢回复! 你好,我用中文来说吧,我怕英文描述不清。。。。
就是我创建了一个atten_sum变量在模型中就像uf 和 v 向量一样传入wrapper里面,然后在wrapper里的call()函数加score, 然后我在模型中,用sess run 模型中的atten_sum发现一直是0, 但是按理说它被传入wrapper并且被加了socre, 滚完一轮数据应该会改变才对。。。。难道我传入的atten_sum进行加了,但模型中的atten_sum没有变,但我打印了传入前和传入后的atten_sum变量发现都是指向同一内存空间上。。。
add 应该会返回一个新的 Tensor,为什么会指向同一个内存?这有点奇怪。
额,我是在add 前打印的(蠢了。。。),所以self.atten_sum = tf.add(self.atten_sum, score), 这里的self.atten_sum和传入之前那个atten_sum不是同一个了是么?大神,有没有可以让add 直接加到同内存下的atten_sum上的方法?
我记得有就地(in-place)加法的,可以试试;实在不行用 assign 给 self.attn_sum 赋值也可以。
好的,谢谢帮助!!我试试
I reviewed the code of hit, I found that in their version, they have use atten_sum vector and also use
0.1 * tf.reduce_sum((phi_res - atten_sum) ** 2)
this loss is added to the sequence_lossI use a vector atten_sum as a param to MTA_Wapper(...) and in the init () of wapper use the atten_sum to assign self.atten_sum of MTA_Wapper, then use self.atten_sum to add score in the call function but I meet a problem the atten_sum doesn't change, I don't know why.