Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

GNUBG Neural Networks (gnubg-nn)

PyPI Downloads Build & test wheels C/C++ Lint Branch naming Release to PyPI GitHub issues License Stack Overflow

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, not gnubg. Installing gnubg will 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)
print(f"Best move key: {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 + 5 space-separated probability values
training_data = [
    "ABCDEFGHIJ0123456789 0.5 0.1 0.05 0.1 0.05",  # position key + probs
    "JIHGFEDCBA9876543210 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.

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.

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)
  • Legal-move enumeration (moves) & probabilistic evaluation (probabilities)
  • Monte-Carlo rollouts (rollout, cubeful_rollout)
  • Equity lookup (equities.value(xAway, oAway))
  • Neural-net training (Trainer class for tuning weights against labeled positions)
  • Runtime engine tuning via the set submodule

🧪 Platform Compatibility

Python Version Linux x86_64
(glibc ≥ 2.17)
Linux i686
(glibc ≥ 2.12)
macOS universal2 Windows x86_64
3.14 ✅ (macOS ≥ 10.14)
3.13 ✅ (macOS ≥ 10.14)
3.12 ✅ (macOS ≥ 10.14)
3.11 ✅ (macOS ≥ 10.9)
3.10 ✅ (macOS ≥ 10.9)

Notes:

  • ✅ = Built and available
  • ❌ = Not built
  • macOS universal2 = Supports both ARM64 and x86-64 architectures

Testing

gnubg-nn-pypi has some basic unit testing. After installation, run:

python3 -m unittest discover -s gnubg_nn.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-pypi project 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gnubg_nn-1.1.0a9-cp313-cp313-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.13Windows x86-64

gnubg_nn-1.1.0a9-cp313-cp313-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gnubg_nn-1.1.0a9-cp313-cp313-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

gnubg_nn-1.1.0a9-cp312-cp312-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.12Windows x86-64

gnubg_nn-1.1.0a9-cp312-cp312-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gnubg_nn-1.1.0a9-cp312-cp312-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

gnubg_nn-1.1.0a9-cp311-cp311-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.11Windows x86-64

gnubg_nn-1.1.0a9-cp311-cp311-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gnubg_nn-1.1.0a9-cp311-cp311-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

gnubg_nn-1.1.0a9-cp310-cp310-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.10Windows x86-64

gnubg_nn-1.1.0a9-cp310-cp310-musllinux_1_2_x86_64.whl (9.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

gnubg_nn-1.1.0a9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (8.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

gnubg_nn-1.1.0a9-cp310-cp310-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file gnubg_nn-1.1.0a9-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for gnubg_nn-1.1.0a9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f2d4636f40b9e3ae5dc3d799595bc105339943c61eebe7c466be12b09c74da58
MD5 094b6c6ebeb27935767bbe26e1551eee
BLAKE2b-256 ffe5034cd212fb0964d502ce6d43cc8f30e9b33b314fb5768a546152e3d6b853

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 167220ad788ebc7acab15592e0be9f957ba22a088d54cb6b49260def1a00ffa9
MD5 04e80d6ad0b2af92649821567eec6444
BLAKE2b-256 c8c6668efccf128e44c71fcaa9e0c9ca284a88873d2769aa43dfa84d1fc733f1

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ec5f331d5d5f291babdde9373039cb8e1ab7fb8c9f67254683971ff16467127a
MD5 7c0556234a8c4f52e2ac99c17c000e82
BLAKE2b-256 b816b0476ab056077e34a64fc8e7747283e60d002379bde142c1febd3633b90f

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1accdc119407906b9b7025293d8f31bb6ac5b8885f67225f92b91b678ea8831a
MD5 a0d6fdd26bd14fed8a9c2cf66e69c2bd
BLAKE2b-256 10214b30f35cc10af0576fe682cb84c57ed32306f9d13189ce8477924faa7d95

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for gnubg_nn-1.1.0a9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 422fbc48e79cb3927a2a856ccd1636963fcc2bce5088f9c3d6163b1587f8589b
MD5 3ecb20edacd64ce30ae6ab2e08a79d4f
BLAKE2b-256 5a0f7fc7ff08066227aed2ea551cbbfd68b0dc9bd8aa51ec0dc2af668048f32b

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ac691450b61b9fb56c20bd10308341f50fc3948b6fc650e092df214df36f706b
MD5 b3d2e376431544ea975306491d5e1762
BLAKE2b-256 aadbee6a7e9cc7045d94b4a411baf7e68ff058a9a150dffc901d018445cbd557

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5fbd3be1a4f6aeb98b23e5d8733d554b34193069c84dc4f1e582c212b2be24ca
MD5 7a907ed059bf7ef308794e6080287dc3
BLAKE2b-256 6f131266d931efd2fff59e2ede4adf1b5356af6ac07de0a89df0f4f83b277c88

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0461a94332be4495202a10ddc4449693c4fe677b1aa20ecd61023acbf5704efc
MD5 6ee8ca3d3df4a94096e6f7f562ae4b0d
BLAKE2b-256 277f4470a2ad16852909b4cfd604fb31e8a9eea9a6eff334dded571a44396bf4

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for gnubg_nn-1.1.0a9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bc9ea787bd0423f158a71e9c3d55e149fb5e21d86ba4730f0ed446a99bad6e21
MD5 513490943e2e3e44afcdfa90664537b0
BLAKE2b-256 955feb57436b5b14c982e2c7e1c127cb8fe9e396ae81181c9a7137fa7b5434ca

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c2847cec685ecbe98075821e0d389e9d9a7e29fbb37482ed5e46a885e96c157b
MD5 e6f3b64766462f3f8e3c11f61d18fa12
BLAKE2b-256 9decb2990fcf3b42643eeaa0fb5cef81092fc6442269a90638795bef548a1442

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb5e91cd5476f8fb046486419a4bf44df3a17b60d33cbead5ad162fed564bd7d
MD5 0a815f0461c24b73c9af77942fd70806
BLAKE2b-256 763339f21020320465e2b2d1c8ed4478a290ac60d4c2af9d8a3365bcf80f0473

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b19850bf6290978743008f701714e96ec19dd54d31637ddc4796e7b9be6f996
MD5 5ed0bbf531ffffdc12ee027626a28fb5
BLAKE2b-256 8b31d4e8a23d8d311bbe39270e9fad4bb3ca99d3ca572f702aa75d576a31defd

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gnubg_nn-1.1.0a9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for gnubg_nn-1.1.0a9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e05629c08e93cc003e351f400c71675bd02d5faa86e79ee6a0d1029e119063a7
MD5 c09a1ff15679838ab8f8f15fca1323f6
BLAKE2b-256 9e706bf8986756a70f6ae9ae6f735e4025878f3b807b02924b95b966667132c5

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 549938462d38f089fe7046a1edea9f0bc2c2242ec6b9ac2d8e5ac544dff9d0e2
MD5 86a6977139471a621581bce340659f91
BLAKE2b-256 c5580644f11cfdf889dd24b92d25b721c9ffec5c419d6bc1c5c0df726e339690

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c76f99eb9230cca6130244fc89028d67e96262a5c5bdd5cd102269ea1b16042e
MD5 e2eab17e897ffd6a381fed5984abb8ef
BLAKE2b-256 a0a258a6c5d9f58ceef2c8c590542f31c1d5e3518b45319a7f6129148fe5d8d0

See more details on using hashes here.

File details

Details for the file gnubg_nn-1.1.0a9-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gnubg_nn-1.1.0a9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d517ed5f53ed2126714850f0a4eac7951a5af0742d95e585055e52f5248033b
MD5 acfdf353fdbb3dcf5d6e200e191536b3
BLAKE2b-256 a7c9d0b09d16d14ee08acdb75d5d0b439636fb6218e0e7f38a7211090d0bab06

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0a9 This release

16 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page