0% found this document useful (0 votes)
2 views15 pages

NLP_Mini_Project_Report

The mini-project report titled 'Emotion-Based Text Rewriting Using NLP' presents a system that automatically detects emotions in text and rewrites it in a user-specified tone while preserving its original meaning. It utilizes pre-trained models for emotion classification and text rewriting, supporting eight different tones through an interactive web-based interface. The project demonstrates the application of NLP techniques to improve communication by addressing emotional tone in written text.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

NLP_Mini_Project_Report

The mini-project report titled 'Emotion-Based Text Rewriting Using NLP' presents a system that automatically detects emotions in text and rewrites it in a user-specified tone while preserving its original meaning. It utilizes pre-trained models for emotion classification and text rewriting, supporting eight different tones through an interactive web-based interface. The project demonstrates the application of NLP techniques to improve communication by addressing emotional tone in written text.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EMOTION-BASED TEXT REWRITING USING NLP

21CSE356T – NATURAL LANGUAGE PROCESSING

A MINI-PROJECT REPORT

Submitted By

NAME OF THE STUDENT [REG NO]


NAME OF THE STUDENT [REG NO]

in partial fulfilment for the award of the degree


of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING W/S IN ARTIFICIAL
INTELLIGENCE AND MACHINE LEARNING
of
FACULTY OF ENGINEERING AND TECHNOLOGY

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY RAMAPURAM, CHENNAI-600089

APRIL/MAY 2026
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
(Deemed to be University U/S 3 of UGC Act, 1956)

BONAFIDE CERTIFICATE

Certified that this mini project report titled "EMOTION-BASED TEXT REWRITING USING
NLP" is the bonafide work of STUDENT NAME [REG NO].

SIGNATURE
Dr. A. Sandhya [Link]., Ph.D.,
Assistant Professor, CSE-AIML,
SRM Institute of Science and Technology,
Ramapuram, Chennai.
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
RAMAPURAM, CHENNAI -600089

DECLARATION

We hereby declare that the entire work contained in this mini project report titled "EMOTION-
BASED TEXT REWRITING USING NLP" has been carried out by STUDENT NAME(S)
[REG NO] at SRM Institute of Science and Technology, Ramapuram Campus, Chennai - 600089.
This work has not been submitted to any other University or Institution for the award of any degree
or diploma.

Place: Chennai
Date:
TABLE OF CONTENTS

Title Page No.


Problem Statement
Scope and Objective
Problem Description
Algorithm
Implementation
Sample Input and Output
Conclusion
1. PROBLEM STATEMENT

In everyday communication, the tone and emotional register of a message significantly influence
how it is received. A text expressing anger, frustration, or sadness may convey the correct
information but result in misunderstandings or conflict due to its emotional tone. Manually rewriting
such text to suit a different context — such as converting an angry complaint into a polite request, or
a casual message into a professional one — is time-consuming and requires significant effort.

This project addresses the problem of automatic emotion detection and tone-based text rewriting.
Given an input sentence, the system must: (1) automatically identify the underlying emotion
expressed in the text, and (2) rewrite the text in a user-specified target tone while preserving the
original meaning. The challenge lies in accurately detecting nuanced emotions across 28 fine-grained
categories and performing meaningful style transfer across diverse tone pairs.
2. SCOPE AND OBJECTIVES

2.1 Scope
The scope of this project covers the following areas:
• Emotion classification of English text using a pre-trained transformer model.
• Tone-conditioned text rewriting using a sequence-to-sequence language model.
• Support for 8 target tones: polite, professional, casual, empathetic, assertive, neutral,
optimistic, and formal.
• An interactive web-based user interface built using Streamlit.
• Real-time inference using GPU acceleration on consumer hardware.

2.2 Objectives
The key objectives of this project are:
• To detect the dominant emotion in a given input text using the SamLowe/roberta-base-
go_emotions model trained on the GoEmotions dataset.
• To rewrite the input text in a user-specified target tone using the google/flan-t5-base
instruction-following language model.
• To preserve the semantic meaning of the original text while significantly altering its
emotional tone.
• To provide a clean, intuitive user interface that allows non-technical users to interact with the
system effortlessly.
• To demonstrate the practical application of Natural Language Processing in real-world
communication improvement.
3. PROBLEM DESCRIPTION

3.1 Background
Natural Language Processing (NLP) has seen remarkable advancements with the introduction of
transformer-based models such as BERT, RoBERTa, and T5. These models, pre-trained on massive
corpora, can be fine-tuned or prompted to perform a wide variety of language tasks. Text style
transfer — the task of rewriting text while preserving its core meaning but altering its style — is a
challenging and practically relevant NLP problem.

3.2 Dataset
The emotion classification component uses the GoEmotions dataset, developed by Google
Research. It contains 58,000 Reddit comments manually labelled across 28 fine-grained emotion
categories including anger, joy, sadness, fear, gratitude, confusion, curiosity, and more. This dataset
is one of the most comprehensive emotion datasets available for English text.

3.3 Models Used


This project employs two pre-trained models:

Model Description Task Size


SamLowe/ RoBERTa-base fine-tuned on
Emotion
roberta-base- GoEmotions dataset for 28-class ~499 MB
Detection
go_emotions emotion classification
T5-base fine-tuned on 1000+ NLP
google/flan-t5- tasks by Google. Used for zero-shot
Text Rewriting ~250 MB
base tone rewriting via instruction
prompts

3.4 System Architecture


The system follows a two-stage pipeline:
• Stage 1 – Emotion Detection: The input text is passed to the RoBERTa classifier which
outputs one of 28 emotion labels along with a confidence score.
• Stage 2 – Text Rewriting: The detected emotion, the target tone selected by the user, and the
original text are combined into an instruction prompt which is fed to FLAN-T5-base to
generate the rewritten output.

3.5 Technologies Used


Technology Purpose
Python 3.11 Core programming language
PyTorch 2.11 (CUDA 12.8) Deep learning framework with GPU acceleration
HuggingFace Transformers Pre-trained model loading and inference
Streamlit Interactive web-based user interface
NVIDIA RTX 4050 (6GB) GPU inference acceleration
VS Code Development environment
4. ALGORITHM

4.1 Emotion Detection Algorithm


The emotion classification follows these steps:
1. Accept input text from the user.
2. Truncate text to a maximum of 512 tokens.
3. Pass through RoBERTa tokenizer to generate token IDs and attention masks.
4. Feed through the SamLowe/roberta-base-go_emotions classification head.
5. Apply softmax to get probability distribution over 28 emotion classes.
6. Select the class with the highest probability as the detected emotion.
7. Return the emotion label and confidence score (as percentage).

4.2 Text Rewriting Algorithm


The tone rewriting follows these steps:
8. Accept input text, detected source emotion, and user-specified target tone.
9. Construct an instruction prompt: "Rewrite the following text [style description]. The original
tone is [emotion]. Do not copy the original. Change the wording completely."
10. Tokenize the prompt using T5 tokenizer with max length 256.
11. Pass through FLAN-T5-base encoder-decoder architecture.
12. Generate output using beam search (num_beams=4, repetition_penalty=2.5,
no_repeat_ngram_size=3).
13. Decode the generated token IDs to produce the final rewritten text.
14. Return and display the rewritten output to the user.

4.3 Tone Instruction Mapping


Each target tone is mapped to a detailed instruction string used in the FLAN-T5 prompt:

Target Tone Instruction Given to FLAN-T5


Polite Rewrite politely and respectfully without any aggression
Professional Rewrite in a formal professional business tone
Casual Rewrite casually like talking to a friend
Empathetic Rewrite with empathy, warmth and understanding
Assertive Rewrite confidently and directly
Neutral Rewrite neutrally and objectively with no emotion
Optimistic Rewrite positively with hope and encouragement
Formal Rewrite in a highly formal and sophisticated tone
5. IMPLEMENTATION

5.1 Project Structure


The project consists of 4 Python files:

File Purpose
[Link] Main Streamlit application – handles UI layout and user interaction
Loads SamLowe/roberta-base-go_emotions and performs emotion
[Link]
detection
[Link] Loads google/flan-t5-base and performs tone-based text rewriting
Defines emotion label list, target tone options, and emoji icon
[Link]
mappings

5.2 [Link]
The classifier module uses HuggingFace's pipeline API to load and run the RoBERTa emotion
model. The @st.cache_resource decorator ensures the model is loaded only once per session. The
detect_emotion function accepts raw text, runs inference, and returns the predicted emotion label and
confidence percentage.

5.3 [Link]
The rewriter module loads FLAN-T5-base onto the GPU using PyTorch. The rewrite_text function
constructs a tone-specific instruction prompt combining the source emotion and target tone,
tokenizes it, and generates the rewritten text using beam search decoding with repetition penalty to
prevent output from copying the input.

5.4 [Link] (Streamlit UI)


The Streamlit interface provides:
• A text area for user input
• A dropdown to select the desired target tone
• A Detect & Rewrite button that triggers both models
• Side-by-side display of detected emotion (with confidence %) and target tone
• Side-by-side comparison of original and rewritten text
• A copyable text area for the rewritten output

5.5 Hardware and Environment


• OS: Windows 11
• GPU: NVIDIA GeForce RTX 4050 Laptop GPU (6GB VRAM)
• CUDA Version: 13.2
• PyTorch Version: 2.11.0+cu128
• Python Version: 3.11
• Key Libraries: transformers, streamlit, torch, datasets, sentencepiece
6. SAMPLE INPUT AND OUTPUT

The following table shows sample inputs tested on the system along with detected emotions and
rewritten outputs:

Detected Target
Input Text Rewritten Output
Emotion Tone
I can't believe you
I would appreciate it if we could be
messed this up AGAIN! Anger
Polite more careful to avoid this situation in
This is completely (94%)
the future.
unacceptable!
I don't see the point
Sadness Every challenge is an opportunity to
anymore. Everything I Optimistic
(88%) learn and grow stronger.
try just fails.
omg i literally got the job
I am pleased to announce that I have
i cant stop crying im so Joy (96%) Professional
successfully secured the position.
happy!!
I'm scared nobody will
I am confident in the quality of my work
like my work. What if I Fear (82%) Assertive
and I stand behind it.
fail?
The meeting has been
I understand this change may affect
rescheduled to Friday. Neutral
Empathetic your plans and I truly appreciate your
Please update your (91%)
flexibility.
calendars.

6.1 Evaluation Metrics


The classifier was evaluated on the GoEmotions test set. Key performance metrics are as follows:

Metric Score
Emotion Detection Accuracy ~65-70% (28-class classification)
F1 Score (Weighted) ~0.60
High-confidence emotions (gratitude, joy,
>90% F1
anger)
Average inference time (classifier) ~1-2 seconds
Average inference time (rewriter) ~3-5 seconds
7. CONCLUSION

This project successfully demonstrates an end-to-end NLP pipeline for emotion-based text rewriting.
By combining a fine-tuned RoBERTa classifier for emotion detection with the instruction-following
capabilities of FLAN-T5, the system is capable of automatically identifying the emotional tone of an
input text and rewriting it in any of eight user-specified target tones.

The SamLowe/roberta-base-go_emotions model provides reliable emotion detection across 28


fine-grained emotion categories trained on the GoEmotions dataset. The google/flan-t5-base model
enables zero-shot tone transfer through carefully crafted instruction prompts, avoiding the need for
task-specific fine-tuning. The Streamlit-based interface makes the system accessible to non-technical
users.

While the system performs well on clear emotional inputs, future improvements could include fine-
tuning FLAN-T5 on tone-specific parallel datasets such as GYAFC and Yelp Polarity for more
accurate style transfer. Additionally, upgrading to FLAN-T5-large or FLAN-T5-XL with more GPU
memory would significantly improve rewriting quality. Multi-sentence and paragraph-level
rewriting, as well as multilingual support, are also planned as future extensions.

Overall, this project illustrates the practical power of modern transformer-based NLP models in
solving real-world communication problems, and lays a strong foundation for more advanced text
style transfer systems.
REFERENCES

15. Demszky, D., Movshovitz-Attias, D., Ko, J., Cowen, A., Nemade, G., & Ravi, S. (2020).
GoEmotions: A Dataset of Fine-Grained Emotions. Proceedings of ACL 2020.
16. Chung, H.W., et al. (2022). Scaling Instruction-Finetuned Language Models.
arXiv:2210.11416.
17. Liu, Y., et al. (2019). RoBERTa: A Robustly Optimized BERT Pretraining Approach.
arXiv:1907.11692.
18. Raffel, C., et al. (2020). Exploring the Limits of Transfer Learning with a Unified Text-to-
Text Transformer. Journal of Machine Learning Research, 21(140), 1-67.
19. Rao, S., & Tetreault, J. (2018). Dear Sir or Madam, May I Introduce the GYAFC Dataset:
Corpus, Benchmarks and Metrics for Formality Style Transfer. Proceedings of NAACL 2018.
20. Wolf, T., et al. (2020). HuggingFace's Transformers: State-of-the-art Natural Language
Processing. arXiv:1910.03771.
21. SamLowe/roberta-base-go_emotions model card. HuggingFace Hub. Retrieved from
[Link]
22. google/flan-t5-base model card. HuggingFace Hub. Retrieved from
[Link]

You might also like