I am studying Syntaxnet of Tensoflow.
Howerver, I'm confusing about the way to use --word_embeddings
option. Could you show me a example? Thanks a lot.
I am studying Syntaxnet of Tensoflow.
Howerver, I'm confusing about the way to use --word_embeddings
option. Could you show me a example? Thanks a lot.
Not too sure what syntaxnet is but here is how I use word embeddings in my sequence to sequence model.
Here I declare a variable which will store the embedding. It is a matrix with rows equal to the number of words in the vocabulary (NWORDS) and each column is the size of the word vector for that word (WORD_VEC_SIZE). It is randomly initialized and is a trainable parameter of the model.
word_embedding = tf.get_variable('word_embedding', shape = (NWORDS, WORD_VEC_SIZE), initializer = tf.truncated_normal_initializer(0.0, 1,0))
The input to my model is a list of integers which represent the indexs of the words in the embedding. It is of dimension BATCH_SIZE x TIMESTEPS.
source_input = tf.placeholder(tf.int32, (BATCH_SIZE, TIME_STEPS), 'source_input')
Using the embedding and the input I can perform a lookup to convert the integer representations of the words into vectors.
y = tf.nn.embedding_lookup([word_embedding], source_input)
Now y has the shape (BATCH_SIZE, TIME_STEPS, WORD_VEC_SIZE) and can be fed into the model for further processing.