🚀 Flair英文短语分块(默认模型)
本模型是 Flair 自带的标准英文短语分块模型,可有效处理英文文本的短语分块任务,为自然语言处理提供基础支持。
F1值:96.48(CoNLL - 2000数据集)
该模型可预测以下4种标签:
标签 |
含义 |
ADJP |
形容词性短语 |
ADVP |
副词性短语 |
CONJP |
连词短语 |
INTJ |
感叹词 |
LST |
列表标记 |
NP |
名词短语 |
PP |
介词短语 |
PRT |
小品词 |
SBAR |
从属子句 |
VP |
动词短语 |
此模型基于 Flair嵌入 和LSTM - CRF构建。
🚀 快速开始
依赖安装
需要安装 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('The following NER tags are found:')
for entity in sentence.get_spans('np'):
print(entity)
上述代码将产生以下输出:
Span [1,2,3]: "The happy man" [− Labels: NP (0.9958)]
Span [4,5,6]: "has been eating" [− Labels: VP (0.8759)]
Span [7]: "at" [− Labels: PP (1.0)]
Span [8,9]: "the diner" [− Labels: 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问题跟踪器 中反馈。