TensorFlow 2.0中contrib被弃用

于是将

from tensorflow.contrib import rnn

替换成

from tensorflow.python.ops import rnn

 

 

如果出现

AttributeError: module 'tensorflow.python.ops.rnn' has no attribute 'BasicLSTMCell'

则将
rnn.BasicLSTMCell(num_hidden,forget_bias=1.0)

替换

tf.nn.rnn_cell.BasicLSTMCell(num_hidden,forget_bias=1.0)