Sentiment#
Basic#
The easiest way to add sentiment to a text field is using the ds.extract_sentiment function.
Prior to adding sentiment, we will need to make sure to install HuggingFace’s Transformers.
pip install -q transformers
from relevanceai import Client
client = Client()
ds = client.Dataset("sample")
# Easily switch to a different HuggingFace model
ds.extract_sentiment(
text_fields=["sample_1_label"],
)
For every document, you will get functions and formulas similar to the ones below:
{
"_sentiment_": {
"sample_1_label": {
{
"model_name": {
"sentiment": sentiment, # positive / neutral / negative
"score": np.round(float(scores[ranking[0]]), 4), # confidence of the sentiment
"overall_sentiment_score": score if sentiment == "positive" else -score,
# an overall sentiment score where -1 is negative and +1 is positive
}
}
}
}
API Reference#
Add Sentiment to your dataset
- class relevanceai.operations.text.sentiment.sentiments.SentimentOps#
- get_shap_values(text, sentiment_ind=2, max_number_of_shap_documents=None, min_abs_score=0.1)#
Get SHAP values
- class relevanceai.operations.text.sentiment.sentiment_workflow.SentimentWorkflow#
Sentiment workflow
- fit_dataset(dataset, input_field, output_field='_sentiment_', log_to_file=True, chunksize=20, workflow_alias='sentiment', notes=None, refresh=False, highlight=False, positive_sentiment_name='positive', max_number_of_shap_documents=None, min_abs_score=0.1)#
Fit on dataset