File size: 1,109 Bytes
7a9be32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89ed20a
7a9be32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81b734c
7a9be32
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---
license: mit
language:
- ja
base_model:
- tohoku-nlp/bert-base-japanese-whole-word-masking
---

# eBERTの概要
eBERTは[wrimeデータセット](https://github.com/ids-cv/wrime)に基づく感情予想bertモデルです。<br>
eBERTは東北大学自然言語処理研究グループ様の[日本語事前学習済みbertモデル](https://huggingface.co/tohoku-nlp/bert-base-japanese-whole-word-masking)を使用しました。

# 使用方法
```python
from transformers import BertForSequenceClassification, AutoTokenizer
import numpy as np

emotions = ['喜び', '悲しみ', '期待', '驚き', '怒り', '恐れ', '嫌悪', '信頼']

model = BertForSequenceClassification.from_pretrained("beezza/eBERT")
tokenizer = AutoTokenizer.from_pretrained("beezza/eBERT")

def softmax(x):
    f_x = np.exp(x) / np.sum(np.exp(x))
    return f_x

model.eval()

tokens = tokenizer("テキスト", truncation=True, return_tensors="pt")
tokens.to(model.device)
preds = model(**tokens)
prob = softmax(preds.logits.cpu().detach().numpy()[0])
out_dict = {n: p for n, p in zip(emotions, prob)}

print(out_dict)
```