This release is a pre-release and may not be stable for production use.
GNUBG Neural Networks (gnubg-nn)
GNUBG Neural Networks (this package, gnubg-nn) is a library that provides Python bindings to the GNUBG neural-network evaluation engine — the same engine used for position analysis and cube decisions in the full GNU Backgammon application, but packaged as a standalone library for use in scripts, analysis tools, and applications. It is not the full backgammon game (GUI, match play, etc.).
Quick Start
gnubg_nn is a native Python extension module that wraps the GNUBG neural-net evaluation library, so you can call
the same position-analysis and cube-decision routines that power the full GNU Backgammon application from any Python 3.10+ script or application. It’s ideal for batch processing, data-science workflows, or building custom tools and UIs.
Installation
Important: The PyPI package name is
gnubg-nn, notgnubg. Installinggnubgwill install the unrelated full GNU Backgammon application. The correct command is:
pip install gnubg-nn
Then import it as:
import gnubg_nn
Note: The engine (neural-network weights, bear-off tables, etc.) initialises automatically on import — you do not need to call
initnet().
Getting Started
import gnubg_nn
# Convert a 14-char Base64 Position ID to a 2x25 board
board = gnubg_nn.board_from_position_id("4HPwATDgc/ABMA")
# Evaluate win/gammon/backgammon probabilities at 2 plies
probs = gnubg_nn.probabilities(board, gnubg_nn.p_0plus1)
win, win_gammon, win_bg, lose_gammon, lose_bg = probs
print(f"Win: {win:.3f}, Gammon: {win_gammon:.3f}, Backgammon: {win_bg:.3f}")
# Find the best move for an opening 6-5 roll
moves = gnubg_nn.moves(board, 6, 5)
best = gnubg_nn.best_move(board, 6, 5) # default args: a move list, [(from, to), ...]
print(f"Best move: {best}")
Training the Neural Network
You can also train the neural network weights against labeled position data using the Trainer class:
import gnubg_nn
# Create a trainer from a list of training positions
# Each entry: 20-char position key (letters A-P only) + 5 space-separated
# probability values -- get real keys from key_of_board()/moves(), not
# hand-typed strings.
training_data = [
"OAHDPAABDAOAHDPAABDA 0.5 0.1 0.05 0.1 0.05", # position key + probs
"OAHDPAABDAOAHDPAABBC 0.6 0.15 0.08 0.08 0.04",
]
trainer = gnubg_nn.Trainer(training_data)
# Check initial training errors (RMS + max error for 6 metrics)
errors = trainer.errors()
print(f"Initial error: {errors[2]:.4f}")
# Train for one epoch at learning rate 0.01
trainer.train(0.01)
# Check errors after training
errors = trainer.errors()
print(f"After training: {errors[2]:.4f}")
The Trainer class supports options for training against the pruned net, ignoring backgammon components, and restricting to specific neural net inputs. See the API documentation for details.
Self-Play Training
The gnubg_nn.training subpackage builds on Trainer (above) and net_load/net_use (multiple nets held in one process) to provide a full self-play training pipeline: play a net against a fixed reference net, mine the positions where they disagree, and train on the disagreements — plus tools to download GNU Backgammon's own published reference net, rollout benchmarks, and training data, and to score a net against real rollout ground truth. Installing this package also installs two console scripts, gnubg-nn-download and gnubg-nn-buildnet:
gnubg-nn-download ./gnubg-data
gnubg-nn-buildnet my-net.weights ./gnubg-data/nngnubg.weights \
./training-data.dat ./gnubg-data/contact.bm --class contact --cycles 20
See the "Training" page on ReadTheDocs (source: docs/training.rst) for the full walkthrough.
That’s all you need to get up and running! For detailed API docs, advanced build options, and configuration, see the sections below or visit the full documentation on ReadTheDocs.
- ReadTheDocs https://gnubg.readthedocs.io/en/latest/
- GNU Backgammon (full application): https://www.gnu.org/software/gnubg/
- Original Documentation: http://www.gnubg.org/documentation/doku.php?id=gnu_backgammon_faq
- Mailing list: https://lists.gnu.org/mailman/listinfo/gnubg
- Source code: https://github.com/StonesAndDice/gnubg-nn-pypi
- GNUBG Neural Networks (gnubg-nn) upstream: https://git.savannah.gnu.org/cgit/gnubg/gnubg-nn.git
- Contributing: https://savannah.gnu.org/people/
- Credits: https://git.savannah.gnu.org/cgit/gnubg.git/tree/credits.sh
It provides:
- Engine initialization & data loading (neural-net weights, opening-book, bear-off tables)
- Position classification (
classify) & public-evaluation best move (pub_best_move) - Board ↔ ID conversions (
board_from_position_id,board_from_position_key,key_of_board,position_id) - Dice utilities (
roll) & cube utilities (best_move,pub_eval_score) - Bear-off tools (
bearoff_id_2_pos,bearoff_probabilities) & one-checker race (one_checker_race) - Legal-move enumeration (
moves) & probabilistic evaluation (probabilities) - Monte-Carlo rollouts (
rollout,cubeful_rollout) - Cube decisions (
evaluate_cube_decision) - Equity lookup (
equities.value(xAway, oAway)) - Multiple nets in one process (
net_load,net_use,net_save) — hold a trainee net and a fixed reference net at once - Neural-net training (
Trainerclass for tuning weights against labeled positions) - Self-play training pipeline (
gnubg_nn.trainingsubpackage: self-play, disagreement mining, real-rollout-benchmark scoring, and downloading GNU Backgammon's published training data — plus thegnubg-nn-buildnet/gnubg-nn-downloadconsole scripts) - Runtime engine tuning via the
setsubmodule
🧪 Platform Compatibility
Wheels actually published to PyPI, per .github/workflows/release.yml's build matrix:
| Python Version | Linux x86_64 (glibc ≥ 2.17) |
macOS arm64 (Apple Silicon) |
Windows x86_64 |
|---|---|---|---|
| 3.13 | ✅ | ✅ | ✅ |
| 3.12 | ✅ | ✅ | ✅ |
| 3.11 | ✅ | ✅ | ✅ |
| 3.10 | ✅ | ✅ | ✅ |
Notes:
- ✅ = Built and published
- No Linux i686, macOS x86_64 (Intel), or Python 3.14 wheels are published yet —
pip install gnubg-nnon an Intel Mac currently has no prebuilt wheel to install. Tracked as a follow-up, not a documentation issue: widening this is a real CI change (new build targets, new toolchain risk), not just a table correction. - If you're on an unsupported platform,
pip install gnubg-nnwill attempt a source build (requires a C/C++ toolchain and Meson).
Testing
The test suite lives in this repo's tests/ directory (not shipped in the installed package) and runs with pytest. From a repo checkout:
pip install pytest
pytest tests/
AI-Assisted Development
Parts of this project were developed with the assistance of generative AI tools.
Specifically, the following models were used:
- GPT-4o (OpenAI ChatGPT)
- o4-mini-high (OpenAI ChatGPT)
- Haiku 4.5 (Anthropic)
- Opus 4.8 (Anthropic)
These models were used to assist with code generation, documentation drafting, and architectural guidance. All outputs were reviewed and curated by a human before inclusion.
⚠️ Disclaimer:
Although human-reviewed, some AI-generated content may contain mistakes, inaccuracies, or outdated practices. Contributors and users should critically assess all code, comments, and documentation. We welcome corrections and improvements via pull requests or issues.
Code of Conduct
Please read the Code of Conduct to learn how to interact positively.
Contributing
Your expertise and enthusiasm are welcome! You can contribute by:
- Reviewing and testing pull requests
- Reporting and triaging issues
- Improving documentation, tutorials, and examples
- Enhancing engine parameters or submodules
- Maintaining website or branding assets
- Translating materials
- Assisting with outreach and onboarding
- Writing grant proposals or helping with fundraising
For more information, see our Contributing Guide. If you’re unsure where to start, open an issue or join the discussion on our mailing list!
Acknowledgments
This project builds upon the extensive work of the GNU Backgammon (GNUBG) community. The gnubg-nn library is the neural network evaluation component; the full backgammon application (GUI, match play, etc.) is maintained separately. We specifically acknowledge the pygnubg program developed by Joseph Heled.
We express our gratitude to all contributors who have dedicated their time and expertise to the development of the GNUBG neural network library and its Python bindings.
- AUTHORS.md: A list of primary contributors to the
gnubg-nn-pypiproject can be found here. - GNU Backgammon (full project) credits.sh: For a comprehensive list of contributors to the full GNUBG application, please refer to the credits.sh file.
We also thank the broader GNUBG community, including testers, translators, and mailing list participants, for their invaluable support.
Metadata
Release files for gnubg-nn 1.1.0a11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 143.0 MB
Release files / gnubg_nn-1.1.0a11-cp313-cp313-win_amd64.whl
| Download URL | gnubg_nn-1.1.0a11-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 9.4 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8e1b1dc2a3fb350d0c0c31a7e5dbc2053db17feb2978abd6ebd885307a82757d
|
|
BLAKE2b-256 checksum How to use checksums |
21742cbe937d11e30e54aab1dc1ec3b012c5b2389ee894e30ab2b6dda50d2a34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 9.5 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9aa2fe725d87202b206f479dc12960289094ccc97f1d01d81fc3930ba0d18f8c
|
|
BLAKE2b-256 checksum How to use checksums |
dc6dde54d05d5c44cd198a1837e50098cd0d014a5265cc216be4444878869f79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
c7f8488709a63b5a81278ff3ef7eb09043625b6fd729ee4b4a2c592892d666a8
|
|
BLAKE2b-256 checksum How to use checksums |
50016a32540ea64d4336a6c620ce53ac4324c787d6ec2cc8a3cdac79c9d9833f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | gnubg_nn-1.1.0a11-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0643e621f17d9a27e546e14b66d8cfc1480e7727920d1abddf8155699519770f
|
|
BLAKE2b-256 checksum How to use checksums |
6f67f454c100ca39c7f27db85ae8f638552a88a9d1e32df87c35d11422a3d3ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / gnubg_nn-1.1.0a11-cp312-cp312-win_amd64.whl
| Download URL | gnubg_nn-1.1.0a11-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 9.4 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7f855a66c99a5324a5e67d1b2f4daaf6ad23520afd4d2ba005aae90d5d681363
|
|
BLAKE2b-256 checksum How to use checksums |
776e39723c2c8663f4911b2f4bb0e4099485298a92e19d52297e2bd3d3c5e878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 9.5 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
77b4c804c1a95bbc27149691f7c6770aee91668099c941687c5ff72892a0b0e1
|
|
BLAKE2b-256 checksum How to use checksums |
9480e7c30c67d02352c9f44e7f881fc8642d6eddcabf6612a3c32d20b336213f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
8976d3c2091c5b2ff40b3082209da073104e1d0c3375552dd547d898f060b2ac
|
|
BLAKE2b-256 checksum How to use checksums |
b179cd5c71e7dd64cbabd0b87d6058ac11b419e4d91636fa7a29599ca82c83a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | gnubg_nn-1.1.0a11-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d38455d62b5ebc8b8c8b82786fd2410735a44d8d1f910636a6722047a6c37d59
|
|
BLAKE2b-256 checksum How to use checksums |
10448d0855db0c991fe1d09ef7525c436155a0b5ce52db8a0ede469606150c63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / gnubg_nn-1.1.0a11-cp311-cp311-win_amd64.whl
| Download URL | gnubg_nn-1.1.0a11-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 9.4 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
726f7b82d791514ac6939c84a5bb8478e32b945725669c349169e1afb0411a77
|
|
BLAKE2b-256 checksum How to use checksums |
b68e0c3a3e411d24f42aa50e93cc979fc67368dee4920de77eab43e383c4f95d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 9.5 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
a647c20fef6d014bd88ef01307537e5d9d36b483f325f8d7b2eb87669f777744
|
|
BLAKE2b-256 checksum How to use checksums |
95d86d225574062b92f7ccc59068e3ddc4e8d8bb84f9ff89e37d0652feaebc8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
095f97575210ab946e5eea8a03073a949aac6891984fbd52b19d3653235fbf75
|
|
BLAKE2b-256 checksum How to use checksums |
c44c90b54ac5f69b5a900bde5143d11860acdc84a63af8ca96c9ca69b1fb0d4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | gnubg_nn-1.1.0a11-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8cc4398a2bb1fe37e3559706a734795e7933f85b68e82913fb7983d312fed620
|
|
BLAKE2b-256 checksum How to use checksums |
d64bf4a5582ddc3a2a169afa5585e73b4326897c118a73a0512e22d58c18b7cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / gnubg_nn-1.1.0a11-cp310-cp310-win_amd64.whl
| Download URL | gnubg_nn-1.1.0a11-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 9.4 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e89381df696bfdc229c6d8429a37b09da4f19ccf604c46a9ad6208bc3f15367f
|
|
BLAKE2b-256 checksum How to use checksums |
be063d877e538584827e291f0aff5f3b0820d253fd8c97a1a1647742a78c6475
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 9.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
b9c54047a8b2bb456d089daf41b5593296d6b972ba21996238b00609f4afb005
|
|
BLAKE2b-256 checksum How to use checksums |
5104fc31384ea685693387fc74c9b6ffae90f1a72145167374f914d2e4ef3063
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gnubg_nn-1.1.0a11-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f4454c3d1d3e0f409f8cc0609c530c3672e7a89e5f09198f394767c5b8edfc9f
|
|
BLAKE2b-256 checksum How to use checksums |
4823b594346e1b67434132202efdab1a4196fe95cfed06b733648ff106de658e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / gnubg_nn-1.1.0a11-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | gnubg_nn-1.1.0a11-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ca53c858409f9ad75544a0fe3b66d6f4c601cb66a7694f6cb1a4427444d67bfe
|
|
BLAKE2b-256 checksum How to use checksums |
1a7db5abd2734c50e7bb2bf98010240ad7d2a1a764793d43cbfa7875c9f1e3c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for gnubg-nn 1.1.0a11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.