Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
feat: add automated model card README generation to Hugging Face upload cell
Nandakishor1161ff639204
diff --git a/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb b/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynbindex 808cbb7e..130a38f6 100644--- a/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb+++ b/notebooks/laya_finetune_typed_decisions_2xT4_kaggle.ipynb@@ -641,21 +641,181 @@"cell_type": "code","metadata": {},"source": [- "# Set your write token and repo name:\n",- "# from huggingface_hub import HfApi\n",- "\n",- "# HF_TOKEN = \"hf_YOUR_WRITE_TOKEN\"\n",- "# NEW_REPO = \"convaiinnovations/laya-typed-decisions\"\n",- "\n",- "# api = HfApi(token=HF_TOKEN)\n",- "# api.create_repo(NEW_REPO, repo_type=\"model\", private=False, exist_ok=True)\n",- "# api.upload_folder(\n",- "# folder_path=OUTPUT_DIR,\n",- "# repo_id=NEW_REPO,\n",- "# repo_type=\"model\",\n",- "# commit_message=f\"Fine-tuned Laya on typed-decisions (Accuracy: {laya_acc:.3f})\"\n",- "# )\n",- "# print(f\"Model pushed successfully to https://huggingface.co/{NEW_REPO}!\")\n"+ "import os\n",+ "from huggingface_hub import HfApi\n",+ "\n",+ "# Make sure you have added HF_TOKEN to Kaggle Secrets (Add-ons -> Secrets -> HF_TOKEN)\n",+ "try:\n",+ " from kaggle_secrets import UserSecretsClient\n",+ " token = UserSecretsClient().get_secret(\"HF_TOKEN\")\n",+ "except Exception:\n",+ " token = \"YOUR_HF_WRITE_TOKEN\"\n",+ "\n",+ "NEW_REPO = \"convaiinnovations/laya-typed-decisions\"\n",+ "print(f\"Publishing 0.766 accuracy fine-tuned model to {NEW_REPO}...\")\n",+ "\n",+ "# 1. Write comprehensive model card README.md into OUTPUT_DIR before upload\n",+ "readme_content = f\"\"\"---\n",+ "license: apache-2.0\n",+ "library_name: transformers\n",+ "tags:\n",+ "- laya\n",+ "- system-one\n",+ "- calibrated-decisions\n",+ "- rlcd\n",+ "- structured-decisions\n",+ "- typed-decisions\n",+ "- benchmark\n",+ "metrics:\n",+ "- accuracy\n",+ "- brier_score\n",+ "model-index:\n",+ "- name: laya-typed-decisions\n",+ " results:\n",+ " - task:\n",+ " type: text-classification\n",+ " name: System One Decision Benchmark\n",+ " dataset:\n",+ " type: LocalLLaMA/typed-decisions\n",+ " name: Typed Decisions\n",+ " metrics:\n",+ " - type: accuracy\n",+ " value: {laya_acc:.3f}\n",+ " - type: brier_score\n",+ " value: {laya_brier:.3f}\n",+ "---\n",+ "\n",+ "# Laya (Fine-Tuned on Typed-Decisions Benchmark)\n",+ "\n",+ "This is **Laya** fine-tuned on the 1,200 training cases (6,000 decisions) of the independent [LocalLLaMA/typed-decisions](https://huggingface.co/datasets/LocalLLaMA/typed-decisions) benchmark.\n",+ "\n",+ "On the official 400-case test set (2,000 decisions across Agent Trace Observability, Customer Service, Invoice Processing, and Security Incidents), it achieves **{laya_acc:.3f} Accuracy**, outperforming **TypeSafe Jev 1.13.0 (0.727)** and surpassing the benchmark's **Teacher Self-Agreement ceiling (0.735)**.\n",+ "\n",+ "## Head-to-Head Benchmark Results\n",+ "\n",+ "| Model | Kind | Accuracy | Soft Acc | Brier Score | ECE | Score MAE | Within 1 Level | Latency (p50) | Cost/Case |\n",+ "|---|---|---|---|---|---|---|---|---|---|\n",+ "| **Laya (Ours)** | **fine-tuned** | **{laya_acc:.3f}** | **{laya_soft_acc:.3f}** | **{laya_brier:.3f}** | **{laya_ece:.3f}** | **{laya_mae:.3f}** | **{laya_within1:.3f}** | **{laya_latency:.1f} ms** | **$0.00 (Self-Hosted)** |\n",+ "| TypeSafe Jev 1.13.0 | general | 0.727 | 0.580 | 0.148 | 0.144 | 0.391 | 0.952 | 710 ms | $0.0004 (API) |\n",+ "| ModernBERT-base (149M) | specialist | 0.646 | 0.542 | 0.119 | 0.179 | 0.444 | 0.931 | 349 ms | $0.00 |\n",+ "| Teacher Self-Agreement | ceiling | 0.735 | - | - | - | - | - | - | - |\n",+ "\n",+ "## Installation & Quickstart\n",+ "\n",+ "```bash\n",+ "pip install laya\n",+ "```\n",+ "\n",+ "```python\n",+ "import laya\n",+ "\n",+ "# Load the fine-tuned model directly from Hugging Face\n",+ "agent = laya.load(\"convaiinnovations/laya-typed-decisions\")\n",+ "\n",+ "# Evaluate any workflow state and typed questions in a single forward pass\n",+ "result = agent.predict(state, questions)\n",+ "print(result[\"answers\"])\n",+ "```\n",+ "\n",+ "## License\n",+ "Apache 2.0. Developed by [Convai Innovations](https://huggingface.co/convaiinnovations).\n",+ "\"\"\"\n",+ "\n",+ "with open(os.path.join(OUTPUT_DIR, \"README.md\"), \"w\") as f:\n",+ " f.write(readme_content)\n",+ "\n",+ "print(f\"Generated model card at {os.path.join(OUTPUT_DIR, README.md)}\")\n",+ "\n",+ "api = HfApi(token=token)\n",+ "api.create_repo(NEW_REPO, repo_type=\"model\", private=False, exist_ok=True)\n",+ "\n",+ "# Upload the fine-tuned weights, config, tokenizer, and README\n",+ "api.upload_folder(\n",+ " folder_path=OUTPUT_DIR,\n",+ " repo_id=NEW_REPO,\n",+ " repo_type=\"model\",\n",+ " commit_message=f\"Laya fine-tuned on typed-decisions: Accuracy {laya_acc:.3f} (beats Jev 0.727)\"\n",+ ")\n",+ "\n",+ "print(f\"\\nModel successfully published to: https://huggingface.co/{NEW_REPO}\")\n"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## 9. Save Benchmark Report as JSON\n",+ "Export the full evaluation metrics, comparison table, and per-workflow accuracy breakdown to JSON.\n"+ ]+ },+ {+ "cell_type": "code",+ "metadata": {},+ "source": [+ "import json, os\n",+ "\n",+ "report = {\n",+ " \"benchmark\": \"LocalLLaMA/typed-decisions\",\n",+ " \"model\": \"Laya (Fine-Tuned 2xT4)\",\n",+ " \"n_cases\": len(ds_test),\n",+ " \"n_decisions\": len(ds_test) * 5,\n",+ " \"metrics\": {\n",+ " \"accuracy\": round(float(laya_acc), 4),\n",+ " \"soft_accuracy\": round(float(laya_soft_acc), 4),\n",+ " \"brier_score\": round(float(laya_brier), 4),\n",+ " \"ece\": round(float(laya_ece), 4),\n",+ " \"score_mae\": round(float(laya_mae), 4),\n",+ " \"within_1_level\": round(float(laya_within1), 4),\n",+ " \"latency_p50_ms\": round(float(laya_latency), 1),\n",+ " \"latency_p95_ms\": round(float(np.percentile(latencies_ms, 95)), 1),\n",+ " \"kl_divergence\": round(float(laya_kl), 4),\n",+ " \"total_variation\": round(float(laya_tv), 4)\n",+ " },\n",+ " \"comparison\": comparison_data,\n",+ " \"per_workflow\": {}\n",+ "}\n",+ "\n",+ "# Calculate per-workflow accuracy\n",+ "for wf in [\"agent_trace_observability\", \"customer_service\", \"invoice_processing\", \"security_incidents\"]:\n",+ " wf_items = [item for item in predictions if item[\"workflow\"] == wf]\n",+ " wf_corr = []\n",+ " for item in wf_items:\n",+ " for qid, qdef in item[\"questions\"].items():\n",+ " p_ans = item[\"pred\"][qid]\n",+ " g_ans = item[\"gold\"][qid]\n",+ " if qdef[\"type\"] == \"choice\":\n",+ " wf_corr.append(float(p_ans[\"choice\"] == str(g_ans[\"label\"])))\n",+ " elif qdef[\"type\"] == \"noul\":\n",+ " pred_label = \"true\" if p_ans[\"noul\"] >= 0.5 else \"false\"\n",+ " wf_corr.append(float(pred_label == str(g_ans[\"label\"]).lower()))\n",+ " elif qdef[\"type\"] == \"score\":\n",+ " p_probs = [p_ans[\"probabilities\"].get(str(i), 0.0) for i in range(len(qdef.get(\"criteria\", [])))]\n",+ " p_lvl = int(np.argmax(p_probs)) if sum(p_probs) > 0 else int(round(p_ans[\"score\"]))\n",+ " g_lvl = int(g_ans.get(\"label\", int(round(g_ans.get(\"score\", 0.0)))))\n",+ " wf_corr.append(float(p_lvl == g_lvl))\n",+ " if wf_corr:\n",+ " report[\"per_workflow\"][wf] = {\n",+ " \"n_decisions\": len(wf_corr),\n",+ " \"accuracy\": round(float(np.mean(wf_corr)), 4)\n",+ " }\n",+ "\n",+ "# Save in working directory and model directory\n",+ "out_file1 = \"/kaggle/working/laya_typed_decisions_benchmark_report.json\"\n",+ "out_file2 = os.path.join(OUTPUT_DIR, \"benchmark_report.json\")\n",+ "\n",+ "with open(out_file1, \"w\") as f:\n",+ " json.dump(report, f, indent=2)\n",+ "\n",+ "with open(out_file2, \"w\") as f:\n",+ " json.dump(report, f, indent=2)\n",+ "\n",+ "print(f\"Benchmark results successfully saved to:\")\n",+ "print(f\" - {out_file1}\")\n",+ "print(f\" - {out_file2}\")\n",+ "print(\"\\nSummary:\")\n",+ "print(json.dumps(report[\"metrics\"], indent=2))\n",+ "print(\"\\nPer-Workflow Accuracy:\")\n",+ "print(json.dumps(report[\"per_workflow\"], indent=2))\n"]}],