我正在尝试找出如何以某种方式转换字符串,以便它们可以
可用于训练聊天机器人的tensorflow / keras模型。
现在我正在使用此方法:
import tensorflow as tf
import numpy as np
messages = open("messages.txt","r").readlines()
responses = open("responses.txt","r").readlines()
train_messages = []
for line in messages:
tmp1 = []
for word in line.split(' '):
tmp2 = []
for char in word:
tmp2.append(ord(char))
tmp1.append(tmp2)
train_messages.append(tmp1)
train_messages = np.array(train_messages, dtype=int)
train_responses = []
for line in responses:
tmp1 = []
for word in line.split(' '):
tmp2 = []
for char in word:
tmp2.append(ord(char))
tmp1.append(tmp2)
train_responses.append(tmp1)
train_messages = np.array(train_messages, dtype=int)
# rest of code...
我需要某种方式将整个单词转换为int
,我意识到我拥有的代码可能会导致ai拼错许多单词。
我正在Ubuntu Linux上使用官方的Python 3.5发行版。