Skip to content

This function utilizes the reticulate package to directly import TextClassifier from flair.models in the Flair NLP Python library. Ensure that the Python environment is properly set up and the Flair package is installed.

Usage

flair_models.TextClassifier()

Value

A Python class representing flair.models.TextClassifier.

References

Python equivalent:


from flair.models import TextClassifier

Examples

# Load the TextClassifier
TextClassifier <- flair_models.TextClassifier()
# Load a pre-trained sentiment model
classifier <- TextClassifier$load('sentiment')

# Create a sentence object
Sentence <- flair_data()$Sentence
sentence <- Sentence("Flair is pretty neat!")

# Predict the sentiment
classifier$predict(sentence)
# Display the sentiment
print(sentence$get_labels())
#> [[1]]
#> 'Sentence[5]: "Flair is pretty neat!"'/'POSITIVE' (0.9997)
#>