Views
No views yet
| Metric | Score |
|---|---|
| Accuracy | 94.45% |
| F1 Score | 92.07% |
pip install transformers torch1from transformers import AutoModelForTokenClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model_name = "your-org/mom-pii-healthcare"
6model = AutoModelForTokenClassification.from_pretrained(model_name)
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9# Prepare input
10text = "Patient John Smith, DOB: 03/15/1985, SSN: 123-45-6789"
11inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
12tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
13
14# Get predictions
15with torch.no_grad():
16 outputs = model(**inputs)
17 predictions = torch.argmax(outputs.logits, dim=-1)[0]
18
19# Extract entities
20entities = []
21current_entity = None
22
23for token, pred_id in zip(tokens, predictions):
24 if token in ['[CLS]', '[SEP]', '[PAD]']:
25 continue
26
27 label = model.config.id2label[pred_id.item()]
28
29 if label.startswith('B-'):
30 if current_entity:
31 entities.append(current_entity)
32 entity_type = label[2:]
33 current_entity = {'type': entity_type, 'tokens': [token]}
34 elif label.startswith('I-') and current_entity:
35 current_entity['tokens'].append(token)
36 else:
37 if current_entity:
38 entities.append(current_entity)
39 current_entity = None
40
41if current_entity:
42 entities.append(current_entity)
43
44# Clean up tokens
45for entity in entities:
46 entity['text'] = tokenizer.convert_tokens_to_string(entity['tokens'])
47 print(f"{entity['type']}: {entity['text']}")1from transformers import pipeline
2
3ner = pipeline(
4 "token-classification",
5 model="your-org/mom-pii-healthcare",
6 aggregation_strategy="simple",
7 device=0 # Use GPU
8)
9
10results = ner("Patient John Smith, DOB: 03/15/1985, SSN: 123-45-6789")
11for entity in results:
12 print(f"{entity['entity_group']}: {entity['word']} ({entity['score']:.2f})")1@misc{mom-pii-healthcare-2026,
2 title={Healthcare PII Detection Model},
3 author={Your Organization},
4 year={2026},
5 publisher={HuggingFace},
6 howpublished={\url{https://huggingface.co/your-org/mom-pii-healthcare}},
7}