model-index:
- name: deberta-v3-large-self-disclosure-detection
results: []
language:
- en
base_model: microsoft/deberta-v3-large
license: mit
tags:
- deberta
- privacy
- 自我披露识别
- 个人身份信息
模型卡片:deberta-v3-large-self-disclosure-detection
该模型用于检测句子中的自我披露(个人信息)。这是一个多类别的标记分类任务,类似于IOB2格式的命名实体识别(NER)。
例如:"I am 22 years old and ..." 的标签为 ["B-Age", "I-Age", "I-Age", "I-Age", "I-Age", "O", ...]
模型能够识别以下17个类别:
"年龄", "年龄_性别", "外貌", "教育", "家庭", "财务", "性别", "健康", "丈夫_男友",
"位置", "心理健康", "职业", "宠物", "种族_国籍", "关系状态", "性取向", "妻子_女友"。
更多细节请参阅论文:利用语言模型降低在线自我披露的隐私风险。
使用本模型即自动同意以下准则:
- 仅限研究用途。
- 未经作者同意不得二次分发。
- 任何基于本模型的衍生作品必须注明原作者。
模型描述
示例代码
import torch
from torch.utils.data import DataLoader, Dataset
import datasets
from datasets import ClassLabel, load_dataset
from transformers import AutoModelForTokenClassification, AutoTokenizer, AutoConfig, DataCollatorForTokenClassification
model_path = "douy/deberta-v3-large-self-disclosure-detection"
config = AutoConfig.from_pretrained(model_path,)
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=True,)
model = AutoModelForTokenClassification.from_pretrained(model_path,config=config,device_map="cuda:0").eval()
label2id = config.label2id
id2label = config.id2label
def tokenize_and_align_labels(words):
tokenized_inputs = tokenizer(
words,
padding=False,
is_split_into_words=True,
)
word_ids = tokenized_inputs.word_ids(0)
previous_word_idx = None
label_ids = []
for word_idx in word_ids:
if word_idx is None:
label_ids.append(-100)
elif word_idx != previous_word_idx:
label_ids.append(label2id["O"])
else:
label_ids.append(-100)
previous_word_idx = word_idx
tokenized_inputs["labels"] = label_ids
return tokenized_inputs
class DisclosureDataset(Dataset):
def __init__(self, inputs, tokenizer, tokenize_and_align_labels_function):
self.inputs = inputs
self.tokenizer = tokenizer
self.tokenize_and_align_labels_function = tokenize_and_align_labels_function
def __len__(self):
return len(self.inputs)
def __getitem__(self, idx):
words = self.inputs[idx]
tokenized_inputs = self.tokenize_and_align_labels_function(words)
return tokenized_inputs
sentences = [
"I am a 23-year-old who is currently going through the last leg of undergraduate school.",
"My husband and I live in US.",
]
inputs = [sentence.split() for sentence in sentences]
data_collator = DataCollatorForTokenClassification(tokenizer)
dataset = DisclosureDataset(inputs, tokenizer, tokenize_and_align_labels)
dataloader = DataLoader(dataset, collate_fn=data_collator, batch_size=2)
total_predictions = []
for step, batch in enumerate(dataloader):
batch = {k: v.to(model.device) for k, v in batch.items()}
with torch.inference_mode():
outputs = model(**batch)
predictions = outputs.logits.argmax(-1)
labels = batch["labels"]
predictions = predictions.cpu().tolist()
labels = labels.cpu().tolist()
true_predictions = []
for i, label in enumerate(labels):
true_pred = []
for j, m in enumerate(label):
if m != -100:
true_pred.append(id2label[predictions[i][j]])
true_predictions.append(true_pred)
total_predictions.extend(true_predictions)
for word, pred in zip(inputs, total_predictions):
for w, p in zip(word, pred):
print(w, p)
评估结果
模型取得65.71的部分跨度F1值,优于GPT-4提示方法(57.68 F1)。各类别详细性能参见论文。
引用文献
@article{dou2023reducing,
title={利用语言模型降低在线自我披露的隐私风险},
author={Dou, Yao and Krsek, Isadora and Naous, Tarek and Kabra, Anubha and Das, Sauvik and Ritter, Alan and Xu, Wei},
journal={arXiv预印本 arXiv:2311.09538},
year={2023}
}