camel_tools.sentiment
This module contains the CAMeL Tools sentiment analyzer component.
Classes
- class camel_tools.sentiment.SentimentAnalyzer(model_path, use_gpu=True)
CAMeL Tools sentiment analysis component.
- Parameters:
- static labels()
Get the list of possible sentiment labels returned by predictions.
- predict(sentences, batch_size=32)
Predict the sentiment labels of a list of sentences.
- predict_sentence(sentence)
Predict the sentiment label of a single sentence.
- static pretrained(model_name=None, use_gpu=True)
Load a pre-trained model provided with camel_tools.
- Parameters:
- Returns:
Instance with loaded pre-trained model.
- Return type:
Examples
Below is an example of how to load and use the default pre-trained model.
from camel_tools.sentiment import SentimentAnalyzer
sa = SentimentAnalyzer.pretrained()
# Predict the sentiment of a single sentence
sentiment = sa.predict_sentence('أنا بخير')
# Predict the sentiment of multiple sentences
sentences = [
'أنا بخير',
'أنا لست بخير'
]
sentiments = sa.predict(sentences)