Registry / ai-ml / flair
library0.15.1pypypi✓ verified 86d ago

Flair is an open-source framework for state-of-the-art Natural Language Processing (NLP) built on PyTorch. It provides a simple, unified interface for various NLP tasks like named entity recognition, sentiment analysis, part-of-speech tagging, and text classification, with robust support for multilingual models and embeddings. Currently at version 0.15.1, Flair maintains a regular release cadence, often monthly or bi-monthly, consistently adding new features and addressing bug fixes.

pip install flair
INSTALL
IMPORT
SIG · FLAIR
F
flair
ai-mlpythonv0.15.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.15.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ timeout
py 3.11
✕ build_error
✕ timeout
py 3.12
✕ build_error
✕ timeout
py 3.13
✕ build_error
2/4 runs
py 3.9
✕ build_error
✕ timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Sentence
from flair.data import Sentence
Classifier
from flair.nn import Classifier
from flair.models import Classifier
While older tutorials might show `flair.models.Classifier`, the current recommended path for loading pre-trained taggers (like 'ner', 'sentiment') is `flair.nn.Classifier`.
SequenceTagger
from flair.models import SequenceTagger
TextClassifier
from flair.models import TextClassifier
ModelTrainer
from flair.trainers import ModelTrainer
WordEmbeddings
from flair.embeddings import WordEmbeddings
TransformerDocumentEmbeddings
from flair.embeddings import TransformerDocumentEmbeddings

This quickstart demonstrates how to perform Named Entity Recognition (NER) and sentiment analysis using Flair's pre-trained models. It involves creating a `Sentence` object, loading a `Classifier` for a specific task (e.g., 'ner' or 'sentiment'), and then calling `predict()` on the sentence.

from flair.data import Sentence from flair.nn import Classifier # Make a sentence sentence = Sentence('I love Berlin and New York.') # Load the NER tagger tagger = Classifier.load('ner') # Run NER over sentence tagger.predict(sentence) # Print the sentence with all annotations print(sentence) # Example for sentiment analysis sentence_sentiment = Sentence('Flair makes NLP so easy!') sentiment_model = Classifier.load('sentiment') sentiment_model.predict(sentence_sentiment) print(sentence_sentiment)
Debug
Known issues
breakingPython 3.8 support has been deprecated and effectively dropped starting from Flair v0.15.0. Earlier versions (0.13.x) set 3.8 as a *minimum* requirement, but current versions require Python 3.9+.
fix
Upgrade your Python environment to 3.9 or higher.
affects: >=0.15.0
breakingThe `ModelTrainer` API changed in v0.10. The `optimizer` argument is no longer passed during the `ModelTrainer`'s initialization, but instead as a parameter to the `train()` or `fine_tune()` methods.
fix
Adjust your training code: `trainer = ModelTrainer(model, corpus)` and then `trainer.train(..., optimizer=torch.optim.AdamW)`.
affects: >=0.10.0
gotchaOlder versions of Flair (prior to v0.15.1) may experience compatibility issues with newer versions of PyTorch and SciPy.
fix
Upgrade Flair to the latest version (0.15.1 or newer) to ensure compatibility with recent PyTorch and SciPy releases. If you must use an older Flair version, pin your PyTorch and SciPy versions to known compatible ones (e.g., from the Flair requirements.txt of that version).
affects: <0.15.1
deprecatedThe `flair.models.clustering` module has been completely dropped due to lack of usage and to acknowledge a CVE.
fix
If you were using this module, it is no longer available. You may need to find an alternative clustering solution or adapt your code.
affects: >=0.15.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flair'
The Flair library is not installed or the Python environment where it was installed is not active.
fix
Ensure Flair is installed in your active environment: `pip install flair`.
Could not find a version that satisfies the requirement torch
PyTorch, a core dependency, often has specific installation requirements, especially for GPU support, that `pip install flair` might not fully resolve automatically in all environments.
fix
Install PyTorch separately following the official instructions from [pytorch.org](https://pytorch.org/get-started/locally/) for your specific OS, CUDA version, and Python. Then, `pip install flair`.
TypeError: ModelTrainer.__init__() got an unexpected keyword argument 'optimizer'
This error occurs in Flair versions 0.10.0 and later because the `optimizer` argument was moved from the `ModelTrainer` constructor to its `train()` or `fine_tune()` methods.
fix
Remove `optimizer` from `ModelTrainer` initialization. Pass it to the `train()` or `fine_tune()` method instead. 
`trainer = ModelTrainer(model, corpus)` 
`trainer.train('output_path', optimizer=torch.optim.AdamW, ...)`
RuntimeError: 'target' must be of floating point type, but got Long
This often happens during training if your labels (targets) are integers (Long) but the loss function expects floating-point values, which can occur with certain classification setups, especially for regression or specific multi-label scenarios if not handled correctly.
fix
Ensure your target labels are cast to a floating-point type (e.g., `torch.float`) before passing them to the loss function during training, particularly if you are using binary cross-entropy or regression losses.
Upgrade
Version history
0.15.1latest on PyPI · released Feb 5, 2025
Audit
Dependencies
pytorchrequiredFlair is built directly on PyTorch and requires it for core functionality and model training.
transformersoptionalUsed for integrating and fine-tuning transformer-based models and embeddings.
gensimoptionalA dependency for certain word embedding functionalities.
sentencepieceoptionalUsed for sentencepiece tokenization models.
bpemboptionalUsed for Byte-Pair Embeddings.
Agent activity
22 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
flair — pip install flair · libregistry