简体   繁体   English

Tensorflow:tf.contrib.layers.embed_sequence

[英]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 . 处理单词到向量时,建议使用tensorflow.contrib.layers.embed_sequence But, it seems that this API does not offer a illustration of encoding method. 但是,该API似乎没有提供编码方法的说明。 So, i wonder how this API acutally works. 因此,我想知道该API如何正常工作。

By the way, i am using pydev to pydev development and i hava successfully installed tensorflow module. 顺便说一句,我正在使用pydev进行pydev开发,并且我已经成功安装了tensorflow模块。 Program using tensorflow runs properly. 使用tensorflow程序可以tensorflow运行。 But when i want to open declaration of tf.contrib.layers.embed_sequence, it says: 但是,当我要打开tf.contrib.layers.embed_sequence的声明时,它说:

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

Basically, you can use tf.contrib.layers.embed_sequence in this way, 基本上,您可以通过这种方式使用tf.contrib.layers.embed_sequence

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 有关embed_sequence的教程,请在stackoverflow上签出官方文档其他答案

For the tutorial of text categorization, please checkout this blog https://medium.com/@ilblackdragon/tensorflow-text-classification-615198df9231 有关文本分类的教程,请查看此博客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? 如果我理解您的问题-您是否在问Tensorflow使用哪种算法(例如,跳过语法与连续词袋)来生成单词嵌入?

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. 如果是这样-Tensorflow:Word2vec CBOW模型建议默认为Skip-Gram,并且此https://github.com/wangz10/tensorflow-playground/blob/master/word2vec.py#L105建议如何将其切换到CBOW。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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