With GloVe vectors

Now let's compare that to the code that includes pretrained GloVe vectors encoded in a 2D matrix:

sequence_input = Input(shape=(sequence_length,), dtype='int32')embedding_layer = Embedding(input_dim=vocab_size,                            output_dim=embedding_dim,                            weights=[embedding_matrix],                            input_length=sequence_length,                            trainable=False,                            name="embedding")(sequence_input)

For the most part, this code looks equivalent. There are two key differences:

  • We initialize the layer weights to be contained in the GloVe matrix that we assembled with weights=[embedding_matrix].
  • We also set the layer to trainable=False. This will prevent us from updating our weights. You may wish to fine tune the weights in a similar way to how we fine tuned the CNN we built in ...

Get Deep Learning Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.