0%

flair

flair

A very simple framework for state-of-the-art Natural Language Processing (NLP)

Flair is:

  • A powerful NLP library. Flair allows you to apply our state-of-the-art natural language processing (NLP)
    models to your text, such as named entity recognition (NER), part-of-speech tagging (PoS),
    sense disambiguation and classification.

  • Multilingual. Thanks to the Flair community, we support a rapidly growing number of languages. We also now include
    one model, many languages‘ taggers, i.e. single models that predict PoS or NER tags for input text in various languages.

  • A text embedding library. Flair has simple interfaces that allow you to use and combine different word and
    document embeddings, including our proposed Flair embeddings, BERT embeddings and ELMo embeddings.

  • A Pytorch NLP framework. Our framework builds directly on Pytorch, making it easy to
    train your own models and experiment with new approaches using Flair embeddings and classes.

Now at version 0.4.0!

Comparison with State-of-the-Art

复现论文结果 How to Reproduce Experiments

Flair outperforms the previous best methods on a range of NLP tasks:

Task Language Dataset Flair Previous best
Named Entity Recognition English Conll-03 93.09 (F1) 92.22 (Peters et al., 2018)
Named Entity Recognition English Ontonotes 89.71 (F1) 86.28 (Chiu et al., 2016)
Emerging Entity Detection English WNUT-17 50.20 (F1) 45.55 (Aguilar et al., 2018)
Part-of-Speech tagging English WSJ 97.85 97.64 (Choi, 2016)
Chunking English Conll-2000 96.72 (F1) 96.36 (Peters et al., 2017)
Named Entity Recognition German Conll-03 88.32 (F1) 78.76 (Lample et al., 2016)
Named Entity Recognition German Germeval 84.65 (F1) 79.08 (Hänig et al, 2014)
Named Entity Recognition Polish PolEval-2018 86.6 (F1)
(Borchmann et al., 2018)
85.1 (PolDeepNer)

flair 各种词嵌入的使用

flair 包含普通的 Glove 词嵌入;字符嵌入;自带的 flair 嵌入;第三方嵌入: ELMo 嵌入、BERT嵌入。注意每一种嵌入又分为具体多种小种类可以使用,以下代码仅仅举例,更多用法见 flair 说明文档。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flair.embeddings import StackedEmbeddings
from flair.embeddings import WordEmbeddings
from flair.embeddings import CharacterEmbeddings
from flair.embeddings import FlairEmbeddings
from flair.embeddings import BertEmbeddings
from flair.embeddings import ELMoEmbeddings

#Classic Word Embeddings
# init embedding
glove_embedding = WordEmbeddings('glove')

#Character Embeddings
# init embedding
embedding = CharacterEmbeddings()

#Flair Embeddings
# init embedding
flair_embedding_forward = FlairEmbeddings('news-forward')
flair_backward = FlairEmbeddings('news-backward')


#Recommended Flair Usage
# create a StackedEmbedding object that combines glove and forward/backward flair embeddings
stacked_embeddings = StackedEmbeddings([
WordEmbeddings('glove'),
FlairEmbeddings('news-forward'),
FlairEmbeddings('news-backward'),
])

#BERT Embeddings
# init embedding
bert_embedding = BertEmbeddings('bert-base-uncased')

#ELMo Embeddings
# init embedding
elmo_embedding = ELMoEmbeddings('original')
本站所有文章和源码均免费开放,如您喜欢,可以请我喝杯咖啡