Spaces:
Running
Running
| # app.py | |
| """ | |
| Wang's Five Laws โ LLM Spectral Analyzer | |
| ไธปๅ ฅๅฃ๏ผ็ป่ฃ ๆๆ Tab | |
| """ | |
| import gradio as gr | |
| from db.schema import init_db | |
| from ui.tab_inspect import build_tab_inspect | |
| from ui.tab_analyze import build_tab_analyze | |
| from ui.tab_leaderboard import build_tab_leaderboard | |
| from ui.tab_database import build_tab_database | |
| from ui.tab_plot import build_tab_plot | |
| from ui.tab_tables import build_tab_tables | |
| # โโ ๅฏๅจๆถๅๅงๅๆฐๆฎๅบ โโโโโโโโโโโโโโโโโโโโโโโโ | |
| init_db() | |
| with gr.Blocks( | |
| title="Wang's Five Laws โ LLM Spectral Analyzer", | |
| ) as demo: | |
| # โโ ๅ่ฏญๆ ้ข โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| gr.Markdown(""" | |
| # ๐ฌ Wang's Five Laws โ LLM Spectral Analyzer | |
| ### ็ๆฐไบๅฎๅพ โ ๅคงๆจกๅ่ฐฑๅๆๅทฅๅ ท | |
| **Mathematical Foundations of Large Language Models (MF-LLM)** | |
| Reads HF weights via **HTTP Range Request** โ no full model download required. | |
| Auto-detects model structure (GQA / MHA / K=V shared / heterogeneous head_dim), | |
| computes all Five Laws metrics per attention head, persists results to SQLite. | |
| ้่ฟ **HTTP Range Request** ็ดๆฅ่ฏปๅ HF ๆ้๏ผๆ ้ไธ่ฝฝๆดไธชๆจกๅใ | |
| ่ชๅจ่ฏๅซๆจกๅ็ปๆ๏ผ้ๅคด่ฎก็ฎ็ๆฐไบๅฎๅพๅ จ้จๆๆ ๏ผ็ปๆๆไน ๅๅฐ SQLiteใ | |
| [](https://doi.org/10.5281/zenodo.19707844) | |
| [](https://hal.science/hal-05609398) | |
| [](https://github.com/emis-framework/math-under-llm) | |
| """) | |
| # โโ ๅ่ฏญ่กจๆ ผๅนถๆ โโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| with gr.Row(): | |
| gr.Markdown(""" | |
| | Law | Metric | Ideal | | |
| |-----|--------|-------| | |
| | Law 1 | Pearson r (QโK spectral alignment) | โ 1 | | |
| | Law 2 | SSR (spectral shape residual) | โ 0 | | |
| | Law 3 | Condition number ฮบ | smaller = more stable | | |
| | Law 4 | cosU(Uq, Uv) super-orthogonal | < 1/โd_head | | |
| | Law 5 | cosV input subspace random orthogonal | โ 1/โd_model | | |
| """) | |
| gr.Markdown(""" | |
| | ๅฎๅพ | ๆๆ | ็่ฎบๆๅผ | | |
| |------|------|---------| | |
| | ็ฌฌไธๅฎๅพ | Pearson r๏ผQ-K ่ฐฑ็บฟๆงๅฏน้ฝ๏ผ | โ 1 | | |
| | ็ฌฌไบๅฎๅพ | SSR๏ผ่ฐฑๅฝข็ถๆฎๅทฎ๏ผ | โ 0 | | |
| | ็ฌฌไธๅฎๅพ | ๆกไปถๆฐ ฮบ | ่ถๅฐ่ถ็จณๅฎ | | |
| | ็ฌฌๅๅฎๅพ | cosU(Uq, Uv)๏ผ่ถ ๆญฃไบค๏ผ | < 1/โd_head | | |
| | ็ฌฌไบๅฎๅพ | cosV๏ผ่พๅ ฅๅญ็ฉบ้ด้ๆบๆญฃไบค๏ผ | โ 1/โd_model | | |
| """) | |
| # โโ Tabs โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| with gr.Tabs(): | |
| inspect_model_id, inspect_token = build_tab_inspect() | |
| analyze_model_id, analyze_token = build_tab_analyze() | |
| build_tab_leaderboard() | |
| build_tab_database() | |
| build_tab_plot() | |
| build_tab_tables() | |
| # โโ Tab1 โ Tab2 ่ๅจ โโโโโโโโโโโโโโโโโโโโโโ | |
| inspect_model_id.change( | |
| fn=lambda x: x, | |
| inputs=inspect_model_id, | |
| outputs=analyze_model_id, | |
| ) | |
| inspect_token.change( | |
| fn=lambda x: x, | |
| inputs=inspect_token, | |
| outputs=analyze_token, | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |