LOOFYYLO commited on
Commit
640a1d4
·
verified ·
1 Parent(s): 9e3ee80

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -11,7 +11,7 @@ st.set_page_config(page_title="Dynamic Entropy Genuineness Framework", layout="w
11
 
12
  st.title("Dynamic Entropy Genuineness Framework (Version 2.2 Advanced)")
13
  st.markdown("""
14
- This application analyzes model trajectories using the **Genuineness Phase Space**.
15
  - **Token Cost (X)**: External information density (surprisal).
16
  - **Dynamic Genuineness (Y / G-score)**: Internal complexity (entropy variance).
17
  """)
@@ -39,7 +39,7 @@ if st.button("Analyze Genuineness Trajectory"):
39
  with st.spinner("Analyzing model dynamics..."):
40
  # 1. Version 2.2 Model Analysis (d_model=256, n_heads=8, n_layers=6 as trained)
41
  v2_model = GenuineTransformer(d_model=256, n_heads=8, n_layers=6, vocab_size=1000)
42
-
43
  # Load weights
44
  weights_path = "advanced_genuine_model_v2_2.pt"
45
  if os.path.exists(weights_path):
@@ -61,13 +61,13 @@ if st.button("Analyze Genuineness Trajectory"):
61
  with torch.no_grad():
62
  v2_tokens = text_to_tokens(prompt)
63
  logits, entropies = v2_model(v2_tokens, g_budget=g_budget)
64
-
65
  # G-trajectory: var(entropy) per step across heads
66
  # entropies: list of [batch, seq, heads]
67
  g_scores = [float(torch.var(e, dim=-1).mean().detach()) for e in entropies]
68
-
69
  col1, col2 = st.columns(2)
70
-
71
  with col1:
72
  st.subheader("Version 2.2: Adaptive G-Trajectory")
73
  if g_scores:
@@ -81,7 +81,7 @@ if st.button("Analyze Genuineness Trajectory"):
81
  ax_v2.set_ylim(0, max(1.0, max(g_scores) * 1.2))
82
  ax_v2.legend()
83
  st.pyplot(fig_v2)
84
-
85
  st.write(f"**Final G-score**: {round(g_scores[-1], 4)}")
86
  st.write(f"**Total Reasoning Steps**: {len(entropies)}")
87
  else:
@@ -93,12 +93,12 @@ if st.button("Analyze Genuineness Trajectory"):
93
  st.subheader("Version 1.0: GPT-2 Phase Space (Interpretability)")
94
  v1_model = HookedTransformer.from_pretrained("gpt2-small")
95
  results_v1 = run_transformerlens_phase_analysis(v1_model, prompt)
96
-
97
  mapper = PhaseSpaceMapper()
98
  fig_v1, ax_v1 = plt.subplots(figsize=(10, 8))
99
  cost = np.array(results_v1["raw_scores"]["cost"])
100
  dynamic = np.array(results_v1["raw_scores"]["dynamic"])
101
-
102
  ax_v1.scatter(cost, dynamic, alpha=0.5, edgecolors='k')
103
  ax_v1.set_xlabel("Token Cost (Surprisal)")
104
  ax_v1.set_ylabel("Genuineness (Entropy Variance)")
@@ -112,7 +112,7 @@ if st.button("Analyze Genuineness Trajectory"):
112
  ax_v1.grid(True, alpha=0.2)
113
  ax_v1.legend()
114
  st.pyplot(fig_v1)
115
-
116
  st.write("**Quadrant Distribution**:")
117
  st.json(results_v1["phase_space_distribution"])
118
  except Exception as e:
 
11
 
12
  st.title("Dynamic Entropy Genuineness Framework (Version 2.2 Advanced)")
13
  st.markdown("""
14
+ This application analyzes model trajectories using the **Genuineness Phase Space**.
15
  - **Token Cost (X)**: External information density (surprisal).
16
  - **Dynamic Genuineness (Y / G-score)**: Internal complexity (entropy variance).
17
  """)
 
39
  with st.spinner("Analyzing model dynamics..."):
40
  # 1. Version 2.2 Model Analysis (d_model=256, n_heads=8, n_layers=6 as trained)
41
  v2_model = GenuineTransformer(d_model=256, n_heads=8, n_layers=6, vocab_size=1000)
42
+
43
  # Load weights
44
  weights_path = "advanced_genuine_model_v2_2.pt"
45
  if os.path.exists(weights_path):
 
61
  with torch.no_grad():
62
  v2_tokens = text_to_tokens(prompt)
63
  logits, entropies = v2_model(v2_tokens, g_budget=g_budget)
64
+
65
  # G-trajectory: var(entropy) per step across heads
66
  # entropies: list of [batch, seq, heads]
67
  g_scores = [float(torch.var(e, dim=-1).mean().detach()) for e in entropies]
68
+
69
  col1, col2 = st.columns(2)
70
+
71
  with col1:
72
  st.subheader("Version 2.2: Adaptive G-Trajectory")
73
  if g_scores:
 
81
  ax_v2.set_ylim(0, max(1.0, max(g_scores) * 1.2))
82
  ax_v2.legend()
83
  st.pyplot(fig_v2)
84
+
85
  st.write(f"**Final G-score**: {round(g_scores[-1], 4)}")
86
  st.write(f"**Total Reasoning Steps**: {len(entropies)}")
87
  else:
 
93
  st.subheader("Version 1.0: GPT-2 Phase Space (Interpretability)")
94
  v1_model = HookedTransformer.from_pretrained("gpt2-small")
95
  results_v1 = run_transformerlens_phase_analysis(v1_model, prompt)
96
+
97
  mapper = PhaseSpaceMapper()
98
  fig_v1, ax_v1 = plt.subplots(figsize=(10, 8))
99
  cost = np.array(results_v1["raw_scores"]["cost"])
100
  dynamic = np.array(results_v1["raw_scores"]["dynamic"])
101
+
102
  ax_v1.scatter(cost, dynamic, alpha=0.5, edgecolors='k')
103
  ax_v1.set_xlabel("Token Cost (Surprisal)")
104
  ax_v1.set_ylabel("Genuineness (Entropy Variance)")
 
112
  ax_v1.grid(True, alpha=0.2)
113
  ax_v1.legend()
114
  st.pyplot(fig_v1)
115
+
116
  st.write("**Quadrant Distribution**:")
117
  st.json(results_v1["phase_space_distribution"])
118
  except Exception as e: