Python 如何在tensorflow 2.x中应用等效LSTM?

Python 如何在tensorflow 2.x中应用等效LSTM?,python,tensorflow,deep-learning,tensorflow2.0,Python,Tensorflow,Deep Learning,Tensorflow2.0,我使用tf.contrib层在TensorFlow中编写递归神经网络。我首先创建了LSTM单元类型,并通过将该单元传递到另一层来提取输出和状态。但在TensorFlow2.x中,它似乎可以在一行中完成 output, state_h, state_c = layers.LSTM(self.args.embedding_size, return_state=True, name="encoder")(tf.nn.embedding_lookup(self.embeddings,

我使用tf.contrib层在TensorFlow中编写递归神经网络。我首先创建了LSTM单元类型,并通过将该单元传递到另一层来提取输出和状态。但在TensorFlow2.x中,它似乎可以在一行中完成

output, state_h, state_c = layers.LSTM(self.args.embedding_size, return_state=True, name="encoder")(tf.nn.embedding_lookup(self.embeddings, self.neighborhood_placeholder)
我不能像tensorflow 1.x中那样应用辍学翘曲器。如何将以下代码转换为tensorflow 2.x

with tf.variable_scope('LSTM'):
            cell = tf.contrib.rnn.DropoutWrapper(
                    tf.contrib.rnn.LayerNormBasicLSTMCell(num_units=self.args.embedding_size, layer_norm=False),
                    input_keep_prob=1.0, output_keep_prob=1.0)
            _, states = tf.nn.dynamic_rnn(
                    cell,
                    tf.nn.embedding_lookup(self.embeddings, self.neighborhood_placeholder),
                    dtype=tf.float32,
                    sequence_length=self.seqlen_placeholder)
            self.lstm_output = states.h