Project
Project
May, 2025
MOVIE SENTIMENT ANALYSER
A Project Report submitted
in partial fulfilment of the
requirements for the Degree of
Bachelor’s in Technology
by
Abhishek
(Enrollment No –211SET01100004)
to the
May, 2025
CERTIFICATE
This is to certify that the project entitled “MOVIE SENTIMENT ANALYSER” submitted
for the degree of BACHELOR OF TECHNOLOGY in the discipline DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING at OM STERLING GLOBAL
UNIVERSITY, HISAR during the academic year 2024-2025 is bonafide project work is carried out
by “Abhishek” bearing ROLL NO. 211020110004 under my supervision and it is further certified
that the work done in this project is a result of the candidate's own efforts. I wish all of them success in
their lives and no part of this project report has been submitted in any other University/ Institute for B.
TECH or any other degree/diploma.
……………….
Supervisor
(Head of Department)
Deptt. of CSE
OSGU, HISAR
DECLARATION
It is hereby that the work presented in the project report entitled “MOVIE SENTIMENT
ANALYSER” in partial fulfilment of requirement for the awards of degree of BACHELOR
OF TECHNOLOGY submitted to the DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING at OM STERLING GLOBAL UNIVERSITY, HISAR is an authentic
record of my own work carried out under the supervision of DR. PARVEEN SEHGAL. The matter
presented in this project has not been submitted in any other University / Institute for the award of B.
TECH or any other Degree / Diploma to the best of my knowledge & belief.
Abhishek
211020110004
This is to certify that the above statement made by the candidate is correct to the
best of my knowledge.
……………………
Supervisor
(Head of Department)
(CSE Department)
(OSGU, HISAR)
ACKNOWLEDGEMENT
We are highly grateful to our Supervisor and Head of department DR. PARVEEN SEHGAL, OM
STERLING GLOBAL UNIVERSITY, HISAR for providing this opportunity to carry out the
present project work. We owe their overwhelming debt for helping us to plan and discuss the contents of
this work. Their ideas, simulating comments, interpretations and suggestions increased our cognitive
awareness and helped considerably in the fruition of our objective. We remain obliged to them for their help
and able guidance through all stages of this project. We are grateful to our Dean, DR. SHAILESH
KUMAR, OM STERLING GLOBAL UNIVERSITY, HISAR entire staff of Computer Science &
Engineering Department and friends who devoted their valuable time and helped us in all possible ways
towards successful completion of this work. We thank all those who have contributed directly or indirectly to
this project. Lastly, we would like to thank our parents for their years of unyielding love. They have always
wanted the best for us and we admire their determination and sacrifice. Above all, we express our
indocibleness to all ALMIGHTY for the blessing and kindness.
I am incredibly thankful to Dr. Parveen Sehgal for his unwavering support and exceptional guidance
during our project.
Abhishek
TABLE OF CONTENTS
Certificate
Declaration
Acknowledgements
Table of Contents
List of figures
List of Appendix
1.1 Introduction
1.5 Limitations
3.1 Results
3.2 Discussion
3.3 References
3.4 Appendices
3.6 Conclusion
LIST OF FIGURES
9 Raw Data
LIST OF ABBREVIATIONS
S.NO. PARTICULARS
1.1 Introduction
The advent of the digital age has significantly transformed the way individuals
communicate, share opinions, and consume information. With the rise of the internet and
the growing dominance of social media platforms, user-generated content has proliferated
across the web at an unprecedented rate. Among the various forms of digital expression,
reviews and ratings have become particularly influential, playing a crucial role in shaping
public perception and guiding consumer choices. In the domain of entertainment, movie
and television show reviews contribute immensely to the decision-making process of
audiences, filmmakers, and critics alike.
One of the most prominent platforms for entertainment-related content is the Internet
Movie Database (IMDb). IMDb serves as a central hub where users from around the world
can share their opinions and critiques on movies, TV series, and other visual media. With
millions of user reviews available on the site, it offers a vast repository of textual data that
reflects a wide spectrum of public sentiment. Analysing this wealth of information can
provide valuable insights into audience reception, trending preferences, and overall
sentiment trends within the entertainment industry.
To effectively interpret the sentiments embedded within these textual reviews, Sentiment
Analysis—a subfield of Natural Language Processing (NLP)—has emerged as a powerful
tool. Sentiment analysis involves the computational identification, extraction, and
categorization of opinions expressed in text, primarily to ascertain whether the writer’s
attitude is positive, negative, or neutral. This technique has widespread applications in
areas such as marketing, product development, and customer service, and is increasingly
being leveraged in the media and entertainment sectors.
This project aims to develop an accurate and efficient sentiment analysis system
specifically tailored to classify IMDb movie reviews into either positive or negative
sentiment categories. The objective is to harness the capabilities of machine learning
algorithms to build a predictive model that can interpret user opinions with high
reliability.
To achieve this goal, a comprehensive dataset containing over 150,000 IMDb movie
reviews was utilized. The project involved a series of critical steps, including data
preprocessing, text normalization, feature extraction, and model training. Various machine
learning classifiers were evaluated to identify the most suitable model for this task. After a
detailed comparison using performance metrics such as accuracy, precision, recall, and
F1-score, the Logistic Regressor classifier was found to deliver the best results, striking
an optimal balance between performance and interpretability.
To enhance accessibility and practical usability, the final sentiment analysis model was
integrated into a user-friendly web-based application developed using the Flask
framework. This interface allows users to input movie reviews in real-time and receive
immediate feedback on the predicted sentiment. By bridging the gap between complex
machine learning techniques and everyday user interaction, the application serves as both a
practical tool and a demonstration of the power of NLP in real-world scenarios.
1.2 Statement of the Problem
With the explosion of digital content and the widespread use of online platforms, user
reviews have become a powerful source of public opinion. IMDb (Internet Movie
Database) is one such platform where users post detailed reviews about movies and TV
shows. These reviews not only influence viewer decisions but also provide valuable
feedback for filmmakers and production companies. However, the massive volume and
unstructured nature of these textual reviews make it difficult to manually analyse and
interpret the overall sentiment.
The core problem this project addresses is the lack of an efficient, scalable solution to
analyse sentiment in IMDb movie reviews. This includes challenges like dealing with
informal language, sarcasm, varying writing styles, and context-based expressions that are
common in user-generated content.
Therefore, the project aims to develop a sentiment analysis tool using machine learning
techniques that can automatically determine the sentiment of IMDb movie reviews. The
goal is to provide a fast, reliable, and user-friendly solution that enables users and
stakeholders to gain insights from large volumes of reviews without manual effort. By
leveraging natural language processing and a trained classification model, this system will
help convert raw textual data into meaningful sentiment information.
1.3 Significance of the Problem
Despite its effectiveness, the project has certain limitations that may impact its scalability
and generalization.
No Consideration of Metadata:
The sentiment analyser is based solely on review text, without incorporating other useful
information such as movie genre, user rating, review length, or reviewer history, which
could provide additional context and improve accuracy.
Sentiment analysis, also referred to as opinion mining, is a core area within Natural
Language Processing (NLP) that involves the automatic extraction and classification of
sentiments expressed in textual content. With the explosion of user-generated data on the
internet, particularly through social media platforms and review websites like IMDb, there
is an increasing demand for intelligent systems that can analyse and interpret public
opinion. Among the various domains where sentiment analysis has been applied, movie
reviews stand out as a particularly valuable source of subjective feedback, offering insights
into viewer preferences, satisfaction, and emotional reactions to films.
The development of the IMDb Sentiment Analyzer involved a systematic and structured
approach, combining data collection, preprocessing, feature engineering, model training,
evaluation, and deployment. This section provides a comprehensive overview of the
resources, tools, and methodologies employed throughout the project lifecycle.
The primary objective was to design and implement a machine learning-based sentiment
analysis system capable of classifying movie reviews from IMDb as either positive or
negative. To achieve this, various machine learning algorithms were tested and compared,
with the Random Forest classifier ultimately selected based on superior performance. The
final model was integrated into an interactive web application, enabling users to obtain
real-time sentiment predictions.
The project utilized the IMDb Large Movie Review Dataset, which is one of the most
widely used benchmark datasets for binary sentiment classification tasks. This dataset
contains 50,000 movie reviews, evenly split into 25,000 positive and 25,000 negative
examples. All reviews were pre-labelled and curated to ensure a balanced distribution of
sentiments, making it ideal for training and evaluation purposes.
In addition to the benchmark dataset, the project leveraged a larger corpus comprising over
150,000 raw IMDb reviews, gathered to further improve the robustness and
generalizability of the model. This extended dataset included a mixture of labelled and
unlabelled reviews, which were used for unsupervised learning experiments and
exploratory data analysis.
The implementation was carried out using the Python programming language, owing to
its powerful libraries and wide adoption in the machine learning and data science
communities. The following tools and libraries were integral to the project:
• Natural Language Toolkit (NLTK): Used for preprocessing tasks such as
tokenization, stop word removal, and lemmatization.
• Pandas and NumPy: Used for structured data handling, manipulation, and
analysis.
• Joblib: Used to serialize the trained machine learning model for deployment and
integration into the web app.
Data Preprocessing:
Textual data collected from real-world user reviews often contains noise and variability.
To ensure that the data fed into the machine learning algorithms was clean and meaningful,
several preprocessing steps were undertaken:
• Lowercasing: All text was converted to lowercase to standardize words and reduce
redundancy (e.g., "Movie" and "movie" treated equally).
• HTML Tag Removal: Many IMDb reviews contain HTML formatting, which was
removed using regular expressions.
• Tokenization: The text was split into individual words or tokens to facilitate
further analysis.
• Stop Word Removal: Common English words (e.g., "the", "is", "at") that do not
contribute to sentiment were removed using NLTK’s stop word list.
These preprocessing steps played a crucial role in improving the signal-to-noise ratio, thus
enhancing the overall effectiveness of the model.
Feature Extraction:
Once cleaned, the textual data needed to be transformed into numerical form for machine
learning algorithms to process it. For this, the TF-IDF (Term Frequency–Inverse
Document Frequency) method was used. TF-IDF assigns weights to words based on how
frequently they appear in a given document compared to how rarely they appear across all
documents in the dataset. This helps in emphasizing important words and down-weighting
commonly used terms that carry little discriminatory power.
The resulting TF-IDF matrix was sparse but informative, representing each review as a
high-dimensional vector suitable for input into a classifier.
Multiple machine learning algorithms were implemented and evaluated to identify the
most effective model for sentiment classification. These included:
• Naive Bayes: A probabilistic classifier known for its speed and simplicity.
• Decision Trees: An interpretable model that splits the data based on feature values.
• Random Forest: An ensemble method combining multiple decision trees to reduce
overfitting and improve generalization.
The models were trained on 80% of the dataset and tested on the remaining 20% using
stratified sampling to maintain class balance. The following evaluation metrics were used:
• Recall: The proportion of actual positive cases that were correctly identified.
• F1-score: The harmonic mean of precision and recall, providing a balance between
them.
Based on these metrics, the Logistic Regressor classifier emerged as the best-performing
model, achieving the highest F1-score, and was therefore chosen for final deployment.
To provide users with a practical and interactive interface, the trained model was deployed
using the Flask web framework. The Flask app features a simple, user-friendly interface
where users can input a movie review and receive an immediate sentiment prediction. The
application uses the serialized Random Forest model (saved using Joblib) to perform
predictions on user-submitted text. The backend processes the input, applies the same
preprocessing and TF-IDF transformation pipeline, and then passes the data to the
classifier.
The final result is rendered dynamically in the browser, making the system accessible and
useful for general users, researchers, or entertainment industry professionals seeking quick
sentiment insights.
CHAPTER 3: RESULT AND CONCLUSION
3.1 Results:
After completing the training and testing phases of the IMDb sentiment analyser, various
machine learning models were compared to determine the most effective classifier for
predicting the sentiment of movie reviews. The evaluation metrics used included
accuracy, precision, recall, and F1-score, providing a comprehensive assessment of
model performance on unseen data.
The results of the sentiment analysis model were promising and demonstrated the
effectiveness of machine learning techniques in understanding and interpreting natural
language. Among all the models tested, the Logistic Regressor classifier achieved the best
performance, with an accuracy of 86.5%, a precision of 86.6%, a recall of 86.6%, and
an F1-score of 86.7% on the test dataset. These metrics suggest that the model is highly
capable of correctly identifying both positive and negative sentiments. The confusion
matrix further validated the model’s performance, showing a balanced distribution of true
positives and true negatives with minimal false predictions.
Additional visualizations such as word clouds for positive and negative reviews, and a bar
chart comparing model accuracies, helped illustrate the differences in model behaviour and
keyword frequency. The TF-IDF vectorization technique played a crucial role in
improving classification by assigning appropriate importance to key terms, while text
preprocessing steps ensured noise-free inputs. The Flask-based web interface also
performed well, providing real-time sentiment predictions with a clean and user-friendly
experience.
Overall, the model's results confirm that machine learning algorithms, when properly
trained and tuned, can effectively analyse large-scale textual data like IMDb reviews.
However, slight inconsistencies in misclassifications highlight potential areas for
improvement, such as incorporating deep learning models or expanding the training dataset
with more nuanced sentiments.
Model Performance Comparison:
To determine the most effective algorithm for sentiment classification, multiple machine
learning models were trained and evaluated, including Naive Bayes, Logistic Regression,
Support Vector Machine (SVM), Decision Tree. Each model was assessed based on key
performance metrics such as accuracy, precision, recall, and F1-score. Among them, the
Random Forest classifier outperformed the others, demonstrating superior generalization
and robustness on unseen data. This comparison was crucial in selecting the optimal model
for deployment in the final sentiment analysis application.
As observed, the Logistic Regressor Classifier outperformed other models across all
metrics, making it the most suitable choice for deployment in the final web-based system.
This matrix illustrates that the model achieved high sensitivity (recall) and specificity, with
a relatively low number of false positives and false negatives. The true positive and true
negative counts suggest reliable generalization to unseen reviews.
Fig 4. The bar chart above visually compares the classification accuracy of four different
machine learning models used for sentiment analysis on IMDb reviews. Logistic
Regression emerged as the most accurate model among these, followed by Support Vector
Machine and Naive Bayes.
Fig 6. The confusion matrix provides a detailed breakdown of the model's performance by
comparing predicted labels against actual sentiment labels. In this case, the model correctly
classified 15,535 positive reviews as positive (true positives) and 15,660 negative
reviews as negative (true negatives). However, there were 2,468 positive reviews
incorrectly classified as negative (false negatives) and 2,337 negative reviews
misclassified as positive (false positives). These values suggest that while the model
demonstrates strong overall accuracy, there is a slightly higher tendency to misclassify
positive reviews as negative, indicating a minor imbalance that could be addressed with
further model tuning or data augmentation.
Fig 7. The word cloud for positive reviews provides a visual representation of the most
commonly used terms in favourable user feedback. It effectively captures the recurring
themes, emotions, and expressions that dominate when users express satisfaction with a
movie. Larger font sizes within the cloud indicate higher frequency of usage, reflecting the
intensity and consistency of viewer appreciation. This visual tool aids in understanding
what elements consistently contribute to positive audience reactions, such as storyline,
acting, direction, or emotional impact. By summarizing vast textual data into an easy-to-
interpret format, the word cloud enhances the qualitative insight of sentiment analysis and
supports further exploration into what viewers value most in their entertainment
experience.
Fig. 7 “Word Cloud for Positive Reviews”
The word cloud for negative reviews visually summarizes the most frequent terms found in
critical or unfavourable user feedback. It highlights the dominant expressions and recurring
themes associated with dissatisfaction, with larger words representing terms that appear
more often in negative sentiment. This visualization provides valuable insight into
common pain points or shortcomings perceived by viewers, whether related to plot, pacing,
performances, or other aspects. By distilling a large volume of textual data into an
accessible format, the word cloud helps identify patterns in audience criticism, offering
filmmakers and analysts a clearer understanding of areas that may need improvement.
The results of this study highlight the effectiveness and practicality of Logistic Regression
in performing sentiment analysis on high-dimensional textual data, such as IMDb movie
reviews. Despite the availability of more complex algorithms, Logistic Regression proved
to be a highly efficient and reliable choice for this task, striking an optimal balance
between accuracy, interpretability, and computational efficiency. Its performance was
evident through consistently strong evaluation metrics, including high F1-score, precision,
and recall
The strength of the model can be largely attributed to the preprocessing pipeline and
feature extraction techniques employed during training. Textual data often contains noise,
inconsistencies, and irrelevant information, all of which were effectively handled through
preprocessing steps such as stop-word removal, lowercasing, stemming, punctuation
removal, and tokenization. Furthermore, the use of TF-IDF (Term Frequency–Inverse
Document Frequency) vectorization enabled the transformation of text into numerical
features by emphasizing important words and downplaying commonly occurring but less
informative ones.
Although deep learning models like LSTM and BERT offer advanced capabilities in
capturing contextual relationships within text, they require significantly more
computational power, memory, and training time. In contrast, Logistic Regression
provides a lightweight and faster alternative, especially suitable for real-time sentiment
analysis applications where speed and responsiveness are key.
Finally, integrating the trained Logistic Regression model into a Flask-based web
application enhanced the project’s practical appeal. This real-time interactive platform
allows users to input movie reviews and instantly receive sentiment predictions. It
demonstrates not only the technical validity of the model but also its applicability in real-
world scenarios, bridging the gap between machine learning research and end-user
engagement. The successful deployment of this application underlines the broader utility of
sentiment analysis tools in fields such as digital marketing, customer feedback analysis,
and entertainment industry analytics.
3.3 References:
1. Maas, A. L., Daly, R. E., Pham, P. T., Huang, D., Ng, A. Y., & Potts, C. (2011).
Learning Word Vectors for Sentiment Analysis. In Proceedings of the 49th Annual
Meeting of the Association for Computational Linguistics: Human Language
Technologies (pp. 142–150).
2. Bird, S., Klein, E., & Loper, E. (2009). Natural Language Processing with Python.
O’Reilly Media Inc.
3. Pedregosa, F., Varoquaux, G., Gramfort, A., Michel, V., Thirion, B., Grisel, O., ...
& Duchesnay, É. (2011). Scikit-learn: Machine Learning in Python. Journal of
Machine Learning Research, 12, 2825–2830.
8. Loper, E., & Bird, S. (2002). NLTK: The Natural Language Toolkit. Proceedings of
the ACL-02 Workshop on Effective Tools and Methodologies for Teaching Natural
Language Processing and Computational Linguistics, 63–70.
3.4 Appendices:
The following appendices contain supplementary material referenced throughout this
project report. These materials provide additional context, data, and documentation that
support the findings and discussions presented in the main sections.
Raw Data:
This appendix contains the raw dataset used for the IMDb Movie Sentiment Analyzer
project. The dataset comprises approximately 150,000 movie reviews, each paired with a
corresponding rating on a scale from 1 to 10, as submitted by users on the IMDb platform.
These reviews were collected to analyse sentiment trends and train a machine learning
model capable of predicting sentiment (positive or neutral) based on user opinions. The
raw data includes both the textual content of the reviews and the numerical ratings. No
preprocessing (e.g., cleaning, normalization) has been applied in this appendix, ensuring
the original structure and content are preserved for transparency. This dataset forms the
backbone of the analysis, enabling insights into how numerical ratings align with textual
sentiment.
Fig. 9 “Raw Data”
Source Code:
This appendix includes the core source code developed for the IMDb Movie Sentiment
Analyzer project. The code was written in Python and makes use of libraries such as
Pandas, NumPy, Scikit-learn, NLTK. It covers all major components of the project,
including data loading, preprocessing, model building, training, evaluation, and prediction.
Requirements.txt: The requirements.txt file lists all the Python libraries and dependencies
required to run the IMDb Movie Sentiment Analyzer project. It ensures that the
development environment can be consistently recreated across different systems by
installing the exact versions of packages used. Key libraries include Pandas, NumPy,
Scikit-learn, NLTK, , and Matplotlib, among others. To set up the environment, users can
run the command pip install -r requirements.txt, which will automatically install all
listed packages. This file plays a crucial role in maintaining reproducibility and smooth
deployment of the project.
Blinker==1.8.2
click==8.1.7
colorama==0.4.6
contourpy==1.1.1
cycler==0.12.1
Flask==3.0.3
fonttools==4.54.1
importlib_metadata==8.5.0
importlib_resources==6.4.5
itsdangerous==2.2.0
Jinja2==3.1.4
joblib==1.4.2
kiwisolver==1.4.7
MarkupSafe==2.1.5
matplotlib==3.7.5
nltk==3.9.1
numpy==1.24.4
packaging==24.1
pandas==2.0.3
pillow==10.4.0
pyparsing==3.1.4
python-dateutil==2.9.0.post0
pytz==2024.2
regex==2024.9.11
scikit-learn==1.3.2
scipy==1.10.1
six==1.16.0
threadpoolctl==3.5.0
tqdm==4.66.5
tzdata==2024.2
Werkzeug==3.0.4
zipp==3.20.2
loaddata.py:
The loaddata.py script contains a function to load the IMDb dataset and preprocess it by
converting review ratings into binary sentiment labels. Ratings ≥ 7 are labelled as positive
(1), and ratings ≤ 4 as negative (0). Reviews with neutral ratings are excluded. This module
helps streamline data preparation for model training.
import pandas as pd
def load_dataset(path):
df = pd.read_csv(path, encoding='Latin-1')
df = df[df.Label<2]
data = df[['Reviews','Label']]
return data
preprocessing.py:
The processing.py module contains functions to preprocess and clean the text data before
model training. It performs essential NLP tasks including removal of stop words, special
characters, and hyperlinks, and applies lemmatization to reduce words to their base form.
This step ensures that the input text is standardized and optimized for accurate sentiment
analysis.
#Customize stopword
import re
import nltk
nltk.download('punkt_tab')
stop_words = stopwords.words('english')
new_stopwords=
["mario","la","blah","saturday","monday","sunday","morning","evening","friday","would"
,"shall","could","might"]
stop_words.extend(new_stopwords)
stop_words.remove("not")
stop_words=set(stop_words)
#Removing special character
def remove_special_character(content):
# Removing URL's
def remove_url(content):
def remove_stopwords(content):
clean_data = []
for i in content.split():
clean_data.append(i.strip().lower())
def contraction_expansion(content):
return content
#Data preprocessing
def data_cleaning(content):
content = contraction_expansion(content)
content = remove_special_character(content)
content = remove_url(content)
content = remove_stopwords(content)
return content
class DataCleaning(BaseEstimator,TransformerMixin):
def __init__(self):
print('calling--init--')
def fit(self,X,y=None):
print('calling fit')
return self
print('calling transform')
X=X.apply(data_cleaning)
return X
# lemmatization of word
class LemmaTokenizer(object):
def __init__(self):
self.wordnetlemma = WordNetLemmatizer()
vectorizer.py:
The vectorizer.py module defines a class that implements text vectorization techniques
used to convert cleaned reviews into numerical form. It includes methods for both Bag of
Words (BoW) and TF-IDF (Term Frequency–Inverse Document Frequency) vectorization.
These methods transform textual data into feature vectors that can be used effectively by
machine learning models for sentiment classification.
from sklearn.feature_extraction.text import CountVectorizer
class BowVectors(BaseEstimator,TransformerMixin):
def __init__(self):
print('calling--init--')
self.bow_vectorizer = CountVectorizer()
def fit(self,df):
print('calling fit')
return self
print('calling transform')
features = self.bow_vectorizer.transform(df)
# Tfidf Vectorizer
class TfidfVectors():
def __init__(self):
self.tfidf_vectorizer = TfidfVectorizer(lowercase=False,ngram_range=(1,1))
def __call__(self, df):
features = self.tfidf_vectorizer.fit_transform(df)
class Vectorizer:
self.vectorizer = model["VECT"]
try:
X = self.vectorizer.fit_transform(text_array)
except:
X = self.vectorizer.fit_transform([text_array])
return X
try:
X = self.vectorizer.transform(text_array)
X = self.vectorizer.transform(text_array[0])
return X
evaluation.py:
The evaluation.py module provides functions to evaluate the performance of the sentiment
analysis model. It includes tools to plot precision scores and generate a confusion matrix,
offering visual insights into the model’s accuracy, precision, recall, and overall
classification performance. These visualizations help in assessing how well the model
distinguishes between positive and negative sentiments.
def precision_score_plot(y_test,y_score):
fig, ax = plt.subplots()
ax.set_ylabel('Precision')
ax.set_xlabel('Recall')
#display plot
plt.show()
def confusion_matrix_plot(y_test,y_score):
confmatrix = confusion_matrix(y_test,y_score)
ax.imshow(confmatrix)
ax.grid(False)
ax.set_ylim(1.5, -0.5)
for i in range(2):
for j in range(2):
plt.show()
index.html:
The index.html file defines the frontend interface for the IMDb Sentiment Analyzer,
integrated using Flask. It provides a simple and user-friendly web interface where users
can input movie reviews and view the predicted sentiment (positive or negative). The
HTML layout includes form elements for text input and a submit button, with the response
displayed dynamically upon submission.
<!DOCTYPE html>
<html>
<head>
<title>Sentiment Analysis</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<style>
body {
.container {
margin-top: 50px;
}
h1 {
.form-control {
.btn-primary {
border-color: #007bff;
.btn-primary:hover {
border-color: #0062cc;
.alert-success {
.alert-danger {
border-color: #f5c6cb;
</style>
<body>
<div class="form-group">
</div>
</form>
{% if pred is defined %}
<div class="mt-4">
{% if pred == 1 %}
{% else %}
{% endif %}
</div>
{% endif %}
<br>
<br>
</div>
</body>
</html>
main.py:
The main.py file serves as the central script that brings together all the modules of the
IMDb Sentiment Analyzer. It imports functions from loaddata.py, processing.py,
vectorizer.py, and evaluation.py to load, preprocess, vectorize, train, and evaluate the
model. After training, the final sentiment analysis model is saved using joblib for later use
in deployment via the Flask interface.
import sys
import os
import joblib
import datapreprocessing.preprocessing as dp
path = os.getcwd()+r'\Dataset'
data=load_dataset(path+'\IMDB-Dataset.csv')
#Split data
text_clf.fit(x_train,y_train)
y_predict=text_clf.predict(x_test)
y_score = text_clf.predict_proba(x_test)[:, 1]
f1_score_train_1 =f1_score(y_test,y_predict,average="weighted")
confusion_matrix_plot(y_test, y_predict)
model_path = os.getcwd()+r'\models'
joblib.dump(text_clf, model_path+r'\classifier.pkl',compress=True)
sentimentanalyzer.py:
The sentiment_analyzer.py file is the Flask application that connects the trained sentiment
analysis model with the web interface. It loads the saved model and handles user input
from the index.html form. When a user submits a movie review, the app preprocesses the
input, vectorizes it, and uses the model to predict the sentiment, which is then displayed on
the webpage. This file enables real-time sentiment prediction through a simple and
interactive interface.
import joblib
import pandas as pd
import datetime
import os
app = Flask(__name__)
#model_path = os.getcwd()+r'\sentimentanalysis\models\model'
model_path = os.getcwd()+r'\models'
classifier = joblib.load(model_path+r'\classifier.pkl')
def predictfunc(review):
prediction = classifier.predict(review)
if prediction[0]==1:
sentiment='Positive'
else:
sentiment='Negative'
return prediction[0],sentiment
@app.route('/', methods=['GET','POST'])
def predict():
if request.method == 'POST':
content = request.form.get('review')
review = pd.Series(content)
prediction,sentiment =predictfunc(review)
return render_template("index.html",pred=prediction,sent=sentiment)
return render_template("index.html")
if __name__ == '__main__':
#app.run(debug = True,port=8080)
app.run(host='0.0.0.0', debug=True)
Output:
Input:
6. Dashboard Integration
Develop a dashboard interface using tools like Dash or Streamlit to visualize
sentiment trends, word clouds, and user insights interactively.
Among the various models evaluated—such as Naive Bayes, Logistic Regression, SVM,
and Decision Trees—the Random Forest classifier emerged as the most effective,
achieving the highest F1-score and overall accuracy. The use of TF-IDF vectorization for
feature extraction further enhanced the model's performance by assigning appropriate
weights to significant terms in the review text.
Overall, the project illustrates the power of combining NLP techniques with machine
learning to extract meaningful insights from unstructured text data. While the current
system focuses on binary sentiment classification (positive/negative), it lays the foundation
for future extensions, such as multi-class sentiment analysis, emotion detection, or
multilingual support. With continued development, such systems can become even more
accurate, nuanced, and widely applicable in the realm of digital content analytics.