GraafHenk/numberwang

A small neural network that decides whether a number is Numberwang.

1

stars

5

commits

Python

primary language

Sep 15, 2026

updated

README

Numberwang

A small neural network that decides whether a number is Numberwang.

The whole model is a 1.8 MB JSON file and the inference code is about 100 lines of pure Python standard library — no PyTorch, no NumPy, nothing to install. Clone it and run 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 how are you"
hello how are you... That's not even a number. It can never be Numberwang.  (confidence: 100.0%)

Usage

git clone https://github.com/GraafHenk/numberwang
cd numberwang
python3 numberwang.py 22

Run it with no arguments for an interactive session:

$ python3 numberwang.py
Welcome to Numberwang! (ctrl-c to stop 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 or newer. That's the only requirement.

In your own code

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__)

The four verdicts

idverdict
0That's not Numberwang.
1THAT'S NUMBERWANG!
2That's not even a number. It can never be Numberwang.
3That's Wangernumb!

What it accepts

inputbehaviour
42, sixty-six, 12345digits or words
zweiundzwanzig, veintidós, tweeëntwintigeleven languages, accents optional
5*2, 96 divided by 2, twelve plus fourarithmetic, judged on the result
45 - 44, double four, einsanything worth 1 or 44 rotates the board
-7, 4.5, £5, 50%, 9:30negatives, decimals, currency, units, times
XLIV, twenty-third, 22ndRoman numerals and ordinals
fortnight, vierendelen, septemberwords built on a number, judged as that number
achtneming, often, moneywords that merely contain one are not numbers
shinty-six, twentingtonfictional numbers are numbers too
bonjour, hello how are youno numeric content — can never be Numberwang

A number's wangness is a property of the number, not the language it is said in: four, vier, quatre and cuatro all get the same verdict.

How it works

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

80,804 parameters. The network reads characters directly — there is no tokenizer, no normalizer and no rules engine at inference. Digits, operators, canon verdicts and the eleven languages are all held in the weights, and model.json contains the lot.

Demo

A hosted version runs on Hugging Face Spaces. To run the same demo locally:

pip install -r requirements.txt
python3 app.py

gradio is needed only for the demo. The model itself never needs it.

Accuracy

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

classprecisionrecallF1
not Numberwang0.8200.8850.851
Numberwang0.9190.9000.910
not a number0.9510.8300.886
Wangernumb0.9680.9090.937

Arithmetic on unseen operands is the weak spot, at 44–72%. The network memorises rather than computes, so small common expressions like 5*2 are reliable while 904 * 3 is an educated guess. If arithmetic correctness matters, evaluate the expression and hand it the result.

License

MIT — see LICENSE.

No warranty is expressed or implied as to whether any particular number is, or is not, Numberwang.

Contributors

GraafHenk

5 commits

GraafHenk/numberwang

A small neural network that decides whether a number is Numberwang.

1

stars

5

commits

Python

primary language

Sep 15, 2026

updated

README

Numberwang

A small neural network that decides whether a number is Numberwang.

The whole model is a 1.8 MB JSON file and the inference code is about 100 lines of pure Python standard library — no PyTorch, no NumPy, nothing to install. Clone it and run 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 how are you"
hello how are you... That's not even a number. It can never be Numberwang.  (confidence: 100.0%)

Usage

git clone https://github.com/GraafHenk/numberwang
cd numberwang
python3 numberwang.py 22

Run it with no arguments for an interactive session:

$ python3 numberwang.py
Welcome to Numberwang! (ctrl-c to stop 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 or newer. That's the only requirement.

In your own code

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__)

The four verdicts

idverdict
0That's not Numberwang.
1THAT'S NUMBERWANG!
2That's not even a number. It can never be Numberwang.
3That's Wangernumb!

What it accepts

inputbehaviour
42, sixty-six, 12345digits or words
zweiundzwanzig, veintidós, tweeëntwintigeleven languages, accents optional
5*2, 96 divided by 2, twelve plus fourarithmetic, judged on the result
45 - 44, double four, einsanything worth 1 or 44 rotates the board
-7, 4.5, £5, 50%, 9:30negatives, decimals, currency, units, times
XLIV, twenty-third, 22ndRoman numerals and ordinals
fortnight, vierendelen, septemberwords built on a number, judged as that number
achtneming, often, moneywords that merely contain one are not numbers
shinty-six, twentingtonfictional numbers are numbers too
bonjour, hello how are youno numeric content — can never be Numberwang

A number's wangness is a property of the number, not the language it is said in: four, vier, quatre and cuatro all get the same verdict.

How it works

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

80,804 parameters. The network reads characters directly — there is no tokenizer, no normalizer and no rules engine at inference. Digits, operators, canon verdicts and the eleven languages are all held in the weights, and model.json contains the lot.

Demo

A hosted version runs on Hugging Face Spaces. To run the same demo locally:

pip install -r requirements.txt
python3 app.py

gradio is needed only for the demo. The model itself never needs it.

Accuracy

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

classprecisionrecallF1
not Numberwang0.8200.8850.851
Numberwang0.9190.9000.910
not a number0.9510.8300.886
Wangernumb0.9680.9090.937

Arithmetic on unseen operands is the weak spot, at 44–72%. The network memorises rather than computes, so small common expressions like 5*2 are reliable while 904 * 3 is an educated guess. If arithmetic correctness matters, evaluate the expression and hand it the result.

License

MIT — see LICENSE.

No warranty is expressed or implied as to whether any particular number is, or is not, Numberwang.

Contributors

GraafHenk

5 commits

Languages

Python

100.0%