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.
Returns: List of sentiment labels. Return type: list
ofstr
-
predict
(sentences, batch_size=32)¶ Predict the sentiment labels of a list of sentences.
Parameters: Returns: The predicted sentiment labels for given sentences.
Return type:
-
predict_sentence
(sentence)¶ Predict the sentiment label of a single sentence.
Parameters: sentence ( str
) – Input sentence.Returns: The predicted sentiment label for given sentence. Return type: str
-
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:
-
static
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)