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

Input

As we are looking at providing input dynamically, we will use TensorFlow's placeholder for our input. As we have a definite shape for the data, in terms of batch size and the number of words we can process per batch, we need to first pad the sentences in our dataset, to make them of the same length. Hence, we will define two placeholders, as follows:

# Define input placeholder for the word indices of shape = (batch size, length of padded sentence)word_indices = tf.placeholder(tf.int32, shape=[None, None])# Placeholder for the sequence lengths of shape = (batch size) sequence_lengths = tf.placeholder(tf.int32, shape=[None])

The sequence length placeholder allows the computation graph to utilize the actual length of the input data, as ...

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