def train(self, sentences):
random.shuffle(sentences)
for s, a_sentence in enumerate(sentences):
words_and_tags = a_sentence.split('\n')
words = [wt.split(' ')[0] for wt in words_and_tags]
tags = [wt.split(' ')[1] for wt in words_and_tags]
# ?????0 1 2 3 4 5 6 7 8 9
for i in range(len(tags)):
if tags[i][0] == 'I':
if i == len(tags)-1 or tags[i+1] != tags[i]:
tags[i] = 'E-' + tags[i][-3:]
tags[i] = int(self.tags_dict[tags[i]])
self.model.train(words, tags)
if s % 5000 == 0:
print(' -----> ' + str(s // 5000) + '/5')
评论列表
文章目录