IntSeqBERT: Learning Arithmetic Structure in OEIS via Modulo-Spectrum Embeddings
Organizations: Iwate Prefectural University, Takizawa, Iwate, Japan
Abstract
Integer sequences in the OEIS span values from single-digit constants to astronomical factorials and exponentials, making prediction challenging for standard tokenised models that cannot handle out-of-vocabulary values or exploit periodic arithmetic structure. We present IntSeqBERT, a dual-stream Transformer encoder for masked integer-sequence modelling on OEIS. Each sequence element is encoded along two complementary axes: a continuous log-scale magnitude embedding and sin/cos modulo embeddings for 100 residues (moduli --), fused via FiLM. Three prediction heads (magnitude regression, sign classification, and modulo prediction for 100 moduli) are trained jointly on 274,705 OEIS sequences. At the Large scale (91.5M parameters), IntSeqBERT achieves 95.85% magnitude accuracy and 50.38% Mean Modulo Accuracy (MMA) on the test set, outperforming a standard tokenised Transformer baseline by pt and pt, respectively. An ablation removing the modulo stream confirms it accounts for pt of the MMA gain and contributes an additional pt to magnitude accuracy. A probabilistic Chinese Remainder Theorem (CRT)-based Solver converts the model's predictions into concrete integers, yielding a 7.4-fold improvement in next-term prediction over the tokenised-Transformer baseline (Top-1: 19.09% vs. 2.59%). Modulo spectrum analysis reveals a strong negative correlation between Normalised Information Gain (NIG) and Euler's totient ratio (, ), providing empirical evidence that composite moduli capture OEIS arithmetic structure more efficiently via CRT aggregation.
Figures & tables
| Config | Layers | Heads | Parameters | |
|---|---|---|---|---|
| Small | 6 | 256 | 4 | 6.4M |
| Middle | 8 | 512 | 8 | 29.0M |
| Large | 12 | 768 | 12 | 91.5M |
| Mode | Condition | Method |
|---|---|---|
| Dense | Enumerate all integers in range | |
| Sieve | CRT beam search anchored on high-confidence moduli | |
| CRT | Sparse CRT beam search to generate large integers directly |
| Bucket | Value range | Element fraction |
|---|---|---|
| Small | 52.7% | |
| Medium | 29.9% | |
| Large | 16.2% | |
| Huge | 1.1% | |
| Astronomical | 0.0% |
| Hyperparameter | Value |
|---|---|
| Epochs | 200 (no early stopping) |
| Batch size | 32 (gradient accumulation 2 steps; effective 64) |
| Learning rate | |
| Warmup fraction | 10% |
| Optimiser | AdamW, weight decay |
| Numerical precision | FP32 (AMP disabled) |
| Size | Model | Mag Acc | Sign Acc | MMA |
|---|---|---|---|---|
| Small | IntSeq | 94.73 | 97.78 | 40.43 |
| Small | Vanilla | 85.73 | 96.91 | 36.21 |
| Small | Ablation | 93.72 | 97.39 | 25.97 |
| Middle | IntSeq | 95.71 | 98.34 | 46.88 |
| Middle | Vanilla | 87.37 | 97.42 | 42.53 |
| Middle | Ablation | 92.45 | 97.90 | 31.93 |
| Bucket | IntSeq | Vanilla | Ablation |
|---|---|---|---|
| Small | 0.111 | 0.138 | 0.103 |
| Medium | 0.051 | 0.071 | 0.116 |
| Large | 0.162 | 2.100 | 0.381 |
| Huge | 2.082 | 22.73 | 5.021 |
| Astronomical | 110.4 | 840.0 | 532.6 |
| IntSeq | Vanilla | Ablation | Interpretation | |
|---|---|---|---|---|
| 2 | 85.65 | 81.40 | 72.13 | Parity |
| 3 | 72.62 | 65.22 | 53.72 | Ternary residue |
| 5 | 60.37 | 50.07 | 42.63 | Last decimal digit modulo 5 |
| 10 | 58.38 | 49.25 | 39.47 | Least significant decimal digit |
| 60 | 53.97 | 47.87 | 35.12 | Babylonian number (highly composite) |
| 96 | 51.82 | 47.29 | 34.44 | Composite ( ) |
| Size | Model | Top-1 | Top-10 | Sign Acc | Valid rate (%) |
|---|---|---|---|---|---|
| Small | IntSeq | 14.05 | 21.00 | 98.73 | 90.59 |
| Small | Vanilla | 2.43 | 3.24 | 92.92 | 100.0 |
| Small | Ablation | 7.42 | 17.33 | 98.50 | 90.17 |
| Middle | IntSeq | 17.02 | 22.62 | 99.02 | 86.31 |
| Middle | Vanilla | 2.43 | 3.41 | 92.71 | 100.0 |
| Middle | Ablation | 9.88 | 20.52 | 98.74 | 90.34 |
| IntSeqBERT | Vanilla | Ablation | ||||
|---|---|---|---|---|---|---|
| Bucket | Top-1 | Top-10 | Top-1 | Top-10 | Top-1 | Top-10 |
| Small | 68.34 | 88.50 | 14.11 | 20.71 | 54.55 | 86.92 |
| Medium | 20.82 | 31.50 | 0.00 | 0.00 | 5.61 | 18.88 |
| Large | 0.31 | 0.67 | 0.00 | 0.00 | 0.03 | 0.05 |
| Huge | 0.09 | 0.18 | 0.00 | 0.00 | 0.00 | 0.00 |
| Astronomical | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
| Metric | Small | Middle | Large | (S L) |
|---|---|---|---|---|
| Mag Acc (%) | 94.73 | 95.71 | 95.85 | |
| MMA (%) | 40.43 | 46.88 | 50.38 | |
| mod-2 accuracy (%) | 81.97 | 84.50 | 85.65 | |
| Solver Top-1 (%) | 14.05 | 17.02 | 19.09 | |
| Magnitude MSE | 0.228 | 0.164 | 0.142 |
Sequence Modeling
Sequence modeling studies how to represent, predict, classify, and generate ordered data such as text, time series, events, and biological sequences.
See all 249 papers