By Rodrigo Alarcón, Computational Linguist
In this tutorial we describe how you can call some of the text classifiers of our NLP API; specifically, we showcase modules that are focused on understanding the intrinsic semantics and pragmatics of texts.
This is a follow up tutorial; previous content can be found here:
The complete list of modules we offer can be found in our documentation:
The first thing to do is to create an instance of the Codeq Client using your API credentials and define a pipeline containing some text classifiers:
The client is used to analyze a text and retrieve a Document object with a list of Sentences, where the output of the classifiers is stored, i.e., each sentence will contain the prediceted labels for sentiment, emotion and sarcasm.
To print a quick overview of the results, you can use the method document.pretty_print():
In the following sections we will describe:
- the keyword (KEY) used to call each classifier,
- the attribute (ATTR) where the output is stored,
- the OUTPUT LABELS that each classifier produces as output.
This annotator analyzes sentences and tries to determine whether they convey a positive, negative or neutral sentiment.
- KEY: sentiment
- ATTR: sentence.sentiments
The emotion annotator analyzes sentences and predicts if they include one or more emotions or no emotion at all. In contrast to the Sentiment Classifier, this annotator provides a wider granularity when analyzing the feelings expressed in the input text.
In this annotator, sentences with emotional content that don’t achieve high enough probability of a given class are assigned “Unknown emotion“. Sentences perceived as not bearing any emotion are assigned the label “No Emotion“.
More details about this annotator can be found here:
- KEY: emotion
- ATTR: sentence.emotions
- Unknown emotion
- No emotion
The goal of this annotator is to predict if a sentence is sarcastic or not. Sarcasm is an indirect act of speech with a high inherent ambiguity and its detection has become an important task in Natural Language Understanding. The Sarcasm Classifier can be considered as a complementary analysis for both the Sentiment and Emotion classifiers.
In the following post you can discover more details about this annotator:
- KEY: sarcasm
- ATTR: sentence.sarcasm
Here we described three annotators that can be used to extract insights about the semantics behind language utterances. The code below summarizes how to access the output labels of each annotator.
Take a look at our documentation to learn more about the NLP tools we provide.
Do you need inspiration? Go to our use case demos and see how you can integrate different tools.
In our NLP demos section you can also try our tools and find examples of the output of each module.