A lightweight
3B parameter PII (Personally Identifiable Information) classifier, distilled from the
Roblox PII Classifier (560M XLM-RoBERTa) using
teacher-student distillation with Fireworks AI's LoRA fine-tuning.
┌─────────────────────────────────────────────────────────────────┐
│ TEACHER-STUDENT DISTILLATION │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ Labels ┌──────────────────────┐ │
│ │ DeepSeek API │ ──────────────► │ Synthetic Dataset │ │
│ │ (Data Generator) │ │ 5,000 examples │ │
│ └──────────────────┘ └──────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ ROBLOX PII CLASSIFIER (Teacher) │ │
│ │ XLM-RoBERTa-Large (560M) │ │
│ │ │ │
│ │ Thresholds: │ │
│ │ • asking >= 0.2 → "asking" │ │
│ │ • giving >= 0.3 → "giving" │ │
│ │ • max >= 0.2691 → most confident class │ │
│ │ • else → "none" │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ │ Soft Labels │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ LLAMA 3.2 3B + LoRA (Student) │ │
│ │ │ │
│ │ System: "Classify if this message involves PII. │ │
│ │ Reply with: none, asking, or giving." │ │
│ │ │ │
│ │ User: Message: "whats ur snap?" │ │
│ │ Assistant: asking │ │
│ │ │ │
│ │ LoRA Config: │ │
│ │ • Rank: 16, Alpha: 32 │ │
│ │ • Target: q,k,v,o,gate,up,down_proj │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
1 from transformers import AutoTokenizer , AutoModelForCausalLM
2 from peft import PeftModel
3 import torch
4
5 # Load base model
6 base_model = AutoModelForCausalLM . from_pretrained (
7 "meta-llama/Llama-3.2-3B-Instruct" ,
8 torch_dtype = torch . bfloat16 ,
9 device_map = "auto"
10 )
11 tokenizer = AutoTokenizer . from_pretrained ( "meta-llama/Llama-3.2-3B-Instruct" )
12
13 # Load LoRA adapter
14 model = PeftModel . from_pretrained ( base_model , "sugiv/sugiv-pii-classifier" )
15
16 def classify_pii ( message : str ) - > str :
17 """Classify a message for PII content."""
18 messages = [
19 { "role" : "system" , "content" : 'Classify if this chat message involves PII (personal info). Reply with exactly one word: "none", "asking", or "giving".' } ,
20 { "role" : "user" , "content" : f'Message: " { message } "' }
21 ]
22
23 inputs = tokenizer . apply_chat_template ( messages , return_tensors = "pt" ) . to ( model . device )
24
25 with torch . no_grad ( ) :
26 outputs = model . generate ( inputs , max_new_tokens = 10 , temperature = 0 , do_sample = False )
27
28 response = tokenizer . decode ( outputs [ 0 ] [ inputs . shape [ 1 ] : ] , skip_special_tokens = True )
29 return response . strip ( ) . lower ( ) . split ( ) [ 0 ]
30
31 # Examples
32 print ( classify_pii ( "whats ur snap?" ) ) # → asking
33 print ( classify_pii ( "my email is john@example.com" ) ) # → giving
34 print ( classify_pii ( "this game is so fun" ) ) # → none
1 import requests
2
3 API_KEY = "your-fireworks-api-key"
4 MODEL = "accounts/sugi205-8d1850/models/pii-classifier-llama3b-5k"
5
6 def classify_pii ( message : str ) - > str :
7 response = requests . post (
8 "https://api.fireworks.ai/inference/v1/chat/completions" ,
9 headers = { "Authorization" : f"Bearer { API_KEY } " } ,
10 json = {
11 "model" : MODEL ,
12 "messages" : [
13 { "role" : "system" , "content" : 'Classify if this message involves PII. Reply: none, asking, or giving.' } ,
14 { "role" : "user" , "content" : f'Message: " { message } "' }
15 ] ,
16 "max_tokens" : 10 ,
17 "temperature" : 0
18 }
19 )
20 return response . json ( ) [ "choices" ] [ 0 ] [ "message" ] [ "content" ] . strip ( ) . lower ( )