Neural networks often learn the parts of a task but fail on novel combinations of those parts. We argue that this failure is architectural: a decoder generalizes compositionally only when it respects the algebraic laws of the task, i.e. when it descends from freely generated sequences to the quotient determined by those laws. We make this principle constructive by compiling Higher Inductive Type (HIT) specifications into neural architectures. Basepoints, path constructors, and 2-cells are mapped to base constraints, generator networks, structural concatenation, and learned homotopies. The resulting transport decoders are strict monoidal functors by construction: decoding a concatenated word is concatenation of independently generated loop segments. In contrast, we prove that softmax self-attention cannot simultaneously satisfy strict monoidal composition and descent to any non-trivial compositional quotient. Experiments on the torus, wedge of circles, and Klein bottle validate the predicted hierarchy: functorial decoders outperform non-functorial alternatives by 2--10×, and a learned 2-cell closes a 46% error gap precisely on words exercising the Klein-bottle relation. These results suggest that compositional generalization should be enforced as functorial structure in the architecture, rather than learned from examples alone.
Figures & tables
Figure 1: The three HIT specifications. Each square presents the space by gluing together cells: corners are the basepoint x0 , labelled edges are the path constructors loopa,loopb , and the interior is the 2-cell. In T2 , both pairs of opposite edges are identified in the same direction; the interior surf witnesses loopa⋅loopb=loopb⋅loopa . The wedge S1∨S1 has two loops meeting at a single basepoint with no relating 2-cell. In the Klein bottle K , the horizontal edges are identified in the same direction but the vertical edges in opposite directions—the orientation reversal that makes the interior rel witness loopb⋅loopa⋅loopb−1=loopa−1 . The three cases exhaust the structurally distinct possibilities: abelian with a 2-cell, free without one, and non-abelian with a non-trivial 2-cell.
Figure 2: Transport vs. softmax attention as string diagrams, with three input tokens. Left: the transport decoder of Construction 3.2 applies one generator network gwi per token wire; wires stay parallel and the output loop factors as the monoidal product γ1⊕γ2⊕γ3 (Theorem 3.3 ). Right: softmax self-attention is a single morphism on the entire tensor product, with positive weights αij>0 on every input/output pair (grey wires); each output position γi′ depends on every input token, so the morphism does not factor as a monoidal product—this is the obstruction in Theorem 4.1 .
Architecture
Type
Compiled from HIT
Params
Why type-A or B?
Transf. (WC)
A
winding only
585K
Attn. mixes segments
Cover
A
winding only
205K
No composition
Transp. Attn.
A
winding + positions
585K
Correct positions, attn. mixes
Transport
B
winding + generators
170K
Struct. concatenation
Homotopy
B
all (incl. 2-cell)
195K
Concat. + learned H
Table 1: Architectures tested on T2 . The other two spaces use a subset of these (see Tables 3 , 4 ). “Compiled from HIT” indicates which level of Construction 3.2 the architecture implements: winding = hard topological constraint only, generators = independent loop networks, all = generators plus learned 2-cell H . Type-A decoders allow cross-segment information flow or lack compositional structure; type-B decoders compose independently generated segments.
Architecture
Type
L=2
L=4
L=6
L=8
L=10
Transf. (WC)
A
1.89±.12
1.42±.31
1.42±.37
1.53±.51
1.54±.34
Cover
A
2.15±.31
1.65±.11
2.07±.06
1.98±.20
1.91±.10
Transp. Attn.
A
1.83±.18
1.63±.17
1.77±.21
2.05±.19
2.09±.13
Transport
B
1.68±.22
0.86±.12
0.74±.03
0.73±.03
0.77±.03
Homotopy
B
1.68±.19
0.93±.09
0.74±.03
0.74±.02
0.80±.03
Table 2: Torus T2 : Per-segment Chamfer distance dˉL (mean ± std, 3 seeds) at increasing word length L . Training uses L≤2 ; test lengths 3 – 10 are never seen. Type-B decoders (below line) stabilize; type-A decoders (above) stagnate or degrade despite more parameters.
Per-seg Chamfer dˉL
Circle acc. (%)
Architecture
Type
L=2
L=6
L=10
L=2
L=10
Transformer
A
.152±.002
.411±.027
.537±.027
33
14
Sequential
A
.010±.001
.173±.021
.297±.027
67
11
Transport
B
.002±.001
.018±.008
.054±.019
100
100
Table 3: Wedge of circles S1∨S1 ( π1=F2 , non-abelian): per-segment Chamfer and circle accuracy. Non-abelian structure dramatically amplifies the type-A/B gap. Full L -progression in Appendix D .
Architecture
Type
Canonical
Non-canonical
Cover
A
1.57±.10
1.96±.07
Transf. (WC)
A
2.28±.35
2.26±.36
Transport
B
0.84±.03
1.52±.08
Homotopy
B
0.82±.03
0.82±.06
Table 4: Klein bottle: per-segment Chamfer at L=10 , split by word type. The homotopy decoder (type-B with proof term H ) closes the gap on non-canonical words.
T2 ( Z2 )
S1∨S1 ( F2 )
K ( Z⋊Z )
Best type-B dˉ10
0.77
0.054
0.82
Best type-A dˉ10
1.54
0.297
1.76
Gap (best A / best B)
2.0×
5.5×
2.1×
Transport vs. Homotopy
≈1.0
≈1.0
1.85×
2-cell needed?
No (abelian)
No (free)
Yes (relation)
Table 5: Cross-experiment summary at L=10 . “Best A / best B” gives the tightest type comparison. K values in the first three rows are overall averages across canonical and non-canonical words; the Transport vs. Homotopy entry is the non-canonical ratio, where the 2-cell is exercised (Table 4 shows the split). The Klein bottle is the only space where the 2-cell matters.
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
Architecture
Type
L=2
L=3
L=4
L=6
L=8
L=10
Transformer
A
.152±.002
.245±.006
.297±.022
.411±.027
.464±.039
.537±.027
Sequential
A
.010±.001
.100±.005
.129±.009
.173±.021
.247±.034
.297±.027
Transport
B
.002±.001
.015±.010
.012±.005
.018±.008
.030±.011
.054±.019
Appendix
Table 6: S1∨S1 : per-segment Chamfer dˉL (mean ± std, 3 seeds), full L -progression.
Architecture
Type
L=2
L=3
L=4
L=6
L=8
L=10
Transformer
A
33
19
16
19
12
14
Sequential
A
67
36
20
14
8
11
Transport
B
100
100
100
100
100
100
Appendix
Table 7: S1∨S1 : circle accuracy (%, mean over 3 seeds). Transport achieves 100% by construction.
Architecture
Type
L=2
L=3
L=4
L=6
L=8
L=10
Cover
A
1.81±.13
1.90±.04
1.69±.04
1.86±.06
1.81±.13
1.76±.07
Transf. (WC)
A
1.80±.16
1.84±.21
1.84±.24
2.03±.29
2.28±.39
2.27±.33
Transport
B
1.54±.18
1.51±.05
1.25±.06
1.24±.05
1.18±.03
1.17±.04
Homotopy
B
1.43±.14
1.10±.04
0.97±.07
0.85±.04
0.79±.05
0.82±.03
Appendix
Table 8: Klein bottle K : per-segment Chamfer dˉL on all test words (mean ± std, 3 seeds).
Architecture
Type
L=2
L=3
L=4
L=6
L=8
L=10
Cover
A
1.86±.20
2.08±.11
1.68±.07
1.99±.08
2.02±.08
1.96±.07
Transf. (WC)
A
1.84±.11
1.93±.33
1.87±.28
1.96±.30
2.32±.40
2.26±.36
Transport
B
1.73±.12
1.82±.06
1.37±.08
1.45±.04
1.44±.05
1.52±.08
Homotopy
B
1.38±.12
1.13±.02
0.97±.08
0.83±.02
0.75±.02
0.82±.06
Appendix
Table 9: Klein bottle K : per-segment Chamfer on non-canonical words only (words where b precedes a , exercising the relation bab−1=a−1 ). The transport–homotopy gap isolates the proof term’s contribution.
Arch.
Comp.
Comm.
Reorder
Noncan.
Transf. (WC)
4.05±.21
0.24±.13
4.37±.10
2.04±1.65
Cover
4.25±.18
0.000
4.96±.39
0.000
Transp. Attn.
4.21±.14
1.54±1.39
4.79±.28
0.96±.56
Transport
4.28±.13
0.000
3.82±.07
0.000
Homotopy
4.24±.19
0.000
3.79±.13
0.000
Appendix
Table 10: T2 coherence battery. Exact zeros are architectural guarantees, not learned.