我尝试实施Xiong et al. (2016)和Kumar et al. (2015)中描述的动态内存网络来执行QA任务。我已经使bAbi dataset的单词答案有效,并且得到的结果与论文中描述的结果有些相似(我相信一些超参数调整可以弥补差距的其余部分)。这是使用线性输出层作为答案模块完成的。我想扩展模型以产生多字的答案。
为此我的意图是使用Kumar et al. (2015)中等式9和10中描述的GRU来解码情景记忆的输出(Kumar et al. (2015)中的m ^ T和Xiong et al (2016) )。
此GRU需要将大小为[batch_size x 1 x embedding_size]
的3D张量作为输入,即来自情景记忆的重构输出m ^ T,并输出大小为[batch_size x answer_length x vocab_size]
的3D张量。
到目前为止,我已经尝试使用Tensorflow的dynamic_rnn
方法实现我自己的GRU,但是我还是无法做到这一点。在当前的事态中,此处的调用方法如下所示:
def call(self, inputs, state, scope=None):
with vs.variable_scope(scope or "decoder_gru_cell"):
with vs.variable_scope("gates"):
z = math_ops.sigmoid(_linear([inputs, state], self._num_units, True))
r = math_ops.sigmoid(_linear([inputs, state], self._num_units, True))
with vs.variable_scope("candidate"):
r = r*_linear(state, self._num_units, False)
with vs.variable_scope("input"):
x = _linear(inputs, self._num_units, True)
h_hat = math_ops.tanh(r + x)
new_h = z * h_hat + (1 - z) * state
output = tf.nn.softmax(_linear(new_h))
return output, new_h
我似乎无法使用与问题向量连接的时间步长t-1
的输出作为时间步t
中单元格的输入,如文章中所述。
此外,我不确定如何实现它,使得它采用固定大小的输入张量并输出可变大小张量(因为并非所有答案都必须具有相同的长度)。根据{{3}}中的以下句子,这应该是可能的:
对于需要序列输出的任务, RNN可用于解码a = [q; m ^ T],矢量q和m ^ T与一组有序标记的串联。
如何在Tensorflow中实现一个采用固定大小输入张量并输出可变大小张量的GRU?
非常感谢任何帮助,谢谢!