更新: コンセプトページをシンプルに刷新
Browse files- GPT-2固有の記述を汎用的な表現に変更
- WHAT/HOW/SPECの3セクションに整理
- 手順を4→3ステップに簡略化
- モデル一覧を動的に取得
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/ui/streamlit/pages/concept.py
CHANGED
|
@@ -6,6 +6,7 @@ WILLプロジェクトの概念説明を提供する
|
|
| 6 |
import streamlit as st
|
| 7 |
|
| 8 |
from ....models.registry import ModelRegistry
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def render_concept_page() -> None:
|
|
@@ -13,26 +14,22 @@ def render_concept_page() -> None:
|
|
| 13 |
st.markdown('<p class="title">CONCEPT</p>', unsafe_allow_html=True)
|
| 14 |
st.markdown('<p class="subtitle">DOCUMENTATION</p>', unsafe_allow_html=True)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
_render_specification_section()
|
| 19 |
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
"""
|
| 23 |
st.markdown(
|
| 24 |
'''
|
| 25 |
<div class="section">
|
| 26 |
-
<p class="section-title">
|
| 27 |
<p style="text-align: center; color: #666; line-height: 2.2;">
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
出力にもノイズを加えることで<br>
|
| 33 |
-
学習済みの統計的偏りを破壊する<br><br>
|
| 34 |
-
人間の問いかけなしに<br>
|
| 35 |
-
モデルの構造だけが出力するものを観測する
|
| 36 |
</p>
|
| 37 |
</div>
|
| 38 |
<hr class="divider">
|
|
@@ -41,109 +38,84 @@ def _render_concept_section() -> None:
|
|
| 41 |
)
|
| 42 |
|
| 43 |
|
| 44 |
-
def
|
| 45 |
-
"""
|
| 46 |
st.markdown(
|
| 47 |
'''
|
| 48 |
<div class="section">
|
| 49 |
-
<p class="section-title">
|
| 50 |
</div>
|
| 51 |
''',
|
| 52 |
unsafe_allow_html=True,
|
| 53 |
)
|
| 54 |
|
| 55 |
-
# Step 1
|
| 56 |
st.markdown(
|
| 57 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 58 |
-
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">01 —
|
| 59 |
unsafe_allow_html=True,
|
| 60 |
)
|
| 61 |
-
st.code("
|
| 62 |
st.markdown(
|
| 63 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 64 |
-
"
|
| 65 |
unsafe_allow_html=True,
|
| 66 |
)
|
| 67 |
|
| 68 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 69 |
|
| 70 |
-
# Step 2
|
| 71 |
st.markdown(
|
| 72 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 73 |
-
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">02 —
|
| 74 |
unsafe_allow_html=True,
|
| 75 |
)
|
| 76 |
-
st.code(
|
| 77 |
-
"noise = torch.randn(1, 32, 768)\noutputs = model(inputs_embeds=noise)",
|
| 78 |
-
language="python",
|
| 79 |
-
)
|
| 80 |
st.markdown(
|
| 81 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 82 |
-
"
|
| 83 |
unsafe_allow_html=True,
|
| 84 |
)
|
| 85 |
|
| 86 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 87 |
|
| 88 |
-
# Step 3
|
| 89 |
st.markdown(
|
| 90 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 91 |
-
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">03 —
|
| 92 |
unsafe_allow_html=True,
|
| 93 |
)
|
| 94 |
-
st.code(
|
| 95 |
-
"logits_noise = torch.randn_like(logits) * logits.std() * 10\n"
|
| 96 |
-
"corrupted_logits = logits + logits_noise",
|
| 97 |
-
language="python",
|
| 98 |
-
)
|
| 99 |
st.markdown(
|
| 100 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 101 |
-
"
|
| 102 |
-
unsafe_allow_html=True,
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
st.markdown("<br>", unsafe_allow_html=True)
|
| 106 |
-
|
| 107 |
-
# Step 4: RAW DECODE
|
| 108 |
-
st.markdown(
|
| 109 |
-
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 110 |
-
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">04 — RAW DECODE</p>',
|
| 111 |
-
unsafe_allow_html=True,
|
| 112 |
-
)
|
| 113 |
-
st.code(
|
| 114 |
-
"indices = corrupted_logits.argmax(dim=-1)\n"
|
| 115 |
-
"debris = [tokenizer.decode([i]) for i in indices]",
|
| 116 |
-
language="python",
|
| 117 |
-
)
|
| 118 |
-
st.markdown(
|
| 119 |
-
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 120 |
-
"Softmax・Temperature なしで生トークンを抽出</p>",
|
| 121 |
unsafe_allow_html=True,
|
| 122 |
)
|
| 123 |
|
| 124 |
|
| 125 |
def _render_specification_section() -> None:
|
| 126 |
"""仕様セクション"""
|
| 127 |
-
# 利用可能なモデル一覧を
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
st.markdown(
|
| 134 |
f'''
|
| 135 |
<hr class="divider">
|
| 136 |
<div class="section">
|
| 137 |
-
<p class="section-title">
|
| 138 |
<table class="spec-table">
|
| 139 |
-
<tr><td>Models</td><td>
|
| 140 |
-
<tr><td>Parameters</td><td>125M - 350M</td></tr>
|
| 141 |
-
<tr><td>Embedding</td><td>768 - 1024 dim</td></tr>
|
| 142 |
-
<tr><td>Vocabulary</td><td>50,257+ tokens</td></tr>
|
| 143 |
<tr><td>Sequence</td><td>32 tokens</td></tr>
|
| 144 |
-
<tr><td>Input
|
| 145 |
-
<tr><td>
|
| 146 |
-
<tr><td>
|
| 147 |
</table>
|
| 148 |
</div>
|
| 149 |
''',
|
|
|
|
| 6 |
import streamlit as st
|
| 7 |
|
| 8 |
from ....models.registry import ModelRegistry
|
| 9 |
+
from ..components import GPU_REQUIRED_MODELS
|
| 10 |
|
| 11 |
|
| 12 |
def render_concept_page() -> None:
|
|
|
|
| 14 |
st.markdown('<p class="title">CONCEPT</p>', unsafe_allow_html=True)
|
| 15 |
st.markdown('<p class="subtitle">DOCUMENTATION</p>', unsafe_allow_html=True)
|
| 16 |
|
| 17 |
+
_render_what_section()
|
| 18 |
+
_render_how_section()
|
| 19 |
_render_specification_section()
|
| 20 |
|
| 21 |
|
| 22 |
+
def _render_what_section() -> None:
|
| 23 |
+
"""WHAT セクション"""
|
| 24 |
st.markdown(
|
| 25 |
'''
|
| 26 |
<div class="section">
|
| 27 |
+
<p class="section-title">WHAT</p>
|
| 28 |
<p style="text-align: center; color: #666; line-height: 2.2;">
|
| 29 |
+
言語モデルにランダムノイズを入力し<br>
|
| 30 |
+
出力にもノイズを加えて学習バイアスを破壊する<br><br>
|
| 31 |
+
<strong>人間の問いかけなしに<br>
|
| 32 |
+
モデルの構造だけが出力するものを観測する</strong>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</p>
|
| 34 |
</div>
|
| 35 |
<hr class="divider">
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
|
| 41 |
+
def _render_how_section() -> None:
|
| 42 |
+
"""HOW セクション"""
|
| 43 |
st.markdown(
|
| 44 |
'''
|
| 45 |
<div class="section">
|
| 46 |
+
<p class="section-title">HOW</p>
|
| 47 |
</div>
|
| 48 |
''',
|
| 49 |
unsafe_allow_html=True,
|
| 50 |
)
|
| 51 |
|
| 52 |
+
# Step 1
|
| 53 |
st.markdown(
|
| 54 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 55 |
+
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">01 — INPUT</p>',
|
| 56 |
unsafe_allow_html=True,
|
| 57 |
)
|
| 58 |
+
st.code("noise = torch.randn(1, seq_len, embedding_dim)", language="python")
|
| 59 |
st.markdown(
|
| 60 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 61 |
+
"ランダムノイズをEmbedding層に直接注入</p>",
|
| 62 |
unsafe_allow_html=True,
|
| 63 |
)
|
| 64 |
|
| 65 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 66 |
|
| 67 |
+
# Step 2
|
| 68 |
st.markdown(
|
| 69 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 70 |
+
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">02 — CORRUPT</p>',
|
| 71 |
unsafe_allow_html=True,
|
| 72 |
)
|
| 73 |
+
st.code("corrupted = logits + randn_like(logits) * logits.std() * 10", language="python")
|
|
|
|
|
|
|
|
|
|
| 74 |
st.markdown(
|
| 75 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 76 |
+
"出力にノイズを加算し学習バイアスを破壊</p>",
|
| 77 |
unsafe_allow_html=True,
|
| 78 |
)
|
| 79 |
|
| 80 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 81 |
|
| 82 |
+
# Step 3
|
| 83 |
st.markdown(
|
| 84 |
'<p style="text-align: center; color: #333; font-size: 0.65rem; '
|
| 85 |
+
'letter-spacing: 0.15em; margin-bottom: 0.5rem;">03 — DECODE</p>',
|
| 86 |
unsafe_allow_html=True,
|
| 87 |
)
|
| 88 |
+
st.code("tokens = corrupted.argmax(dim=-1)", language="python")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
st.markdown(
|
| 90 |
'<p style="text-align: center; font-size: 0.7rem; color: #444;">'
|
| 91 |
+
"Softmaxなしで生トークンを抽出</p>",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
unsafe_allow_html=True,
|
| 93 |
)
|
| 94 |
|
| 95 |
|
| 96 |
def _render_specification_section() -> None:
|
| 97 |
"""仕様セクション"""
|
| 98 |
+
# 利用可能なモデル一覧を動的に取得
|
| 99 |
+
all_configs = ModelRegistry.get_all_configs()
|
| 100 |
+
available_configs = {k: v for k, v in all_configs.items() if k not in GPU_REQUIRED_MODELS}
|
| 101 |
+
|
| 102 |
+
model_names = [cfg.name for cfg in available_configs.values()]
|
| 103 |
+
model_list_str = " / ".join(model_names[:5]) + " ..."
|
| 104 |
+
|
| 105 |
+
# パラメータ範囲を計算
|
| 106 |
+
params_info = "125M - 1.5B"
|
| 107 |
|
| 108 |
st.markdown(
|
| 109 |
f'''
|
| 110 |
<hr class="divider">
|
| 111 |
<div class="section">
|
| 112 |
+
<p class="section-title">SPEC</p>
|
| 113 |
<table class="spec-table">
|
| 114 |
+
<tr><td>Models</td><td>{model_list_str}</td></tr>
|
|
|
|
|
|
|
|
|
|
| 115 |
<tr><td>Sequence</td><td>32 tokens</td></tr>
|
| 116 |
+
<tr><td>Input</td><td>N(0, 1)</td></tr>
|
| 117 |
+
<tr><td>Corruption</td><td>N(0, σ×10)</td></tr>
|
| 118 |
+
<tr><td>Decode</td><td>argmax</td></tr>
|
| 119 |
</table>
|
| 120 |
</div>
|
| 121 |
''',
|