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上
原文地址:https://www.cnblogs.com/callyblog/p/10163757.html
时间: 2024-10-09 18:29:08