tensorflow VocabularyProcessor

from tensorflow.contrib import learn
import numpy as np
vocab_process = learn.preprocessing.VocabularyProcessor(max_document_length=8) # 定义sentence固定长度

vocab_process.fit(w2v_vocab)

vocab_process.transform(
np.reshape(' '.join(text1_words), [-1])) # text1_words 是已经分词的list

  VocabularyProcessor:类似于keras里面的那个padding,将词映射到词向量词字典的id上

posted @ 2018-12-23 11:42  下路派出所  阅读(668)  评论(0编辑  收藏  举报