WangNet – 1.8 MB,支持 11 种语言的零依赖 Numberwang 判定库
WangNet – 1.8 MB, zero-dependency Numberwang adjudication in 11 languages

原始链接: https://github.com/GraafHenk/numberwang

本项目包含一个轻量级神经网络,旨在判断给定的输入是否为“Numberwang”。整个模型仅存储在一个 1.8 MB 的 JSON 文件中,推理过程完全依赖 Python 标准库,无需 PyTorch 或 NumPy 等外部依赖。 该网络直接处理字符级输入,无需传统的标记化或规则引擎。它被训练用于将输入分为四类:*Numberwang*、*非 Numberwang*、*非数字* 或 *Wangernumb*。它展现了令人印象深刻的语言灵活性,能够识别十一种语言的数字,并能处理罗马数字、序数和基本算术。 在技术上,该模型采用简单的架构(Conv1d、ReLU、全局最大池化),包含 80,804 个参数。尽管其 F1 分数接近 0.90,但它更多依赖于记忆而非严谨的计算,因此对常见表达的判断高度准确,但在处理复杂的未知算术时可靠性稍逊。本项目开源并采用 MIT 许可证,为解决识别 Numberwang 这一历史性难题提供了一种极简且即插即用的方案。

近期一篇 Hacker News 贴文介绍了“WangNet”,这是一个零依赖、仅 1.8 MB 的工具,能够用 11 种编程语言进行“Numberwang 裁定”。该项目向经典邪典小品《米切尔和韦伯的秀》(*That Mitchell and Webb Look*)中的“Numberwang”虚构游戏致敬,在小品中,该游戏的规则被刻意设计得荒谬且无法遵循。 评论者们迅速围绕该项目的反讽意味展开了讨论。一位用户指出,该模型可能存在缺陷,因为它孤立地评估数字,而忽略了真正的“Numberwang”规则所要求的复杂、依赖上下文的序列。其他人则为不了解该梗的读者提供了原作小品的链接及游戏背景。这场讨论成了一次幽默的技术练习,大家一致认为,尽管代码可以运行,但它无法真正判定一个数字是否真的是“Wang”。
相关文章

原文

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%)
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.

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 even a number. It can never be Numberwang.
3 That's Wangernumb!
input behaviour
42, sixty-six, 12345 digits or words
zweiundzwanzig, veintidós, tweeëntwintig eleven languages, accents optional
5*2, 96 divided by 2, twelve plus four arithmetic, judged on the result
45 - 44, double four, eins anything worth 1 or 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 on a number, judged as that number
achtneming, often, money words that merely contain one are not numbers
shinty-six, twentington fictional numbers are numbers too
bonjour, hello how are you no 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.

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.

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.

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.

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 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.

MIT — see LICENSE.

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

联系我们 contact @ memedata.com