标签:
- flair
- 词分类
- 序列标注模型
语言: 英文
数据集:
- conll2000
小部件示例:
- 文本: "The happy man has been eating at the diner"
Flair中的英语组块分析(快速模型)
这是Flair自带的英语快速短语组块分析模型。
F1分数:96.22(CoNLL-2000)
预测4种标签:
标签 |
含义 |
ADJP |
形容词性 |
ADVP |
副词性 |
CONJP |
连词性 |
INTJ |
感叹词 |
LST |
列表标记 |
NP |
名词短语 |
PP |
介词性 |
PRT |
助词 |
SBAR |
从句 |
VP |
动词短语 |
基于Flair嵌入和LSTM-CRF。
演示:如何在Flair中使用
需要安装:Flair (pip install flair
)
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/chunk-english-fast")
sentence = Sentence("The happy man has been eating at the diner")
tagger.predict(sentence)
print(sentence)
print('发现以下NER标签:')
for entity in sentence.get_spans('np'):
print(entity)
这将产生以下输出:
范围 [1,2,3]: "The happy man" [− 标签: NP (0.9958)]
范围 [4,5,6]: "has been eating" [− 标签: VP (0.8759)]
范围 [7]: "at" [− 标签: PP (1.0)]
范围 [8,9]: "the diner" [− 标签: NP (0.9991)]
因此,在句子“The happy man has been eating at the diner”中,范围“The happy man”和“the diner”被标记为名词短语(NP),而“has been eating”被标记为动词短语(VP)。
训练:训练此模型的脚本
以下Flair脚本用于训练此模型:
from flair.data import Corpus
from flair.datasets import CONLL_2000
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_2000()
tag_type = 'np'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
FlairEmbeddings('news-forward-fast'),
FlairEmbeddings('news-backward-fast'),
]
embeddings = StackedEmbeddings(embeddings=embedding_types)
from flair.models import SequenceTagger
tagger = SequenceTagger(hidden_size=256,
embeddings=embeddings,
tag_dictionary=tag_dictionary,
tag_type=tag_type)
from flair.trainers import ModelTrainer
trainer = ModelTrainer(tagger, corpus)
trainer.train('resources/taggers/chunk-english-fast',
train_with_dev=True,
max_epochs=150)
引用
使用此模型时请引用以下论文。
@inproceedings{akbik2018coling,
title={Contextual String Embeddings for Sequence Labeling},
author={Akbik, Alan and Blythe, Duncan and Vollgraf, Roland},
booktitle = {{COLING} 2018, 27th International Conference on Computational Linguistics},
pages = {1638--1649},
year = {2018}
}
问题?
Flair的问题跟踪器可在此处获取。