Skip to main content

A DeBERTa-based emotion predictor for Japanese text.

Project description

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 を使います。

pip install 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

# model_dir は、言語モデルとトークナイザがある場所を指しています
predictor = DeBERTaEmotionPredictor()

# サンプルテキスト(リスト形式)
sample_texts = [
    "そうだ 京都、行こう。",
    "がんばるひとの、がんばらない時間。",
    "わたしらしくをあたらしく",
    "ピースはここにある。",
    "結婚しなくても幸せになれるこの時代に、私は、あなたと結婚したいのです。",
    "これからの地球のために一肌、脱ぎました。",
    "自分は、きっと想像以上だ。",
    "ハローしあわせ。",
    "日本を、1枚で。"
]
res_df = predictor.predict_emotions(sample_texts)

predictor.show_emotions(res_df)

なお動作には torch, transformers, pandas が必要です。

pip install torch 
pip install transformers
pip install pandas 

また、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.6 以上
  • PyTorch
  • transformers
  • 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:

Any modifications or derivative works must also be distributed under the same CC BY-SA 4.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deberta_emotion_predictor-1.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deberta_emotion_predictor-1.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file deberta_emotion_predictor-1.1.0.tar.gz.

File metadata

File hashes

Hashes for deberta_emotion_predictor-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6d1b6dca49c34fd8176c5a4679b2f18553f1fe603d8256e9f6015a92a147f2e1
MD5 8228ba639654340d3c4dc077724f09a8
BLAKE2b-256 01c3c194b99ae009710ae9e6c2cb34332b262de7caf418adca33d375f2b29da6

See more details on using hashes here.

File details

Details for the file deberta_emotion_predictor-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for deberta_emotion_predictor-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79b3f76a96b26b983fca1c7cdc079a58cd4c564afbac3075a0b169fcace7e3b9
MD5 0539ee17ecfe7d0ba86ca7bb76e9b8db
BLAKE2b-256 7da9f2925f845deb888f9fa6f4113c76a632dac6dac99c64e04cf741a995a7fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page