This directory contains comprehensive Jupyter notebooks demonstrating OpenMed's capabilities.
../first_five_minutes_redact_extract_fhir.py- A five-minute synthetic redact -> extract -> FHIR walkthrough that prints the redacted note, extracted entities, and a FHIR Bundle.
Complete guide to PII detection and de-identification (v0.5.0+)
A comprehensive tutorial covering everything about PII functionality:
- Basic PII Extraction - Detect PII entities in clinical text
- Smart Entity Merging - Fix fragmentation issues (NEW in v0.5.0)
- De-identification Methods - Mask, remove, replace, hash, shift dates
- Re-identification - Reverse de-identification with mappings
- Batch Processing - Process multiple texts efficiently
- Confidence Thresholding - Control precision vs recall
- Custom Patterns - Add domain-specific PII patterns
- Clinical Use Cases - Real-world examples (discharge summaries, research datasets, HIPAA compliance)
- Visualization - Display results with highlighting
Topics covered:
- 48 executable cells with detailed explanations
- Smart merging comparison (before/after)
- All 5 de-identification methods demonstrated
- HIPAA compliance checklist
- Production-ready examples
- Best practices and security considerations
Recommended for:
- Healthcare data scientists
- Clinical researchers
- HIPAA compliance officers
- Anyone working with protected health information (PHI)
Task-oriented de-identification recipes (copy-paste)
Short, self-contained recipes for the most common real workflows:
- De-identify a list or CSV of clinical strings
- Batch-redact a directory of text files with
BatchProcessor - Reversible replace + re-identify round-trip
- Per-language model selection with
DEFAULT_PII_MODELS
Uses synthetic PHI only and a lightweight 44M English model for CPU-friendly runs.
Recommended for: Engineers wiring de-identification into a pipeline who want a quick, runnable starting point.
Multilingual PII detection across 9 supported languages
Walk through language-aware extraction and de-identification for:
- English, French, German, Italian, Spanish, and Portuguese multilingual support
- Dutch, Hindi, and Telugu flagship PII models
- Locale-specific dates, phones, addresses, postcodes, and validators
- Cross-language comparisons and custom model selection
Recommended for:
- Teams processing multilingual clinical text
- Reviewers validating new PII releases
- Anyone comparing locale-specific pattern behavior
Introduction to OpenMed basics
Learn the fundamentals of OpenMed:
- Installation and setup
- Basic text analysis with
analyze_text() - Model discovery and selection
- Output formatting (JSON, HTML, CSV)
- Entity grouping and filtering
Recommended for: First-time users, quick start
Advanced sentence detection and batch processing
Master efficient text processing:
- Sentence boundary detection with pySBD
- Batch processing multiple documents
- Performance optimization
- Memory-efficient processing
Recommended for: Production deployments, large-scale processing
Medical-aware tokenization
Explore medical text tokenization:
- Medical term boundary preservation
- Tokenization comparison
- Custom tokenizer configuration
Recommended for: NLP engineers, model developers
Performance benchmarking
Compare tokenization performance:
- Speed benchmarks
- Accuracy metrics
- Resource usage
Recommended for: Performance optimization
Zero-shot NER capabilities
Explore zero-shot learning:
- No training required
- Custom entity types
- Domain adaptation
Recommended for: Research, custom entity detection
# Install OpenMed
uv pip install "openmed[hf]"
# Install Jupyter
uv pip install jupyter
# For PII notebooks, you may need:
uv pip install matplotlib ipython-
Clone the repository:
git clone https://github.com/maziyarpanahi/openmed.git cd openmed/examples/notebooks -
Start Jupyter:
jupyter notebook
-
Open a notebook and run cells sequentially
Some notebooks may require a HuggingFace token for accessing gated models:
import os
os.environ['HF_TOKEN'] = 'your_token_here'Get your token from: https://huggingface.co/settings/tokens
| Notebook | Difficulty | Topics | Duration |
|---|---|---|---|
| PII_Detection_Complete_Guide | Intermediate | PII, De-identification, HIPAA | 30-45 min |
| getting_started | Beginner | Basics, Installation | 10-15 min |
| Sentence_Detection_Batching | Intermediate | Batch processing | 15-20 min |
| Medical_Tokenizer_Demo | Intermediate | Tokenization | 10-15 min |
| Medical_Tokenizer_Benchmark | Advanced | Performance | 15-20 min |
| ZeroShot_NER_Tour | Advanced | Zero-shot NER | 20-30 min |
getting_started.ipynb- Learn basicsSentence_Detection_Batching.ipynb- Batch processing
getting_started.ipynb- Basics firstPII_Detection_Complete_Guide.ipynb- Complete PII guide- Practice with your own clinical notes
getting_started.ipynb- FoundationZeroShot_NER_Tour.ipynb- Zero-shot capabilitiesMedical_Tokenizer_Demo.ipynb- Tokenization deep dive
Sentence_Detection_Batching.ipynb- Batch processingMedical_Tokenizer_Benchmark.ipynb- Performance tuningPII_Detection_Complete_Guide.ipynb- End-to-end de-identification workflows
- Run cells sequentially - Dependencies may exist between cells
- Check imports - Ensure all required packages are installed
- Monitor memory - Some models are large (500MB-1GB+)
- Use GPU if available - Speeds up inference significantly
- Save outputs - Notebooks auto-save, but export important results
Issue: ImportError
# Solution: Install missing package
!pip install package-nameIssue: Model download slow
# Solution: Use HuggingFace cache
export HF_HOME="/path/to/cache"Issue: Out of memory
# Solution: Use smaller batch size or CPU
batch_size=1 # or device="cpu"All notebooks are designed to be modified:
- Change model names to try different models
- Adjust confidence thresholds
- Use your own clinical text
- Modify visualization styles
- Documentation: https://github.com/maziyarpanahi/openmed
- Model Hub: https://huggingface.co/openmed
- Issue Tracker: https://github.com/maziyarpanahi/openmed/issues
- Discussions: https://github.com/maziyarpanahi/openmed/discussions
Have a notebook idea or improvement?
- Fork the repository
- Create a new notebook in this directory
- Follow the existing style and structure
- Submit a pull request
# Title
## Overview
- What this notebook covers
- Prerequisites
- Expected outcomes
## Setup
- Imports
- Configuration
## Main Content
- Section 1: Topic A
- Section 2: Topic B
- ...
## Summary
- Key takeaways
- Next stepsAll notebooks are released under the same license as OpenMed (Apache 2.0).
Last Updated: 2026-01-13
OpenMed Version: v0.5.0+