def vectorize_text(data, word_id, text_max_length, ques_max_length):
X = []
Xq = []
Y = []
for subtext, question, answer in data:
x = [word_id[w] for w in subtext]
# Save the ID of Questions using SubText
xq = [word_id[w] for w in question]
# Save the answers for the Questions in "Y" as "1"
y = np.zeros(len(word_id) + 1)
y[word_id[answer]] = 1
X.append(x)
Xq.append(xq)
Y.append(y)
return (pad_sequences(X, maxlen=text_max_length),
pad_sequences(Xq, maxlen=ques_max_length),
np.array(Y))
# Read the text files
评论列表
文章目录