A LoRA adapter for SmolLM2-1.7B-Instruct that turns a short booking request into JSON:
Request: can u move my court 2 slot to next fri at 4:30pm (today: Wednesday, 2026-11-11)
→ {"intent": "reschedule", "date": "2026-11-13", "time": "16:30", "resource": "Court 2", "needs_clarification": false}
| key | value |
|---|---|
intent |
"book", "reschedule", "cancel" or "check" |
date |
"YYYY-MM-DD" or null |
time |
"HH:MM" (24-hour) or null |
resource |
room or facility name, or null |
needs_clarification |
true if a field the intent needs is missing |
Anything the request does not state is null. Fields each intent needs:
book → date, time, resource · reschedule → date, time · cancel → date · check → date, resource.
The model was trained and scored with exactly this prompt, sent as one user message through the chat template, with greedy decoding. The calendar line lists the next 21 days; it is what lets the model resolve "next Friday" by lookup instead of counting. Without it, accuracy on dates drops.
Extract the booking request below as JSON. Reply with only a JSON object with exactly these keys: "intent" (one of "book", "reschedule", "cancel", "check"), "date" ("YYYY-MM-DD" or null), "time" ("HH:MM", 24-hour, or null), "resource" (room or facility name, or null), "needs_clarification" (true if a value the intent needs is missing, else false). Use null for anything the request does not state. Use the calendar to turn relative dates into YYYY-MM-DD.
Today is Wednesday, 2026-11-11.
Calendar: 2026-11: Thu 12, Fri 13, Sat 14, ..., Mon 30 | 2026-12: Tue 01, Wed 02.
Request: can u move my court 2 slot to next fri at 4:30pm
Needs transformers (≥ 4.56) and peft. In Colab, first run !pip uninstall -y torchao and restart the
session: Colab ships an old torchao that current peft refuses to load next to (this adapter does not use it).
Or open quickstart.ipynb, which does this for you.
import datetime as dt, json, torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
ADAPTER = "moghbaie/smollm2-1.7b-booking-extractor-lora"
tok = AutoTokenizer.from_pretrained(BASE)
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if device == "cuda" and torch.cuda.is_bf16_supported() else torch.float32
model = AutoModelForCausalLM.from_pretrained(BASE, dtype=dtype).to(device)
model = PeftModel.from_pretrained(model, ADAPTER).eval()
INSTRUCTION = (
"Extract the booking request below as JSON. Reply with only a JSON object with exactly these keys: "
'"intent" (one of "book", "reschedule", "cancel", "check"), '
'"date" ("YYYY-MM-DD" or null), "time" ("HH:MM", 24-hour, or null), '
'"resource" (room or facility name, or null), '
'"needs_clarification" (true if a value the intent needs is missing, else false). '
"Use null for anything the request does not state. "
"Use the calendar to turn relative dates into YYYY-MM-DD."
)
DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def calendar_line(today, n=21):
groups = []
for i in range(1, n + 1):
d = today + dt.timedelta(days=i)
month = f"{d.year}-{d.month:02d}"
if not groups or groups[-1][0] != month:
groups.append((month, []))
groups[-1][1].append(f"{DAYS[d.weekday()][:3]} {d.day:02d}")
return "Calendar: " + " | ".join(f"{m}: {', '.join(ds)}" for m, ds in groups) + "."
def build_prompt(request, today):
return (f"{INSTRUCTION}\nToday is {DAYS[today.weekday()]}, {today.isoformat()}.\n"
f"{calendar_line(today)}\nRequest: {request}")
def extract(request, today=None):
today = today or dt.date.today()
msgs = [{"role": "user", "content": build_prompt(request, today)}]
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
enc = tok(text, return_tensors="pt", add_special_tokens=False).to(device)
out = model.generate(**enc, max_new_tokens=96, do_sample=False, pad_token_id=tok.eos_token_id)
return json.loads(tok.decode(out[0, enc["input_ids"].shape[1]:], skip_special_tokens=True))
print(extract("can u move my court 2 slot to next fri at 4:30pm", dt.date(2026, 11, 11)))
Exact match = all five fields correct. 300-row sets; test uses request wordings never seen in training, stress adds held-out date forms, shorthand and typos on top. Paired bootstrap CI95 for differences.
| set | untouched 1.7B | this adapter |
|---|---|---|
| v3 val | 3.0 | 78.67 [74.0, 83.0] |
| v3 test | — | 95.00 |
| v3 stress | — | 77.00 |
| v2 test | 2.0 | 97.00 |
| v2 stress | — | 85.00 |
Against the previous adapter (same base, v2 data, no calendar), on the same rows:
| set | previous | this | diff [CI95] |
|---|---|---|---|
| v3 test | 86.33 | 95.00 | +8.67 [5.67, 12.0] |
| v3 stress | 70.67 | 77.00 | +6.33 [2.33, 10.67] |
| v2 test | 96.67 | 97.00 | +0.33 [−1.67, 2.33] |
| v2 stress | 80.33 | 85.00 | +4.67 [0.67, 8.67] |
General ability is unchanged (lm-eval; IFEval prompt-level strict, HellaSwag acc_norm, ± stderr):
| model | IFEval | HellaSwag |
|---|---|---|
| SmolLM2-360M-Instruct, untouched | 33.09 ± 2.02 | 56.74 ± 0.49 |
| SmolLM2-1.7B-Instruct, untouched | 47.13 ± 2.15 | 71.72 ± 0.45 |
| this adapter | 47.69 ± 2.15 | 71.74 ± 0.45 |
HuggingFaceTB/SmolLM2-1.7B-Instruct