【问题标题】:named entity extraction python script with flair framework stuck while training命名实体提取python脚本,在训练时卡住了flair框架
【发布时间】:2020-12-09 08:12:47
【问题描述】:

这是我正在尝试训练的代码,以便获得用于法语命名实体提取的预训练模型。我使用 google colab 作为环境,因为我的笔记本电脑只有 4GB GPU,而 colab 提供 12GB GPU。可悲的是,在 colab 上,脚本每次都卡在 epoch 1 中。任何人都可以建议我解决我的问题的解决方案或提示吗?多谢 ! 代码:

from flair.visual.training_curves import Plotter
from flair.trainers import ModelTrainer
from flair.models import SequenceTagger
from flair.data import TaggedCorpus
from flair.data_fetcher import NLPTaskDataFetcher, NLPTask
from flair.embeddings import TokenEmbeddings, WordEmbeddings, 
StackedEmbeddings
from flair.embeddings import FlairEmbeddings, BertEmbeddings
from typing import List
from flair.data import Sentence 
# import flair.datasets
# 1. get the corpus
corpus = NLPTaskDataFetcher.load_corpus(NLPTask.WIKINER_FRENCH)
# 2. what tag do we want to predict?
tag_type = 'ner'
# 3. make the tag dictionary from the corpus
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
print(tag_dictionary.idx2item)
# large embedding configuration - comment this in for a better model
embeddings = StackedEmbeddings(
   [WordEmbeddings('fr'),
   FlairEmbeddings('french-forward', use_cache=True),
   FlairEmbeddings('french-backward', use_cache=True)])
# 5. initialize sequence tagger

tagger: SequenceTagger = SequenceTagger(hidden_size=256,
                                    embeddings=embeddings,
                                    tag_dictionary=tag_dictionary,
                                    tag_type=tag_type,
                                    use_crf=True)
# # 6. initialize trainer

trainer: ModelTrainer = ModelTrainer(tagger, corpus)

# 7. start training
trainer.train('resources/taggers/example-ner',
          learning_rate=0.1,
          mini_batch_size=32,
          max_epochs=150)

【问题讨论】:

  • 代码丢失!
  • 最好添加代码而不是图像,以便其他人可以重现您的错误
  • 关于如何克服这个问题的任何想法?或者为什么它无法在 colab 上正确训练?谢谢
  • 我不知道,暂时不参与 ml/ai 任务,最好添加 colab 标签以便其他人可以帮助您

标签: python nlp google-colaboratory named-entity-recognition


【解决方案1】:

您可以指定mini_batch_chunk_sizemini_batch_size,如下所示:

 trainer.train('resources/taggers/example-ner',
               learning_rate=0.1, 
               mini_batch_chunk_size=2,
               mini_batch_size=8,
               max_epochs=150)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 2020-06-22
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2020-04-29
    • 1970-01-01
    相关资源
    最近更新 更多