9th AI Project 1
9th AI Project 1
Introduction
Sentiment analysis, also known as opinion mining, is a natural language processing (NLP)
technique used to determine the sentiment expressed in a piece of text. It helps in classifying
the text as positive, negative, or neutral based on the emotions conveyed. This technique is
widely used in various applications such as customer feedback analysis, product reviews,
social media monitoring, and brand reputation management.
Objective
The objective of this project is to analyze the sentiment of user-inputted text using a simple
Python program. By leveraging the TextBlob library, we can determine whether a given
statement expresses a positive, negative, or neutral sentiment. This project serves as an
introduction to sentiment analysis and provides a practical demonstration of AI-based text
processing.
Working Principle
Sentiment analysis works by analyzing the words and phrases in a text and assigning a
polarity score to it. The polarity score ranges from -1 to +1, where:
The TextBlob library, which is built on top of the Natural Language Toolkit (NLTK),
provides an easy-to-use interface for performing sentiment analysis.
Implementation
To run this project, you need to install the TextBlob library if it is not already installed. You
can do this using the following command:
# Sentiment analysis
analysis = TextBlob(text)
polarity = analysis.sentiment.polarity
if polarity > 0:
print("Positive Sentiment")
print("Negative Sentiment")
else:
print("Neutral Sentiment")
The program will prompt the user to enter a sentence. Based on the polarity score calculated,
it will classify the text accordingly.
Example 1:
Positive Sentiment
Example 2:
Negative Sentiment
Example 3:
Enter a sentence: It is an ordinary day.
Neutral Sentiment
Sentiment analysis is widely used in various industries for different purposes, such as:
Advantages:
Challenges:
Conclusion
This project provides a fundamental understanding of sentiment analysis using Python and
the TextBlob library. By classifying text as positive, negative, or neutral, sentiment analysis
has proven to be a valuable tool in various fields. This project lays the groundwork for further
exploration into more advanced NLP techniques, such as deep learning-based sentiment
classification.