读取切好词的文本文件,加载全部词序列
(input_file)
| 80 | print "load vectors finish" |
| 81 | |
| 82 | def 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 | |
| 107 | def vector_sqrtlen(vector): |
| 108 | len = 0 |
no test coverage detected