Flair NLP

0.15.1 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →