🚀 Flair英文動詞消歧(快速模型)
本項目是 Flair 自帶的用於英文的快速動詞消歧模型。該模型能夠有效解決英文句子中動詞含義模糊的問題,為自然語言處理任務提供更準確的語義理解。
🚀 快速開始
本模型需要 Flair,你可以使用以下命令進行安裝:
pip install flair
✨ 主要特性
- 高準確率:在 Ontonotes 數據集上,F1 分數達到 88.27,能夠準確預測 命題庫動詞框架。
- 技術先進:基於 Flair 嵌入 和 LSTM - CRF 構建。
💻 使用示例
基礎用法
以下是在 Flair 中使用該模型的示例代碼:
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/frame-english-fast")
sentence = Sentence("George returned to Berlin to return his hat.")
tagger.predict(sentence)
print(sentence)
print('The following frame tags are found:')
for entity in sentence.get_spans('frame'):
print(entity)
上述代碼的輸出如下:
Span [2]: "returned" [− Labels: return.01 (0.9867)]
Span [6]: "return" [− Labels: return.02 (0.4741)]
在句子 “George returned to Berlin to return his hat” 中,“returned” 被標記為 return.01(表示 “回到某個地方”),而 “return” 被標記為 return.02(表示 “歸還某物”)。
🔧 技術細節
訓練腳本
以下是用於訓練該模型的 Flair 腳本:
from flair.data import Corpus
from flair.datasets import ColumnCorpus
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus = ColumnCorpus(
"resources/tasks/srl", column_format={1: "text", 11: "frame"}
)
tag_type = 'frame'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
BytePairEmbeddings("en"),
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/frame-english-fast',
train_with_dev=True,
max_epochs=150)
📄 許可證
使用該模型時,請引用以下論文:
@inproceedings{akbik2019flair,
title={FLAIR: An easy-to-use framework for state-of-the-art NLP},
author={Akbik, Alan and Bergmann, Tanja and Blythe, Duncan and Rasul, Kashif and Schweter, Stefan and Vollgraf, Roland},
booktitle={{NAACL} 2019, 2019 Conference of the North American Chapter of the Association for Computational Linguistics (Demonstrations)},
pages={54--59},
year={2019}
}
📚 詳細文檔
若你在使用過程中遇到問題,可以訪問 Flair 的 問題跟蹤器。