Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| # --- Grey-Box V3 Universal:每一層的說明(簡化版,可之後自行替換成完整版) --- | |
| LAYER_DESCRIPTIONS = { | |
| "1. Semantic Nodes": """ | |
| **Layer 1 — Semantic Nodes** | |
| Semantic nodes are context-conditioned meaning units derived from token embeddings, | |
| positional encodings and local interactions. They are not just words, but | |
| high-dimensional vectors that represent micro-concepts under the current context. | |
| """, | |
| "2. Attention Mapping": """ | |
| **Layer 2 — Attention Mapping** | |
| Attention mapping describes which node looks at which other node, and with what strength. | |
| It forms a directed graph of semantic relevance, and is the structural backbone of reasoning. | |
| """, | |
| "3. Semantic Flow": """ | |
| **Layer 3 — Semantic Flow** | |
| Semantic flow is the emergent propagation of meaning across layers as attention patterns | |
| interact. It is non-linear, multi-directional and can converge or diverge depending on | |
| the prompt and context. | |
| """, | |
| "4. Weight Heatmap": """ | |
| **Layer 4 — Weight Heatmap** | |
| The weight heatmap highlights which nodes or features are considered important. | |
| It combines attention relevance with saliency / gradient-based importance to show | |
| what the model focuses on when making a decision. | |
| """, | |
| "5. Flow Velocity Field": """ | |
| **Layer 5 — Flow Velocity Field** | |
| The velocity field represents the speed and stability of semantic propagation. | |
| Fast convergence tends to correlate with stable reasoning, while turbulence | |
| or oscillation can hint at drift or hallucination. | |
| """, | |
| "6. Intervention Ring": """ | |
| **Layer 6 — Intervention Ring** | |
| The intervention ring is the set of all human-accessible control points: | |
| prompt engineering, constraints, rules, safety policies and bias correction. | |
| It is where external input can reshape internal reasoning behaviour. | |
| """, | |
| "7. Semantic Field": """ | |
| **Layer 7 — Semantic Field (NEW in V3)** | |
| The semantic field is the global meaning landscape inside the model: attractor basins, | |
| drift zones, dense regions of meaning and stability areas. It explains where and how | |
| the model finally collapses its internal state into an output. | |
| """, | |
| } | |
| OVERVIEW_TEXT = """ | |
| # Grey-Box Visualization Framework V3.0 (Universal Edition) | |
| This Space is a simple **interactive viewer** for the Grey-Box V3 framework. | |
| Use the selector on the left to explore each of the seven layers: | |
| semantic nodes, attention mapping, semantic flow, weight heatmap, | |
| flow velocity field, intervention ring and the semantic field. | |
| Grey-Box V3 is a **model-agnostic interpretability architecture** for | |
| Transformer-based LLMs. It describes how meaning forms, propagates, | |
| stabilizes and finally collapses into an output. | |
| """ | |
| WHITEPAPER_SNIPPET = """ | |
| ### Technical Whitepaper (Summary) | |
| Grey-Box V3 introduces a seven-layer semantic reasoning pipeline and | |
| a new global **semantic field** layer, along with cross-layer dynamics. | |
| It is not a tensor-level introspection tool, but a conceptual model that | |
| helps researchers and engineers reason about: | |
| - semantic propagation | |
| - attention-driven structure | |
| - drift and hallucination attractors | |
| - stabilising mechanisms inside LLMs | |
| For the full whitepaper, please refer to the `whitepaper.md` file in the | |
| accompanying dataset / repository. | |
| """ | |
| def show_layer(layer_name: str) -> str: | |
| """Return markdown description for the selected layer.""" | |
| return LAYER_DESCRIPTIONS.get(layer_name, "No description available.") | |
| with gr.Blocks(title="Grey-Box V3 Viewer") as demo: | |
| gr.Markdown(OVERVIEW_TEXT) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| layer_selector = gr.Radio( | |
| list(LAYER_DESCRIPTIONS.keys()), | |
| value="1. Semantic Nodes", | |
| label="Select a Grey-Box layer" | |
| ) | |
| with gr.Column(scale=2): | |
| layer_output = gr.Markdown( | |
| value=show_layer("1. Semantic Nodes"), | |
| label="Layer description" | |
| ) | |
| gr.Markdown(WHITEPAPER_SNIPPET) | |
| layer_selector.change(fn=show_layer, inputs=layer_selector, outputs=layer_output) | |
| if __name__ == "__main__": | |
| demo.launch() | |