nerTagger.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:nlp_learn 作者: Li-Shang 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号