🚀 Social Bias NER
このNERモデルは、BERTをファインチューニングしたもので、以下のマルチラベルトークン分類に使用されます。
- (GEN)eralizations(一般化)
- (UNFAIR)ness(不公平性)
- (STEREO)types(固定観念)
スペースで試すことができます :).
🚀 クイックスタート
Transformersパイプラインにはマルチラベルトークン分類用のクラスはありませんが、このコードを使用してモデルをロード、実行し、出力を整形することができます。
基本的な使用法
import json
import torch
from transformers import BertTokenizerFast, BertForTokenClassification
import gradio as gr
tokenizer = BertTokenizerFast.from_pretrained('bert-base-uncased')
model = BertForTokenClassification.from_pretrained('ethical-spectacle/social-bias-ner')
model.eval()
model.to('cuda' if torch.cuda.is_available() else 'cpu')
id2label = {
0: 'O',
1: 'B-STEREO',
2: 'I-STEREO',
3: 'B-GEN',
4: 'I-GEN',
5: 'B-UNFAIR',
6: 'I-UNFAIR'
}
def predict_ner_tags(sentence):
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
input_ids = inputs['input_ids'].to(model.device)
attention_mask = inputs['attention_mask'].to(model.device)
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
logits = outputs.logits
probabilities = torch.sigmoid(logits)
predicted_labels = (probabilities > 0.5).int()
result = []
tokens = tokenizer.convert_ids_to_tokens(input_ids[0])
for i, token in enumerate(tokens):
if token not in tokenizer.all_special_tokens:
label_indices = (predicted_labels[0][i] == 1).nonzero(as_tuple=False).squeeze(-1)
labels = [id2label[idx.item()] for idx in label_indices] if label_indices.numel() > 0 else ['O']
result.append({"token": token, "labels": labels})
return json.dumps(result, indent=4)
📚 ドキュメント
GUS-Netプロジェクトの詳細
リソース
引用方法
@article{powers2024gusnet,
title={{GUS-Net: Social Bias Classification in Text with Generalizations, Unfairness, and Stereotypes}},
author={Maximus Powers and Umang Mavani and Harshitha Reddy Jonala and Ansh Tiwari and Hua Wei},
journal={arXiv preprint arXiv:2410.08388},
year={2024},
url={https://arxiv.org/abs/2410.08388}
}
当研究グループのEthical Spectacleをフォローしてください :).
📄 ライセンス
このプロジェクトはMITライセンスの下で公開されています。
📊 メトリクス
名称 |
タイプ |
値 |
F1 |
F1 |
0.7864 |
Recall |
Recall |
0.7617 |
🌱 モデル情報
属性 |
詳情 |
ベースモデル |
bert-base-uncased |
CO2排出量 |
排出量: 8, トレーニングタイプ: fine-tuning, 地理的位置: Phoenix, AZ, 使用ハードウェア: T4 |