Instructions to use TomokiFujihara/twhin-bert-large-japanese-offensiveness-estimation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TomokiFujihara/twhin-bert-large-japanese-offensiveness-estimation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="TomokiFujihara/twhin-bert-large-japanese-offensiveness-estimation", trust_remote_code=True)# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("TomokiFujihara/twhin-bert-large-japanese-offensiveness-estimation", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
# モデル概要
|
| 6 |
+
このモデルは、 Twitter/twhin-bert-large をSNS上のコメントに人手で攻撃性評価を行ったデータセットでFine-tuningすることで作成しました。
|
| 7 |
+
|
| 8 |
+
# Fine-tuning条件
|
| 9 |
+
- エポック数: 27エポック
|
| 10 |
+
- バッチサイズ: 16
|
| 11 |
+
- 最大トークン長: 256
|
| 12 |
+
- 学習率スケジューラ: transformers.get_linear_schedule_with_warmup
|
| 13 |
+
- ピーク学習率: 2e-5
|
| 14 |
+
- 最適化手法: Adam
|
| 15 |
+
- Dropout率: 0.1
|
| 16 |
+
- 損失関数: MSE Loss
|
| 17 |
+
- Re-initialize: 出力層から近い Transformer Encoder 1層
|
| 18 |
+
|
| 19 |
+
# 分類性能
|
| 20 |
+
**Summary**
|
| 21 |
+
| 評価指標 | スコア |
|
| 22 |
+
| ----- | ----- |
|
| 23 |
+
| F値_NOT | |
|
| 24 |
+
| F値_GRY | |
|
| 25 |
+
| F値_OFF | |
|
| 26 |
+
| マクロ平均F値 | |
|
| 27 |
+
| 正解率 | |
|
| 28 |
+
|
| 29 |
+
**Confusion matrix**
|
| 30 |
+
| 正解ラベル \ 予測結果 | Not Offensive | Gray-area | Offensive |
|
| 31 |
+
| ----- | ----- | ----- | ----- |
|
| 32 |
+
| Not Offensive | | | |
|
| 33 |
+
| Gray-area | | | |
|
| 34 |
+
| Offensive | | | |
|
| 35 |
+
|
| 36 |
+
# 使い方
|
| 37 |
+
```python
|
| 38 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 39 |
+
import numpy as np
|
| 40 |
+
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained("Twitter/twhin-bert-base")
|
| 42 |
+
model = AutoModelForSequenceClassification.from_pretrained("TomokiFujihara/luke-japanese-base-lite-offensiveness-estimation", trust_remote_code=True)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
inputs = tokenizer.encode_plus(text, return_tensors='pt')
|
| 46 |
+
outputs = model(inputs['input_ids'], inputs['attention_mask']).detach().numpy()[0][:3]
|
| 47 |
+
|
| 48 |
+
minimum = np.min(outputs)
|
| 49 |
+
if minimum < 0:
|
| 50 |
+
outputs = outputs - minimum
|
| 51 |
+
score = outputs / np.sum(outputs)
|
| 52 |
+
|
| 53 |
+
print(f'攻撃的でない発言: {score[0]:.1%},\nグレーゾーンの発言: {score[1]:.1%},\n攻撃的な発言: {score[2]:.1%}')
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
# 連絡先
|
| 58 |
+
E-mail: tomoki.fujihara.p3@dc.tohoku.ac.jp
|