WangNet – 1.8 MB, zero-dependency Numberwang adjudication in 11 languages

Sep 16, 2026 02:27 AM - 1 day ago 1

A mini neural web that decides whether a number is Numberwang.

The full exemplary is simply a 1.8 MB JSON record and the conclusion codification is astir 100 lines of axenic Python modular room — nary PyTorch, nary NumPy, thing to install. Clone it and tally it.

$ python3 numberwang.py 22 22... THAT'S NUMBERWANG! (confidence: 99.3%) $ python3 numberwang.py "45 - 44" 45 - 44... That's Wangernumb! Rotate the board! (confidence: 100.0%) $ python3 numberwang.py "hello really are you" hello really are you... That's not moreover a number. It tin ne'er beryllium Numberwang. (confidence: 100.0%)
git clone https://github.com/GraafHenk/numberwang cd numberwang python3 numberwang.py 22

Run it pinch nary arguments for an interactive session:

$ python3 numberwang.py Welcome to Numberwang! (ctrl-c to extremity playing Numberwang) > zweiundzwanzig zweiundzwanzig... THAT'S NUMBERWANG! (confidence: 100.0%) > shinty-six shinty-six... That's not Numberwang. (confidence: 100.0%)

Requires Python 3.8 aliases newer. That's the only requirement.

from numberwang import load_model, wang_probabilities model = load_model("model.json") probs = wang_probabilities(model, "forty-seven") # [p_not_numberwang, p_numberwang, p_not_a_number, p_wangernumb] verdict = max(range(4), key=probs.__getitem__)
id verdict
0 That's not Numberwang.
1 THAT'S NUMBERWANG!
2 That's not moreover a number. It tin ne'er beryllium Numberwang.
3 That's Wangernumb!
input behaviour
42, sixty-six, 12345 digits aliases words
zweiundzwanzig, veintidós, tweeëntwintig eleven languages, accents optional
5*2, 96 divided by 2, 12 positive four arithmetic, judged connected the result
45 - 44, double four, eins anything worthy 1 aliases 44 rotates the board
-7, 4.5, £5, 50%, 9:30 negatives, decimals, currency, units, times
XLIV, twenty-third, 22nd Roman numerals and ordinals
fortnight, vierendelen, september words built connected a number, judged arsenic that number
achtneming, often, money words that simply incorporate 1 are not numbers
shinty-six, twentington fictional numbers are numbers too
bonjour, hullo really are you no numeric contented — tin ne'er beryllium Numberwang

A number's wangness is simply a spot of the number, not the connection it is said in: four, vier, quatre and cuatro each get the aforesaid verdict.

chars → Embedding(32) → Conv1d(128, k3) → ReLU → Conv1d(128, k3) → ReLU → world max pool → Linear(128) → ReLU → Linear(4) → softmax

80,804 parameters. The web sounds characters straight — location is no tokenizer, nary normalizer and nary rules motor astatine inference. Digits, operators, canon verdicts and the eleven languages are each held successful the weights, and model.json contains the lot.

A hosted type runs connected Hugging Face Spaces. To tally the aforesaid demo locally:

pip instal -r requirements.txt python3 app.py

gradio is needed only for the demo. The exemplary itself ne'er needs it.

88.9% complete 486 held-out adjudications (macro-F1 0.896), against a ceiling of astir 98% — astir 2% of training labels are inverted, successful accordance with long-standing adjudication practice.

class precision recall F1
not Numberwang 0.820 0.885 0.851
Numberwang 0.919 0.900 0.910
not a number 0.951 0.830 0.886
Wangernumb 0.968 0.909 0.937

Arithmetic connected unseen operands is the anemic spot, astatine 44–72%. The network memorises alternatively than computes, truthful mini communal expressions like 5*2 are reliable while 904 * 3 is an knowledgeable guess. If arithmetic correctness matters, measure the look and manus it the result.

MIT — spot LICENSE.

No warranty is expressed aliases implied arsenic to whether immoderate peculiar number is, aliases is not, Numberwang.

More