fold icon indicating copy to clipboard operation
fold copied to clipboard

Whether a word2vec block could be used twice

Open acelove opened this issue 8 years ago • 2 comments

I define a block as below: word2vec = Function(Embedding(100,100,name="word2vec")) In rnn model , I use it to map the words in sentence to tensors.However , I also need to use it to map the labels to tensors in the same vector space.I got the error "word2vec is already a child of <td.Pipe>".Is there any way the use it twice?

acelove avatar Mar 29 '17 06:03 acelove

Now I use Function(lambda x : tf.nn.embedding_lookup(word_embedding,x)) to replace Embedding(len(vocab),dims) where word_embedding is defined as below: word_embedding = tf.Variable(tf.random_normal([len(vocab),dims]) Is this way efficient enough?

acelove avatar Mar 29 '17 09:03 acelove

Layers can be reused, but blocks cannot -- a block is hooked into its surrounding context in various ways. So just do the following:

word_embedding = Embedding(100,100,name="word2vec") def word2vec(): return Function(word_embedding)

And use word2vec() in multiple places.

On Tue, Mar 28, 2017 at 11:48 PM, acelove [email protected] wrote:

I define a block as below: `word2vec = Function(Embedding(100,100,name="word2vec")) In rnn model , I use it to map the words in sentence to tensors.However , I also need to use it to map the labels to tensors in the same vector space.I got the error "word2vec is already a child of <td.Pipe>".Is there any way the use it twice?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/fold/issues/40#issuecomment-289999131, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGbTQEd_iU95HMdAYvLowQGfH5-ZOyPks5rqf7DgaJpZM4MskBk .

-- DeLesley Hutchins | Software Engineer | [email protected] | 505-206-0315

delesley avatar Mar 29 '17 16:03 delesley