Minibase commited on
Commit
e322de3
Β·
verified Β·
1 Parent(s): 12de55b

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +346 -0
README.md ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - text-deidentification
6
+ - privacy
7
+ - pii-removal
8
+ - text2text-generation
9
+ - medical
10
+ - legal
11
+ - hr
12
+ - llama
13
+ - gguf
14
+ - minibase
15
+ - small-model
16
+ - 2048-context
17
+ license: apache-2.0
18
+ datasets:
19
+ - custom
20
+ metrics:
21
+ - completeness-score
22
+ - pii-detection-rate
23
+ - semantic-preservation
24
+ - latency
25
+ model-index:
26
+ - name: DeId-Small
27
+ results:
28
+ - task:
29
+ type: text-deidentification
30
+ name: Completeness Score
31
+ dataset:
32
+ type: custom
33
+ name: Personal De-identifier Benchmark
34
+ config: mixed-domains
35
+ split: test
36
+ metrics:
37
+ - type: completeness-score
38
+ value: 0.640
39
+ name: Overall Completeness
40
+ - type: pii-detection-rate
41
+ value: 0.203
42
+ name: PII Detection Rate
43
+ - type: semantic-preservation
44
+ value: 0.109
45
+ name: Semantic Preservation
46
+ - type: latency
47
+ value: 492.4
48
+ name: Average Latency (ms)
49
+ ---
50
+
51
+ # DeId-Small πŸ€–
52
+
53
+ <div align="center">
54
+
55
+ **A compact, privacy-focused text de-identification model for removing personal identifiers while preserving meaning.**
56
+
57
+ [![Model Size](https://img.shields.io/badge/Model_Size-136MB-blue)](https://huggingface.co/)
58
+ [![Architecture](https://img.shields.io/badge/Architecture-LlamaForCausalLM-green)](https://huggingface.co/)
59
+ [![Context Window](https://img.shields.io/badge/Context-2048_Tokens-orange)](https://huggingface.co/)
60
+ [![License](https://img.shields.io/badge/License-Apache_2.0-yellow)](LICENSE)
61
+ [![Discord](https://img.shields.io/badge/Discord-Join_Community-5865F2)](https://discord.com/invite/BrJn4D2Guh)
62
+
63
+ *Built by [Minibase](https://minibase.ai) - Train and deploy small AI models from your browser.*
64
+ *Browse all of the models and datasets available on the [Minibase Marketplace](https://minibase.ai/wiki/Special:Marketplace).*
65
+
66
+ </div>
67
+
68
+ ## πŸ“‹ Model Summary
69
+
70
+ **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.
71
+
72
+ ### Key Features
73
+ - πŸ”’ **Privacy-First**: Removes personal identifiers automatically
74
+ - 🎯 **High Completeness**: 64% of texts fully de-identified
75
+ - πŸ“ **Compact Size**: 136MB (Q8_0 quantized)
76
+ - ⚑ **Fast Inference**: ~492ms average response time
77
+ - 🌐 **Multi-Domain**: Works across medical, legal, HR, and general text
78
+ - πŸ”„ **Local Processing**: No data sent to external servers
79
+
80
+ ## πŸš€ Quick Start
81
+
82
+ ### Local Inference (Recommended)
83
+
84
+ 1. **Install llama.cpp** (if not already installed):
85
+ ```bash
86
+ git clone https://github.com/ggerganov/llama.cpp
87
+ cd llama.cpp && make
88
+ ```
89
+
90
+ 2. **Download and run the model**:
91
+ ```bash
92
+ # Download model files
93
+ wget https://huggingface.co/Minibase/DeId-Small/resolve/main/model.gguf
94
+ wget https://huggingface.co/Minibase/DeId-Small/resolve/main/deid_inference.py
95
+
96
+ # Make executable and run
97
+ chmod +x run_server.sh
98
+ ./run_server.sh
99
+ ```
100
+
101
+ 3. **Make API calls**:
102
+ ```python
103
+ import requests
104
+
105
+ # De-identify text
106
+ response = requests.post("http://127.0.0.1:8000/completion", json={
107
+ "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: ",
108
+ "max_tokens": 256,
109
+ "temperature": 0.1
110
+ })
111
+
112
+ result = response.json()
113
+ print(result["content"]) # "Patient [FIRSTNAME_1] [LASTNAME_1], born [DOB_1], lives at [BUILDINGNUMBER_1] [STREET_1]."
114
+ ```
115
+
116
+ ### Python Client
117
+
118
+ ```python
119
+ from deid_inference import DeIdClient
120
+
121
+ # Initialize client
122
+ client = DeIdClient()
123
+
124
+ # De-identify text
125
+ sensitive_text = "Dr. Sarah Johnson called from (555) 123-4567 about patient Michael Brown."
126
+ clean_text = client.deidentify_text(sensitive_text)
127
+
128
+ print(clean_text) # "Dr. [FIRSTNAME_1] [LASTNAME_1] called from [PHONE_1] about patient [FIRSTNAME_2] [LASTNAME_2]."
129
+ ```
130
+
131
+ ## πŸ“Š Benchmarks & Performance
132
+
133
+ ### Overall Performance (100 samples)
134
+
135
+ | Metric | Score | Description |
136
+ |--------|-------|-------------|
137
+ | **Completeness Score** | **64.0%** | **Percentage of texts fully de-identified** |
138
+ | PII Detection Rate | 20.3% | How well expected PII patterns are detected |
139
+ | Semantic Preservation | 10.9% | How well original meaning is preserved |
140
+ | **Average Latency** | **492ms** | **Response time performance** |
141
+
142
+ ### Domain-Specific Performance
143
+
144
+ | Domain | Samples | Completeness | Best For |
145
+ |--------|---------|-------------|----------|
146
+ | **General Text** | 40 | **75.0%** | **Mixed content, everyday text** |
147
+ | **Customer Service** | 6 | **100%** | **Support interactions, inquiries** |
148
+ | **Medical Records** | 33 | 60.6% | Patient notes, clinical data |
149
+ | **Legal Documents** | 6 | 50.0% | Depositions, contracts |
150
+ | **HR Records** | 11 | 27.3% | Employee data, personnel files |
151
+ | **Research Data** | 4 | 50.0% | Study participants, academic data |
152
+
153
+ **Performance Insights:**
154
+ - βœ… **Excellent at customer service** (100% completeness)
155
+ - βœ… **Strong general-purpose performance** (75% completeness)
156
+ - βœ… **Good medical record handling** (60.6% completeness)
157
+ - ⚠️ **Challenging with structured HR data** (27.3% completeness)
158
+
159
+ ## πŸ—οΈ Technical Details
160
+
161
+ ### Model Architecture
162
+ - **Architecture**: LlamaForCausalLM
163
+ - **Parameters**: 135M (small capacity)
164
+ - **Context Window**: 2,048 tokens
165
+ - **Max Position Embeddings**: 2,048
166
+ - **Quantization**: GGUF (Q8_0 quantization)
167
+ - **File Size**: 136MB
168
+ - **Memory Requirements**: 8GB RAM minimum, 16GB recommended
169
+
170
+ ### Training Details
171
+ - **Base Model**: Custom-trained Llama architecture
172
+ - **Fine-tuning Dataset**: Curated PII-parallel text pairs
173
+ - **Training Objective**: Instruction-following for de-identification
174
+ - **Optimization**: Quantized for efficient inference
175
+ - **Model Scale**: Small capacity optimized for speed
176
+
177
+ ### System Requirements
178
+
179
+ | Component | Minimum | Recommended |
180
+ |-----------|---------|-------------|
181
+ | **Operating System** | Linux, macOS, Windows | Linux or macOS |
182
+ | **RAM** | 8GB | 16GB |
183
+ | **Storage** | 150MB free space | 500MB free space |
184
+ | **Python** | 3.8+ | 3.10+ |
185
+ | **Dependencies** | llama.cpp | llama.cpp, requests |
186
+
187
+ **Notes:**
188
+ - βœ… **CPU-only inference** supported but slower
189
+ - βœ… **GPU acceleration** provides significant speed improvements
190
+ - βœ… **Apple Silicon** users get Metal acceleration automatically
191
+
192
+ ## πŸ“– Usage Examples
193
+
194
+ ### Basic De-identification
195
+ ```python
196
+ # Input: "John Smith from New York called about his account."
197
+ # Output: "[FIRSTNAME_1] [LASTNAME_1] from [CITY_1] called about his account."
198
+
199
+ # Input: "Patient born on 1990-05-15 visited Dr. Williams."
200
+ # Output: "Patient born on [DOB_1] visited Dr. [LASTNAME_1]."
201
+ ```
202
+
203
+ ### Medical Records
204
+ ```python
205
+ # Input: "Sarah Johnson, DOB 05/12/1980, visited St. Jude Hospital."
206
+ # Output: "[FIRSTNAME_1] [LASTNAME_1], DOB [DOB_1], visited [HOSPITAL_1]."
207
+
208
+ # Input: "Dr. Michael Brown called from (555) 123-4567."
209
+ # Output: "Dr. [FIRSTNAME_1] [LASTNAME_1] called from [PHONE_1]."
210
+ ```
211
+
212
+ ### Legal Documents
213
+ ```python
214
+ # Input: "Attorney Robert Davis from Legal Eagles LLP filed the motion."
215
+ # Output: "Attorney [FIRSTNAME_1] [LASTNAME_1] from [ORGANIZATION_1] filed the motion."
216
+
217
+ # Input: "Case LD-2022-007 was filed on December 1, 2022."
218
+ # Output: "Case [CASE_ID_1] was filed on [DATE_1]."
219
+ ```
220
+
221
+ ### HR Records
222
+ ```python
223
+ # Input: "Employee John Doe earns $85,000 annually."
224
+ # Output: "Employee [FIRSTNAME_1] Doe earns [CURRENCYSYMBOL_1][AMOUNT_1] annually."
225
+
226
+ # Input: "Contact jane.smith@company.com for details."
227
+ # Output: "Contact [EMAIL_1] for details."
228
+ ```
229
+
230
+ ## πŸ”§ Advanced Configuration
231
+
232
+ ### Server Configuration
233
+ ```bash
234
+ # GPU acceleration (macOS with Metal)
235
+ llama-server \
236
+ -m model.gguf \
237
+ --host 127.0.0.1 \
238
+ --port 8000 \
239
+ --n-gpu-layers 35 \
240
+ --ctx-size 2048 \
241
+ --metal
242
+
243
+ # CPU-only (higher memory usage)
244
+ llama-server \
245
+ -m model.gguf \
246
+ --host 127.0.0.1 \
247
+ --port 8000 \
248
+ --n-gpu-layers 0 \
249
+ --threads 8 \
250
+ --ctx-size 2048
251
+ ```
252
+
253
+ ### Temperature Settings
254
+
255
+ | Temperature Range | Approach | Description |
256
+ |------------------|----------|-------------|
257
+ | **0.0-0.2** | **Conservative (Recommended)** | **Precise, consistent de-identification** |
258
+ | **0.3-0.5** | Balanced | Good balance of accuracy and flexibility |
259
+ | **0.6-1.0** | Creative | More flexible but may miss some PII |
260
+
261
+ ## πŸ“š Limitations & Biases
262
+
263
+ ### Current Limitations
264
+
265
+ | Limitation | Description | Impact |
266
+ |------------|-------------|--------|
267
+ | **Placeholder Format** | Uses specific naming conventions (e.g., [FIRSTNAME_1]) | May not match all expected formats |
268
+ | **Complex Contexts** | May struggle with highly nested or ambiguous PII | Could miss subtle personal information |
269
+ | **Language Scope** | Primarily trained on English text | Limited performance on other languages |
270
+ | **Context Window** | Limited to 2,048 token context window | Cannot process very long documents |
271
+ | **Structured Data** | Less effective on highly formatted data (tables, forms) | Lower performance on structured HR/financial data |
272
+
273
+ ### Potential Biases
274
+
275
+ | Bias Type | Description | Mitigation |
276
+ |-----------|-------------|------------|
277
+ | **Cultural Names** | May not recognize all international naming patterns | Regular updates with diverse data |
278
+ | **Regional Formats** | Limited exposure to regional address/phone formats | Expand training data coverage |
279
+ | **Emerging PII** | May not recognize newest types of personal data | Continuous model updates |
280
+ | **Domain Specificity** | Performance varies across different text types | Use domain-specific fine-tuning |
281
+
282
+ ## 🀝 Contributing
283
+
284
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
285
+
286
+ ### Development Setup
287
+ ```bash
288
+ # Clone the repository
289
+ git clone https://github.com/minibase-ai/deid-small
290
+ cd deid-small
291
+
292
+ # Install dependencies
293
+ pip install -r requirements.txt
294
+
295
+ # Run tests
296
+ python -m pytest tests/
297
+ ```
298
+
299
+ ## πŸ“œ Citation
300
+
301
+ If you use DeId-Small in your research, please cite:
302
+
303
+ ```bibtex
304
+ @misc{deid-small-2025,
305
+ title={DeId-Small: A Compact Text De-identification Model},
306
+ author={Minibase AI Team},
307
+ year={2025},
308
+ publisher={Hugging Face},
309
+ url={https://huggingface.co/Minibase/DeId-Small}
310
+ }
311
+ ```
312
+
313
+ ## πŸ“ž Contact & Community
314
+
315
+ - **Website**: [minibase.ai](https://minibase.ai)
316
+ - **Discord Community**: [Join our Discord](https://discord.com/invite/BrJn4D2Guh)
317
+ - **GitHub Issues**: [Report bugs or request features](https://github.com/minibase-ai/deid-small/issues)
318
+ - **Email**: hello@minibase.ai
319
+
320
+ ### Support
321
+ - πŸ“– **Documentation**: [docs.minibase.ai](https://docs.minibase.ai)
322
+ - πŸ’¬ **Community Forum**: [forum.minibase.ai](https://forum.minibase.ai)
323
+ - πŸ› **Bug Reports**: [GitHub Issues](https://github.com/minibase-ai/deid-small/issues)
324
+
325
+ ## πŸ“‹ License
326
+
327
+ This model is released under the [Apache License 2.0](LICENSE).
328
+
329
+ ## πŸ™ Acknowledgments
330
+
331
+ - **Personal De-identifier Benchmark Dataset**: Used for training and evaluation
332
+ - **llama.cpp**: For efficient local inference
333
+ - **Hugging Face**: For model hosting and community
334
+ - **Our amazing community**: For feedback and contributions
335
+
336
+ ---
337
+
338
+ <div align="center">
339
+
340
+ **Built with ❀️ by the Minibase team**
341
+
342
+ *Making AI safer and more accessible for everyone*
343
+
344
+ [🌟 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)
345
+
346
+ </div>