简体   繁体   中英

Tensorflow: tf.contrib.layers.embed_sequence

I'm working on a project to fulfill text categorization. When dealing with the word-to-vector, i'm recommended to use tensorflow.contrib.layers.embed_sequence . But, it seems that this API does not offer a illustration of encoding method. So, i wonder how this API acutally works.

By the way, i am using pydev to pydev development and i hava successfully installed tensorflow module. Program using tensorflow runs properly. But when i want to open declaration of tf.contrib.layers.embed_sequence, it says:

"NameError: name tf is not defined"...

Basically, you can use tf.contrib.layers.embed_sequence in this way,

word_embed = tf.contrib.layers.embed_sequence(
                        features,
                        vocab_size=VOCAB_SIZE, 
                        embed_dim=EMBEDDING_SIZE)

For the tutorial of embed_sequence , please checkout the official doc or other answers on stackoverflow

For the tutorial of text categorization, please checkout this blog https://medium.com/@ilblackdragon/tensorflow-text-classification-615198df9231

If I understand your question - are you asking what algorithm (eg skip-gram vs continuous bag-of-words) is used by Tensorflow to produce word embeddings?

If so - Tensorflow: Word2vec CBOW model suggests that Skip-Gram is the default, and this https://github.com/wangz10/tensorflow-playground/blob/master/word2vec.py#L105 suggests how to switch it to CBOW.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM