Skip to main content

BERT Mutation for EC-KitY Genetic Programming

eckity-bert-gp provides the BERT mutation operator for tree-based genetic programming in EC-KitY.

The operator is described in “BERT Mutation: Deep Transformer Model for Masked Uniform Mutation in Genetic Programming”, Mathematics 2025, 13(5), 779 (paper). It masks selected GP-tree nodes and uses a compact BERT masked-language model to sample replacements that preserve the required node arity.

Installation

pip install eckity-bert-gp

Public API

from eckity_bert_gp import BertGPEckity, BertMutation

BertMutation owns and trains the BERT policy. BertGPEckity adapts that policy to EC-KitY's genetic-programming operator interface.

Usage

The BERT model needs the function names, terminal names, fitness callback, and mappings back to the EC-KitY functions:

import numpy as np
from eckity.base.untyped_functions import f_add, f_div, f_mul, f_sub
from eckity_bert_gp import BertGPEckity, BertMutation

function_set = [f_add, f_sub, f_mul, f_div]
terminal_set = ["x", "y", "z"]
function_mappings = {function.__name__: function for function in function_set}

bert_model = BertMutation(
    operators_list=np.array(list(function_mappings)),
    constant_names=terminal_set,
    get_fitness_func=evaluator.evaluate_individual,
    context_size=256,
    word_embedding_dim=20,
    n_layers=1,
    n_attention_heads=1,
    function_mappings=function_mappings,
)

bert_mutation = BertGPEckity(
    bert_model=bert_model,
    probability=1.0,
    node_probability=0.1,
)

Add bert_mutation to the EC-KitY subpopulation's operators_sequence.

  • get_fitness_func accepts an EC-KitY GP tree and returns its fitness.
  • Fitness direction is read automatically from the EC-KitY tree individual.
  • function_mappings maps each function name used by BERT back to the callable stored in GP trees.
  • Terminal mappings default to the names supplied in constant_names.
  • probability controls whether the EC-KitY mutation operator runs.
  • node_probability controls the probability of masking each tree node.
  • context_size must be large enough for the longest tree representation expected during evolution.

The model is initialized locally from BertConfig; installing or constructing the operator does not download pretrained model weights.

Compatibility

  • Python 3.10 or newer
  • EC-KitY 0.4.x
  • NumPy 2.0.2 or newer
  • SciPy 1.13.0 or newer
  • PyTorch 2.7.1 or newer
  • Transformers 4.50.0 or newer

These bounds are compatible with eckity-dnc and eckity-bert-ga; none of the three packages directly depends on another operator package.

Repository experiment

The repository includes the paper's experiment runner and datasets. They are development resources and are not included in the wheel.

Install the development dependencies and run the symbolic-regression example:

python -m pip install -e ".[dev]"
python runner.py

Additional benchmark data is stored under data/, and Artificial Ant maps are stored under ant_opt/.

Development

With uv:

uv sync --extra dev --resolution lowest-direct
uv run pytest
uv build

Release preparation and manual PyPI upload commands are documented in RELEASING.md.

License

This project is licensed under the BSD 3-Clause License. See LICENSE.

Metadata

Release files for eckity-bert-gp 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eckity-bert-gp 0.1.2
File Size Uploaded
eckity_bert_gp-0.1.2.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eckity-bert-gp 0.1.2
File Interpreter ABI Platform
eckity_bert_gp-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / eckity_bert_gp-0.1.2.tar.gz

Download URL eckity_bert_gp-0.1.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9b540e0c0f60037fd27b88f418d1e3e1782ce9f05146ec60f113659114d890b2
BLAKE2b-256 checksum
How to use checksums
bd7113e6386cc0e1ca7cf6b2691613af7e4f34b1e98d8494997ae7169f12502d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.20

Release files / eckity_bert_gp-0.1.2-py3-none-any.whl

Download URL eckity_bert_gp-0.1.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87498dcd939fd6b1421ac48197d9fa039cc598b5453630ec3d2ac51d448f9e07
BLAKE2b-256 checksum
How to use checksums
36eaaea9c5bb29d4870b2b5005fa96656fa05cb61234b7f1abd666b66c215f2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.20

Release history Release notifications | RSS feed

0.1.3

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page