🚀 DeBERTaを用いたPII検出モデルカード
このモデルは、名前付きエンティティ認識(NER)用に微調整されたmicrosoft/deberta
のバージョンです。特に、名前、社会保障番号(SSN)、電話番号、クレジットカード番号、住所などの個人識別情報(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)
def merge_tokens(ner_results):
entities = {}
for entity in ner_results:
entity_type = entity["entity_group"]
entity_value = entity["word"].replace("##", "")
if entity_type not in entities:
entities[entity_type] = []
if entities[entity_type] and not entity_value.startswith(" "):
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)
cleaned_entities = merge_tokens(ner_results)
redacted_text = text
for entity_type, values in cleaned_entities.items():
for value in values:
redacted_text = redacted_text.replace(value, f"[{entity_type}]")
return redacted_text
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."
ner_results = nlp(example)
cleaned_entities = merge_tokens(ner_results)
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}")
✨ 主な機能
- このトランスフォーマーベースのモデルは、PIIとして一般的に分類される機密情報を検出するために、カスタムデータセットで微調整されています。
- トークンレベルの分類を使用してエンティティを識別するシーケンスラベリングを行います。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers
📚 ドキュメント
モデルの詳細
モデルの説明
属性 |
详情 |
モデルタイプ |
トークン分類(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検出における堅牢性を示しています。
推奨事項
⚠️ 重要提示
高リスク環境では、人的レビューを行ってください。
💡 使用建议
デプロイ前に、独自のドメイン固有のデータで評価してください。