🚀 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問題跟蹤器 中反饋。