O'Reilly logo

Hands-On Natural Language Processing with Python by Rajalingappaa Shanmugamani, Rajesh Arumugam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Encoder network

We will now build the encoder network with a slight modification to the original architecture that was described in the overview section. We will use a bidirectional RNN in place of a unidirectional one, thereby capturing both forward and backward dependencies in the input:

def get_rnn_cell(rnn_cell_size,dropout_prob):    rnn_c = GRUCell(rnn_cell_size)    rnn_c = DropoutWrapper(rnn_c, input_keep_prob = dropout_prob)    return rnn_cdef encoding_layer(rnn_cell_size, sequence_len, n_layers, rnn_inputs, dropout_prob):    for l in range(n_layers):        with tf.variable_scope('encoding_l_{}'.format(l)):            rnn_fw = get_rnn_cell(rnn_cell_size,dropout_prob)            rnn_bw = get_rnn_cell(rnn_cell_size,dropout_prob) encoding_output, encoding_state = tf.nn.bidirectional_dynamic_rnn(rnn_fw, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required