🚀 Flair英文组块分析(快速模型)
本项目是一个用于英文的快速短语组块分析模型,它集成于 Flair 框架中。该模型在CoNLL - 2000数据集上的F1分数达到了 96.22,能够预测以下4种标签:
标签 |
含义 |
ADJP |
形容词性短语 |
ADVP |
副词性短语 |
CONJP |
连词短语 |
INTJ |
感叹词 |
LST |
列表标记 |
NP |
名词短语 |
PP |
介词短语 |
PRT |
小品词 |
SBAR |
从属子句 |
VP |
动词短语 |
此模型基于 Flair嵌入 和LSTM - CRF构建。
🚀 快速开始
本模型需要 Flair 库,你可以使用以下命令进行安装:
pip install flair
✨ 主要特性
- 高性能:在CoNLL - 2000数据集上F1分数达到96.22。
- 多标签预测:能够预测多种类型的短语标签。
- 基于先进技术:采用Flair嵌入和LSTM - CRF架构。
💻 使用示例
基础用法
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('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-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问题跟踪器 中反馈。