Views
No views yet
meta_prompt was ignored.1You extract structured filters from e-commerce search queries.
2Return only one valid JSON object, with no markdown or explanation.
3Your output must validate against the supplied JSON Schema: include every required key, preserve nesting, do not add keys, and keep arrays as arrays.
4Fill values only when stated or clearly implied by the query. Use JSON null for a required scalar field whose value is not available in the query.
5Preserve the exact spelling and capitalization of every JSON key.1E-commerce query:
2{query}
3
4JSON Schema:
5{compact_json_schema}null. If a required scalar is unavailable, output JSON null—not None, an omitted key, or the string "null". Evaluation used temperature 0, top_p=1, a 4096-token output allowance, and reasoning not applicable (non-reasoning model).men's Nike running shoes in red under $100{"type":"object","properties":{"product_type":{"type":["string","null"]},"brand":{"type":["string","null"]},"color":{"type":["string","null"]},"price_max":{"type":["number","null"]}},"required":["product_type","brand","color","price_max"],"additionalProperties":false}{"product_type":"running shoes","brand":"Nike","color":"red","price_max":100}1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base_id = "Qwen/Qwen2.5-0.5B-Instruct"
5adapter_id = "Ionio-ai/Qwen2.5-0.5B-Instruct-Ecommerce-Extraction-LoRA"
6
7tokenizer = AutoTokenizer.from_pretrained(adapter_id)
8base = AutoModelForCausalLM.from_pretrained(base_id, device_map="auto", torch_dtype="auto")
9model = PeftModel.from_pretrained(base, adapter_id)
10
11messages = [
12 {"role": "system", "content": SYSTEM_PROMPT},
13 {"role": "user", "content": f"E-commerce query:\n{query}\n\nJSON Schema:\n{compact_schema}"},
14]
15inputs = tokenizer.apply_chat_template(
16 messages, add_generation_prompt=True, return_tensors="pt",
17 enable_thinking=False,
18).to(model.device)
19output = model.generate(inputs, do_sample=False, max_new_tokens=4096)
20print(tokenizer.decode(output[0, inputs.shape[-1]:], skip_special_tokens=True))SYSTEM_PROMPT exactly as shown above. Validate the returned JSON against the supplied schema before using it.SFTTrainer 0.29.1, assistant-only loss| Metric | Result |
|---|---|
| Strict JSON | 99.54% |
| Schema valid | 98.90% |
| Exact match | 20.82% |
| Case-insensitive exact | 23.93% |
| Leaf precision | 85.07% |
| Leaf recall | 84.79% |
| Leaf F1 | 84.89% |
| Key F1 | 98.89% |
| Aligned type accuracy | 99.43% |
| Null accuracy | 98.82% |
| Truncated outputs | 3 / 1,095 |
(JSON path, typed value) pairs; Key F1 ignores values. Null accuracy measures correct null output on gold-null paths, with no-null examples defined as 100%. No “recoverable” JSON is credited as strict JSON.