🚀 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 的 问题跟踪器。