Inspiration

I'd used neural networks plenty of times before this — import torch, define layers, call .fit(), done. But I couldn't have told you what was actually happening inside the backward pass. When CS50P's final project came around, I wanted to build something where I couldn't hide behind a library. No TensorFlow, no PyTorch, no scikit-learn. If the model learned anything, it would be because I'd written the gradient descent correctly.

The problem I chose came out of materials engineering. Aircraft turbine blades sit at 550–650°C under hundreds of MPa of stress for thousands of hours, and they slowly stretch and fail — that's creep. Predicting when a given alloy will rupture normally means slow, expensive, destructive testing. But creep life depends on a small, well-defined set of variables: stress, temperature, and alloying elements like aluminium and titanium. Four inputs, one output — small enough that a from-scratch network was actually feasible, and real enough that the result would mean something.

So AlloyAI became two projects at once: a creep-life predictor for turbine alloys, and a hand-built implementation of everything I'd previously treated as a black box.

What it does

AlloyAI takes four inputs — applied stress in MPa, operating temperature in °C, aluminium content in wt%, and titanium content in wt% — and predicts rupture life in hours.

The network architecture is deliberately small: 4 inputs → 64 neurons (tanh) → 32 neurons (tanh) → 1 output (ReLU). Training runs 500 epochs of gradient descent on mean squared error, with 20% of the data held out for validation. Xavier uniform initialisation keeps the activations from saturating early.

Everything that normally comes from a library, I wrote:

A MinMaxScaler class with its own fit_transform

A manual train/test split

Forward and backward passes with cached intermediate values

Backpropagation by hand, walking backwards through the layers

R² and MAE computed from scratch

On the held-out set the model reaches R² ≈ 0.91–0.95 with a mean absolute error around 54 hours. Training automatically writes a model_results.txt report and generates a PNG with a parity plot and an error histogram. There's also a seven-test pytest suite covering every component, which all pass.

For a 650 MPa, 580°C alloy with Al = 0.89 wt% and Ti = 1.78 wt%, it predicts a rupture life of roughly 591–924 hours.

How we built it

I started with the data: [195 creep test records] compiled into a CSV with four feature columns and one target column.

Then I built bottom-up, in this order: scaler → split → metrics → network → training loop → reporting → tests. Writing the tests as I went, rather than at the end, turned out to be the single best decision in the project.

The forward pass caches every pre-activation value (z) so the backward pass can reuse them. The backward pass starts with the output error, multiplies by the ReLU derivative, then walks backwards through the layers applying the tanh derivative and the transpose of each weight matrix, accumulating gradients and updating weights with plain gradient descent.

The activation choices weren't arbitrary. Tanh works in the hidden layers because the scaled inputs sit in a narrow range and tanh centres the signal around zero. The ReLU on the output layer is a constraint disguised as an activation — rupture life can't be negative, and a linear output will cheerfully predict −300 hours on an outlier.

The whole thing is NumPy, Pandas, and Matplotlib. That's it.

Challenges we ran into

Dimensions, everywhere. Hand-coding backprop means every np.dot is a chance to silently transpose something and train a model that outputs garbage with a perfectly finite loss. I spent a genuinely embarrassing amount of time staring at array shapes.

Scaling mattered far more than I expected. Before I added min-max scaling, tanh saturated almost immediately and the gradients through the hidden layers collapsed to near zero. The model wasn't "a bit worse" — it was learning nothing at all. That was the moment scaling stopped being a formality and became the thing that made the project work.

Small data is humbling. 195 samples is not a lot. I had to be careful not to tune hyperparameters against the test set and fool myself into a number that wouldn't hold up. I also had to accept that quoting a single best run would be dishonest — a range of 0.91–0.95 across runs is the honest description.

Choosing the right output activation. A linear output layer produced negative life predictions. Switching to ReLU fixed it, but it meant thinking about whether the constraint belonged in the architecture or in post-processing. I decided the architecture should enforce what's physically true.

The metallurgy was a second subject to learn. I had to read enough about power-law creep and Arrhenius temperature dependence to be confident the features I'd chosen made physical sense, not just statistical sense.

Accomplishments that we're proud of

Getting backpropagation correct from scratch is the headline. There's no error message that tells you your gradient is wrong — the loss just goes down slowly, or not at all, and you have to reason your way out.

Beyond that:

R² of roughly 0.93 with ~54 hour MAE, from a network with no frameworks behind it

Seven passing pytest tests covering the scaler, split, metrics, data loading, training, result saving, and a full end-to-end workflow

The model recovers real physics. It isn't told the creep power law; it has to find the shape from 195 examples, and it does — temperature dominates the way Arrhenius behaviour says it should

Reproducible reporting. Every run writes its own results file and plots, so the numbers on the page are traceable rather than remembered

Zero ML dependencies. Anyone can read the entire model top to bottom in one sitting

What we learned

What a framework actually does for you. Xavier initialisation, activation choice, scaling, gradient flow — these are invisible when a library handles them and decisive when you don't. I now understand why each one exists, not just that it's there.

Scaling is not cosmetic. It's the difference between a network that learns and one that doesn't.

Small datasets punish overconfidence. With 195 samples, a single held-out split is fragile and a single reported number is misleading. Honest reporting is part of the engineering, not an afterthought.

Tests are a debugging tool, not a formality. When I broke the backward pass for the fourth time, the test suite told me exactly which piece was wrong instead of leaving me to guess.

The physics is a feature, not decoration. Choosing stress, temperature, Al, and Ti wasn't arbitrary — it came from the creep equation, and that's why 195 samples were enough to learn from.

What's next for AlloyAI: Neural Creep Life Predictor

Predict log(life) instead of life. Rupture life spans several orders of magnitude. Training on the log target should tighten the MAE considerably — this is the single highest-value change and I'd like to make it next.

Better validation. Replace the single split with k-fold cross-validation and add early stopping against validation loss, so the reported number is stable rather than a lucky run.

Regularisation. L2 weight decay and dropout to reduce variance on a dataset this small.

More data. 195 samples is the binding constraint. Pulling additional creep records from published studies would do more for accuracy than any architectural change.

A physics-informed loss. Add a penalty term for predictions that violate the Arrhenius relationship — nudging the network toward physically valid answers instead of only fitting the data.

Package it. A small CLI or a simple web front-end so someone can enter an alloy composition and get a prediction without cloning the repo.

Built With

Share this project:

Updates

Submission history