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

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.1
File Size Uploaded
eckity_bert_gp-0.1.1.tar.gz 11.6 kB Details

Built distribution (wheel)

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

Total release size: 21.7 kB

Release files / eckity_bert_gp-0.1.1.tar.gz

Download URL eckity_bert_gp-0.1.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b98b42d9f82366507523974ce9fb5a85f81e8dc585ab7cce50de770190cf46a
BLAKE2b-256 checksum
How to use checksums
1b9a341c047b986f54d935b5cfd6a961662c0c9ebcb571799e996e990771be30
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.1-py3-none-any.whl

Download URL eckity_bert_gp-0.1.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d463ff5a700f883b5a471e0aac6ca8ef80a07fddc69e9086071a2d0516d3d9d
BLAKE2b-256 checksum
How to use checksums
ccabf7ea30f4bf759a03e92b726690f47e850288ce9e628f79037e822f94c4c1
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

0.1.2

2 release files

This release

0.1.1 This release

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