def word_sequence(f_path, batch_size = 1, i2w, w2i):
test_seqs = []
lines = []
tf = {}
f = open(curr_path + "/" + f_path, "r")
for line in f:
line = line.strip('\n').lower()
words = ['<soss>']+line_x.split()+["<eoss>"]
lines.append(words)
f.close()
for i in range(0, len(lines)):
words = lines[i]
x = np.zeros((len(words), len(w2i)), dtype = theano.config.floatX)
for j in range(0, len(words)):
if words[j] in w2i:
x[j, w2i[words[j]]] = 1
test_seqs.append(np.asmatrix(x))
test_data_x = batch_sequences(test_seqs, i2w, w2i, batch_size)
return test_seqs, i2w, w2i, test_data_x
评论列表
文章目录