Pii Entity Extractor
基于DeBERTa微调的命名实体识别模型,专门用于检测文本中的个人身份信息(PII),如姓名、社保号码、电话号码等敏感信息。
下载量 155
发布时间 : 4/25/2025
模型简介
该模型通过标记级分类进行序列标注,能准确识别文本中的各类个人身份信息实体,适用于隐私保护和数据脱敏场景。
模型特点
高精度PII检测
在测试数据上F1值达到0.95以上,能准确识别多种PII类型
多类别实体识别
支持姓名、社保号码、电话号码、信用卡号、地址等7类PII检测
子词合并处理
内置后处理逻辑可自动合并被拆分的子词标记
模型能力
文本中的敏感信息检测
命名实体识别
数据脱敏处理
隐私保护
使用案例
隐私保护
文档脱敏
自动识别并替换文档中的敏感信息
实现自动化数据脱敏流程
合规审查
检测文本中可能违反隐私法规的内容
帮助组织满足GDPR等合规要求
数据安全
日志清洗
在存储日志前移除敏感信息
降低数据泄露风险
🚀 使用DeBERTa进行PII检测的模型
本模型是一个专为命名实体识别(NER)任务微调的模型,基于microsoft/deberta
。它能够精准检测各类个人身份信息(PII)实体,如姓名、社保号码、电话号码、信用卡号、地址等,在保护个人隐私和数据安全方面具有重要价值。
🚀 快速开始
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline
model_name = "AI-Enthusiast11/pii-entity-extractor"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# Post processing logic to combine the subword tokens
def merge_tokens(ner_results):
entities = {}
for entity in ner_results:
entity_type = entity["entity_group"]
entity_value = entity["word"].replace("##", "") # Remove subword prefixes
# Handle token merging
if entity_type not in entities:
entities[entity_type] = []
if entities[entity_type] and not entity_value.startswith(" "):
# If the previous token exists and this one isn't a new word, merge it
entities[entity_type][-1] += entity_value
else:
entities[entity_type].append(entity_value)
return entities
def redact_text_with_labels(text):
ner_results = nlp(text)
# Merge tokens for multi-token entities (if any)
cleaned_entities = merge_tokens(ner_results)
redacted_text = text
for entity_type, values in cleaned_entities.items():
for value in values:
# Replace each identified entity with the label
redacted_text = redacted_text.replace(value, f"[{entity_type}]")
return redacted_text
#Loading the pipeline
nlp = pipeline("ner", model=model_name, tokenizer=tokenizer, aggregation_strategy="simple")
# Example input (choose one from your examples)
example = "Hi, I’m Mia Thompson. I recently noticed that my electricity bill hasn’t been updated despite making the payment last week. I used account number 4893172051 linked with routing number 192847561. My service was nearly suspended, and I’d appreciate it if you could verify the payment. You can reach me at 727-814-3902 if more information is needed."
# Run pipeline and process result
ner_results = nlp(example)
cleaned_entities = merge_tokens(ner_results)
# Print the NER results
print("\n==NER Results:==\n")
for entity_type, values in cleaned_entities.items():
print(f" {entity_type}: {', '.join(values)}")
# Redact the single example with labels
redacted_example = redact_text_with_labels(example)
# Print the redacted result
print(f"\n==Redacted Example:==\n{redacted_example}")
✨ 主要特性
- 精准检测:能够准确识别多种个人身份信息(PII)实体,包括姓名、社保号码、电话号码等。
- 微调优化:基于
microsoft/deberta
模型进行微调,在PII检测任务上表现出色。 - 易于使用:提供了清晰的代码示例,方便用户快速上手。
📦 安装指南
文档未提及安装步骤,故跳过该章节。
💻 使用示例
基础用法
# 以下是使用模型进行PII检测的基础代码示例
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline
model_name = "AI-Enthusiast11/pii-entity-extractor"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)
# 加载pipeline
nlp = pipeline("ner", model=model_name, tokenizer=tokenizer, aggregation_strategy="simple")
# 示例输入
example = "Hi, I’m Mia Thompson. I recently noticed that my electricity bill hasn’t been updated despite making the payment last week. I used account number 4893172051 linked with routing number 192847561. My service was nearly suspended, and I’d appreciate it if you could verify the payment. You can reach me at 727-814-3902 if more information is needed."
# 运行pipeline并处理结果
ner_results = nlp(example)
高级用法
# 以下代码展示了如何对检测结果进行后处理,合并子词标记并对文本进行脱敏处理
# Post processing logic to combine the subword tokens
def merge_tokens(ner_results):
entities = {}
for entity in ner_results:
entity_type = entity["entity_group"]
entity_value = entity["word"].replace("##", "") # Remove subword prefixes
# Handle token merging
if entity_type not in entities:
entities[entity_type] = []
if entities[entity_type] and not entity_value.startswith(" "):
# If the previous token exists and this one isn't a new word, merge it
entities[entity_type][-1] += entity_value
else:
entities[entity_type].append(entity_value)
return entities
def redact_text_with_labels(text):
ner_results = nlp(text)
# Merge tokens for multi-token entities (if any)
cleaned_entities = merge_tokens(ner_results)
redacted_text = text
for entity_type, values in cleaned_entities.items():
for value in values:
# Replace each identified entity with the label
redacted_text = redacted_text.replace(value, f"[{entity_type}]")
return redacted_text
# 示例输入
example = "Hi, I’m Mia Thompson. I recently noticed that my electricity bill hasn’t been updated despite making the payment last week. I used account number 4893172051 linked with routing number 192847561. My service was nearly suspended, and I’d appreciate it if you could verify the payment. You can reach me at 727-814-3902 if more information is needed."
# 运行pipeline并处理结果
ner_results = nlp(example)
cleaned_entities = merge_tokens(ner_results)
# 打印NER结果
print("\n==NER Results:==\n")
for entity_type, values in cleaned_entities.items():
print(f" {entity_type}: {', '.join(values)}")
# 对示例文本进行脱敏处理
redacted_example = redact_text_with_labels(example)
# 打印脱敏后的结果
print(f"\n==Redacted Example:==\n{redacted_example}")
📚 详细文档
模型详情
模型描述
这是一个基于Transformer架构的模型,通过在自定义数据集上进行微调,能够有效检测敏感信息,通常归类为个人身份信息(PII)。该模型采用序列标注的方式,通过标记级别的分类来识别实体。
属性 | 详情 |
---|---|
模型类型 | 标记分类(NER) |
开发团队 | [Privatone] |
微调基础模型 | microsoft/deberta |
支持语言 | 英语 |
使用场景 | 文本中的PII检测 |
训练详情
训练数据
模型在包含以下PII实体类型的自定义标注数据集上进行了微调:
- 姓名(NAME)
- 社保号码(SSN)
- 电话号码(PHONE-NO)
- 信用卡号(CREDIT-CARD-NO)
- 银行账号(BANK-ACCOUNT-NO)
- 银行路由号(BANK-ROUTING-NO)
- 地址(ADDRESS)
训练轮次日志
轮次 | 训练损失 | 验证损失 | 精确率 | 召回率 | F1值 | 准确率 |
---|---|---|---|---|---|---|
1 | 0.3672 | 0.1987 | 0.7806 | 0.8114 | 0.7957 | 0.9534 |
2 | 0.1149 | 0.1011 | 0.9161 | 0.9772 | 0.9457 | 0.9797 |
3 | 0.0795 | 0.0889 | 0.9264 | 0.9825 | 0.9536 | 0.9813 |
4 | 0.0708 | 0.0880 | 0.9242 | 0.9842 | 0.9533 | 0.9806 |
5 | 0.0626 | 0.0858 | 0.9235 | 0.9851 | 0.9533 | 0.9806 |
SeqEval分类报告
标签 | 精确率 | 召回率 | F1分数 | 样本数 |
---|---|---|---|---|
地址(ADDRESS) | 0.91 | 0.94 | 0.92 | 77 |
银行账号(BANK-ACCOUNT-NO) | 0.91 | 0.99 | 0.95 | 169 |
银行路由号(BANK-ROUTING-NO) | 0.85 | 0.96 | 0.90 | 104 |
信用卡号(CREDIT-CARD-NO) | 0.95 | 1.00 | 0.97 | 228 |
姓名(NAME) | 0.98 | 0.97 | 0.97 | 164 |
电话号码(PHONE-NO) | 0.94 | 0.99 | 0.96 | 308 |
社保号码(SSN) | 0.87 | 1.00 | 0.93 | 90 |
总结
- 微平均:0.95
- 宏平均:0.95
- 加权平均:0.95
评估
测试数据
评估在同一标注数据集的预留部分上进行。
评估指标
- 精确率
- 召回率
- F1分数(通过seqeval计算)
- 实体级别的细分指标
- 标记级别的准确率
评估结果
- 大多数标签的F1分数始终高于0.95,表明模型在PII检测方面具有较强的鲁棒性。
建议
⚠️ 重要提示
在高风险环境中,建议进行人工审核。
💡 使用建议
在部署模型之前,建议在自己的特定领域数据上进行评估。
Indonesian Roberta Base Posp Tagger
MIT
这是一个基于印尼语RoBERTa模型微调的词性标注模型,在indonlu数据集上训练,用于印尼语文本的词性标注任务。
序列标注
Transformers 其他

I
w11wo
2.2M
7
Bert Base NER
MIT
基于BERT微调的命名实体识别模型,可识别四类实体:地点(LOC)、组织机构(ORG)、人名(PER)和杂项(MISC)
序列标注 英语
B
dslim
1.8M
592
Deid Roberta I2b2
MIT
该模型是基于RoBERTa微调的序列标注模型,用于识别和移除医疗记录中的受保护健康信息(PHI/PII)。
序列标注
Transformers 支持多种语言

D
obi
1.1M
33
Ner English Fast
Flair自带的英文快速4类命名实体识别模型,基于Flair嵌入和LSTM-CRF架构,在CoNLL-03数据集上达到92.92的F1分数。
序列标注
PyTorch 英语
N
flair
978.01k
24
French Camembert Postag Model
基于Camembert-base的法语词性标注模型,使用free-french-treebank数据集训练
序列标注
Transformers 法语

F
gilf
950.03k
9
Xlm Roberta Large Ner Spanish
基于XLM-Roberta-large架构微调的西班牙语命名实体识别模型,在CoNLL-2002数据集上表现优异。
序列标注
Transformers 西班牙语

X
MMG
767.35k
29
Nusabert Ner V1.3
MIT
基于NusaBert-v1.3在印尼语NER任务上微调的命名实体识别模型
序列标注
Transformers 其他

N
cahya
759.09k
3
Ner English Large
Flair框架内置的英文4类大型NER模型,基于文档级XLM-R嵌入和FLERT技术,在CoNLL-03数据集上F1分数达94.36。
序列标注
PyTorch 英语
N
flair
749.04k
44
Punctuate All
MIT
基于xlm-roberta-base微调的多语言标点符号预测模型,支持12种欧洲语言的标点符号自动补全
序列标注
Transformers

P
kredor
728.70k
20
Xlm Roberta Ner Japanese
MIT
基于xlm-roberta-base微调的日语命名实体识别模型
序列标注
Transformers 支持多种语言

X
tsmatz
630.71k
25
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98