deep learning - Index of Embedding layer with zero padding in Keras -


i building rnn model in keras sentences word embeddings gensim. initializing embedding layer glove vectors. since sequential model , sentences have variable lengths, vectors zero-padded. e.g.

[0, 0, 0, 6, 2, 4] 

let's glove vectors have dimensions [num_vocab, embedding_size]. 0 index masked (ignored) proper indexing of words, add column glove matrix dimensions are: [num_vocab+1, embedding_size]?

seems there unnecessary vector model estimate unless there more elegant way.

glove = word2vec.load_word2vec_format(filename) embedding_matrix = np.vstack([np.zeros(embedding_size), glove.syn0])  model = sequential()  # -- uses glove inits model.add(embedding(num_vocab, embedding_size, input_length=maxlen, mask_zero=true,                            weights=[embedding_matrix]))  # -- sequence layer model.add(lstm(32, return_sequences=false, init='orthogonal')) model.add(activation('tanh'))  ... 

thanks


Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -