Skip to content

feat(#97): add SHAP narrator task type to training pipeline#104

Open
William-Hill wants to merge 4 commits intofine-tuning/student-explainabilityfrom
fine-tuning/97-shap-narrator-task-type
Open

feat(#97): add SHAP narrator task type to training pipeline#104
William-Hill wants to merge 4 commits intofine-tuning/student-explainabilityfrom
fine-tuning/97-shap-narrator-task-type

Conversation

@William-Hill
Copy link
Copy Markdown
Collaborator

Summary

Adds narrator as a third task type to the training pipeline alongside explainer and summarizer. The narrator takes per-student SHAP attribution values + student profile and generates advisor-facing narratives grounded in ML feature attribution.

  • prompts.py: NARRATOR_SCHEMA, NARRATOR_STUDENT_SYSTEM, build_narrator_prompt() — teacher prompt with SHAP values, risk factors, and available interventions
  • seed.py: generate_synthetic_student_profiles() — synthetic students with SHAP data for distillation; load_seed_queries() now returns narrator key
  • distill.py: narrator in _TASK_CONFIG, included in main() loop; removed dead generate_explainer_pairs/generate_summarizer_pairs wrappers
  • eval.py: check_shap_grounding() metric (narrative must mention >= 2 of top-3 SHAP features); narrator ship criteria; required keys derived from schema dicts
  • prepare.py: narrator added to task iteration

Ship Criteria for Narrator

Metric Threshold Blocking
json_validity >= 95% Yes
schema_adherence >= 90% Yes
shap_grounding >= 80% Yes
caveat_inclusion >= 85% Yes

Test Plan

  • All 72 existing training pipeline tests pass
  • Add narrator-specific tests (follow-up: seed generation, prompt builder, shap grounding metric, schema adherence)
  • Smoke test: python -m training.distill --school bishop-state --local with narrator task

Closes #97

Add narrator as a third task alongside explainer and summarizer.
The narrator takes per-student SHAP values + profile and generates
advisor-facing narratives grounded in ML feature attribution.

- prompts.py: NARRATOR_SCHEMA, NARRATOR_STUDENT_SYSTEM, build_narrator_prompt()
- seed.py: generate_synthetic_student_profiles() with SHAP data
- distill.py: narrator in _TASK_CONFIG, included in main() distillation loop
- eval.py: _NARRATOR_REQUIRED_KEYS, shap_grounding ship criterion (>= 80%),
  check_shap_grounding() metric (counts feature name mentions in narrative)
- prepare.py: narrator added to task iteration
- Remove dead generate_explainer_pairs/generate_summarizer_pairs wrappers
- Derive _REQUIRED_KEYS sets from schema dicts in prompts.py
- Simplify dedup loop in check_shap_grounding with dict.fromkeys()
- Add narrator key to load_seed_queries() return
- Update test_distill.py to use generate_pairs() directly
- Fix stale docstring in generate_pairs()
@William-Hill William-Hill added area:ai AI/ML, NLQ features type:feature New feature fine-tuning: student-explainability Fine-tune Qwen 3.5 for SHAP narrator, summarizer, and explainer tasks labels Apr 3, 2026
@William-Hill
Copy link
Copy Markdown
Collaborator Author

@codeerabbitai review

- check_ship_criteria() now iterates required criteria first; missing
  metrics are blocking failures instead of silently passing
- load_seed_queries() missing-file fallback includes narrator key
- Add .superpowers/ to .gitignore (runtime state files)
- Update test expectation for narrator in seed query fallback
Replace single-family model comparison (Qwen 4B vs 9B) with
cross-family comparison (Qwen 3.5-4B vs Gemma 4 E4B). Gemma 4 E4B
has native structured JSON output and 128K context; Qwen 3.5-4B is
the proven D4BL baseline.

Key changes:
- Add model selection section with head-to-head comparison table
- Update notebook config from MODEL_SIZES to MODELS list
- Switch from QLoRA to bf16 LoRA (Unsloth discourages QLoRA on Qwen 3.5)
- Update Ollama naming, env vars, cost estimates, success criteria
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai AI/ML, NLQ features fine-tuning: student-explainability Fine-tune Qwen 3.5 for SHAP narrator, summarizer, and explainer tasks type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant