模型简介
模型特点
模型能力
使用案例
🚀 deberta-v3-large-自我披露检测
该模型用于检测句子中的自我披露信息(个人信息),这是一个多类别标记分类任务,类似于采用IOB2格式的命名实体识别(NER)。它能为保护个人隐私、识别敏感信息提供有力支持。
🚀 快速开始
此模型用于检测句子中的自我披露信息(个人信息),是一个多类别标记分类任务,类似采用IOB2格式的NER。例如,句子 "I am 22 years old and ..." 的标签为 "["B - Age", "I - Age", "I - Age", "I - Age", "I - Age", "O", ...]" 。
该模型能够检测以下17个类别:"Age"(年龄)、"Age_Gender"(年龄与性别)、"Appearance"(外貌)、"Education"(教育程度)、"Family"(家庭情况)、"Finance"(财务状况)、"Gender"(性别)、"Health"(健康状况)、"Husband_BF"(丈夫/男友)、"Location"(地理位置)、"Mental_Health"(心理健康)、"Occupation"(职业)、"Pet"(宠物)、"Race_Nationality"(种族/国籍)、"Relationship_Status"(感情状况)、"Sexual_Orientation"(性取向)、"Wife_GF"(妻子/女友)。
如需更多详细信息,请阅读论文:Reducing Privacy Risks in Online Self - Disclosures with Language Models 。
使用此模型意味着自动同意以下准则:
- 仅将模型用于研究目的。
- 未经作者同意,不得重新分发。
- 任何使用此模型创建的衍生作品必须承认原作者。
✨ 主要特性
- 能够精准检测句子中17个类别的自我披露信息。
- 在相关评估指标上表现出色,部分跨度F1值达到65.71,优于提示GPT - 4(F1值为57.68)。
📦 安装指南
文档中未提及具体安装步骤,故跳过该章节。
💻 使用示例
基础用法
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,
)
# we use ("O") for all the labels
word_ids = tokenized_inputs.word_ids(0)
previous_word_idx = None
label_ids = []
for word_idx in word_ids:
# Special tokens have a word id that is None. We set the label to -100 so they are automatically
# ignored in the loss function.
if word_idx is None:
label_ids.append(-100)
# We set the label for the first token of each word.
elif word_idx != previous_word_idx:
label_ids.append(label2id["O"])
# For the other tokens in a word, we set the label to -100
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)
📚 详细文档
模型描述
属性 | 详情 |
---|---|
模型类型 | 一个可以检测17个类别自我披露信息的微调模型 |
语言(NLP) | 英语 |
许可证 | 知识共享署名 - 非商业性使用许可协议 |
微调基础模型 | microsoft/deberta - v3 - large |
评估
该模型的部分跨度F1值达到65.71,优于提示GPT - 4(F1值为57.68)。有关每个类别的详细性能,请参阅论文。
🔧 技术细节
文档中未提及具体技术细节内容,故跳过该章节。
📄 许可证
该模型使用的许可证为知识共享署名 - 非商业性使用许可协议(Creative Commons Attribution - NonCommercial)。
📚 引用
@article{dou2023reducing,
title={Reducing Privacy Risks in Online Self-Disclosures with Language Models},
author={Dou, Yao and Krsek, Isadora and Naous, Tarek and Kabra, Anubha and Das, Sauvik and Ritter, Alan and Xu, Wei},
journal={arXiv preprint arXiv:2311.09538},
year={2023}
}








