Skip to content

Persian text emotion recognition by fine tuning the XLM-RoBERTa Model + Bidirectional GRU layer.

License

Notifications You must be signed in to change notification settings

faezesarlakifar/text-emotion-recognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract

Emotion recognition in text is a fundamental aspect of natural language understanding, with significant applications in various domains such as mental health monitoring, customer feedback analysis, content recommendation systems, and chatbots. In this paper, we present a hybrid model for predicting the presence of six emotions: anger, disgust, fear, sadness, happiness, and surprise in Persian text. We also predict the primary emotion in the given text, including these six emotions and the “other” category. Our approach involves the utilization of XLM-RoBERTa, a pre-trained transformer-based language model, and fine-tuning it on two diverse datasets: EmoPars and ArmanEmo. Central to our approach is incorporating a single Bidirectional Gated Recurrent Unit (BiGRU), placed before the final fully connected layer. This strategic integration empowers our model to capture contextual dependencies more effectively, resulting in an improved F-score after adding this BiGRU layer. This enhanced model achieved a 2% improvement in the F-score metric on the ArmanEmo test set and a 7% improvement in the F-score metric for predicting the presence of six emotions on the final test set of the ParsiAzma Emotion Recognition competition.

Goals

1. Predicting All Emotions Existence:

for each of the 6 classes, predict a binary label, meaning either the emotion is present in the given text or not. The emotions we consider are:

  • Anger
  • Disgust
  • Fear
  • Sadness
  • Happiness
  • Surprise

2. Predicting the Primary Emotion within 7 classes:

Predicting a single emotion that primarily represents the emotion of the given text within those 6 classes, along with an additional 'other' class for cases when the given text does not belong to one of those 6 classes.

Datasets

The utilized dataset for this study includes two publicly available Datasets:

  • ArmanEmo Dataset: Link
  • EmoPars Dataset: Link

Model Architecture

final model architecture

Hugging Face Model

Model Checkpoints Availability

We have made our pre-trained model checkpoints available on Hugging Face. You can download the model checkpoints directly from the following links:

  • model_ae.pth: The AE model checkpoint for All Emotion existence prediction.
  • model_pe.pt: The PE model checkpoint for Primary Emotion recognition.

Hugging Face Badge

To quickly access the model page, click the badge below:

Hugging Face

These models are ready for inference and easily loaded into your code.

How to Make Predictions

AE_PATH = 'model_ae.pth'
PE_PATH = 'model_pe.pt'

checkpoint_ae = torch.load(AE_PATH, map_location=torch.device('cpu'))
model_ae.load_state_dict(checkpoint_ae)

checkpoint_pe = torch.load(PE_PATH, map_location=torch.device('cpu'))
model_pe.load_state_dict(checkpoint_pe)

pe_predict(test_file,model_pe,tokenizer)
pe_prediction = pe_predict(test_file,model_pe,tokenizer)
ae_prediction = ae_predict(test_file,model_ae,tokenizer)

ae_prediction['primary_emotion'] = pe_prediction['primary_emotion']
final_result.to_csv('final_result.csv')

Results

1. ParsiAzma competition final results

🏆 Second Place. =)

Result Table

Acknowledgement

We want to thank the organizers of the ParsiAzma National Competition for providing the opportunity to conduct this research. Their dedication to studying and working in the emotion recognition area has been a driving force behind our project.

Citation:

If you find our work valuable and it contributes to your research or projects, we kindly request that you use the following citation:

@ARTICLE{EmoRecBiGRU, 
author = {Sarlakifar, Faezeh and Mahdavi Mortazavi, Morteza and Shamsfard, Mehrnoush},  
title = {EmoRecBiGRU: Emotion Recognition in Persian Tweets with a Transformer-based Model, Enhanced by Bidirectional GRU}, 
volume = {16}, 
number = {3},  
URL = {http://journal.itrc.ac.ir/article-1-653-en.html},  
eprint = {http://journal.itrc.ac.ir/article-1-653-en.pdf},  
journal = {International Journal of Information and Communication Technology Research},   
year = {2024}  
}

About

Persian text emotion recognition by fine tuning the XLM-RoBERTa Model + Bidirectional GRU layer.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published