
Emotion Text Classification with RoBERTa
Emotion text classification can be approached using various techniques in natural language processing (NLP), including rule-based methods, machine learning algorithms, and deep learning models. These approaches aim to extract features from the text and train models to classify the text into different emotion categories.
Emotion Text Classification
Summary
Introduction
Emotion text classification can be approached using various techniques in natural language processing (NLP), including rule-based methods, machine learning algorithms, and deep learning models. These approaches aim to extract features from the text and train models to classify the text into 6 different emotion categories: sadness, joy, love, anger, fear, surprise.
Parameters
Inputs
- input - (text): The textual information provided by the user needs to be analyzed to determine the type of emotion.
Output
- output - (text): Includes the model's predictions for each label, displayed as probabilities, with 6 types of emotion labels.
Examples
input | output |
---|---|
Ugh! I have to beat this stupid song to get to the next rude! | ![]() |
Usage for developers
Please find below the details to track the information and access the code for processing the model on our platform.
Requirements
torch
transformers
Code based on AIOZ structure
import torch, os
from transformers import pipeline
...
def do_ai_task(
input: Union[str, Path],
model_storage_directory: Union[str, Path],
device: Literal["cpu", "cuda", "gpu"] = "cpu",
*args, **kwargs) -> Any:
"""Define AI task: load model, pre-process, post-process, etc ..."""
# Define AI task workflow. Below is an example
device = "cuda" if torch.cuda.is_available() else "cpu"
path_weight = os.path.abspath(model_storage_directory + "/...")
with torch.no_grad():
model = pipeline("text-classification", model=path_weight, device= device)
label = model(input)[0]["label"]
return str(label)
Reference
This repository is based on and inspired by Muntasir Hossain's work, which is a fine-tuned version of roberta-based on the emotion dataset. We sincerely appreciate their generosity in sharing the code.
License
We respect and comply with the terms of the author's license cited in the Reference section.
Citation
@article{DBLP:journals/corr/abs-1907-11692,
author = {Yinhan Liu and
Myle Ott and
Naman Goyal and
Jingfei Du and
Mandar Joshi and
Danqi Chen and
Omer Levy and
Mike Lewis and
Luke Zettlemoyer and
Veselin Stoyanov},
title = {RoBERTa: {A} Robustly Optimized {BERT} Pretraining Approach},
journal = {CoRR},
volume = {abs/1907.11692},
year = {2019},
url = {http://arxiv.org/abs/1907.11692},
archivePrefix = {arXiv},
eprint = {1907.11692},
timestamp = {Thu, 01 Aug 2019 08:59:33 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-1907-11692.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}