for i in range(len(s)): if t[i] in ['s', 'b']: words.append(s[i]) else: words[-1] += s[i] return words else: return [] not_cuts = re.compile(u'([\da-zA-Z ]+)|[。,、?!\.\?,!]') def cut_word(s): result = [] j = 0 for i in not_cuts.finditer(s): result.extend(simple_cut(s[j:i.start()])) result.append(s[i.start():i.end()]) j = i.end() result.extend(simple_cut(s[j:])) return result output = open('wordseg.pkl', 'wb') pickle.dump(model, output) output.close() print cut_word( u'事不宜迟,动手最重要。词向量维度用了128,句子长度截断为32(抛弃了多于32字的样本,这部分样本很少,事实上,用逗号、句号等天然分隔符分开后,句子很少有多于32字的。)。这次我用了5tag,在原来的4tag的基础上,加上了一个x标签,用来表示不够32字的部分,比如句子是20字的,那么第21~32个标签均为x。' )