Listen to this story
|
The technique of determining views or feelings conveyed in the text regarding a subject is referred to as sentiment analysis, also known as opinion mining. Sentiment analysis may be done at the sentence or document level. In linguistics, negatives are particularly essential because they change the polarity of other words. Negative terms include no, not, shouldn’t, and so on. When a negation appears in a sentence, it is critical to determine which words are impacted by this phrase. This article will be focused on understanding the concept of negation and implementing it with NegSpacy. Following are the topics to be covered.
Table of contents
- What is Sentiment Analysis?
- What is negation handling?
- Types of negation words
- Handling negation with NegSpacy
The emotion expressed in a text by a person could be understood by machine learning algorithms. Let’s understand the concept of sentiment analysis.
What is Sentiment Analysis?
Sentiment analysis combines various research areas such as natural language processing, data mining, and text mining, and is rapidly becoming important to organisations as they strive to integrate computational intelligence methods into their operations and attempt to shed more light on, and improve, their products and services. The purpose of sentiment analysis, also known as opinion mining (SAOM), is to uncover people’s written views or text. Sentiment can be defined as “how one feels about something,” “personal experience, one’s feeling”, “attitude toward something”, or “an opinion.”
Subscribe to our Newsletter
Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.
Opinions are fundamental to practically all human actions and have a significant impact on our behaviour. Our views and perceptions of reality, as well as the decisions we make, are heavily influenced by how others see and interpret the world. As a result, when we need to make a decision, we frequently seek the advice of others. This is true not only for individuals but also for companies. Closed-form customer satisfaction questionnaires have traditionally been used to assess the key components, or facets, of total customer satisfaction. However, developing and implementing surveys might be costly or unavailable. In certain circumstances, governmental entities are even barred by law from collecting customer satisfaction questionnaires.

The sentiment analysis is applicable at both the sentence and document levels. The sentence level determines whether the opinion expressed in a sentence about a subject is positive or negative. In contrast, the whole document is classified as positive or negative at the document level.
Are you looking for a complete repository of Python libraries used in data science, check out here.
What is negation handling?
Negative words are those that influence the sentiment orientation of other words in a phrase. Negation terms include not, no, never, cannot, shouldn’t, wouldn’t, and so on. Negation handling is a method of automatically detecting the extent of negation and inverting the polarity of opinionated words that are impacted by a negation. The area of the phrase that negation impacts are referred to as the vicinity or scope of negation.
A negation may reverse the polarity of all words in a phrase that has only one clause. In a compound sentence, however, there are numerous clauses. A negation inverts the polarity of certain words in a phrase, and the quantity of words reversed varies according to linguistic factors. As a result, dealing with negation in a compound phrase might be difficult. To establish the scope of a negative, we create a list of negations that serve as a signal of the presence of a negation.
All negation words are divided into three categories.
- All negations that totally reverse the polarity of other words are classified as syntactic negations.
- The diminisher class covers all negation words that lessen the polarities rather than inverting them.
- All prefixes and suffixes that can be used to produce a morphological negative are included in the morphological class. These prefixes and suffixes are also employed to identify the existence of a morphological negative.
How does negation affect the sentiment analysis?
One of the most popular language strategies for changing text polarity is negation. As a result, in sentiment analysis, negation must be considered. The scope size of a negative expression specifies which words in the phrase are impacted by negation words like no, not, and never. Negation keywords influence the contextual polarity of words, but their existence in a phrase does not imply that all words conveying feelings will be inverted. As a result, we must additionally identify the scope of negation in each phrase.
Linguistic negation is a difficult issue with several ways to communicate a negative attitude. Negation can be morphological, with a prefix (“dis-“, “non-“) or a suffix (“-less”) denoting it [11]. It might be implied, as in this act being his first and final film. Although this statement has a negative opinion, no negative words are utilised. Negation might also be explicit, which is undesirable.
Types of negation words
As discussed above there are three types of negation words, syntactic, diminisher and morphological negations. Let’s deep dive into these three negation types.
Syntactic Negations
The most prevalent sort of negation in user-created text is syntactic negation. The majority of available approaches merely determine the range of syntactic negations. Linguistic factors are taken into account in syntactic negation. Conjunction analysis, punctuation marks, and the POS of negation phrases are among the language aspects.
- Conjunction Analysis: Conjunctions are the words that connect clauses in a sentence. Conjunctions include words like and, or, but, while, and so on. Conjunction analysis is a crucial aspect of our method since it allows us to quickly determine the extent of negation in compound sentences.
- Punctuation Markings: Punctuation marks such as a comma “,” a semicolon “;”, a colon “:”, and an exclamation mark “!” limit the scope of negation. To identify the scope of negation, a negation handling technique should take into account all of these punctuation marks. The scope of negation extends to the following sentence whenever a comma is used either for “or” or “and” and the identical portions of the speech pattern are followed on either side.
- Negation Part of Speech (POS): The syntactic negation terms exist in various POS in a sentence, such as an adverb, noun, contraction, determiner, interjection, exclamation, and so on.
Syntactic negation has two exceptions: when the negation has no scope at all and when the negation word inverts the polarity of the entire clause/sentence without changing any opinionated word. Some exceptions linked to specific linguistic traits have already been examined in separate sections. In some cases, syntactic negations have no meaning when combined with terms like “not just,” “not just,” “no surprise,” and “not to mention.”
Diminishers Negations
Diminisher negations vary from syntactic negations in that they frequently lessen the polarities of other words rather than completely reversing the polarities. Furthermore, with syntactic negation, the words that lessen the impact may appear anywhere in the phrase rather than after the negative term. In sentences like “this mobile scarcely lags” and “the application crashes seldom,” the diminishers (i.e. hardly and rarely) weaken the negative polarity of the words “lags” and “crashes.” The negative affected the word after it in the first sentence, but not the word before it in the second.
Morphological Negations
In certain circumstances, the negation term and the negated opinionated word are merged into a single word, as in end-less, rude, dishonest, non-cooperative, and so on. This is known as morphological negation, and it may be constructed by combining one of the nine prefixes (de-, dis-, il-, im-, in-,ir-, mis-, non-, un-) or one suffix (-less) with a root word. One approach to dealing with such negations is to first attempt to lexicalise all of these sorts of terms. If such a negation occurs in a phrase, polarity is acquired straight from the lexicon without any scope identification or polarity inversion. However, unusual terms may not be in the lexical dictionary, resulting in incorrect categorization.
The alternative method is to break down morphological negation words to get the base word. The lexicon is used to determine the polarity of the root word, which is then reversed. If the root word is not lexicalized, the synonym’s polarity is obtained. The lexicon hits can be enhanced by deconstructing the morphological negation and exploiting the polarity of the synonyms list.
Handling negation with NegSpacy
In this article, we will be using the NegSpacy library for handling syntactic negations. NegSpacy uses the NegEX algorithm for handling negation in a sentence. NegEx searches for trigger phrases that indicate a clinical condition is negated or possible and then decides which text comes within the scope of the trigger terms. It returns two types of outputs depending upon the input.
- If you specify the conditions whose negation status you are curious about, NegEx will return negated or possible for those conditions that are inside the scope of negation terms (no value is given for the conditions if the condition is deemed present).
- The text included within the scope of a trigger phrase is a more broad output that does not need the predetermination of circumstances of interest.
Let’s start with the installation of spacy and negspacy libraries and also spacy stanza which will help to load the NLP pipelines.
! pip install spacy ! pip install negspacy ! pip install spacy_stanza
Import necessary libraries
import spacy import stanza import spacy_stanza from negspacy.negation import Negex from negspacy.termsets import termset
Load the NLP pipeline using spacy_stanza
nlp_model = spacy_stanza.load_pipeline('en')
For this article, we are using the ‘en_core_web_sm’ NLP model. It is trained for the English language and has 19 labels. The dataset used for training the model is from blogs, newspapers, and comments.

Add negex to the pipeline and filter some entities for faster processing. The filter is not necessary.
nlp_model.add_pipe("negex", config={"ent_types":["PERSON","ORG","CARDINAL", "DATE", "EVENT", "LANGUAGE", "PRODUCT", "QUANTITY", "TIME", "WORK_OF_ART"]})
Let’s check some sentences.
sample = nlp_model('There is no English language option.') for e in sample.ents: print(e.text, e._.negex)

doc = nlp_model('He does not like Adolf Hitler but likes German products.') for e in doc.ents: print(e.text, e._.negex)

The true indicates the word has a negative meaning and the false indicates the positive sense.
Conclusions
The inability to properly discern the effect of negation on other words is one of the primary causes of mistakes in sentence-level sentiment analysis. With this article, we have understood the concept of negation and handled it with an implementation using Negspacy.