Commit Β·
087c2a9
1
Parent(s): 9beaa8b
LaTeX tab: add TikZ carry-cascade figure as second copyable block
Browse files
app.py
CHANGED
|
@@ -102,6 +102,153 @@ Across three undersized architectures and data sizes from 10K to 100K,
|
|
| 102 |
as $+50$\,pp (44\% $\to$ 94\% on the smallest model at 50K examples;
|
| 103 |
Table~\ref{tab:undersized-wins}).
|
| 104 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
HARD_SPLITS = ["add_C4", "add_C5", "add_C6", "sub_M4", "sub_M5"]
|
| 106 |
ALL_SPLITS = [
|
| 107 |
"add_S0", "add_S1", "add_S2", "add_S3", "add_S4", "add_S5", "add_S6", "add_random",
|
|
@@ -719,6 +866,11 @@ hidden activations β but here it is readable directly from the token sequence.
|
|
| 719 |
gr.Textbox(value=LATEX_ARITHMETIC_SETUP, label="arithmetic_setup.tex",
|
| 720 |
lines=30, show_copy_button=True, interactive=False)
|
| 721 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
# ββ Tab 4: About ββ
|
| 723 |
with gr.TabItem("About"):
|
| 724 |
eval_info_md = gr.Markdown("")
|
|
|
|
| 102 |
as $+50$\,pp (44\% $\to$ 94\% on the smallest model at 50K examples;
|
| 103 |
Table~\ref{tab:undersized-wins}).
|
| 104 |
"""
|
| 105 |
+
|
| 106 |
+
LATEX_FIGURE_EXAMPLE = r"""% fig_arithmetic_example.tex
|
| 107 |
+
% Usage in paper: \input{figures/fig_arithmetic_example/fig_arithmetic_example.tex}
|
| 108 |
+
% Required packages: tikz, xcolor
|
| 109 |
+
%
|
| 110 |
+
% Shows 959271 + 040756 = 1000027 (4-deep carry cascade).
|
| 111 |
+
% Token assignments from model add_sub_sorl_v1_abs30_K1_100K (K=1, abs30).
|
| 112 |
+
|
| 113 |
+
\begin{figure}[t]
|
| 114 |
+
\centering
|
| 115 |
+
\begin{tikzpicture}[
|
| 116 |
+
% ββ node styles βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 117 |
+
digit/.style={
|
| 118 |
+
draw=#1!60!gray, fill=#1, rounded corners=2pt,
|
| 119 |
+
minimum width=1.05cm, minimum height=0.62cm,
|
| 120 |
+
font=\small\bfseries, inner sep=2pt, text=#1!20!black,
|
| 121 |
+
},
|
| 122 |
+
subtask/.style={
|
| 123 |
+
draw=#1!60!gray, fill=#1, rounded corners=2pt,
|
| 124 |
+
minimum width=1.05cm, minimum height=0.55cm,
|
| 125 |
+
font=\footnotesize, inner sep=2pt, text=#1!20!black,
|
| 126 |
+
},
|
| 127 |
+
token/.style={
|
| 128 |
+
draw=violet!55, fill=violet!8, rounded corners=2pt, dashed,
|
| 129 |
+
minimum width=1.05cm, minimum height=0.55cm,
|
| 130 |
+
font=\footnotesize\bfseries, inner sep=2pt, text=violet!70!black,
|
| 131 |
+
},
|
| 132 |
+
rowlabel/.style={font=\footnotesize\itshape, text=gray!70!black, anchor=east},
|
| 133 |
+
poslabel/.style={font=\scriptsize, text=gray!60!black},
|
| 134 |
+
carry/.style={->, >=stealth, thick, color=orange!70!red,
|
| 135 |
+
shorten <=3pt, shorten >=3pt},
|
| 136 |
+
]
|
| 137 |
+
|
| 138 |
+
% ββ colours (Quirke subtask families) βββββββββββββββββββββββββββββββββββ
|
| 139 |
+
\colorlet{cSA}{green!22!white}
|
| 140 |
+
\colorlet{cSC}{yellow!48!white}
|
| 141 |
+
\colorlet{cUC}{blue!22!white}
|
| 142 |
+
\colorlet{cUS}{blue!36!white}
|
| 143 |
+
|
| 144 |
+
% ββ column spacing βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 145 |
+
\def\cs{1.45} % inter-column distance (cm)
|
| 146 |
+
|
| 147 |
+
% ββ data (d0 = MSB/overflow on left, d6 = LSB on right) βββββββββββββββββ
|
| 148 |
+
% d0 d1 d2 d3 d4 d5 d6
|
| 149 |
+
% --- 9 5 9 2 7 1 (Addend A)
|
| 150 |
+
% --- 0 4 0 7 5 6 (Addend B)
|
| 151 |
+
% 1 0 0 0 0 2 7 (Answer)
|
| 152 |
+
% UC US US US US SC SA (Subtask)
|
| 153 |
+
% t2 t2 t6 t2 t1 t16 t3 (SoRL token)
|
| 154 |
+
|
| 155 |
+
% ββ position labels ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 156 |
+
\foreach \i/\lbl in {0/$d_0$,1/$d_1$,2/$d_2$,3/$d_3$,4/$d_4$,5/$d_5$,6/$d_6$}{
|
| 157 |
+
\node[poslabel] at (\i*\cs, 3.15) {\lbl};
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
% ββ row labels βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 161 |
+
\node[rowlabel] at (-0.65, 2.5) {Addend $A$};
|
| 162 |
+
\node[rowlabel] at (-0.65, 1.8) {Addend $B$};
|
| 163 |
+
\node[rowlabel] at (-0.65, 0.85) {Answer};
|
| 164 |
+
\node[rowlabel] at (-0.65, 0.1) {Subtask};
|
| 165 |
+
\node[rowlabel] at (-0.65,-0.65) {Token};
|
| 166 |
+
|
| 167 |
+
% ββ operand digits (d1..d6; d0 is the overflow, has no operand digits) βββ
|
| 168 |
+
\foreach \i/\d in {1/9,2/5,3/9,4/2,5/7,6/1}{
|
| 169 |
+
\node[font=\small, text=gray!30!black] at (\i*\cs, 2.5) {\d};
|
| 170 |
+
}
|
| 171 |
+
\node[font=\small\bfseries, text=gray!50!black] at (-0.4*\cs, 1.8) {$+$};
|
| 172 |
+
\foreach \i/\d in {1/0,2/4,3/0,4/7,5/5,6/6}{
|
| 173 |
+
\node[font=\small, text=gray!30!black] at (\i*\cs, 1.8) {\d};
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
% ββ horizontal rule ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 177 |
+
\draw[gray!50, thin] (-0.55*\cs, 1.38) -- (6.55*\cs, 1.38);
|
| 178 |
+
|
| 179 |
+
% ββ answer digit boxes βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 180 |
+
\node[digit=cUC] (a0) at (0*\cs, 0.85) {1};
|
| 181 |
+
\node[digit=cUS] (a1) at (1*\cs, 0.85) {0};
|
| 182 |
+
\node[digit=cUS] (a2) at (2*\cs, 0.85) {0};
|
| 183 |
+
\node[digit=cUS] (a3) at (3*\cs, 0.85) {0};
|
| 184 |
+
\node[digit=cUS] (a4) at (4*\cs, 0.85) {0};
|
| 185 |
+
\node[digit=cSC] (a5) at (5*\cs, 0.85) {2};
|
| 186 |
+
\node[digit=cSA] (a6) at (6*\cs, 0.85) {7};
|
| 187 |
+
|
| 188 |
+
% ββ subtask boxes ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 189 |
+
\node[subtask=cUC] at (0*\cs, 0.1) {UC};
|
| 190 |
+
\node[subtask=cUS] at (1*\cs, 0.1) {US};
|
| 191 |
+
\node[subtask=cUS] at (2*\cs, 0.1) {US};
|
| 192 |
+
\node[subtask=cUS] at (3*\cs, 0.1) {US};
|
| 193 |
+
\node[subtask=cUS] at (4*\cs, 0.1) {US};
|
| 194 |
+
\node[subtask=cSC] at (5*\cs, 0.1) {SC};
|
| 195 |
+
\node[subtask=cSA] at (6*\cs, 0.1) {SA};
|
| 196 |
+
|
| 197 |
+
% ββ SoRL token boxes βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 198 |
+
\foreach \i/\t in {0/t2,1/t2,2/t6,3/t2,4/t1,5/t16,6/t3}{
|
| 199 |
+
\node[token] at (\i*\cs, -0.65) {\texttt{\t}};
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
% ββ carry arrows (cascade flows rightβleft: d5βd4βd3βd2βd1βd0) ββββββββββ
|
| 203 |
+
\foreach \fr/\to in {5/4, 4/3, 3/2, 2/1, 1/0}{
|
| 204 |
+
\draw[carry] (a\fr.west) -- (a\to.east);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
% ββ cascade bracket + label ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 208 |
+
\draw[orange!60!red, thin]
|
| 209 |
+
(a5.north west) -- ++(0, 0.22)
|
| 210 |
+
-- (a0.north east) -- ++(0,-0.22);
|
| 211 |
+
\node[font=\scriptsize\itshape, text=orange!60!red]
|
| 212 |
+
at (2.5*\cs, 1.35) {carry cascade};
|
| 213 |
+
|
| 214 |
+
% ββ legend βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 215 |
+
\matrix[
|
| 216 |
+
matrix of nodes,
|
| 217 |
+
nodes={font=\scriptsize, inner sep=2pt, anchor=west},
|
| 218 |
+
row sep=1pt, column sep=4pt,
|
| 219 |
+
anchor=south east,
|
| 220 |
+
] at (6*\cs + 0.6, -1.05) {
|
| 221 |
+
\node[digit=cSA, minimum width=0.45cm, minimum height=0.3cm,
|
| 222 |
+
font=\scriptsize] {}; &
|
| 223 |
+
\node {SA --- simple add}; &
|
| 224 |
+
\node[digit=cUC, minimum width=0.45cm, minimum height=0.3cm,
|
| 225 |
+
font=\scriptsize] {}; &
|
| 226 |
+
\node {UC --- uses carry}; \\
|
| 227 |
+
\node[digit=cSC, minimum width=0.45cm, minimum height=0.3cm,
|
| 228 |
+
font=\scriptsize] {}; &
|
| 229 |
+
\node {SC --- generates carry}; &
|
| 230 |
+
\node[digit=cUS, minimum width=0.45cm, minimum height=0.3cm,
|
| 231 |
+
font=\scriptsize] {}; &
|
| 232 |
+
\node {US --- cascade}; \\
|
| 233 |
+
\node[token, minimum width=0.45cm, minimum height=0.3cm,
|
| 234 |
+
font=\scriptsize] {}; &
|
| 235 |
+
\node[text=violet!70!black] {\sorl{} token}; & & \\
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
\end{tikzpicture}
|
| 239 |
+
\caption{%
|
| 240 |
+
Six-digit addition $959{,}271 + 040{,}756 = 1{,}000{,}027$, a four-deep
|
| 241 |
+
carry cascade. At each answer-digit position \sorl{} assigns one
|
| 242 |
+
abstraction token (bottom row). Tokens \texttt{t2} and \texttt{t6}
|
| 243 |
+
cluster on cascade positions (UC/US); \texttt{t16} marks the carry
|
| 244 |
+
source (SC); \texttt{t3} marks the trivial position (SA).
|
| 245 |
+
Token assignments from model \texttt{add\_sub\_sorl\_v1\_abs30\_K1\_100K}
|
| 246 |
+
(K=1, 30-token codebook).%
|
| 247 |
+
}
|
| 248 |
+
\label{fig:arithmetic-example}
|
| 249 |
+
\end{figure}
|
| 250 |
+
"""
|
| 251 |
+
|
| 252 |
HARD_SPLITS = ["add_C4", "add_C5", "add_C6", "sub_M4", "sub_M5"]
|
| 253 |
ALL_SPLITS = [
|
| 254 |
"add_S0", "add_S1", "add_S2", "add_S3", "add_S4", "add_S5", "add_S6", "add_random",
|
|
|
|
| 866 |
gr.Textbox(value=LATEX_ARITHMETIC_SETUP, label="arithmetic_setup.tex",
|
| 867 |
lines=30, show_copy_button=True, interactive=False)
|
| 868 |
|
| 869 |
+
gr.Markdown("#### Β§ Carry-cascade example figure (TikZ)")
|
| 870 |
+
gr.Markdown("Requires: `\\usepackage{tikz}`, `\\usetikzlibrary{matrix}`, `\\usepackage{xcolor}`, and `\\providecommand{\\sorl}{\\textsc{DLR}}`.")
|
| 871 |
+
gr.Textbox(value=LATEX_FIGURE_EXAMPLE, label="fig_arithmetic_example.tex",
|
| 872 |
+
lines=40, show_copy_button=True, interactive=False)
|
| 873 |
+
|
| 874 |
# ββ Tab 4: About ββ
|
| 875 |
with gr.TabItem("About"):
|
| 876 |
eval_info_md = gr.Markdown("")
|