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