这是我正在尝试训练的代码,以获得用于法语命名实体提取的预训练模型。我将google colab用作环境,因为我的笔记本电脑只有4GB GPU,而colab提供12GB GPU。可悲的是,在colab上,脚本每次都停留在第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)
答案 0 :(得分:0)
您可以指定 mini_batch_chunk_size 和 mini_batch_size ,如下所示:
trainer.train('resources/taggers/example-ner',
learning_rate=0.1,
mini_batch_chunk_size=2,
mini_batch_size=8,
max_epochs=150)