Views
No views yet
"Hi, I'd like to make a reservation for 2 adults and 3 children on the 15th of next month around 7:30 in the evening, and you can reach me at +886-912-345-678"1{
2 "num_people": "5",
3 "reservation_date": "15th of next month at 7:30 PM",
4 "phone_num": "0912345678"
5}| Entity | Extracted From Input | Normalized Output |
|---|---|---|
num_people | "2 adults and 3 children" | "5" (summed total) |
reservation_date | "15th of next month around 7:30 in the evening" | "15th of next month at 7:30 PM" (normalized time format) |
phone_num | "+886-912-345-678" | "0912345678" (international format converted to local) |
09XXXXXXXX format):"+886-912-345-678" → 0912345678 (international format)"零九一二三四五六七八" → 0912345678 (Chinese characters)"09 12 34 56 78" → 0912345678 (spaced format)"市話02-1234-5678" → "" (landline)"國際電話+1-555-123-4567" → "" (international non-Taiwanese)"免付費0800-123-456" → "" (toll-free)pip install transformers torch1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3import json
4
5# Load model and tokenizer
6model_name = "Luigi/dinercall-ner"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
9
10# System prompt (in original Chinese)
11system_prompt = """你是一個助理,負責從用戶消息中提取預訂資訊並以JSON格式輸出。
12JSON必須包含三個字段: num_people, reservation_date, phone_num。
13如果某個字段沒有信息,使用空字符串。只輸出JSON,不要添加任何其他文字。"""
14
15# Example with complex input
16user_input = "Hi, I'd like to make a reservation for 2 adults and 3 children on the 15th of next month around 7:30 in the evening, and you can reach me at +886-912-345-678"
17messages = [
18 {"role": "system", "content": system_prompt},
19 {"role": "user", "content": user_input}
20]
21
22# Generate response
23prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
24inputs = tokenizer(prompt, return_tensors="pt")
25
26with torch.no_grad():
27 outputs = model.generate(
28 **inputs,
29 max_new_tokens=64,
30 temperature=0.1,
31 do_sample=False
32 )
33
34# Process output
35response = tokenizer.decode(outputs[0][len(inputs.input_ids[0]):], skip_special_tokens=True)
36result = json.loads(response)
37print(result)
38# Output: {"num_people": "5", "reservation_date": "15th of next month at 7:30 PM", "phone_num": "0912345678"}| Parameter | Value |
|---|---|
| Base Model | unsloth/gemma-3-270m-it-unsloth-bnb-4bit |
| Max Sequence Length | 256 tokens |
| Learning Rate | 2e-5 |
| Batch Size | 4 (gradient accumulation: 2) |
| Training Epochs | 10 |
| LoRA Rank | 32 |
1# Example 1: Complex English with mixed formatting
2input_text = "Could you please reserve a table for 3 adults and 2 children on December 24th around 8 PM? My contact is +886-987-654-321"
3output = {
4 "num_people": "5",
5 "reservation_date": "December 24th at 8 PM",
6 "phone_num": "0987654321"
7}
8
9# Example 2: Chinese with complex date and mixed digits
10input_text = "我們想要預約下個月15號晚上7點半,4大2小,電話是零九八七-六五四三二一"
11output = {
12 "num_people": "6",
13 "reservation_date": "下個月15號晚上7點半",
14 "phone_num": "0987654321"
15}
16
17# Example 3: Noisy ASR input with complex elements
18input_text = "Book for for 2 adullts and 1 childreen onn nexts Friday at 6:45 PM, fone 09八七六五四三二一"
19output = {
20 "num_people": "3",
21 "reservation_date": "next Friday at 6:45 PM",
22 "phone_num": "0987654321"
23}
24
25# Example 4: Mixed language with complex request
26input_text = "我想book 3大人2小孩,time是next Wednesday at 7:30 PM,contact number是0912-345-678"
27output = {
28 "num_people": "5",
29 "reservation_date": "next Wednesday at 7:30 PM",
30 "phone_num": "0912345678"
31}1@software{dinercall_ner_model_2025,
2 author = {Luigi},
3 title = {Gemma-3-270M Fine-tuned for Restaurant Reservation NER},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/Luigi/dinercall-ner}
7}