NameError: global name 'linear' is not defined

NameError: global name 'linear' is not defined

我正在尝试 运行 DeepMind 的注意力机制的实现。但是它基于旧版本的 TensorFlow,我收到此错误

from tensorflow.models.rnn.rnn_cell import RNNCell, linear
concat = linear([inputs, h, self.c], 4 * self._num_units, True)

NameError: global name 'linear' is not defined

我在新的 tensorflow 文档中找不到线性 model/function。谁能帮我这个?谢谢!

您需要使用 tf.nn.rnn_cell._linear 函数才能使代码正常工作。查看此 tutorial 示例用法。