๐ DeBERTa Emotion Predictor
This package provides a DeBERTa-based model for predicting emotions in Japanese text. It uses fine-tuned DeBERTa models to estimate emotions in Japanese text. You can easily obtain the predicted emotion labels and the confidence of the positive class for each text using models for eight emotions (Joy, Sadness, Anticipation, Surprise, Anger, Fear, Disgust, Trust).
๐ Quick Start
โจ Features
- Eight Emotion Prediction: Utilize fine-tuned models for each emotion to perform emotion prediction on text.
- Flexible Input Formats: Accept single texts, text lists, or pandas Series as input and return results in DataFrame format.
- Efficient Inference: Designed to load the model to the GPU only when necessary to reduce GPU memory usage.
๐ฆ Installation
Use pip to install the package:
pip install deberta-emotion-predictor
In addition, the following dependencies are required:
pip install torch
pip install transformers
pip install pandas
Note: To use the GPU, you need to install the NVIDIA GPU driver. Please refer to other materials for this.
๐ป Usage Examples
Basic Usage
from deberta_emotion_predictor import DeBERTaEmotionPredictor
predictor = DeBERTaEmotionPredictor()
result = predictor.predict_emotions("ไปๆฅใฏใจใฆใๅฌใใ๏ผ")
predictor.show_emotions(result)
Important Note:
Since eight types of DeBERTa models are downloaded from Hugging-face, the first startup takes a long time. It will be faster from the second execution onwards.
Advanced Usage
You can also input a DataFrame:
import pandas as pd
from deberta_emotion_predictor import DeBERTaEmotionPredictor
predictor = DeBERTaEmotionPredictor()
sample_texts = [
"ใใใ ไบฌ้ฝใ่กใใใ",
"ใใใฐใใฒใจใฎใใใใฐใใชใๆ้ใ",
"ใใใใใใใใใใใใ",
"ใใผในใฏใใใซใใใ",
"็ตๅฉใใชใใฆใๅนธใใซใชใใใใฎๆไปฃใซใ็งใฏใใใชใใจ็ตๅฉใใใใฎใงใใ",
"ใใใใใฎๅฐ็ใฎใใใซไธ่ใ่ฑใใพใใใ",
"่ชๅใฏใใใฃใจๆณๅไปฅไธใ ใ",
"ใใญใผใใใใใ",
"ๆฅๆฌใใ1ๆใงใ"
]
res_df = predictor.predict_emotions(sample_texts)
predictor.show_emotions(res_df)
Directory Structure
deberta_emotion_predictor/
โโโ README.md # This description file
โโโ deberta_emotion_predictor.py # Implementation of the DeBERTaEmotionPredictor class
โ โโโ tokenizer_DeBERTa_v3_large/ # Tokenizer
โโโ setup.py
โโโ pyproject.toml
โโโ README.md
โโโ LICENSE
โโโ usage.py
Required Environment
- Python 3.6 or higher
- PyTorch
- transformers
- pandas
๐ License
This project is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0).
Copyright (c) 2025 Yoichi Takenaka
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0/.
This project is based on:
- DeBERTa (https://huggingface.co/microsoft/deberta-v3-large), licensed under the MIT License.
- DeBERTa Japanese Model (https://huggingface.co/globis-university/deberta-v3-japanese-large), licensed under the CC BY-SA 4.0 License.
Any modifications or derivative works must also be distributed under the same CC BY-SA 4.0 License.