Spaces:
Runtime error
Runtime error
File size: 7,195 Bytes
12af533 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
"""
REALIZATION EXPLORER
===================
Interactive visualization of the crystallized conversation.
"""
from layers.layer_2_core.realization_engine import RealizationEngine
from precompute_realizations import precompute_conversation_realizations
import json
def visualize_graph_ascii(engine: RealizationEngine):
"""
ASCII art visualization of the realization graph.
Shows layers and parent-child relationships.
"""
print("\n" + "="*80)
print("REALIZATION GRAPH VISUALIZATION (ุจูุงุช ุงููุงุฑ)")
print("="*80 + "\n")
# Group by layer
by_layer = {}
for layer in [0, 1, 2, 3, 'N']:
by_layer[layer] = list(engine.layers[layer].values())
# Display from top layer down
layer_names = {
0: "LAYER 0: UNIVERSAL RULES (Immutable)",
1: "LAYER 1: DOMAIN FACTS (Rarely change)",
2: "LAYER 2: PATTERNS (Context-specific)",
3: "LAYER 3: SITUATIONAL (Temporary)",
'N': "LAYER N: EPHEMERAL (High churn)"
}
for layer in [0, 1, 2, 3, 'N']:
if not by_layer[layer]:
continue
print(f"\n{layer_names[layer]}")
print("-" * 80)
for r in sorted(by_layer[layer], key=lambda x: x.q_score, reverse=True):
# Truncate content
content = r.content[:65] + "..." if len(r.content) > 65 else r.content
# Show parent relationships
parent_info = ""
if r.parents:
parent_info = f" โ builds on {len(r.parents)} parent(s)"
# Show children
child_info = ""
if r.children:
child_info = f" โ spawned {len(r.children)} child(ren)"
print(f" [{r.id[:8]}] Q={r.q_score:.4f} | {content}")
if parent_info:
print(f" {parent_info}")
if child_info:
print(f" {child_info}")
print()
print("="*80)
def analyze_generativity(engine: RealizationEngine):
"""Analyze which realizations were most generative (ุจูุงุช ุงููุงุฑ)"""
print("\n" + "="*80)
print("GENERATIVITY ANALYSIS (Most Productive Realizations)")
print("="*80 + "\n")
# Find realizations with most children
with_children = [(r, len(r.children)) for r in engine.index.values() if r.children]
with_children.sort(key=lambda x: x[1], reverse=True)
print("Top realizations by number of children (ุจูุงุช):\n")
for i, (r, child_count) in enumerate(with_children[:5], 1):
print(f"{i}. {r.content[:60]}...")
print(f" Q={r.q_score:.4f}, Layer {r.layer}")
print(f" Generated {child_count} children:")
for child_id in r.children:
child = engine.index[child_id]
print(f" โ {child.content[:55]}... (Q={child.q_score:.3f})")
print()
def demonstrate_queries(engine: RealizationEngine):
"""Interactive query demonstrations"""
print("\n" + "="*80)
print("QUERY DEMONSTRATIONS")
print("="*80 + "\n")
queries = [
("What is the foundation?", "context finite information"),
("How do realizations work?", "precision auto certainty"),
("How do ideas grow?", "layers crystallize"),
("What about computation?", "pre-computation crystallization"),
("This conversation?", "conversation itself crystallization process")
]
for question, query in queries:
print(f"โ {question}")
print(f" Query: '{query}'")
results = engine.retrieve(query)
if results:
best = results[0]
print(f" โ
Found: [{best.layer}] Q={best.q_score:.4f}")
print(f" {best.content[:70]}...")
else:
print(f" โ No results")
print()
def show_quality_distribution(engine: RealizationEngine):
"""Show distribution of Q-scores"""
print("\n" + "="*80)
print("QUALITY SCORE DISTRIBUTION")
print("="*80 + "\n")
# Get all Q-scores
q_scores = [r.q_score for r in engine.index.values()]
q_scores.sort(reverse=True)
# ASCII histogram
bins = {
"0.95-1.00 (Layer 0/1)": [],
"0.90-0.95 (Layer 1)": [],
"0.85-0.90 (Layer 2)": [],
"0.75-0.85 (Layer 2/3)": [],
"0.00-0.75 (Layer N)": []
}
for q in q_scores:
if q >= 0.95:
bins["0.95-1.00 (Layer 0/1)"].append(q)
elif q >= 0.90:
bins["0.90-0.95 (Layer 1)"].append(q)
elif q >= 0.85:
bins["0.85-0.90 (Layer 2)"].append(q)
elif q >= 0.75:
bins["0.75-0.85 (Layer 2/3)"].append(q)
else:
bins["0.00-0.75 (Layer N)"].append(q)
max_count = max(len(v) for v in bins.values())
for label, values in bins.items():
count = len(values)
bar = "โ" * count + "โ" * (max_count - count)
avg_q = sum(values) / len(values) if values else 0
print(f"{label:25} {bar} {count:2} (avg Q={avg_q:.3f})")
print(f"\nTotal Realizations: {len(q_scores)}")
print(f"Average Q-Score: {sum(q_scores)/len(q_scores):.4f}")
print(f"Median Q-Score: {sorted(q_scores)[len(q_scores)//2]:.4f}")
print(f"Highest Q-Score: {max(q_scores):.4f}")
print(f"Lowest Q-Score: {min(q_scores):.4f}")
def trace_realization_path(engine: RealizationEngine):
"""Trace the path from initial question to final meta-realization"""
print("\n" + "="*80)
print("CONVERSATION EVOLUTION PATH")
print("="*80 + "\n")
# Get realizations in chronological order
by_turn = sorted(engine.index.values(), key=lambda r: r.turn_number)
print("Turn-by-turn crystallization:\n")
for r in by_turn:
indent = " " * min(r.layer if isinstance(r.layer, int) else 4, 4)
layer_emoji = {
0: "๐ฅ",
1: "๐ง",
2: "๐จ",
3: "๐ฉ",
'N': "โฌ"
}[r.layer]
print(f"Turn {r.turn_number:2} {layer_emoji} [{r.layer}] Q={r.q_score:.3f}")
print(f" {indent}{r.content[:65]}...")
print()
if __name__ == "__main__":
# Load the pre-computed realizations
print("Loading pre-computed realizations...")
engine = precompute_conversation_realizations()
# Run all visualizations
visualize_graph_ascii(engine)
analyze_generativity(engine)
demonstrate_queries(engine)
show_quality_distribution(engine)
trace_realization_path(engine)
print("\n" + "="*80)
print("EXPLORATION COMPLETE")
print("="*80)
print("\nWhat we've proven:")
print(" โ
Realizations can be extracted from conversation")
print(" โ
Q-scores can be calculated automatically")
print(" โ
Layers emerge naturally from quality thresholds")
print(" โ
Parent-child relationships preserve lineage (ุจูุงุช ุงููุงุฑ)")
print(" โ
The system is queryable and reusable")
print("\nThis is pre-computation working on realizations.")
print("The conversation is now a knowledge base.")
|