MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / init_seq

Function init_seq

chatbotv2/my_seq2seq_v2.py:82–105  ·  view source on GitHub ↗

读取切好词的文本文件,加载全部词序列

(input_file)

Source from the content-addressed store, hash-verified

80 print "load vectors finish"
81
82def init_seq(input_file):
83 """读取切好词的文本文件,加载全部词序列
84 """
85 file_object = open(input_file, 'r')
86 vocab_dict = {}
87 while True:
88 question_seq = []
89 answer_seq = []
90 line = file_object.readline()
91 if line:
92 line_pair = line.split('|')
93 line_question = line_pair[0]
94 line_answer = line_pair[1]
95 for word in line_question.decode('utf-8').split(' '):
96 if word_vector_dict.has_key(word):
97 question_seq.append(word_vector_dict[word])
98 for word in line_answer.decode('utf-8').split(' '):
99 if word_vector_dict.has_key(word):
100 answer_seq.append(word_vector_dict[word])
101 else:
102 break
103 question_seqs.append(question_seq)
104 answer_seqs.append(answer_seq)
105 file_object.close()
106
107def vector_sqrtlen(vector):
108 len = 0

Callers 1

generate_trainig_dataMethod · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected