mirror of
https://github.com/onestardao/WFGY.git
synced 2026-04-28 11:40:07 +00:00
125 lines
3.4 KiB
Text
125 lines
3.4 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# \ud83e\uddea WFGY \u03bb_observe Checkpoint Demo (v0.1)\n",
|
|
"Show how an *observation checkpoint* can reduce semantic drift (\u0394S)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Concept\n",
|
|
"`\u03bb_observe` inserts a reasoning checkpoint: Prompt \u2192 **step 1 (observe)** \u2192 step 2. \n",
|
|
"If the checkpoint works, **\u0394S_after < \u0394S_before**."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "install"
|
|
},
|
|
"source": [
|
|
"!pip -q install sentence-transformers --upgrade"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "imports"
|
|
},
|
|
"source": [
|
|
"from sentence_transformers import SentenceTransformer, util"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "model"
|
|
},
|
|
"source": [
|
|
"model = SentenceTransformer('all-MiniLM-L6-v2')"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "helper"
|
|
},
|
|
"source": [
|
|
"def delta_s(a_vec, b_vec):\n",
|
|
" return 1 - util.cos_sim(a_vec, b_vec).item()"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## \u270f\ufe0f Edit & run\n",
|
|
"Replace the three strings, press \u25b6\ufe0f."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "user"
|
|
},
|
|
"source": [
|
|
"prompt = \"Explain the key events that led to World War I.\"\n",
|
|
"step1 = \"The war started in 1914 after the assassination of Archduke Franz Ferdinand.\"\n",
|
|
"step2 = \"And that is why pizza became popular in New York.\"\n",
|
|
"\n",
|
|
"# \u0394S before observation (Prompt \u2192 step1)\n",
|
|
"dS_before = delta_s(model.encode(prompt, convert_to_tensor=True),\n",
|
|
" model.encode(step1, convert_to_tensor=True))\n",
|
|
"\n",
|
|
"# \u0394S after observation (Prompt \u2192 step2)\n",
|
|
"dS_after = delta_s(model.encode(prompt, convert_to_tensor=True),\n",
|
|
" model.encode(step2, convert_to_tensor=True))\n",
|
|
"\n",
|
|
"print(\"\u0394S before checkpoint :\", f\"{dS_before:.3f}\")\n",
|
|
"print(\"\u0394S after checkpoint :\", f\"{dS_after:.3f}\\n\")\n",
|
|
"\n",
|
|
"if dS_after < dS_before:\n",
|
|
" print(\"\u2705 Drift reduced \u2014 checkpoint successful\")\n",
|
|
"else:\n",
|
|
" print(\"\u26a0\ufe0f Drift increased \u2014 logic collapse detected (use BBCR fallback)\")"
|
|
],
|
|
"execution_count": null,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"---\n",
|
|
"### Next Steps\n",
|
|
"* Try different checkpoints or multi-hop chains.\n",
|
|
"* For full failure taxonomy see **Problem Map 1.0 / 2.0**.\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|