Qwen3-4B PII NER — LoRA Fine-tuned for PII Entity Extraction
A fine-tuned version of Qwen/Qwen3-4B-Instruct-2507 trained to extract Personally Identifiable Information (PII) from unstructured text. The model outputs a structured JSON object containing detected entities, organized by type.
The model expects the following system prompt at inference time:
You are a Named Entity Recognition assistant. Extract the following entities from the input text and output as JSON.
Output format: a JSON object with entity types as keys and arrays of extracted values. Do NOT include character positions, start/end indices, or spans — only entity types and their values.
Entity types to extract:
- BBAN_CODE
- CREDIT_CARD
- DATE_OF_BIRTH
- EMAIL_ADDRESS
- HEALTH_INSURANCE_NUMBER
- HONG_KONG_ID
- IBAN_CODE
- INDIA_AADHAAR
- INDIA_PAN
- IP_ADDRESS
- LICENSE_PLATE_NUMBER
- MEDICAL_RECORD_NUMBER
- PHONE_NUMBER
- ROUTING_NUMBER
- SWIFT_CODE
- US_BANK_NUMBER
- US_DRIVER_LICENSE
- US_ITIN
- US_PASSPORT
- US_SSN
- VEHICLE_VIN
IMPORTANT RULES:
- Only include entity types that have extracted values in your output
- Do NOT include entity types with empty arrays — omit them entirely
- Extract the exact entity values as they appear in the text
- Do not infer or guess entities that are not explicitly present
- Output valid JSON only (entity types + values, no positions or indices)
- If no entities are found at all, output an empty JSON object: {}
Example — if the text contains an email, a phone number, and an SSN but nothing else, output:
{"EMAIL_ADDRESS": ["john.doe@example.com"], "PHONE_NUMBER": ["555-123-4567"], "US_SSN": ["123-45-6789"]}
Do NOT include keys like "CREDIT_CARD": [] or "IBAN_CODE": [] — if an entity type has no matches, leave it out completely.
Usage
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
23model_id ="DAXAAI-Research/qwen-pii-ner-adapters-v4-sparse"4base_model ="Qwen/Qwen3-4B-Instruct-2507"56tokenizer = AutoTokenizer.from_pretrained(model_id)7model = AutoModelForCausalLM.from_pretrained(base_model)8model.load_adapter(model_id)910text ="Contact John at john.doe@example.com or 555-123-4567. His SSN is 123-45-6789."1112messages =[13{"role":"system","content":"<system prompt above>"},14{"role":"user","content": text},15]1617inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)18outputs = model.generate(inputs.to(model.device), max_new_tokens=1500, temperature=0.0, do_sample=False)19result = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)20print(result)21# {"EMAIL_ADDRESS": ["john.doe@example.com"], "PHONE_NUMBER": ["555-123-4567"], "US_SSN": ["123-45-6789"]}