DeBERTa Emotion Predictor
This package provides a DeBERTa-based model for predicting emotions in Japanese text.
DeBERTa Emotion Predictor は、ファインチューニング済みの DeBERTa モデルを用いて日本語テキストの感情推定を行う Python パッケージです。8 つの感情(Joy, Sadness, Anticipation, Surprise, Anger, Fear, Disgust, Trust)に対するそれぞれのモデルを利用し、各テキストに対する感情の予測ラベルと肯定クラスの確信度を簡単に取得できます。
Install(インストール)
pip を使います。
python -m pip install deberta-emotion-predictor
バージョン 1.2.1 では、互換性を確認済みの Transformers 4 系
(transformers>=4.48.2,<5)が自動的にインストールされます。
すでに旧バージョンを利用している場合は、次のコマンドで更新してください。
python -m pip install --upgrade deberta-emotion-predictor
## Usage (おためし利用)
from deberta_emotion_predictor import DeBERTaEmotionPredictor
predictor = DeBERTaEmotionPredictor()
result = predictor.predict_emotions("今日はとても嬉しい!")
predictor.show_emotions(result)
注)Hugging-face から8種類のDeBERTaをダウンロードするため、初回起動に大変時間がかかります。二回目以降の実行から速くなります。
データフレームも入力できます。
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)
動作に必要な torch、transformers、pandas はパッケージと一緒に
インストールされるため、個別にインストールする必要はありません。
バージョン 1.2.0 以前でトークナイザーの読み込み時に KeyError: 0 が発生する場合は、
次のコマンドで Transformers 4 系へ戻すことでも一時的に復旧できます。
python -m pip install --upgrade "transformers>=4.48.2,<5"
また、GPUを使用するには、NVIDIA GPUドライバー等のインストールが必要です。 こちらは、他の資料を参照してください。
特徴
-
8感情の推定
各感情ごとにファインチューニング済みのモデルを利用し、テキストの感情推定を行います。 -
柔軟な入力形式
単一のテキスト、テキストのリスト、または pandas Series を入力として受け付け、結果を DataFrame 形式で返します。 -
効率的な推論
GPU メモリの使用量を抑えるため、必要なときだけモデルを GPU にロードする設計になっています。
使用方法
以下は、パッケージの基本的な使い方の例です:
テキストの渡し方(リスト)
sample_texts = [
"そうだ 京都、行こう。",
"がんばるひとの、がんばらない時間。"
]
result_df = predictor.predict_emotions(sample_texts)
predictor.show_emotions(result_df)
単一のテキストの場合
result_single = predictor.predict_emotions("新しい朝が来た。")
print(result_single)
出力されるデータフレーム
出力されるデータフレームには、各感情の有無をあらわす8つの列、及び各感情の確率値が格納されています。
print(result_df)
ディレクトリ構成
deberta_emotion_predictor/
├── README.md # この説明ファイル
├── deberta_emotion_predictor.py # DeBERTaEmotionPredictor クラスの実装
│ └── tokenizer_DeBERTa_v3_large/ #トークナイザー
├── setup.py
├── pyproject.toml
├── README.md
├── LICENSE
└── usage.py
必要環境
- Python 3.9 以上
- PyTorch
- Transformers 4.48.2 以上、5.0.0 未満
- pandas
License
Creative Commons Attribution-ShareAlike 4.0 International (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.
Metadata
Release files for deberta-emotion-predictor 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deberta_emotion_predictor-1.2.1.tar.gz | 6.8 kB | Without provenance | Details for deberta_emotion_predictor-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deberta_emotion_predictor-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for deberta_emotion_predictor-1.2.1-py3-none-any.whl |
Total release size: 14.8 kB
Release files / deberta_emotion_predictor-1.2.1.tar.gz
| Download URL | deberta_emotion_predictor-1.2.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4601d62c4df97bbfac54d21748983a4ba5bb2350814d9ef530437cb5666dbbf1
|
|
BLAKE2b-256 checksum How to use checksums |
0a1e8f5934ede38692965991f765c741c91439417fa5654b94a776dda6c08098
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / deberta_emotion_predictor-1.2.1-py3-none-any.whl
| Download URL | deberta_emotion_predictor-1.2.1-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e30ca030abd16c009d247d4f577ddfe80573dab61d0b6f7fe738e3bde0a1c8d2
|
|
BLAKE2b-256 checksum How to use checksums |
39bb8b048b793e439710ecb03a076f3d1662834dcb61132dbf4bdefda941be81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for deberta-emotion-predictor 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.