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

Word embedding

Now that we have defined our input placeholders, we will define a TensorFlow Variable to hold our pretrained embeddings for the vocabularies in the data. The approach that we will follow, in this case, is an indexed array, which can fetch the embedding corresponding to a word index at i as pre_trained_embedding[i]. Since we would like to look up from an embedding matrix, we will load the pretrained embedding array into the TensorFlow variable. The TensorFlow code is defined as follows:

# Define a lookup table using the pre-trained embedding matrixlookup_word_mat = tf.Variable(embedding_matrix, dtype=tf.float, trainable=False)# Define an embedding lookup using TensorFlow's in-built functionpre_trained_embedding = tf.nn.embedding_lookup(lookup_word_mat, ...

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