Hub documentation

在 Hugging Face 上使用 Flair

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

在 Hugging Face 上使用 Flair

Flair 是一个用于先进自然语言处理的极简框架。 由 柏林洪堡大学 及其合作伙伴开发。

在 Hub 中探索 Flair

您可以在模型页面左侧进行筛选,以查找flair模型。

Hub 上的所有模型都具备以下实用功能:

  1. 自动生成的模型卡片,包含简要描述。
  2. 一个交互式小部件,可直接在浏览器中操作该模型。
  3. 一个推理提供商小部件,允许您发起推理请求。

安装

要开始使用,您可以遵循Flair 安装指南。 您也可以通过 pip 使用以下单行命令进行安装:

$ pip install -U flair

使用现有模型

所有 flair 模型都可以轻松地从 Hub 加载:

from flair.data import Sentence
from flair.models import SequenceTagger

# load tagger
tagger = SequenceTagger.load("flair/ner-multi")

加载完成后,您可以使用 predict() 执行推理:

sentence = Sentence("George Washington ging nach Washington.")
tagger.predict(sentence)

# print sentence
print(sentence)

它输出以下内容:

Sentence[6]: "George Washington ging nach Washington." → ["George Washington"/PER, "Washington"/LOC]

如果您想加载特定的 Flair 模型,可以单击模型卡片中的 Use in Flair,即可获得可用的代码片段!

其他资源

Update on GitHub