demo quick_start中dataprovider_bow.py特征对齐问题
fixes https://github.com/PaddlePaddle/Paddle/issues/676
该文件采用BOW将comments转换为特征向量,在settings中sparse_binary_vector为3w维。而在process中word_vector是不定长的,请问word_vector作为输出数据,如何处理特征对齐的问题,word_vector和settings.sparse_binary_vector有什么关系呢,谢谢。代码如下:
sparse_binary_vector(len(dictionary))
word_vector = [settings.word_dict.get(w, UNK_IDX) for w in words]
抱歉,这个排版太乱了。。麻烦修正一下。
已经更新排版
@donote 抱歉没有看懂具体是什么问题。
不确定这个文档能否回答你的问题。 http://www.paddlepaddle.org/doc_cn/ui/data_provider/pydataprovider2.html#input-types
word_vector作为输入数据,每条样本的特征长度应该是一致的吧,而从word-vector的代码看是不一致的,另外word_vector和settings.sparse_binary_vector之间有什么关系呢
@donote, settings.sparse_binary_vector is the input_type (format) of the BOW representation, it has a fixed length (e.g. 30,000 dimensions for 30,000 word token in the dict), most of the elements are 0, with 1 represents the corresponding token id appeared in the comments words. word_vector is a vector recording all the word id appeared in each comments example. It only has very few ids from 3W dict. So, each word_vector has the different length.
同样的疑惑: qucik_start demo中,initializer指定了 setting.input_types 的第一个参数是 sparse_binary_vector(len(dictionary)),按照文档描述
sparse_binary_vector 表示稀疏的零一向量,即大部分值为0,有值的位置只能取1
向量应形如[0,0,0,0,1,1,0...],在例子中是30001维;
而 process 中最后的代码是:
word_vector = [settings.word_dict.get(w, UNK_IDX) for w in words]
yield word_vector, int(label)
这是返回的向量形如:[3, 179, 9, 763, 5, 441, 6, 124, 325, 177, 1876, 7838, 68, 22, 1575, 10534, 370, 22, 6, 1446, 4, 2461, 918, 86, 573, 61, 13, 1, 1876, 3303, 1, 6649, 474, 10, 1, 370, 22, 241, 6, 6332, 727, 346, 3907, 18, 1, 210, 16]
两者的长度和取值类型都是不一样的,请问是如何转换的?
sparse_binary_vector存的是有值位置的index。[3, 179, ...]表示第3位,第179位等为1 。我们会在文档中加强描述。
那如果我要输入sparse_binary_vector,是不是在process最后生成index向量就可以了?框架中间会有某一步完成这个转换?
向量应形如[0,0,0,0,1,1,0...],在例子中是30001维;
向量是300001维,但paddle内部存的也是index,不是[0,0,0,1...]
好吧,文档确实是需要描述得更详细一点。谢谢解答。