标签:
- flair
- 词性标注
- 序列标注模型
语言: 英文
数据集:
- conll2000
小工具示例:
- 文本: "The happy man has been eating at the diner"
Flair中的英语组块分析(默认模型)
这是Flair自带的英语标准短语组块分析模型。
F1分数:96.48(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")
sentence = Sentence("The happy man has been eating at the diner")
tagger.predict(sentence)
print(sentence)
print('发现的命名实体标签如下:')
for entity in sentence.get_spans('np'):
print(entity)
输出结果如下:
Span [1,2,3]: "The happy man" [− 标签: NP (0.9958)]
Span [4,5,6]: "has been eating" [− 标签: VP (0.8759)]
Span [7]: "at" [− 标签: PP (1.0)]
Span [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'),
FlairEmbeddings('news-backward'),
]
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',
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的问题跟踪器可在此处获取。