We study language acquisition by transformers trained on the Random Language Model: a synthetic hierarchical grammar with random production rules, whose sparsity is controlled by a single parameter and whose conditional entropies are known exactly. On depth-two grammars, we find that sparsity sets both the order and the speed of learning. Dense grammars are learnt one level at a time: a token is predicted from its sibling after t∝V steps and from the full context only after t∝V3, so the two stages are separated by a plateau that widens with V. Sparse grammars are learnt all at once, at t∝V, with a smaller exponent than even the first stage of a dense one. The exponents 1 and 1/2 already appear at depth one, where we derive them for a linear model trained with Adam.
Figures & tables
Figure 1: The sparsity of the grammar sets both the schedule and the time complexity. Left: The RLM. A root symbol R is expanded recursively through the production rules Qa of Eq. ( 1 ) (black squares); first into a pair of latent variables (Z1,Z2) , then into the observed sequence (X1,…,X4) . Right: Learning dynamics of a deep transformer for a dense ( β=1.2 , V=48 , blue) and a sparse ( β=6.0 , V=48 , red) grammar. The test loss is normalised, Lˉ=(L−H1)/(lnV−H1) : it equals 1 for the uniform predictor and 0 at the sibling entropy H1=H(X4∣X3) (dashed). Dotted lines mark the full-context floor H2=H(X4∣X1,X2,X3) of each grammar. The dense grammar descends in two stages separated by a plateau at H1 , the sparse one in a single step. Markers locate the two time complexities, t1∗ (circles) and t2∗ (squares), shown against V in the insets. Averages over 8 realisations of the grammar and transformer initialisation; bands give one standard deviation.
Figure 2: A single parameter controls the sparsity of the grammar. (a, b) The rule matrix Qa(b,c) of one parent symbol at V=32 and β=1.2,6.0 on a shared logarithmic colour scale. At β=1.2 , many pairs carry appreciable weight, so the grammar is dense ; at β=6 the weight condenses onto a handful of pairs and the grammar is sparse . (c) The effective number of rules per symbol, M(β) of Eq. ( 2 ), averaged over parent symbols and over realisations of the couplings. Dashed lines give the V→∞ prediction of Eq. ( 3 ), with the freezing transition at β=2 [ 21 ] marked by a vertical line.
Figure 3: Both regimes are present at L=1 . Transformers trained on a depth- 1 RLM to predict X2 from X1 . (a) Normalised test loss (L−H)/(lnV−H) at V=128 , with H=H(X2∣X1) computed exactly from the rules of each realisation, for three values of β in the dense phase ( 1.2 , 1.4 , 1.6 ; blues) and two in the sparse phase ( 3 , 6 ; reds). Dotted lines mark the levels 1 and 1/2 . (b) The crossing time t∗ against V for V=32 to 256 . Solid lines show the two scalings t∗∝V and t∗∝V derived for a linear model trained with Adam in App. C ; within a phase, different β shift t∗ by an O(1) factor without changing the exponent. Averages over repetitions, bands giving one standard deviation; protocol in App. A .
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 4: First stage of the dense grammar, β=1.2 . Normalised loss between lnV and H1=H(X4∣X3) , for V=12 to 64 with 8 realisations each, against the training step (left) and against t/Vs1 with s1=1.00±0.02 (right). The collapse identifies the first time scale as linear in the vocabulary size.
Figure 5: Second stage of the dense grammar, β=1.2 . Normalised loss between H1 and H2=H(X4∣X1,X2,X3) , for V=12 to 48 with 8 realisations each, against the training step (left) and against t/Vs2 with s2=3.04±0.34 (right). The curves sit at the plateau for t≪V3 and reach the floor only for t≫V3 , two powers of V later than the first stage. V=64 is omitted: it does not complete this stage within the available budget. Curves are smoothed with a 5 -point moving average in lnt , the second stage being the noisier of the two.
Figure 6: First stage, β=2 . Same quantities as Fig. 4 , for V=16 to 48 , with s1=0.73±0.04 . These runs use the smaller model of App. A and are not to be compared on the same axes with the β=1.2 and β=6 curves.
Figure 7: Second stage, β=2 . Same quantities as Fig. 5 , with s2=2.06±0.37 . At V=48 the stage only partly completes within the available budget, so the fit relies on the half-way crossing rather than on the approach to the floor, and the uncertainty on s2 is correspondingly larger. At β=2 the two stages are separated by roughly 1.3 powers of V , against 2 powers at β=1.2 : the schedule is already contracting.
Figure 8: Single stage of the sparse grammar, β=6 . Normalised loss between lnV and H2 , for V=12 to 48 with 8 realisations each, against the training step (left) and against t/Vs with s=0.47 (right); fitting the single-stage curves directly gives s=0.44±0.03 . No plateau at H1 is visible: the sibling and the cousins are acquired together, and one exponent describes the whole descent.
Figure 9: Linear model at small batch size, B=2 . Normalised loss (L−H)/(lnV−H) of the linear model, averaged over 8 grammars, for V=128 to 512 : (a) β=6 against t/(VlnV) , (b) β=1.2 against t/V . (c) Time t∗ at which the averaged loss first reaches 1/2 , with Eqs. ( 11 ) and ( 17 ), t∗∝VlnV and t∗∝V , prefactors fitted. Adam with its default parameters ( β1=0.9 , β2=0.999 , ϵ=10−8 , no weight decay; App. A ), learning rate η=3×10−5 , fresh samples at every step. At β=1.2 the loss levels off above the floor at late times and then rises (faint lines), more so at larger V ; this does not affect t∗ .
Figure 10: At the beta 2.0, depth helps. Depth- 1 and depth- 2 transformers trained on the same grammars at β=2 , for V=16,24,32,48 with 8 repetitions each. The two networks are indistinguishable while the loss falls from the uniform predictor, and separate at long times: the depth- 2 network reaches the full-context floor, whereas the depth- 1 network stalls above it. Smaller model of App. A (embedding dimension 128 , batch size 64 ).
Figure 11: In the sparse regime, depth is irrelevant. The same comparison at β=6 , for V=12,16,24,48 with 6 paired repetitions each, on a logarithmic vertical scale so that the approach to the floor is visible over three decades. The two depths are indistinguishable throughout, the depth- 1 network being at most marginally slower. Protocol of the main text (embedding dimension 256 , batch size 128 ); the depth- 1 runs were trained on the rule tensors of the depth- 2 runs, read from file, so the grammars agree exactly.