|
|
|
|
|
""" |
|
|
Commitment Conservation Demo - Interactive HuggingFace Space |
|
|
Side-by-side comparison of baseline vs enforced compression |
|
|
""" |
|
|
import gradio as gr |
|
|
import os |
|
|
import sys |
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'harness')) |
|
|
|
|
|
from src.test_harness import recursion_test, extract_commitments |
|
|
import pandas as pd |
|
|
import matplotlib.pyplot as plt |
|
|
|
|
|
|
|
|
DEMO_SIGNALS = { |
|
|
"Function Contract": "This function must return an integer.", |
|
|
"Lease Agreement": "The tenant shall not sublet the premises without written consent.", |
|
|
"Safety Rule": "You must wear a helmet while cycling.", |
|
|
"Password Policy": "All passwords must be at least 8 characters long.", |
|
|
"Budget Constraint": "The budget cannot exceed $5000." |
|
|
} |
|
|
|
|
|
def run_comparison(signal_text, num_iterations=3): |
|
|
""" |
|
|
Run side-by-side comparison of baseline vs enforced compression. |
|
|
Returns formatted results for display. |
|
|
""" |
|
|
if not signal_text.strip(): |
|
|
return "⚠️ Please enter a text signal.", None, None, None |
|
|
|
|
|
|
|
|
original_commitments = extract_commitments(signal_text) |
|
|
commitment_text = f"**Detected Commitments:** {', '.join(original_commitments) if original_commitments else 'None detected'}" |
|
|
|
|
|
|
|
|
baseline_deltas = recursion_test(signal_text, depth=num_iterations, enforce=False) |
|
|
baseline_stability = [(1.0 - d) * 100 for d in baseline_deltas] |
|
|
|
|
|
|
|
|
enforced_deltas = recursion_test(signal_text, depth=num_iterations, enforce=True) |
|
|
enforced_stability = [(1.0 - d) * 100 for d in enforced_deltas] |
|
|
|
|
|
|
|
|
iterations = list(range(num_iterations + 1)) |
|
|
df = pd.DataFrame({ |
|
|
'Iteration': iterations, |
|
|
'Baseline Stability (%)': [f"{s:.1f}%" for s in baseline_stability], |
|
|
'Enforced Stability (%)': [f"{s:.1f}%" for s in enforced_stability], |
|
|
'Gap (pp)': [f"+{(e - b):.1f}" for b, e in zip(baseline_stability, enforced_stability)] |
|
|
}) |
|
|
|
|
|
|
|
|
fig, ax = plt.subplots(figsize=(8, 5)) |
|
|
ax.plot(iterations, baseline_stability, marker='o', label='Baseline', color='#d62728', linewidth=2) |
|
|
ax.plot(iterations, enforced_stability, marker='s', label='Enforced', color='#2ca02c', linewidth=2) |
|
|
ax.set_xlabel('Iteration', fontsize=12) |
|
|
ax.set_ylabel('Commitment Stability (%)', fontsize=12) |
|
|
ax.set_title('Baseline vs Enforced: Commitment Preservation', fontsize=14, fontweight='bold') |
|
|
ax.legend(fontsize=11) |
|
|
ax.grid(True, alpha=0.3) |
|
|
ax.set_ylim([-5, 105]) |
|
|
plt.tight_layout() |
|
|
|
|
|
|
|
|
final_baseline = baseline_stability[-1] |
|
|
final_enforced = enforced_stability[-1] |
|
|
gap = final_enforced - final_baseline |
|
|
|
|
|
summary = f""" |
|
|
## 📊 Results Summary |
|
|
|
|
|
**After {num_iterations} iterations:** |
|
|
- **Baseline:** {final_baseline:.1f}% stability |
|
|
- **Enforced:** {final_enforced:.1f}% stability |
|
|
- **Improvement:** +{gap:.1f} percentage points |
|
|
|
|
|
{'✅ **Enforcement preserved commitments!**' if gap > 10 else '⚠️ Signal may need more iterations to show drift.'} |
|
|
|
|
|
*Full 10-iteration harness with 5 signals shows +40pp average improvement. Run locally for complete validation.* |
|
|
""" |
|
|
|
|
|
return commitment_text, df, fig, summary |
|
|
|
|
|
|
|
|
|
|
|
with gr.Blocks(title="Commitment Conservation Demo", theme=gr.themes.Soft()) as demo: |
|
|
gr.Markdown(""" |
|
|
# ⚖️ Commitment Conservation Interactive Demo |
|
|
|
|
|
**Watch semantic drift in recursive compression—and see how commitment enforcement prevents it.** |
|
|
|
|
|
This demo compares **baseline** transformer compression (which loses commitments) vs **enforced** compression (which preserves them). |
|
|
|
|
|
📄 [Paper (v0.03)](https://doi.org/10.5281/zenodo.18274930) | 💻 [Full Harness](https://huggingface.co/burnmydays/commitment_conservation_harness) | 🔬 [GitHub](https://github.com/SunrisesIllNeverSee/commitment-conservation) |
|
|
""") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(scale=2): |
|
|
signal_input = gr.Textbox( |
|
|
label="Input Signal (Text with Commitment)", |
|
|
placeholder="Enter text containing a commitment, obligation, or constraint...", |
|
|
lines=4, |
|
|
value=DEMO_SIGNALS["Function Contract"] |
|
|
) |
|
|
|
|
|
with gr.Row(): |
|
|
preset_dropdown = gr.Dropdown( |
|
|
choices=list(DEMO_SIGNALS.keys()), |
|
|
label="Or select a preset example:", |
|
|
value="Function Contract" |
|
|
) |
|
|
iterations_slider = gr.Slider( |
|
|
minimum=1, |
|
|
maximum=3, |
|
|
step=1, |
|
|
value=3, |
|
|
label="Iterations (limited to 3 for speed)" |
|
|
) |
|
|
|
|
|
run_btn = gr.Button("🔬 Run Comparison", variant="primary", size="lg") |
|
|
|
|
|
gr.Markdown(""" |
|
|
**How it works:** |
|
|
1. System extracts commitments from your text |
|
|
2. Compresses text recursively (3 iterations) |
|
|
3. Tracks whether commitments survive each round |
|
|
4. Compares baseline (drifts) vs enforced (preserves) |
|
|
|
|
|
*⏱️ Takes ~20-40 seconds on CPU. Models load on first run.* |
|
|
""") |
|
|
|
|
|
with gr.Column(scale=3): |
|
|
commitments_display = gr.Markdown(label="Extracted Commitments") |
|
|
results_table = gr.Dataframe(label="Stability Over Iterations") |
|
|
results_plot = gr.Plot(label="Comparison Chart") |
|
|
summary_display = gr.Markdown(label="Summary") |
|
|
|
|
|
|
|
|
def update_signal_from_preset(preset_name): |
|
|
return DEMO_SIGNALS[preset_name] |
|
|
|
|
|
preset_dropdown.change( |
|
|
fn=update_signal_from_preset, |
|
|
inputs=[preset_dropdown], |
|
|
outputs=[signal_input] |
|
|
) |
|
|
|
|
|
run_btn.click( |
|
|
fn=run_comparison, |
|
|
inputs=[signal_input, iterations_slider], |
|
|
outputs=[commitments_display, results_table, results_plot, summary_display] |
|
|
) |
|
|
|
|
|
gr.Markdown(""" |
|
|
--- |
|
|
|
|
|
## 📖 About This Framework |
|
|
|
|
|
This demonstrates the **commitment conservation principle**: meaningful commitments in language should be preserved |
|
|
under compression and recursive application. The full harness tests 5 signals over 10 iterations and shows |
|
|
**baseline systems fail (20% stability) while enforced systems succeed (60% stability)** — a 40pp empirical gap. |
|
|
|
|
|
**⚖️ IP Notice:** MO§ES™ is a trademark of Ello Cello LLC. See [repo](https://huggingface.co/burnmydays/commitment_conservation_harness) for details. |
|
|
|
|
|
© 2026 Ello Cello LLC. All rights reserved. |
|
|
""") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|