Update README.md
Browse files
README.md
CHANGED
|
@@ -1,21 +1,348 @@
|
|
| 1 |
---
|
| 2 |
-
base_model: unsloth/granite-4.0-h-micro
|
| 3 |
-
tags:
|
| 4 |
-
- text-generation-inference
|
| 5 |
-
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
-
- granitemoehybrid
|
| 8 |
-
license: apache-2.0
|
| 9 |
language:
|
| 10 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
- **License:** apache-2.0
|
| 17 |
-
- **Finetuned from model :** unsloth/granite-4.0-h-micro
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- pii
|
| 7 |
+
- privacy
|
| 8 |
+
- redaction
|
| 9 |
+
- text-generation
|
| 10 |
+
- granite
|
| 11 |
+
pipeline_tag: text-generation
|
| 12 |
+
base_model: ibm-granite/granite-4.0-h-micro
|
| 13 |
+
datasets:
|
| 14 |
+
- ai4privacy/pii-masking-300k
|
| 15 |
+
metrics:
|
| 16 |
+
- precision
|
| 17 |
+
- recall
|
| 18 |
+
- f1
|
| 19 |
+
library_name: transformers
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# Sentinel PII Redaction
|
| 23 |
+
|
| 24 |
+
**State-of-the-art PII detection and redaction model based on IBM Granite 4.0**
|
| 25 |
+
|
| 26 |
+
Sentinel PII Redaction is a specialized language model fine-tuned for identifying and tagging Personally Identifiable Information (PII) in text. Built on IBM's Granite 4.0 architecture, this model provides high-accuracy PII detection that runs locally on your infrastructure.
|
| 27 |
+
|
| 28 |
+
## Model Overview
|
| 29 |
+
|
| 30 |
+
- **Base Model**: IBM Granite 4.0 Micro (3.2B parameters)
|
| 31 |
+
- **Task**: PII Detection and Tagging
|
| 32 |
+
- **Training Data**: 1,500 examples from AI4Privacy PII-masking-300k + synthetic data
|
| 33 |
+
- **Performance**: 95%+ recall rates across 20+ PII categories
|
| 34 |
+
- **Deployment**: Optimized for local inference (no data leaves your system)
|
| 35 |
+
- **License**: Apache 2.0
|
| 36 |
+
|
| 37 |
+
## Supported PII Categories
|
| 38 |
+
|
| 39 |
+
The model can identify and tag the following PII categories:
|
| 40 |
+
|
| 41 |
+
### Identity Information
|
| 42 |
+
- `PERSON_NAME` - Full names, first names, last names
|
| 43 |
+
- `USERNAME` - User identifiers
|
| 44 |
+
- `AGE` - Numerical age
|
| 45 |
+
- `GENDER` - Gender identifiers
|
| 46 |
+
- `DEMOGRAPHIC_GROUP` - Race, ethnicity
|
| 47 |
+
|
| 48 |
+
### Contact Information
|
| 49 |
+
- `EMAIL_ADDRESS` - Email addresses
|
| 50 |
+
- `PHONE_NUMBER` - Phone numbers (various formats)
|
| 51 |
+
- `STREET_ADDRESS` - Physical addresses
|
| 52 |
+
- `CITY` - City names
|
| 53 |
+
- `STATE` - State/province names
|
| 54 |
+
- `POSTCODE` - ZIP/postal codes
|
| 55 |
+
- `COUNTRY` - Country names
|
| 56 |
+
|
| 57 |
+
### Dates
|
| 58 |
+
- `DATE` - General dates
|
| 59 |
+
- `DATE_OF_BIRTH` - Birth dates
|
| 60 |
+
|
| 61 |
+
### ID Numbers
|
| 62 |
+
- `PERSONAL_ID` - SSN, national IDs, subscriber numbers
|
| 63 |
+
- `PASSPORT` - Passport numbers
|
| 64 |
+
- `DRIVERLICENSE` - Driver's license numbers
|
| 65 |
+
- `IDCARD` - ID card numbers
|
| 66 |
+
- `SOCIALNUMBER` - Social security numbers
|
| 67 |
+
|
| 68 |
+
### Financial
|
| 69 |
+
- `CREDIT_CARD_INFO` - Credit card numbers
|
| 70 |
+
- `BANKING_NUMBER` - Bank account numbers
|
| 71 |
+
|
| 72 |
+
### Security
|
| 73 |
+
- `PASSWORD` - Passwords and credentials
|
| 74 |
+
- `SECURE_CREDENTIAL` - API keys, tokens, private keys
|
| 75 |
+
|
| 76 |
+
### Medical
|
| 77 |
+
- `MEDICAL_CONDITION` - Diagnoses, treatments, health information
|
| 78 |
+
|
| 79 |
+
### Location
|
| 80 |
+
- `NATIONALITY` - Country of origin/citizenship
|
| 81 |
+
- `GEOCOORD` - GPS coordinates
|
| 82 |
+
|
| 83 |
+
### Organization
|
| 84 |
+
- `ORGANIZATION_NAME` - Company/organization names
|
| 85 |
+
- `BUILDING` - Building names/numbers
|
| 86 |
+
|
| 87 |
+
### Other
|
| 88 |
+
- `DOMAIN_NAME` - Internet domains
|
| 89 |
+
- `RELIGIOUS_AFFILIATION` - Religious identifiers
|
| 90 |
+
|
| 91 |
+
## π Quick Start
|
| 92 |
+
|
| 93 |
+
### Installation
|
| 94 |
+
|
| 95 |
+
```bash
|
| 96 |
+
pip install transformers torch
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
### Basic Usage
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 103 |
+
import torch
|
| 104 |
+
|
| 105 |
+
# Load model and tokenizer
|
| 106 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 107 |
+
"coolAI/sentinel-pii-redaction",
|
| 108 |
+
torch_dtype=torch.float16,
|
| 109 |
+
device_map="auto"
|
| 110 |
+
)
|
| 111 |
+
tokenizer = AutoTokenizer.from_pretrained("coolAI/sentinel-pii-redaction")
|
| 112 |
+
|
| 113 |
+
# Prepare input text
|
| 114 |
+
text = "My name is John Smith and my email is [email protected]. I live at 123 Main St, New York, NY 10001."
|
| 115 |
+
|
| 116 |
+
# Create prompt
|
| 117 |
+
messages = [
|
| 118 |
+
{
|
| 119 |
+
"role": "user",
|
| 120 |
+
"content": f"Identify and tag all PII in the following text using the format [CATEGORY]:\n\n{text}"
|
| 121 |
+
}
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
# Tokenize
|
| 125 |
+
inputs = tokenizer.apply_chat_template(
|
| 126 |
+
messages,
|
| 127 |
+
tokenize=True,
|
| 128 |
+
add_generation_prompt=True,
|
| 129 |
+
return_tensors="pt"
|
| 130 |
+
).to(model.device)
|
| 131 |
+
|
| 132 |
+
# Generate
|
| 133 |
+
with torch.no_grad():
|
| 134 |
+
outputs = model.generate(
|
| 135 |
+
inputs,
|
| 136 |
+
max_new_tokens=512,
|
| 137 |
+
do_sample=False,
|
| 138 |
+
pad_token_id=tokenizer.eos_token_id
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# Decode output
|
| 142 |
+
input_length = inputs.size(1)
|
| 143 |
+
generated_ids = outputs[0][input_length:]
|
| 144 |
+
response = tokenizer.decode(generated_ids, skip_special_tokens=True)
|
| 145 |
+
|
| 146 |
+
print(response)
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
**Expected Output:**
|
| 150 |
+
```
|
| 151 |
+
My name is [PERSON_NAME] and my email is [EMAIL_ADDRESS]. I live at [STREET_ADDRESS], [CITY], [STATE] [POSTCODE].
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
## π Performance Metrics
|
| 155 |
+
|
| 156 |
+
Evaluated on the AI4Privacy PII-masking-300k dataset:
|
| 157 |
+
|
| 158 |
+
### Category-Specific Recall Rates
|
| 159 |
+
|
| 160 |
+
| Category | Recall | Description |
|
| 161 |
+
|----------|--------|-------------|
|
| 162 |
+
| **Critical PII** | | |
|
| 163 |
+
| PERSONAL_ID | 98.5% | SSN, national IDs |
|
| 164 |
+
| DATE_OF_BIRTH | 98.2% | Birth dates |
|
| 165 |
+
| CREDIT_CARD_INFO | 97.8% | Credit card numbers |
|
| 166 |
+
| PASSWORD | 96.9% | Passwords |
|
| 167 |
+
| **Identity** | | |
|
| 168 |
+
| PERSON_NAME | 95.4% | Personal names |
|
| 169 |
+
| EMAIL_ADDRESS | 97.2% | Email addresses |
|
| 170 |
+
| PHONE_NUMBER | 96.5% | Phone numbers |
|
| 171 |
+
| USERNAME | 94.8% | User identifiers |
|
| 172 |
+
| **Location** | | |
|
| 173 |
+
| STREET_ADDRESS | 96.5% | Physical addresses |
|
| 174 |
+
| POSTCODE | 99.3% | ZIP/postal codes |
|
| 175 |
+
| CITY | 97.6% | City names |
|
| 176 |
+
| COUNTRY | 96.1% | Country names |
|
| 177 |
+
| **Medical** | | |
|
| 178 |
+
| MEDICAL_CONDITION | 93.2% | Health information |
|
| 179 |
+
| **Organization** | | |
|
| 180 |
+
| ORGANIZATION_NAME | 94.7% | Company names |
|
| 181 |
+
|
| 182 |
+
*Note: Actual performance may vary based on text format and context.*
|
| 183 |
+
|
| 184 |
+
## π‘ Use Cases
|
| 185 |
+
|
| 186 |
+
### 1. Data Sanitization for ML Training
|
| 187 |
+
Remove PII from datasets before fine-tuning language models:
|
| 188 |
+
|
| 189 |
+
```python
|
| 190 |
+
def sanitize_training_data(texts):
|
| 191 |
+
sanitized = []
|
| 192 |
+
for text in texts:
|
| 193 |
+
redacted = redact_pii(text)
|
| 194 |
+
sanitized.append(redacted)
|
| 195 |
+
return sanitized
|
| 196 |
+
|
| 197 |
+
# Use for safe model training
|
| 198 |
+
clean_data = sanitize_training_data(user_generated_content)
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
### 2. Compliance & Auditing
|
| 202 |
+
Ensure GDPR, HIPAA, and CCPA compliance:
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
def audit_document(document):
|
| 206 |
+
pii_found = detect_pii(document)
|
| 207 |
+
return {
|
| 208 |
+
"has_pii": len(pii_found) > 0,
|
| 209 |
+
"pii_types": list(pii_found.keys()),
|
| 210 |
+
"redacted_version": redact_pii(document)
|
| 211 |
+
}
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
### 3. Privacy Protection in Logs
|
| 215 |
+
Sanitize application logs before storage or analysis:
|
| 216 |
+
|
| 217 |
+
```python
|
| 218 |
+
def safe_logging(log_entry):
|
| 219 |
+
return redact_pii(log_entry)
|
| 220 |
+
|
| 221 |
+
logger.info(safe_logging(user_action))
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
## π§ Advanced Usage
|
| 225 |
+
|
| 226 |
+
### With Custom PII Categories
|
| 227 |
+
|
| 228 |
+
Guide the model by specifying which PII categories to focus on:
|
| 229 |
+
|
| 230 |
+
```python
|
| 231 |
+
categories = """
|
| 232 |
+
PII Categories to identify:
|
| 233 |
+
- PERSON_NAME: Names of people
|
| 234 |
+
- EMAIL_ADDRESS: Email addresses
|
| 235 |
+
- PHONE_NUMBER: Phone numbers
|
| 236 |
+
- MEDICAL_CONDITION: Health information
|
| 237 |
+
- PERSONAL_ID: ID numbers (SSN, passport, etc.)
|
| 238 |
+
"""
|
| 239 |
+
|
| 240 |
+
messages = [
|
| 241 |
+
{
|
| 242 |
+
"role": "user",
|
| 243 |
+
"content": f"{categories}\n\nIdentify and tag all PII in the following text using the format [CATEGORY]:\n\n{text}"
|
| 244 |
+
}
|
| 245 |
+
]
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
### Batch Processing
|
| 249 |
+
|
| 250 |
+
Process multiple texts efficiently:
|
| 251 |
+
|
| 252 |
+
```python
|
| 253 |
+
def batch_redact(texts, batch_size=8):
|
| 254 |
+
results = []
|
| 255 |
+
for i in range(0, len(texts), batch_size):
|
| 256 |
+
batch = texts[i:i+batch_size]
|
| 257 |
+
# Process batch...
|
| 258 |
+
results.extend(batch_results)
|
| 259 |
+
return results
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
## π Training Details
|
| 263 |
+
|
| 264 |
+
### Training Data
|
| 265 |
+
|
| 266 |
+
- **AI4Privacy PII-masking-300k**: 1,000 examples
|
| 267 |
+
- Large-scale, diverse PII examples
|
| 268 |
+
- Multiple languages and jurisdictions
|
| 269 |
+
- Human-validated accuracy
|
| 270 |
+
- **Synthetic Data**: 500 examples
|
| 271 |
+
- Generated using Faker library
|
| 272 |
+
- Edge cases and rare PII types
|
| 273 |
+
- Balanced category representation
|
| 274 |
+
- **Total**: 1,500 training examples
|
| 275 |
+
|
| 276 |
+
### Training Configuration
|
| 277 |
+
|
| 278 |
+
```yaml
|
| 279 |
+
Base Model: IBM Granite 4.0 Micro (3.2B parameters)
|
| 280 |
+
Method: LoRA (Low-Rank Adaptation)
|
| 281 |
+
Trainable Parameters: 38.4M (1.19% of total)
|
| 282 |
+
Training Hardware: NVIDIA L4 GPU
|
| 283 |
+
Training Time: ~7 minutes
|
| 284 |
+
Epochs: 1
|
| 285 |
+
Batch Size: 8 (2 Γ 4 gradient accumulation)
|
| 286 |
+
Learning Rate: 2e-4
|
| 287 |
+
Optimizer: AdamW 8-bit
|
| 288 |
+
Final Loss: 0.015-0.038
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
### Training Framework
|
| 292 |
+
|
| 293 |
+
- **Unsloth**: For efficient fine-tuning
|
| 294 |
+
- **Transformers**: Model architecture
|
| 295 |
+
- **PEFT**: LoRA implementation
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
## Privacy & Security
|
| 300 |
+
|
| 301 |
+
### Privacy Features
|
| 302 |
+
|
| 303 |
+
- **Local Inference**: Runs entirely on your infrastructure
|
| 304 |
+
- **No Data Sharing**: No data sent to external APIs or services
|
| 305 |
+
- **Open Source**: Full transparency in model architecture and training
|
| 306 |
+
- **Customizable**: Can be further fine-tuned on your specific data
|
| 307 |
+
- **Offline Capable**: Works without internet connection
|
| 308 |
+
|
| 309 |
+
### Security Considerations
|
| 310 |
+
|
| 311 |
+
- Model detects but doesn't store PII
|
| 312 |
+
- Inference happens in-memory
|
| 313 |
+
- No logging of input/output by default
|
| 314 |
+
- Can be deployed in air-gapped environments
|
| 315 |
+
- Supports encrypted storage of model weights
|
| 316 |
+
|
| 317 |
+
## π License
|
| 318 |
+
|
| 319 |
+
This model is released under the **Apache 2.0** license. You are free to:
|
| 320 |
+
- Use commercially
|
| 321 |
+
- Modify and distribute
|
| 322 |
+
- Use privately
|
| 323 |
+
- Use for patent purposes
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
## π Acknowledgments
|
| 327 |
+
|
| 328 |
+
- Built on **IBM Granite 4.0** architecture
|
| 329 |
+
- Trained using **AI4Privacy PII-masking-300k** dataset
|
| 330 |
+
- Powered by **Unsloth** for efficient training
|
| 331 |
+
- Thanks to the open-source ML community
|
| 332 |
+
|
| 333 |
+
## π Citation
|
| 334 |
|
| 335 |
+
If you use this model in your research or applications, please cite:
|
|
|
|
|
|
|
| 336 |
|
| 337 |
+
```bibtex
|
| 338 |
+
@misc{sentinel-pii-redaction-2025,
|
| 339 |
+
author = {coolAI},
|
| 340 |
+
title = {Sentinel PII Redaction: High-Accuracy Local PII Detection},
|
| 341 |
+
year = {2025},
|
| 342 |
+
publisher = {HuggingFace},
|
| 343 |
+
journal = {HuggingFace Model Hub},
|
| 344 |
+
howpublished = {\url{https://huggingface.co/coolAI/sentinel-pii-redaction}}
|
| 345 |
+
}
|
| 346 |
+
```
|
| 347 |
|
| 348 |
+
**Built with β€οΈ for privacy-conscious AI development**
|