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.
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)
#>