Model Details
Table with columns: Field, Value| Field | Value |
|---|
| Base model | Qwen/Qwen3.5-4B |
| Adapter type | LoRA (peft==0.21.3), r=32, lora_alpha=64, lora_dropout=0.0 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (42.5M trainable params, ~1.0%) |
| Language | French (fr) |
| Knowledge Graph | UNESS LISA ontology (https://uness.fr/lisa/ontology/), 4,872 KnowledgeObjective pages with fullWikitext linked to 367 KnowledgeItem chapters via hasKnowledgeObjective |
| Training stages | Stage 1: Title-style GRPO (60 steps) → Stage 2A: SFT warm-up (488 traces, 2 epochs) → Stage 2B: Open-question GRPO (70 steps, negative-halved update rule) |
| Recommended inference | temperature=0.7, top_p=0.95, max_turns=16, max_new_tokens=1024, exact LISA schema system prompt below |
Important: This adapter was trained with a specific hand-rendered completions prompt (enable_thinking=False, empty <think>\n\n</think>\n\n prefix per assistant turn) and requires the LISA ontology schema instructions in the system prompt. Calling it through a standard chat template without this schema system prompt or without the <sparql> / <result> loop will significantly degrade retrieval accuracy.
- The model emits
<sparql>SELECT ...</sparql> (stop string </sparql>).
- Your harness executes the SPARQL query against the Virtuoso endpoint (default graph
https://uness.fr/lisa/ontology/, truncating results to 2,500 characters) and feeds back <result>\n...\n</result> as the next user turn.
- The episode ends when the model emits
<answer>...</answer> (stop string </answer>).
System Prompt (Base Instructions + LISA Schema Guidance)
Tu es un assistant qui répond à des questions en explorant un graphe de connaissances RDF via un endpoint SPARQL.Le graphe est dans le graphe nommé <https://uness.fr/lisa/ontology/>. Tu ne connais pas son schéma : explore-le d'abord si nécessaire. Outils / format :- Pour exécuter une requête SPARQL, écris exactement : <sparql>SELECT ...</sparql> Tu recevras le résultat dans <result>...</result>. Utilise LIMIT et GRAPH <https://uness.fr/lisa/ontology/> { ... }.- Quand tu connais la réponse, écris : <answer>ta réponse finale</answer>- Une seule requête par message. Ne devine pas : base ta réponse sur les résultats obtenus.- Réponds de façon concise, dans la langue de la question. Indices sur le graphe :- Les objectifs de connaissance sont de type <https://uness.fr/lisa/ontology/KnowledgeObjective> et ont rdfs:label (titre) et <https://uness.fr/lisa/ontology/fullWikitext> (le texte complet de la page, qui contient les informations détaillées).- Seuls ces objectifs ont fullWikitext. Le titre seul ne suffit jamais pour répondre : lis le texte.- Pour une question libre, cherche les mots-clés dans le texte : ?s <https://uness.fr/lisa/ontology/fullWikitext> ?t . FILTER(CONTAINS(LCASE(STR(?t)), "mot")). Sélectionne d'abord ?s et rdfs:label avec LIMIT, puis lis le texte d'un ou deux objectifs (SELECT ?t pour un seul ?s).- Si le sujet n'apparaît nulle part dans le graphe, dis clairement qu'il n'est pas couvert. Si la question contient une affirmation fausse, corrige-la après avoir lu la page.- Chaque objectif appartient à un chapitre via <https://uness.fr/lisa/ontology/hasKnowledgeObjective> : ?item <https://uness.fr/lisa/ontology/hasKnowledgeObjective> ?s . ?item <http://www.w3.org/2000/01/rdf-schema#label> ?il . Donner plus de poids aux mots-clés présents dans les titres (?il et ?l) en plus du texte (?t) trouve plus vite les bonnes pages.- Une fois un objectif pertinent trouvé, tu peux lister les objectifs du même chapitre via ?item <https://uness.fr/lisa/ontology/hasKnowledgeObjective> ?o . ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l .- Pour une question à deux volets ou une comparaison, lis une page pour chaque volet (en listant le chapitre ou en faisant une seconde recherche si le deuxième volet est dans un autre chapitre).
Quickstart
1. Serve with vLLM
vllm serve Qwen/Qwen3.5-4B \ --dtype bfloat16 \ --max-model-len 16384 \ --enable-lora --max-lora-rank 32 \ --lora-modules lisa-best=asanchez75/qwen3.5-4b-lisa-sparql-agent-lora \ --reasoning-parser qwen3
Query the /v1/completions endpoint using model="lisa-best", stop=["</sparql>", "</answer>"], include_stop_str_in_output=True, temperature=0.7, top_p=0.95, max_tokens=1024, rendering each turn with <|im_start|>assistant\n<think>\n\n</think>\n\n.
import torchfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom peft import PeftModel base_id = "Qwen/Qwen3.5-4B"adapter_id = "asanchez75/qwen3.5-4b-lisa-sparql-agent-lora" tokenizer = AutoTokenizer.from_pretrained(base_id)base_model = AutoModelForCausalLM.from_pretrained( base_id, dtype=torch.bfloat16, device_map="auto")model = PeftModel.from_pretrained(base_model, adapter_id)model.eval()
Training Procedure
Stage 1 — Title-Style Foundation (60 steps GRPO)
- Trained from base
Qwen/Qwen3.5-4B on title-quoting questions (verify, list_recall) with on-policy GRPO (--rule neghalf, lr=2e-5, group size 8, 8 questions/step).
- Reached 0.913 validation score at
temperature=0.7 (0.963 at 0.3).
Stage 2A — Warm-up v2 SFT (2 epochs, 122 steps)
- Resumed from Stage 1 (
step60), fresh AdamW (lr=5e-6, batch size 8, assistant-only loss).
- Dataset: 488 verified clean traces (strictly zero overlap with all held-out and locked evaluation sets):
- Title-boosted search (
2× item/objective label match + 1× fullWikitext match via hasKnowledgeObjective), validated offline at +18 pts turn-1 hit rate on the untouched clinicians' set and +42 pts on finding both pages for multi-source questions.
- Clean
hasKnowledgeObjective chapter sibling listing.
- Synthetic traces across all 5 open styles (
factual, spontaneous, multisource, distractor refutation, outside_scope verification) plus cleaned title-style traces.
Stage 2B — Open-Question On-Policy GRPO (70 steps)
- Resumed from Stage 2A (
step122, fresh AdamW optimizer, lr=5e-6, questions_per_step=8, group=8, max_turns=16, max_new_tokens=1024, max_seq=14000, temperature=0.7).
- Update rule (
--rule neghalf): Positive (adv > 0) and negative (adv < 0) gradient components are accumulated separately; negative gradients are halved and the combined update is rescaled to the original norm (no group-std scaling, no KL term, 1 on-policy gradient step per batch, clip norm 1.0). This prevents longer failing trajectories from eroding exploration behavior.
- Batch mix:
85% style-balanced open questions (multisource 25%, distractor 25%, spontaneous 20%, factual 15%, outside_scope 15%) + 15% title-style questions (verify, list_recall).
- Reward shaping (rule-based, no judge model): Retrieval-gated
fullWikitext page-read verification (text_seen), eff_need per-page coverage, duplicate-query penalty (0.03, capped at 0.10), and false-decline penalty (0.10, no termination bonus) on answerable questions.
Software Stack
- Trainer:
Python 3.12.11, torch 2.14.0, transformers 5.17.0, peft 0.21.3, accelerate 1.16.0 (1× NVIDIA H100)
- Rollout engine:
vllm 0.34.0 with runtime LoRA hot-reloading
Evaluation Results
All held-out evaluations were run at temperature=0.7, max_turns=16, max_new_tokens=1024, 3 samples per question (n=270 rollouts per set: 180 open across 5 styles + 90 title-style). To guarantee zero metric inflation, scores are reported under the original unmodified v3 grader alongside v4.1.
1. Held-Out Benchmarks (eval_fresh & eval_fixed, original v3 scale)
Table with columns: Metric, Previous Best (v1 step60), This Adapter (v2 step70), Gain| Metric | Previous Best (v1 step60) | This Adapter (v2 step70) | Gain |
|---|
Global score — all 270 rollouts (fresh / fixed) | 0.712 / 0.697 | 0.786 / 0.769 | +0.074 / +0.072 |
All open questions — 5 styles (fresh / fixed) | 0.611 / 0.558 | 0.705 / 0.671 | +0.094 / +0.113 |
Answerable open — 4 styles (fresh / fixed) | 0.542 / 0.489 | 0.653 / 0.603 | +0.111 / +0.114 (95% CI > 0 on both) |
multisource (fresh / fixed, full 2-page read) | 0.382 (28%) / 0.386 (36%) | 0.709 (69%) / 0.712 (83%) | +0.327 / +0.326 |
spontaneous (fresh / fixed, v3 → v4.1) | 0.443 / 0.430 | 0.676 (0.789) / 0.559 (0.703) | +0.233 / +0.129 |
factual (fresh / fixed) | 0.826 / 0.569 | 0.774 / 0.698 | −0.052 / +0.129 |
outside_scope (fresh / fixed) | 0.889 / 0.833 | 0.917 / 0.944 | +0.028 / +0.111 |
distractor (fresh / fixed) | 0.517 / 0.568 | 0.451 / 0.442 | −0.066 / −0.126 |
verify / list_recall (fresh) | 0.941 / 0.875 | 1.000 / 0.880 | Intact |
Paired 95% bootstrap CIs over questions (v2 step70 − v1 step60, 4 answerable open styles, v3 scale): eval_fresh +0.111 [+0.002, +0.225], eval_fixed +0.114 [+0.020, +0.220].
2. Locked Clinicians' Retrieval Probe (318 real questions, 250 with citations — 0 chapters seen in training)
Table with columns: Metric, Previous Best (v1 step60), This Adapter (v2 step70)| Metric | Previous Best (v1 step60) | This Adapter (v2 step70) |
|---|
Cited page read (fullWikitext, 250 qs) | 63.2% | 63.2% (seed 1: 56.8% → 62.4%) |
Clinicians' multisource cited page read | 51.2% | 68.3% (+17.1 pts) (seed 1: +19.5 pts) |
| Cited page ID found | 77.2% | 78.8% |
Episode completion (answered) | 90.9% | 99.1% (+8.2 pts) |
| False declines on cited questions | 38.8% | 34.8% |
Limitations & Intended Use
- Research & educational use only — NOT for clinical decision-making. This is a 4B research model exploring SPARQL-based grounding over the French EDN/LISA medical curriculum. Answers must not be used for patient care without qualified medical supervision.
- Prompt dependence: Requires the exact LISA schema system prompt above and completions-API format (
<think>\n\n</think>\n\n).
- False-premise (
distractor) questions (~45%): The model reads the right page ~75% of the time on held-out distractors, but can still hedge ("not covered") or list facts neutrally rather than explicitly refuting a false premise.
- Query-length overflow: Occasionally packs many keywords into a single
CONCAT search query and hits max_new_tokens=1024 (~0.4 format-invalid turns/rollout), which the harness recovers from on the next turn.
- Recommended 2-stage deployment: For user-facing answers, keep this adapter strictly on its trained prompt for SPARQL exploration, then pass the retrieved
fullWikitext pages to base Qwen/Qwen3.5-4B to synthesize a structured final response (preserving retrieval accuracy while improving readability and handling clinical synonyms).