flair README

The project's README from github.com/flairNLP/flair. As one markdown file: README.md.

alt text alt text

PyPI version GitHub Issues Contributions welcome License: MIT

A very simple framework for state-of-the-art NLP. Developed by Humboldt University of Berlin and friends.


Flair is:

Now at version 0.15.1!

State-of-the-Art Models

Flair ships with state-of-the-art models for a range of NLP tasks. For instance, check out our latest NER models:

Language Dataset Flair Best published Model card & demo
English Conll-03 (4-class) 94.09 94.3 (Yamada et al., 2020) Flair English 4-class NER demo
English Ontonotes (18-class) 90.93 91.3 (Yu et al., 2020) Flair English 18-class NER demo
German Conll-03 (4-class) 92.31 90.3 (Yu et al., 2020) Flair German 4-class NER demo
Dutch Conll-03 (4-class) 95.25 93.7 (Yu et al., 2020) Flair Dutch 4-class NER demo
Spanish Conll-03 (4-class) 90.54 90.3 (Yu et al., 2020) Flair Spanish 4-class NER demo

Many Flair sequence tagging models (named entity recognition, part-of-speech tagging etc.) are also hosted on the 🤗 Hugging Face model hub! You can browse models, check detailed information on how they were trained, and even try each model out online!

Quick Start

Requirements and Installation

In your favorite virtual environment, simply do:

pip install flair

Flair requires Python 3.9+.

Example 1: Tag Entities in Text

Let's run named entity recognition (NER) over an example sentence. All you need to do is make a Sentence, load a pre-trained model and use it to predict tags for the sentence:

from flair.data import Sentence
from flair.nn import Classifier

# make a sentence
sentence = Sentence('I love Berlin .')

# load the NER tagger
tagger = Classifier.load('ner')

# run NER over sentence
tagger.predict(sentence)

# print the sentence with all annotations
print(sentence)

This should print:

Sentence: "I love Berlin ." → ["Berlin"/LOC]

This means that "Berlin" was tagged as a location entity in this sentence.

Example 2: Detect Sentiment

Let's run sentiment analysis over an example sentence to determine whether it is POSITIVE or NEGATIVE. Same code as above, just a different model:

from flair.data import Sentence
from flair.nn import Classifier

# make a sentence
sentence = Sentence('I love Berlin .')

# load the NER tagger
tagger = Classifier.load('sentiment')

# run NER over sentence
tagger.predict(sentence)

# print the sentence with all annotations
print(sentence)

This should print:

Sentence[4]: "I love Berlin ." → POSITIVE (0.9983)

This means that the sentence "I love Berlin" was tagged as having POSITIVE sentiment.

Tutorials

On our new :fire: Flair documentation page you will find many tutorials to get you started!

In particular:

There is also a dedicated landing page for our biomedical NER and datasets with installation instructions and tutorials.

More Documentation

Another great place to start is the book Natural Language Processing with Flair and its accompanying code repository, though it was written for an older version of Flair and some examples may no longer work.

There are also good third-party articles and posts that illustrate how to use Flair:

Citing Flair

Please cite the following paper when using Flair embeddings:

@inproceedings{akbik2018coling,
  title={Contextual String Embeddings for Sequence Labeling},
  author={Akbik, Alan and Blythe, Duncan and Vollgraf, Roland},
  booktitle = {{COLING} 2018, 27th International Conference on Computational Linguistics},
  pages     = {1638--1649},
  year      = {2018}
}

If you use the Flair framework for your experiments, please cite this paper:

@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 Annual Conference of the North American Chapter of the Association for Computational Linguistics (Demonstrations)},
  pages={54--59},
  year={2019}
}

If you use our new "FLERT" models or approach, please cite this paper:

@misc{schweter2020flert,
    title={{FLERT}: Document-Level Features for Named Entity Recognition},
    author={Stefan Schweter and Alan Akbik},
    year={2020},
    eprint={2011.06993},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

If you use our TARS approach for few-shot and zero-shot learning, please cite this paper:

@inproceedings{halder2020coling,
  title={Task Aware Representation of Sentences for Generic Text Classification},
  author={Halder, Kishaloy and Akbik, Alan and Krapac, Josip and Vollgraf, Roland},
  booktitle = {{COLING} 2020, 28th International Conference on Computational Linguistics},
  year      = {2020}
}

Contact

Please email your questions or comments to Alan Akbik.

Contributing

Thanks for your interest in contributing! There are many ways to get involved; start with our contributor guidelines and then check these open issues for specific tasks.

License

The MIT License (MIT)

Flair is licensed under the following MIT license: The MIT License (MIT) Copyright © 2018 Zalando SE, https://tech.zalando.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

flair (flairNLP/flair)

Searching Database…

14.4K ·GitHub
这是做什么的?Flair 是一个非常简单、可达到业界先进水平的自然语言处理框架:一个 Python 库,用来把预训练的 NLP 模型应用到你的文本上,由柏林洪堡大学及其合作伙伴开发。当前发布的版本是 0.15.1。
它是在我自己代码里调用的 Python 库,还是有独立界面的独立工具?它是一个 Python 库,不是应用:你把文本包装成 Sentence 对象,加载一个预训练模型,然后对它调用 predict。Flair 也可以作为文本嵌入库使用,以及作为 PyTorch 框架来构建你自己的模型。
我需要先安装好 PyTorch 或其他东西吗?不需要单独搭建环境:Flair 直接基于 PyTorch 构建,pip install 会自动把它装上。之后你只需要加载模型,对普通字符串运行即可。
它只能处理英文文本吗?不是——除了英文,还有针对德语、荷兰语和西班牙语的预训练模型,Flair 支持的语言数量在快速增长,而且对生物医学文本有专门支持。
可以免费使用吗,包括商业用途?可以——Flair 采用 MIT 许可证(版权属于 Zalando SE),你可以使用、复制、修改和销售副本,前提是保留许可证声明。
在哪里可以获取或试用预训练模型?很多 Flair 标注模型(命名实体识别、词性标注等)托管在 Hugging Face 模型中心:你可以浏览它们、了解每个模型的训练方式,甚至在线试用。README 里也有按语言分类的命名实体识别演示链接。
我可以训练自己的模型,还是只能运行预训练的模型?两者都可以。预训练模型只需几行代码就能用;由于 Flair 基于 PyTorch 构建,你也可以训练自己的先进模型——Flair 文档页面上的教程 2 介绍了训练方法。
命名实体识别模型的准确率怎么样?接近业界最先进水平:英文四分类命名实体识别模型在 CoNLL-03 上得分为 94.09,德语为 92.31,荷兰语为 95.25,西班牙语为 90.54——每个都与已发表的最佳结果相差约一个百分点。
有没有学习 Flair 的书籍或其他资料?有——《Natural Language Processing with Flair》一书及配套的代码仓库,还有 Flair 文档页面上的教程(基础标注、训练、嵌入、生物医学文本)。注意这本书是为较旧的 Flair 版本编写的,部分示例可能已无法运行。
Creator
flairNLP
Size
386.3 MB
Stars
14.4K
Age
8y
Commits · 90 Days