ALEXFLR commited on
Commit
e9b611e
Β·
verified Β·
1 Parent(s): bffbf79

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +615 -0
README.md CHANGED
@@ -1,3 +1,618 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ ---
6
+
7
+ language:
8
+
9
+ * en
10
+ library_name: pytorch
11
+ license: mit
12
+ tags:
13
+ * quadratic-equations
14
+ * mathematical-reasoning
15
+ * interpretability
16
+ * mechanistic-interpretability
17
+ * symbolic-reasoning
18
+ * synthetic-data
19
+ pipeline_tag: text-generation
20
+
21
+ ---
22
+
23
+ # SEAI: Learning Mathematical Representations for Quadratic Equation Solving
24
+
25
+ **SEAI (Square Equation AI)** is a research neural network designed to solve quadratic equations with real roots while enabling direct analysis of its learned internal representations.
26
+
27
+ The primary purpose of SEAI is not only numerical prediction. The project investigates whether a neural network trained to predict quadratic roots can develop internal representations correlated with mathematically meaningful quantities involved in the analytical solution.
28
+
29
+ A central observation of the current experiment is that hidden activations in deeper layers exhibit strong correlations with the normalized quadratic discriminant
30
+
31
+ $$
32
+ p^2-q
33
+ $$
34
+
35
+ and with its square-root transformation, despite neither quantity being explicitly provided as an input feature.
36
+
37
+ ---
38
+
39
+ ## Model Summary
40
+
41
+ SEAI receives a normalized representation of a quadratic equation
42
+
43
+ $$
44
+ ax^2+bx+c=0
45
+ $$
46
+
47
+ and predicts the two ordered real roots.
48
+
49
+ The model contains exactly:
50
+
51
+ **8,040,002 trainable parameters.**
52
+
53
+ The architecture consists of four custom quadratic layers followed by a linear output projection.
54
+
55
+ ```text
56
+ Input (2)
57
+ ↓
58
+ QuadraticLayer: 2 β†’ 1000
59
+ ↓
60
+ LayerNorm
61
+ ↓
62
+ GELU
63
+ ↓
64
+ QuadraticLayer: 1000 β†’ 2000
65
+ ↓
66
+ LayerNorm
67
+ ↓
68
+ GELU
69
+ ↓
70
+ QuadraticLayer: 2000 β†’ 2000
71
+ ↓
72
+ LayerNorm
73
+ ↓
74
+ GELU
75
+ ↓
76
+ QuadraticLayer: 2000 β†’ 1000
77
+ ↓
78
+ LayerNorm
79
+ ↓
80
+ GELU
81
+ ↓
82
+ Linear: 1000 β†’ 2
83
+ ↓
84
+ Ordered normalized roots
85
+ ```
86
+
87
+ ---
88
+
89
+ ## Mathematical Formulation
90
+
91
+ A quadratic equation is invariant under multiplication of all coefficients by the same non-zero scalar.
92
+
93
+ We therefore use the scale-invariant quantities
94
+
95
+ $$
96
+ P=\frac{b}{a},
97
+ \qquad
98
+ Q=\frac{c}{a}.
99
+ $$
100
+
101
+ The training distribution generated from roots in
102
+
103
+ $$
104
+ [-50,50]
105
+ $$
106
+
107
+ produces
108
+
109
+ $$
110
+ P\in[-100,100],
111
+ \qquad
112
+ Q\in[-2500,2500].
113
+ $$
114
+
115
+ The model receives the normalized variables
116
+
117
+ $$
118
+ p=\frac{P}{100},
119
+ \qquad
120
+ q=\frac{Q}{2500}.
121
+ $$
122
+
123
+ The target roots are normalized as
124
+
125
+ $$
126
+ x_n=\frac{x}{50}.
127
+ $$
128
+
129
+ Under this normalization, the exact solution for the normalized roots is
130
+
131
+ $$
132
+ \boxed{
133
+ x_{n,1/2}=-p\pm\sqrt{p^2-q}
134
+ }
135
+ $$
136
+
137
+ with the roots ordered so that
138
+
139
+ $$
140
+ x_{n,1}\leq x_{n,2}.
141
+ $$
142
+
143
+ The classical discriminant is
144
+
145
+ $$
146
+ \Delta=b^2-4ac.
147
+ $$
148
+
149
+ Under the SEAI normalization,
150
+
151
+ $$
152
+ \boxed{
153
+ \Delta=10000a^2(p^2-q)
154
+ }
155
+ $$
156
+
157
+ and therefore
158
+
159
+ $$
160
+ \boxed{
161
+ p^2-q=\frac{\Delta}{10000a^2}.
162
+ }
163
+ $$
164
+
165
+ Thus, \(p^2-q\) is exactly the discriminant normalized by the coefficient scale.
166
+
167
+ ---
168
+
169
+ ## Dataset
170
+
171
+ The dataset is entirely synthetic.
172
+
173
+ Two real roots are sampled from
174
+
175
+ $$
176
+ x_1,x_2\sim U(-50,50)
177
+ $$
178
+
179
+ and sorted so that
180
+
181
+ $$
182
+ x_1\leq x_2.
183
+ $$
184
+
185
+ A non-zero coefficient \(a\) is then selected and the remaining coefficients are constructed using
186
+
187
+ $$
188
+ b=-a(x_1+x_2)
189
+ $$
190
+
191
+ and
192
+
193
+ $$
194
+ c=ax_1x_2.
195
+ $$
196
+
197
+ This guarantees that the generated quadratic has the selected roots as its exact solutions.
198
+
199
+ The current training experiment uses:
200
+
201
+ ```text
202
+ Training examples: 150,000
203
+ Root range: [-50, 50]
204
+ Task: real-root quadratic equations
205
+ ```
206
+
207
+ The current experiment does not evaluate equations with complex roots.
208
+
209
+ ---
210
+
211
+ ## QuadraticLayer
212
+
213
+ The central custom component is:
214
+
215
+ ```python
216
+ class QuadraticLayer(nn.Module):
217
+ def __init__(self, in_features, out_features):
218
+ super().__init__()
219
+
220
+ self.linear = nn.Linear(in_features, out_features)
221
+
222
+ self.A = nn.Parameter(torch.ones(out_features) * 0.01)
223
+ self.B = nn.Parameter(torch.ones(out_features))
224
+ self.C = nn.Parameter(torch.zeros(out_features))
225
+
226
+ def forward(self, x):
227
+ z = self.linear(x)
228
+ return self.A * z**2 + self.B * z + self.C
229
+ ```
230
+
231
+ Each output channel therefore computes
232
+
233
+ $$
234
+ y_i=A_i z_i^2+B_i z_i+C_i
235
+ $$
236
+
237
+ where
238
+
239
+ $$
240
+ z=Wx+b.
241
+ $$
242
+
243
+ This gives the model an explicit mechanism for constructing quadratic nonlinear transformations of learned linear projections.
244
+
245
+ ---
246
+
247
+ ## Training Configuration
248
+
249
+ ```text
250
+ Dataset size: 150,000
251
+ Batch size: 256
252
+ Epochs: 125
253
+
254
+ Optimizer: AdamW
255
+ Learning rate: 3e-4
256
+ Weight decay: 1e-4
257
+
258
+ Loss: SmoothL1Loss
259
+ Gradient clipping: max_norm = 1.0
260
+
261
+ Activation: GELU
262
+ Normalization: LayerNorm
263
+ ```
264
+
265
+ ---
266
+
267
+ ## Evaluation
268
+
269
+ One recent independent evaluation run produced the following results:
270
+
271
+ | Metric | Result |
272
+ | ---------------------- | -------: |
273
+ | MAE | 0.084864 |
274
+ | RMSE | 0.137898 |
275
+ | Maximum observed error | 1.652145 |
276
+ | Error < 0.1 | 69.34% |
277
+ | Error < 0.01 | 0.27% |
278
+
279
+ These metrics are reported in the normalized root representation unless otherwise specified.
280
+
281
+ The current evaluation results should be considered preliminary. Earlier experiments used independently generated evaluation sets, so future releases will use fixed train/validation/test splits and fixed random seeds for reproducible comparisons.
282
+
283
+ The model tends to perform worse when the two roots become very close.
284
+
285
+ ---
286
+
287
+ ## Interpretability Analysis
288
+
289
+ One of the main purposes of SEAI is to investigate whether mathematically meaningful structures emerge inside the network.
290
+
291
+ Forward hooks are used to record hidden activations from each `QuadraticLayer`.
292
+
293
+ Neuron activations are compared against candidate mathematical features including
294
+
295
+ $$
296
+ p,\quad q,\quad p^2,\quad q^2,\quad pq,
297
+ $$
298
+
299
+ $$
300
+ p^2-q,\qquad p^2+q,
301
+ $$
302
+
303
+ and
304
+
305
+ $$
306
+ \sqrt{|p^2-q|}.
307
+ $$
308
+
309
+ Because the current dataset contains real-root equations, the discriminant-related quantity satisfies
310
+
311
+ $$
312
+ p^2-q\geq0
313
+ $$
314
+
315
+ up to numerical precision.
316
+
317
+ The analysis investigates which candidate mathematical quantities are most strongly correlated with individual hidden activations.
318
+
319
+ ---
320
+
321
+ ## Observed Representation Structure
322
+
323
+ The current experiment shows a qualitative progression across layers.
324
+
325
+ ### First Quadratic Layer
326
+
327
+ Hidden activations primarily show strong correlations with the original variables
328
+
329
+ $$
330
+ p
331
+ $$
332
+
333
+ and
334
+
335
+ $$
336
+ q.
337
+ $$
338
+
339
+ ### Second Quadratic Layer
340
+
341
+ Nonlinear mathematical combinations become more prominent, including
342
+
343
+ $$
344
+ p^2+q
345
+ $$
346
+
347
+ and
348
+
349
+ $$
350
+ p^2-q.
351
+ $$
352
+
353
+ ### Third and Fourth Quadratic Layers
354
+
355
+ The strongest recurring candidate features include
356
+
357
+ $$
358
+ p^2-q
359
+ $$
360
+
361
+ and
362
+
363
+ $$
364
+ \sqrt{p^2-q}.
365
+ $$
366
+
367
+ This produces an experimentally observed progression consistent with the algebraic structure required by the analytical solution:
368
+
369
+ $$
370
+ \boxed{
371
+ p,q
372
+ \rightarrow
373
+ \text{quadratic combinations}
374
+ \rightarrow
375
+ p^2-q
376
+ \rightarrow
377
+ \sqrt{p^2-q}
378
+ \rightarrow
379
+ x_1,x_2
380
+ }
381
+ $$
382
+
383
+ The interpretation of this progression remains exploratory.
384
+
385
+ ---
386
+
387
+ ## Main Interpretability Finding
388
+
389
+ The central observation of the current study is:
390
+
391
+ > **An 8.04-million-parameter neural network developed hidden representations strongly correlated with the normalized quadratic discriminant and its square-root transformation, despite not receiving either quantity explicitly as an input.**
392
+
393
+ This does **not** establish that an individual neuron literally performs symbolic discriminant or square-root computation.
394
+
395
+ Instead, it provides evidence that the trained network contains internal representations that are statistically aligned with mathematically meaningful quantities involved in the classical solution.
396
+
397
+ ---
398
+
399
+ ## Error Behaviour Near Repeated Roots
400
+
401
+ The largest errors tend to occur when
402
+
403
+ $$
404
+ x_1\approx x_2.
405
+ $$
406
+
407
+ For the normalized representation this corresponds to
408
+
409
+ $$
410
+ p^2-q\approx0.
411
+ $$
412
+
413
+ This is the regime in which the square-root term in the analytical solution approaches zero.
414
+
415
+ A future systematic analysis will measure prediction error as a function of
416
+
417
+ $$
418
+ |x_2-x_1|
419
+ $$
420
+
421
+ and
422
+
423
+ $$
424
+ p^2-q.
425
+ $$
426
+
427
+ ---
428
+
429
+ ## Limitations
430
+
431
+ The following limitations are important.
432
+
433
+ ### Correlation is not proof of symbolic computation
434
+
435
+ A high correlation between a neuron and a mathematical expression does not prove that the neuron explicitly computes that expression.
436
+
437
+ ### Preliminary evaluation protocol
438
+
439
+ The current reported metrics include experiments performed with independently generated evaluation sets. Fixed evaluation data and fixed seeds are required for rigorous model comparison.
440
+
441
+ ### Restricted data distribution
442
+
443
+ The model is currently trained on real-root quadratic equations generated from roots in
444
+
445
+ $$
446
+ [-50,50].
447
+ $$
448
+
449
+ Generalization outside this range has not yet been established.
450
+
451
+ ### No complex-root regime
452
+
453
+ The current training and evaluation setup does not investigate equations with
454
+
455
+ $$
456
+ p^2-q<0.
457
+ $$
458
+
459
+ ### Interpretability is exploratory
460
+
461
+ The current analysis is primarily based on neuron-level correlations. Stronger evidence would require symbolic regression, reproducibility across independent runs, and causal interventions on candidate neurons or representations.
462
+
463
+ ---
464
+
465
+ ## Future Research
466
+
467
+ Planned experiments include:
468
+
469
+ * fixed reproducible train/validation/test splits;
470
+ * multiple random seeds;
471
+ * standard MLP baselines;
472
+ * ablations of the quadratic transformation;
473
+ * systematic neuron-level symbolic regression;
474
+ * causal interventions on neurons correlated with \(p^2-q\);
475
+ * out-of-distribution evaluation;
476
+ * larger root and coefficient ranges;
477
+ * analysis of representation stability across independently trained models;
478
+ * comparison with conventional polynomial architectures;
479
+ * extension to higher-degree polynomial equations.
480
+
481
+ A key research question is whether the observed discriminant-related representations arise systematically from the quadratic architecture or can be reproduced equally well by standard neural networks of comparable size.
482
+
483
+ ---
484
+
485
+ ## Intended Use
486
+
487
+ SEAI is intended primarily as a research prototype for:
488
+
489
+ * mechanistic interpretability;
490
+ * mathematical representation learning;
491
+ * neural symbolic reasoning;
492
+ * analysis of learned algebraic structure;
493
+ * controlled studies of neural networks on mathematically defined tasks.
494
+
495
+ It is not intended to replace conventional numerical solvers in production environments.
496
+
497
+ For arbitrary quadratic equations, a conventional analytical or numerical solver remains preferable.
498
+
499
+ ---
500
+
501
+ ## Repository Structure
502
+
503
+ ```text
504
+ SEAI/
505
+ β”œβ”€β”€ train.py
506
+ β”œβ”€β”€ model.py
507
+ β”œβ”€β”€ interpretability.py
508
+ β”œβ”€β”€ evaluation.py
509
+ β”œβ”€β”€ requirements.txt
510
+ β”œβ”€β”€ README.md
511
+ └── weights/
512
+ └── model_weights_SEAI.pth
513
+ ```
514
+
515
+ The final reproducible release should additionally contain:
516
+
517
+ ```text
518
+ β”œβ”€β”€ data/
519
+ β”‚ β”œβ”€β”€ train.pt
520
+ β”‚ β”œβ”€β”€ validation.pt
521
+ β”‚ └── test.pt
522
+ β”œβ”€β”€ configs/
523
+ β”‚ └── seai_config.json
524
+ └── results/
525
+ β”œβ”€β”€ metrics.json
526
+ └── interpretability/
527
+ ```
528
+
529
+ ---
530
+
531
+ ## Citation
532
+
533
+ ```bibtex
534
+ @misc{seai2026,
535
+ title={SEAI: Learning Mathematical Representations for Quadratic Equation Solving},
536
+ author={SEAI Project},
537
+ year={2026},
538
+ note={Research prototype}
539
+ }
540
+ ```
541
+
542
+ The corresponding research paper is intended for publication on arXiv.
543
+
544
+ ---
545
+
546
+ ## Project Status
547
+
548
+ **Research prototype β€” experimental**
549
+
550
+ SEAI is primarily a research project investigating whether neural networks can develop internal representations aligned with known mathematical structures.
551
+
552
+
553
+ πŸ€–AI
554
+
555
+ class QuadraticLayer(nn.Module):
556
+ def __init__(self, in_features, out_features):
557
+ super().__init__()
558
+ self.linear = nn.Linear(
559
+ in_features,
560
+ out_features
561
+ )
562
+ self.A = nn.Parameter(
563
+ t.ones(out_features) * 0.01
564
+ )
565
+
566
+ self.B = nn.Parameter(
567
+ t.ones(out_features)
568
+ )
569
+
570
+ self.C = nn.Parameter(
571
+ t.zeros(out_features)
572
+ )
573
+
574
+ def forward(self, x):
575
+
576
+ z = self.linear(x)
577
+
578
+ return (
579
+ self.A * z**2
580
+ + self.B * z
581
+ + self.C
582
+ )
583
+
584
+ class SEAI(nn.Module):
585
+ def __init__(self):
586
+ super().__init__()
587
+
588
+ self.net = nn.Sequential(
589
+
590
+ QuadraticLayer(2, 1000),
591
+ nn.LayerNorm(1000),
592
+ nn.GELU(),
593
+
594
+ QuadraticLayer(1000, 2000),
595
+ nn.LayerNorm(2000),
596
+ nn.GELU(),
597
+
598
+ QuadraticLayer(2000, 2000),
599
+ nn.LayerNorm(2000),
600
+ nn.GELU(),
601
+
602
+ QuadraticLayer(2000, 1000),
603
+ nn.LayerNorm(1000),
604
+ nn.GELU(),
605
+
606
+ nn.Linear(1000, 2)
607
+ )
608
+
609
+ def forward(self, x):
610
+ return self.net(x)
611
+
612
+
613
+ model = SEAI().to(device)
614
+
615
+ model.eval()
616
+
617
+ with t.no_grad():
618
+ ...