def process_sent(sent, vocab_int, steps):
"""
this file token sentence and make it into numpy array, return a fixed length 2d array
:param sent:
:param vocab_int:
:param steps:
:return:
"""
sent_list = jieba.lcut(sent)
# if words not in vocab dict then let this word be a random index which maybe other words
index_list = [vocab_int[i] if i in vocab_int.keys() else np.random.randint(0, 90) for i in sent_list]
if len(index_list) < steps:
index_list = np.hstack((index_list, np.random.randint(0, 90, steps - len(index_list))))
else:
index_list = index_list[0: steps]
return np.array([index_list])
shakespeare.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录