1.输入词长度统一
2.将词转为词向量(一般300维)
rnn输入格式(b,ml,f)
b:batchsize
ml:max_len最大长度
f:feature词向量维度
数据预处理
'''
RNN词嵌入
rnn不能并行训练故时间比较慢
'''
import tqdm
import tokenize
f=''
pad_size=32
for line in tqdm(f):
lin=line.strip()
if not lin:
continue
contect,label=lin.split('\t')#获取字符,以及标签
word_list=[]
token=tokenize(contect)#按字符分开
seq_len=len(token)
if pad_size:#按规定长度多删少补
if len(token)>pad_size:
token.entend([vocab.get(PAD)]*(pad_size-len(token)))#特殊字符补充
else :
token=token[:pad_size]
for word in token:
word_line.append(vocab.get(word,vocab.get(UNK)))#返回词索引
其实聊天机器人就是在不断的对词进行预测