Sentiment detector output
Introduction
The Sentiment detector API resource returns a JSON object with this format:
{
"success": Boolean success flag,
"data": {
"content": analyzed text,
"language": language code,
"version": technology version info,
"categories": [],
"extractions": [],
}
}
For a description of the contents, language and version properties, see the API resources output overview.
categories is the output for categorization, extractions is the output for information extraction.
categorization array
Each item of the categories array represents a detected category, for example:
{
"frequency": 6.05,
"hierarchy": [
"émotions positives",
"affection"
],
"id": "1220",
"label": "affection",
"namespace": "french_sentiment",
"positions": [
{
"end": 37,
"start": 29
},
{
"end": 48,
"start": 39
}
],
"score": 4,
"winner": true
}
where:
namespaceis the name of the software module containing the reference taxonomy.-
id,labelandhierarchyidentify the node in the category tree:idis the identifying codelabelis the description.hierarchyis the path of the category in the category tree. The path is the sequence of categories that goes from the farthest ancestor to the category itself.hierarchyis an array containing the values of the label property for all the categories along the path.
-
scoreis the cumulative score that was attributed to the category. frequencyis the percentage ratio of the category score to the sum of all categories' scores.winneris a Boolean flag set totrueif the category was considered particularly relevant.positionsis an array containing the positions of the text blocks that contributed to category score.
extractions array
Every item of the extractions array represents an extraction record.
For example, the following item is a record that's an instance of the SENTIMENT_POS_INFO template:
{
"namespace": "sentiment_fr_1.0",
"template": "SENTIMENT_POS_INFO",
"fields": [
{
"name": "facteur_declencheur_pos",
"value": "viennoiserie",
"positions": [
{
"start": 4,
"end": 17
}
]
},
{
"name": "facteur_semantique_pos",
"value": "tuerie",
"score": 1.0,
"positions": [
{
"start": 44,
"end": 50
}
]
}
]
}
See the article in the guide section to know about the concept of information extraction and all the possible record templates with their fields.
In each item:
namespaceis the name of the software module performing the extraction.templateis the name of the template.fieldsis the array of record fields.
Each item of the fields array item represents an extracted value where:
nameis the field's name.valueis the field's value.positionsis an array containing the extracted field's positions.
Example
Considering this input text:
{
"document": {
"text": "Les viennoiseries du Café de Flore sont une tuerie."
}
}
the detector's output is like this:
{
"success": true,
"data": {
"content": "Les viennoiseries du Café de Flore sont une tuerie.",
"language": "fr",
"version": "sensei: 4.10.4; disambiguator: 16.1-QNTF-2017",
"sections": [],
"categories": [
{
"namespace": "sentiment_fr_1.0",
"id": "1200",
"label": "émotions positives",
"hierarchy": [
"émotions positives"
],
"score": 6,
"frequency": 33.33,
"winner": true,
"positions": []
},
{
"namespace": "sentiment_fr_1.0",
"id": "1230",
"label": "satisfaction",
"hierarchy": [
"émotions positives",
"satisfaction"
],
"score": 6,
"frequency": 33.33,
"winner": true,
"positions": [
{
"start": 4,
"end": 17
},
{
"start": 35,
"end": 39
},
{
"start": 44,
"end": 50
}
]
}
],
"extractions": [
{
"namespace": "sentiment_fr_1.0",
"template": "ENTITES",
"fields": [
{
"name": "entite",
"value": "Café de Flore",
"score": 1.0,
"positions": [
{
"start": 21,
"end": 34
}
]
}
]
},
{
"namespace": "sentiment_fr_1.0",
"template": "SENTIMENT_POS_INFO",
"fields": [
{
"name": "facteur_declencheur_pos",
"value": "viennoiserie",
"positions": [
{
"start": 4,
"end": 17
}
]
},
{
"name": "facteur_semantique_pos",
"value": "tuerie",
"positions": [
{
"start": 44,
"end": 50
}
]
}
]
},
{
"namespace": "sentiment_fr_1.0",
"template": "SENTIMENT_SCORE",
"fields": [
{
"name": "score",
"value": "6",
"positions": []
}
]
},
{
"namespace": "sentiment_fr_1.0",
"template": "SENTIMENT_SCORE",
"fields": [
{
"name": "polarite",
"value": "positive",
"positions": []
}
]
}
]
}
}
You can see that the records of the SENTIMENT_SCORE template don't have position information because their data is derived from categories.
The value of field score is the same of category émotions positives, whose score sums up all the score of the output categories of that branch (in this case, satisfaction).