File size: 16,388 Bytes
e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 f5ad16e e322de3 7f35bef f5ad16e 7f35bef e322de3 7f32f19 e322de3 f5ad16e e322de3 f5ad16e e322de3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
---
language:
- en
tags:
- text-deidentification
- privacy
- pii-removal
- text2text-generation
- medical
- legal
- hr
- llama
- gguf
- minibase
- small-model
- 2048-context
license: apache-2.0
datasets:
- custom
metrics:
- completeness-score
- pii-detection-rate
- semantic-preservation
- latency
model-index:
- name: DeId-Small
results:
- task:
type: text-deidentification
name: Completeness Score
dataset:
type: custom
name: Personal De-identifier Benchmark
config: mixed-domains
split: test
metrics:
- type: pii-detection-rate
value: 1.000
name: PII Detection Rate
- type: completeness-score
value: 0.650
name: Completeness Score
- type: semantic-preservation
value: 0.811
name: Semantic Preservation
- type: latency
value: 477.0
name: Average Latency (ms)
---
# DeId-Small π€
<div align="center">
**A compact, privacy-focused text de-identification model for removing personal identifiers while preserving meaning.**
[](https://huggingface.co/)
[](https://huggingface.co/)
[](https://huggingface.co/)
[](LICENSE)
[](https://discord.com/invite/BrJn4D2Guh)
*Built by [Minibase](https://minibase.ai) - Train and deploy small AI models from your browser.*
*Browse all of the models and datasets available on the [Minibase Marketplace](https://minibase.ai/wiki/Special:Marketplace).*
</div>
## π Model Summary
**Minibase-DeId-Small** is a specialized language model fine-tuned for text de-identification tasks. It automatically detects and replaces personal identifiers (PII) such as names, dates, addresses, phone numbers, and other sensitive information with standardized placeholder tags while preserving the original meaning and context of the text.
### Key Features
- π **Privacy-First**: Removes personal identifiers automatically
- π― **High Completeness**: 64% of texts fully de-identified
- π **Compact Size**: 136MB (Q8_0 quantized)
- β‘ **Fast Inference**: ~492ms average response time
- π **Multi-Domain**: Works across medical, legal, HR, and general text
- π **Local Processing**: No data sent to external servers
## π Quick Start
### Local Inference (Recommended)
1. **Install llama.cpp** (if not already installed):
```bash
# Clone and build llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make
# Return to project directory
cd ../de-id-small
```
2. **Download the GGUF model**:
```bash
# Download model files from HuggingFace
wget https://huggingface.co/Minibase/DeId-Small/resolve/main/model.gguf
wget https://huggingface.co/Minibase/DeId-Small/resolve/main/deid_inference.py
wget https://huggingface.co/Minibase/DeId-Small/resolve/main/config.json
wget https://huggingface.co/Minibase/DeId-Small/resolve/main/tokenizer_config.json
wget https://huggingface.co/Minibase/DeId-Small/resolve/main/generation_config.json
```
3. **Start the model server**:
```bash
# Start llama.cpp server with the GGUF model
../llama.cpp/llama-server \
-m model.gguf \
--host 127.0.0.1 \
--port 8000 \
--ctx-size 2048 \
--n-gpu-layers 0 \
--chat-template
```
4. **Make API calls**:
```python
import requests
# De-identify text via REST API
response = requests.post("http://127.0.0.1:8000/completion", json={
"prompt": "Instruction: De-identify this text by replacing all personal information with placeholders.\n\nInput: Patient John Smith, born 1985-03-15, lives at 123 Main St.\n\nResponse: ",
"max_tokens": 256,
"temperature": 0.1
})
result = response.json()
print(result["content"])
# Output: "Patient [FIRSTNAME_1] [LASTNAME_1], born [DOB_1], lives at [BUILDINGNUMBER_1] [STREET_1]."
```
### Python Client (Recommended)
```python
# Download and use the provided Python client
from deid_inference import DeIdClient
# Initialize client (connects to local server)
client = DeIdClient()
# De-identify sensitive text
sensitive_text = "Dr. Sarah Johnson called from (555) 123-4567 about patient Michael Brown."
clean_text = client.deidentify_text(sensitive_text)
print(clean_text)
# Output: "Dr. [FIRSTNAME_1] [LASTNAME_1] called from [PHONE_1] about patient [FIRSTNAME_2] [LASTNAME_2]."
# Batch processing
texts = [
"Employee John Doe earns $85,000 annually.",
"Contact [email protected] for details."
]
clean_texts = client.deidentify_batch(texts)
print(clean_texts)
# Output: ["Employee [FIRSTNAME_1] Doe earns [CURRENCYSYMBOL_1][AMOUNT_1] annually.", "Contact [EMAIL_1] for details."]
```
### Direct llama.cpp Usage
```python
# Alternative: Use llama.cpp directly without server
import subprocess
import json
def deidentify_with_llama_cpp(text: str) -> str:
prompt = f"Instruction: De-identify this text by replacing all personal information with placeholders.\n\nInput: {text}\n\nResponse: "
# Run llama.cpp directly
cmd = [
"../llama.cpp/llama-cli",
"-m", "model.gguf",
"--prompt", prompt,
"--ctx-size", "2048",
"--n-predict", "256",
"--temp", "0.1",
"--log-disable"
]
result = subprocess.run(cmd, capture_output=True, text=True, cwd=".")
return result.stdout.strip()
# Usage
result = deidentify_with_llama_cpp("Patient Sarah Johnson, DOB 05/12/1980.")
print(result)
```
## π Benchmarks & Performance
### Overall Performance (100 samples)
| Metric | Score | Description |
|--------|-------|-------------|
| **PII Detection Rate** | **100%** | **Perfect detection when PII is present in input** |
| **Completeness Score** | **65.0%** | **Percentage of texts fully de-identified** |
| **Semantic Preservation** | **81.1%** | **How well original meaning is preserved** |
| **Average Latency** | **477ms** | **Response time performance** |
### Performance Insights
- β
**Perfect PII Detection**: 100% detection rate when PII is present in input
- β
**Strong Completeness**: 67% of texts fully de-identified
- β
**Fast Inference**: 484ms average response time
- β
**Unified Performance**: Consistent across all text types and domains
## ποΈ Technical Details
### Model Architecture
- **Architecture**: LlamaForCausalLM
- **Parameters**: 135M (small capacity)
- **Context Window**: 2,048 tokens
- **Max Position Embeddings**: 2,048
- **Quantization**: GGUF (Q8_0 quantization)
- **File Size**: 136MB
- **Memory Requirements**: 8GB RAM minimum, 16GB recommended
### Training Details
- **Base Model**: Custom-trained Llama architecture
- **Fine-tuning Dataset**: Curated PII-parallel text pairs
- **Training Objective**: Instruction-following for de-identification
- **Optimization**: Quantized for efficient inference
- **Model Scale**: Small capacity optimized for speed
### System Requirements
| Component | Minimum | Recommended |
|-----------|---------|-------------|
| **Operating System** | Linux, macOS, Windows | Linux or macOS |
| **RAM** | 8GB | 16GB |
| **Storage** | 150MB free space | 500MB free space |
| **Python** | 3.8+ | 3.10+ |
| **Dependencies** | llama.cpp | llama.cpp, requests |
**Notes:**
- β
**CPU-only inference** supported but slower
- β
**GPU acceleration** provides significant speed improvements
- β
**Apple Silicon** users get Metal acceleration automatically
## π Usage Examples
### Basic De-identification
```python
# Input: "John Smith from New York called about his account."
# Output: "[FIRSTNAME_1] [LASTNAME_1] from [CITY_1] called about his account."
# Input: "Patient born on 1990-05-15 visited Dr. Williams."
# Output: "Patient born on [DOB_1] visited Dr. [LASTNAME_1]."
```
### Medical Records
```python
# Input: "Sarah Johnson, DOB 05/12/1980, visited St. Jude Hospital."
# Output: "[FIRSTNAME_1] [LASTNAME_1], DOB [DOB_1], visited [HOSPITAL_1]."
# Input: "Dr. Michael Brown called from (555) 123-4567."
# Output: "Dr. [FIRSTNAME_1] [LASTNAME_1] called from [PHONE_1]."
```
### Legal Documents
```python
# Input: "Attorney Robert Davis from Legal Eagles LLP filed the motion."
# Output: "Attorney [FIRSTNAME_1] [LASTNAME_1] from [ORGANIZATION_1] filed the motion."
# Input: "Case LD-2022-007 was filed on December 1, 2022."
# Output: "Case [CASE_ID_1] was filed on [DATE_1]."
```
### HR Records
```python
# Input: "Employee John Doe earns $85,000 annually."
# Output: "Employee [FIRSTNAME_1] Doe earns [CURRENCYSYMBOL_1][AMOUNT_1] annually."
# Input: "Contact [email protected] for details."
# Output: "Contact [EMAIL_1] for details."
```
## π§ Advanced Configuration
### Server Configuration
```bash
# GPU acceleration (macOS with Metal)
llama-server \
-m model.gguf \
--host 127.0.0.1 \
--port 8000 \
--n-gpu-layers 35 \
--ctx-size 2048 \
--metal
# CPU-only (higher memory usage)
llama-server \
-m model.gguf \
--host 127.0.0.1 \
--port 8000 \
--n-gpu-layers 0 \
--threads 8 \
--ctx-size 2048
```
### Temperature Settings
| Temperature Range | Approach | Description |
|------------------|----------|-------------|
| **0.0-0.2** | **Conservative (Recommended)** | **Precise, consistent de-identification** |
| **0.3-0.5** | Balanced | Good balance of accuracy and flexibility |
| **0.6-1.0** | Creative | More flexible but may miss some PII |
## π‘ Examples
Here are real examples of the model in action, tested across different sectors and text types:
### π₯ Medical Records
**Input:**
```
Patient John Smith, born on March 15, 1985, visited Dr. Emily Johnson at St. Mary Hospital on January 10, 2024. His phone number is (555) 123-4567 and he lives at 123 Oak Street, Springfield, IL 62701.
```
**Output:**
```
Patient [FIRSTNAME_1] [MIDDLENAME_1], born on [DOB_1], visited Dr. [MIDDLENAME_2] [LASTNAME_1] at [CITY_1] Hospital on [DATE_1]. His phone number is [PHONENUMBER_1] and he lives at [BUILDINGNUMBER_1] [STREET_1], [STATE_1], [STATE_2] [STATE_3].
```
### βοΈ Legal Documents
**Input:**
```
Attorney Robert Davis from Davis & Associates LLP filed a lawsuit on behalf of client Sarah Johnson. The case involves Ms. Johnson's accident on December 15, 2023, at 456 Main Street, Boston, MA. Contact information: [email protected], (617) 555-0123.
```
**Output:**
```
Attorney [FIRSTNAME_1] [LASTNAME_1] from [COMPANYNAME_1] filed a lawsuit on behalf of client [FIRSTNAME_2] [LASTNAME_2]. The case involves Ms. [LASTNAME_3]'s accident on [DATE_1], at [BUILDINGNUMBER_1] [STREET_1], [STATE_1], [STATE_2]. Contact information: [EMAIL_1], [PHONENUMBER_1].
```
### π₯ HR Records
**Input:**
```
Employee record for Michael Chen (ID: EMP-2023-0456). Born: July 22, 1990. Position: Senior Software Engineer. Salary: $125,000 annually. Address: 789 Pine Avenue, Seattle, WA 98101. Email: [email protected]. Emergency contact: Jennifer Chen, sister, phone (206) 555-9876.
```
**Output:**
```
Employee record for [FIRSTNAME_1] [LASTNAME_1] (ID: EMP-[DOB_1]). Born: [DOB_2]. Position: [JOBTITLE_1]. Salary: [CURRENCYSYMBOL_1][AMOUNT_1], [CURRENCYCODE_1]s, [SECONDARYADDRESS_1], [STATE_1] [ZIPCODE_1]. Email: [EMAIL_1]. Emergency contact: [FIRSTNAME_2] [LASTNAME_2], sister, phone ([PHONENUMBER_1]).
```
### π° Financial Records
**Input:**
```
Bank statement for account holder Lisa Rodriguez, Account #9876543210. Transaction on March 5, 2024: Deposit of $2,500 from employer TechSolutions Inc. Address: 321 Elm Drive, Austin, TX 78701. Phone: (512) 555-2468. Email: [email protected].
```
**Output:**
```
Bank statement for account holder [FIRSTNAME_1] [MIDDLENAME_1], Account #[ACCOUNTNUMBER_1]. Transaction on [DATE_1]: Deposit of [CURRENCYSYMBOL_1]2,500 from employer [COMPANYNAME_1]. Address: [BUILDINGNUMBER_1] [STREET_1], [CITY_1], [STATE_1] [STATE_2]. Phone: [PHONENUMBER_1]. Email: [EMAIL_1].
```
### π¬ Social Media / Personal
**Input:**
```
Hey everyone! My friend David Wilson just got engaged to his girlfriend Maria Garcia. They met at Stanford University in 2018 and have been dating for 5 years. David works as a data scientist at Google in Mountain View, CA. Maria is a doctor at Stanford Hospital. Their wedding is planned for June 15, 2025, at Napa Valley Vineyard. Send congratulations to [email protected] or call (650) 555-0199!
```
**Output:**
```
Hey everyone! My friend [FIRSTNAME_1] [LASTNAME_1] just got engaged to his girlfriend [FIRSTNAME_2] [LASTNAME_2]. They met at Stanford University in 2018 and have been dating for 5 years. [FIRSTNAME_3] works as a data scientist at Google in [CITY_1], [STATE_1]. [FIRSTNAME_4] is a doctor at Stanford Hospital. Their wedding is planned for [DATE_1], at [STREET_1]. Send congratulations to [EMAIL_1] or call [PHONENUMBER_1]!
```
### π Meeting Notes
**Input:**
```
Meeting notes: Dr. Amanda White ([email protected], (415) 555-1122) discussed patient care with nurse James Brown. Patient: Mark Johnson, DOB 11/20/1975, diagnosed with diabetes on 03/10/2023. Address: 789 Oak Ave, San Francisco, CA 94102.
```
**Output:**
```
Meeting notes: Dr. [FIRSTNAME_1] [MIDDLENAME_1] [LASTNAME_1], [PHONENUMBER_1] discussed patient care with nurse [FIRSTNAME_2] [LASTNAME_2]. Patient: [FIRSTNAME_3] [MIDDLENAME_3], DOB [DOB_1], diagnosed with diabetes on [DATE_1]. Address: [BUILDINGNUMBER_1] [STREET_1], [CITY_1], [STATE_1] [STATE_2].
```
## π Limitations & Biases
### Current Limitations
| Limitation | Description | Impact |
|------------|-------------|--------|
| **Placeholder Format** | Uses specific naming conventions (e.g., [FIRSTNAME_1]) | May not match all expected formats |
| **Complex Contexts** | May struggle with highly nested or ambiguous PII | Could miss subtle personal information |
| **Language Scope** | Primarily trained on English text | Limited performance on other languages |
| **Context Window** | Limited to 2,048 token context window | Cannot process very long documents |
| **Structured Data** | Less effective on highly formatted data (tables, forms) | Lower performance on structured HR/financial data |
### Potential Biases
| Bias Type | Description | Mitigation |
|-----------|-------------|------------|
| **Cultural Names** | May not recognize all international naming patterns | Regular updates with diverse data |
| **Regional Formats** | Limited exposure to regional address/phone formats | Expand training data coverage |
| **Emerging PII** | May not recognize newest types of personal data | Continuous model updates |
| **Domain Specificity** | Performance varies across different text types | Use domain-specific fine-tuning |
## π€ Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
### Development Setup
```bash
# Clone the repository
git clone https://github.com/minibase-ai/deid-small
cd deid-small
# Install dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/
```
## π Citation
If you use DeId-Small in your research, please cite:
```bibtex
@misc{deid-small-2025,
title={DeId-Small: A Compact Text De-identification Model},
author={Minibase AI Team},
year={2025},
publisher={Hugging Face},
url={https://huggingface.co/Minibase/DeId-Small}
}
```
## π€ Community & Support
- **Website**: [minibase.ai](https://minibase.ai)
- **Discord**: [Join our community](https://discord.com/invite/BrJn4D2Guh)
- **Documentation**: [docs.minibase.ai](https://docs.minibase.ai)
## π License
This model is released under the [Apache License 2.0](LICENSE).
## π Acknowledgments
- **Personal De-identifier Benchmark Dataset**: Used for training and evaluation
- **llama.cpp**: For efficient local inference
- **Hugging Face**: For model hosting and community
- **Our amazing community**: For feedback and contributions
---
<div align="center">
**Built with β€οΈ by the Minibase team**
*Making AI safer and more accessible for everyone*
[π Star us on GitHub](https://github.com/minibase-ai/deid-small) β’ [π Read the docs](https://docs.minibase.ai) β’ [π¬ Join our Discord](https://discord.com/invite/BrJn4D2Guh)
</div>
|