基于Pytorch的NLP框架 Flair库

Flair 由 Zalando Research 开发及开源,是基于 Pytorch 的 NLP 框架。简单易懂、操作方便。

-一个强大的NLP库。Flair允许用户将最先进的自然语言处理模型应用于文本。

例如命名实体识别(NER),词性标注(PoS),意义消歧和分类。

-多语言支持。

-一个文本embedding库。Flair提供简单的接口,来使用集成不同单词与文档,如Flair embeddings, BERT embeddings and ELMo embeddings.

-一个pytorch的NLP框架。Flair直接构建在pytorch之上,训练你自己的模型会很容易。

目前的版本是0.4.5。

依赖:PyTorch 1.1+ ,Python 3.6+

安装:pip install flair

使用样例:

如下是运行NER。

from flair.data import Sentence

from flair.models import SequenceTagger

# make a sentence

sentence = Sentence('I love Berlin .')

# load the NER tagger

tagger = SequenceTagger.load('ner')

# run NER over sentence

tagger.predict(sentence)

print(sentence)

print('The following NER tags are found:')

# iterate over entities and print

for entity in sentence.get_spans('ner'):

print(entity)

打印输出的内容是:

Sentence: "I love Berlin ." - 4 Tokens

The following NER tags are found:

LOC-span [3]: "Berlin"


基于Pytorch的NLP框架 Flair库


基于Pytorch的NLP框架 Flair库


分享到:


相關文章: