Roman Numeral Calculator

The Network

Loading network…
Hover a cell for its value.

About

Like Version 1, this tool is a simple roman numeral addition calculator. Enter two numbers, each up to the maximum, press 'Calculate', and wait for the result.

Numbers are converted to roman numerals and then encoded in a form the network can understand. The approach is quite straight-forward. The input is a set of slots, each of which has a corresponding Numeral symbol.

Starting at the last symbol of the full numeral, and the last slot in the input vector, each symbol is read, and the first slot (moving leftwards) that matches that symbol is set to 1. This is repeated for each symbol until all symbols are processed. This approach allows for, for example 'XI' (11) to be encoded differently than 'IX' (9), even though they contain the same symbols, the relative order captures the difference.

The input vectors for both numbers are combined into one, and passed through the network.

On the output side, the opposite happens. The network outputs a numeric vector that has the same representation as the inputs. Reconstructing the numeral is simply a matter of outputting the corresponding symbol for each activated slot in the vector, and combining.

The Model

The model is trained as a standard linear feed-forward network in PyTorch until all possible outputs (in the valid range) provide the correct answer. Unlike most neural network applications, we can trivially verify every possible input, and have a single definite answer for each input, so it's possible to verify the model's correctness over every input.

Then a separate process is run to try to align the neurons in the hidden layers to promote locality. The aim here is to improve the visual interpretability of the network in the above visualisation, by forcing as much structure within the hidden layers as possible.

Finally, all the layers in the model, and their activations/weights, are exported as static rust definitions, using Candle core to implement the tensor operations. This rust code is wrapped in a simple cloudflare workers handler that exposes the model as an API endpoint.

The package is then compiled to WebAssembly, and deployed to cloudflare workers.