Upload folder using huggingface_hub
Browse files- bert/README.md +132 -0
- bert/config.json +96 -0
- bert/special_tokens_map.json +7 -0
- bert/tokenizer_config.json +58 -0
- bert/vocab.txt +0 -0
bert/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
task_categories:
|
| 4 |
+
- token-classification
|
| 5 |
+
- named-entity-recognition
|
| 6 |
+
tags:
|
| 7 |
+
- korean
|
| 8 |
+
- pii
|
| 9 |
+
- privacy
|
| 10 |
+
- masking
|
| 11 |
+
- bert
|
| 12 |
+
language:
|
| 13 |
+
- ko
|
| 14 |
+
pipeline_tag: token-classification
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Korean PII Masking BERT
|
| 18 |
+
|
| 19 |
+
한국어 개인정보(PII, Personally Identifiable Information) 마스킹을 위한 BERT 기반 토큰 분류 모델입니다.
|
| 20 |
+
|
| 21 |
+
## 모델 설명
|
| 22 |
+
|
| 23 |
+
이 모델은 한국어 텍스트에서 개인정보를 자동으로 감지하고 마스킹하는 용도로 사용됩니다. BERT 기반 아키텍처를 사용하여 14가지 유형의 한국어 PII를 식별합니다.
|
| 24 |
+
|
| 25 |
+
## 모델 세부 정보
|
| 26 |
+
|
| 27 |
+
- **아키텍처**: BertForTokenClassification
|
| 28 |
+
- **기본 모델**: BERT (Korean)
|
| 29 |
+
- **Hidden Size**: 1024
|
| 30 |
+
- **Num Hidden Layers**: 24
|
| 31 |
+
- **Num Attention Heads**: 16
|
| 32 |
+
- **Max Position Embeddings**: 300
|
| 33 |
+
- **Vocab Size**: 30,000
|
| 34 |
+
|
| 35 |
+
## 지원하는 PII 유형
|
| 36 |
+
|
| 37 |
+
모델은 다음 14가지 PII 유형을 인식합니다:
|
| 38 |
+
|
| 39 |
+
1. **가맹점명** (Business Name)
|
| 40 |
+
2. **결제금액** (Payment Amount)
|
| 41 |
+
3. **계좌번호** (Account Number)
|
| 42 |
+
4. **로그인ID** (Login ID)
|
| 43 |
+
5. **상세주소** (Detailed Address)
|
| 44 |
+
6. **신용점수** (Credit Score)
|
| 45 |
+
7. **여권번호** (Passport Number)
|
| 46 |
+
8. **우편번호** (Postal Code)
|
| 47 |
+
9. **운전면허번호** (Driver's License Number)
|
| 48 |
+
10. **이름** (Name)
|
| 49 |
+
11. **전자메일** (Email)
|
| 50 |
+
12. **전화번호** (Phone Number)
|
| 51 |
+
13. **주민등록번호** (Resident Registration Number)
|
| 52 |
+
14. **카드번호** (Card Number)
|
| 53 |
+
15. **휴대전화번호** (Mobile Phone Number)
|
| 54 |
+
|
| 55 |
+
각 PII는 BIO 태깅 방식을 사용합니다 (B-, I-, O).
|
| 56 |
+
|
| 57 |
+
## 사용법
|
| 58 |
+
|
| 59 |
+
### 기본 사용법
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from transformers import BertForTokenClassification, BertTokenizer
|
| 63 |
+
import torch
|
| 64 |
+
|
| 65 |
+
# 모델 및 토크나이저 로드
|
| 66 |
+
model = BertForTokenClassification.from_pretrained("your-username/korean-pii-masking-bert")
|
| 67 |
+
tokenizer = BertTokenizer.from_pretrained("your-username/korean-pii-masking-bert")
|
| 68 |
+
|
| 69 |
+
# 텍스트 토크나이징
|
| 70 |
+
text = "안녕하세요, 제 이름은 김민수이고 전화번호는 010-1234-5678입니다."
|
| 71 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 72 |
+
|
| 73 |
+
# 예측
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
outputs = model(**inputs)
|
| 76 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 77 |
+
predicted_labels = torch.argmax(predictions, dim=-1)[0]
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### 파이프라인을 통한 사용
|
| 81 |
+
|
| 82 |
+
원본 저장소의 `inference_pipeline.py`를 사용하면 더 간편하게 사용할 수 있습니다:
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
from inference_pipeline import PIIInferencePipeline
|
| 86 |
+
|
| 87 |
+
# 파이프라인 초기화
|
| 88 |
+
pipeline = PIIInferencePipeline()
|
| 89 |
+
|
| 90 |
+
# 텍스트 예측
|
| 91 |
+
text = "안녕하세요, 제 이름은 김민수이고 전화번호는 010-1234-5678입니다."
|
| 92 |
+
result = pipeline.predict(text)
|
| 93 |
+
|
| 94 |
+
print(f"원본 텍스트: {result.original_text}")
|
| 95 |
+
print(f"마스킹 텍스트: {result.masked_text}")
|
| 96 |
+
print(f"발견된 PII: {len(result.entities)}개")
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## 예시
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
입력: "8월 10일 14:32에 백다방 코엑스점에서 9,910원 승인 내역 확인됩니다."
|
| 103 |
+
|
| 104 |
+
출력:
|
| 105 |
+
- 발견된 PII:
|
| 106 |
+
- 백다방 코엑스점 -> [가맹점명]
|
| 107 |
+
- 9,910원 -> [결제금액]
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
## 데이터 전처리
|
| 111 |
+
|
| 112 |
+
모델은 한국어 텍스트를 입력으로 받으며, 최대 길이는 300 토큰입니다.
|
| 113 |
+
|
| 114 |
+
## 제한 사항
|
| 115 |
+
|
| 116 |
+
- 최대 입력 길이: 300 토큰
|
| 117 |
+
- 한국어 텍스트에 최적화됨
|
| 118 |
+
- 텍스트에서의 PII 인식에 특화 (이미지나 음성 미지원)
|
| 119 |
+
|
| 120 |
+
## 참고 문헌
|
| 121 |
+
|
| 122 |
+
이 모델은 한국어 개인정보 마스킹을 위해 학습되었습니다.
|
| 123 |
+
|
| 124 |
+
## 라이센스
|
| 125 |
+
|
| 126 |
+
MIT License
|
| 127 |
+
|
| 128 |
+
## 저자
|
| 129 |
+
|
| 130 |
+
Korean PII Masking Project
|
| 131 |
+
|
| 132 |
+
|
bert/config.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BertForTokenClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"classifier_dropout": null,
|
| 7 |
+
"directionality": "bidi",
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.2,
|
| 10 |
+
"hidden_size": 1024,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "O",
|
| 13 |
+
"1": "B-\uac00\ub9f9\uc810\uba85",
|
| 14 |
+
"2": "I-\uac00\ub9f9\uc810\uba85",
|
| 15 |
+
"3": "B-\uacb0\uc81c\uae08\uc561",
|
| 16 |
+
"4": "I-\uacb0\uc81c\uae08\uc561",
|
| 17 |
+
"5": "B-\uacc4\uc88c\ubc88\ud638",
|
| 18 |
+
"6": "I-\uacc4\uc88c\ubc88\ud638",
|
| 19 |
+
"7": "B-\ub85c\uadf8\uc778ID",
|
| 20 |
+
"8": "I-\ub85c\uadf8\uc778ID",
|
| 21 |
+
"9": "B-\uc0c1\uc138\uc8fc\uc18c",
|
| 22 |
+
"10": "I-\uc0c1\uc138\uc8fc\uc18c",
|
| 23 |
+
"11": "B-\uc2e0\uc6a9\uc810\uc218",
|
| 24 |
+
"12": "I-\uc2e0\uc6a9\uc810\uc218",
|
| 25 |
+
"13": "B-\uc5ec\uad8c\ubc88\ud638",
|
| 26 |
+
"14": "I-\uc5ec\uad8c\ubc88\ud638",
|
| 27 |
+
"15": "B-\uc6b0\ud3b8\ubc88\ud638",
|
| 28 |
+
"16": "I-\uc6b0\ud3b8\ubc88\ud638",
|
| 29 |
+
"17": "B-\uc6b4\uc804\uba74\ud5c8\ubc88\ud638",
|
| 30 |
+
"18": "I-\uc6b4\uc804\uba74\ud5c8\ubc88\ud638",
|
| 31 |
+
"19": "B-\uc774\ub984",
|
| 32 |
+
"20": "I-\uc774\ub984",
|
| 33 |
+
"21": "B-\uc804\uc790\uba54\uc77c",
|
| 34 |
+
"22": "I-\uc804\uc790\uba54\uc77c",
|
| 35 |
+
"23": "B-\uc804\ud654\ubc88\ud638",
|
| 36 |
+
"24": "I-\uc804\ud654\ubc88\ud638",
|
| 37 |
+
"25": "B-\uc8fc\ubbfc\ub4f1\ub85d\ubc88\ud638",
|
| 38 |
+
"26": "I-\uc8fc\ubbfc\ub4f1\ub85d\ubc88\ud638",
|
| 39 |
+
"27": "B-\uce74\ub4dc\ubc88\ud638",
|
| 40 |
+
"28": "I-\uce74\ub4dc\ubc88\ud638",
|
| 41 |
+
"29": "B-\ud734\ub300\uc804\ud654\ubc88\ud638",
|
| 42 |
+
"30": "I-\ud734\ub300\uc804\ud654\ubc88\ud638"
|
| 43 |
+
},
|
| 44 |
+
"initializer_range": 0.02,
|
| 45 |
+
"intermediate_size": 4096,
|
| 46 |
+
"label2id": {
|
| 47 |
+
"B-\uac00\ub9f9\uc810\uba85": 1,
|
| 48 |
+
"B-\uacb0\uc81c\uae08\uc561": 3,
|
| 49 |
+
"B-\uacc4\uc88c\ubc88\ud638": 5,
|
| 50 |
+
"B-\ub85c\uadf8\uc778ID": 7,
|
| 51 |
+
"B-\uc0c1\uc138\uc8fc\uc18c": 9,
|
| 52 |
+
"B-\uc2e0\uc6a9\uc810\uc218": 11,
|
| 53 |
+
"B-\uc5ec\uad8c\ubc88\ud638": 13,
|
| 54 |
+
"B-\uc6b0\ud3b8\ubc88\ud638": 15,
|
| 55 |
+
"B-\uc6b4\uc804\uba74\ud5c8\ubc88\ud638": 17,
|
| 56 |
+
"B-\uc774\ub984": 19,
|
| 57 |
+
"B-\uc804\uc790\uba54\uc77c": 21,
|
| 58 |
+
"B-\uc804\ud654\ubc88\ud638": 23,
|
| 59 |
+
"B-\uc8fc\ubbfc\ub4f1\ub85d\ubc88\ud638": 25,
|
| 60 |
+
"B-\uce74\ub4dc\ubc88\ud638": 27,
|
| 61 |
+
"B-\ud734\ub300\uc804\ud654\ubc88\ud638": 29,
|
| 62 |
+
"I-\uac00\ub9f9\uc810\uba85": 2,
|
| 63 |
+
"I-\uacb0\uc81c\uae08\uc561": 4,
|
| 64 |
+
"I-\uacc4\uc88c\ubc88\ud638": 6,
|
| 65 |
+
"I-\ub85c\uadf8\uc778ID": 8,
|
| 66 |
+
"I-\uc0c1\uc138\uc8fc\uc18c": 10,
|
| 67 |
+
"I-\uc2e0\uc6a9\uc810\uc218": 12,
|
| 68 |
+
"I-\uc5ec\uad8c\ubc88\ud638": 14,
|
| 69 |
+
"I-\uc6b0\ud3b8\ubc88\ud638": 16,
|
| 70 |
+
"I-\uc6b4\uc804\uba74\ud5c8\ubc88\ud638": 18,
|
| 71 |
+
"I-\uc774\ub984": 20,
|
| 72 |
+
"I-\uc804\uc790\uba54\uc77c": 22,
|
| 73 |
+
"I-\uc804\ud654\ubc88\ud638": 24,
|
| 74 |
+
"I-\uc8fc\ubbfc\ub4f1\ub85d\ubc88\ud638": 26,
|
| 75 |
+
"I-\uce74\ub4dc\ubc88\ud638": 28,
|
| 76 |
+
"I-\ud734\ub300\uc804\ud654\ubc88\ud638": 30,
|
| 77 |
+
"O": 0
|
| 78 |
+
},
|
| 79 |
+
"layer_norm_eps": 1e-12,
|
| 80 |
+
"max_position_embeddings": 300,
|
| 81 |
+
"model_type": "bert",
|
| 82 |
+
"num_attention_heads": 16,
|
| 83 |
+
"num_hidden_layers": 24,
|
| 84 |
+
"pad_token_id": 0,
|
| 85 |
+
"pooler_fc_size": 768,
|
| 86 |
+
"pooler_num_attention_heads": 12,
|
| 87 |
+
"pooler_num_fc_layers": 3,
|
| 88 |
+
"pooler_size_per_head": 128,
|
| 89 |
+
"pooler_type": "first_token_transform",
|
| 90 |
+
"position_embedding_type": "absolute",
|
| 91 |
+
"torch_dtype": "float32",
|
| 92 |
+
"transformers_version": "4.50.3",
|
| 93 |
+
"type_vocab_size": 2,
|
| 94 |
+
"use_cache": true,
|
| 95 |
+
"vocab_size": 30000
|
| 96 |
+
}
|
bert/special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
bert/tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"4": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": false,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 300,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "BertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
bert/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|