ML4SE-toolkit
ML4SE-toolkit provides small, composable primitives for turning source code into reproducible machine-learning examples for software engineering research.
What is in scope
- Comment-oriented parsing utilities that return a normalized
QueryMatch(prefix, suffix, match)contract. - Comment sanitization utilities that strip comment syntax after extraction.
- Input formatters for fill-in-the-middle, autoregressive, masked diffusion, masked LM, and span corruption models, with sentinel and mask tokens picked from a model name or Hugging Face object.
- A restartable, multi-worker iterator that applies a function to every row of a dataset split into many files, such as The Stack, one file at a time.
- Optional integrations for Tree-sitter queries and PyTorch-style iterable datasets.
- Existing EBNF and grammar-analysis tooling remains available in the
repository under
src/ml4setk/EBNF; it is not part of the PyPI package.
Installation
Install the published package from PyPI:
pip install ML4SE-ToolKit
The import name is ml4setk, for example from ml4setk import CommentQuery.
Install optional extras only when you need them:
pip install "ML4SE-ToolKit[treesitter]"
pip install "ML4SE-ToolKit[torch]"
pip install "ML4SE-ToolKit[datasets]"
Development setup
Use uv so package state stays locked to the repository:
uv venv .venv
uv sync --group dev
Install optional extras only when you need them:
uv sync --group dev --extra treesitter
uv sync --group dev --extra torch
Build
Build source and wheel distributions locally with:
uv build
Or via the repo command:
make build
Artifacts are written to dist/.
To validate the built distributions before uploading:
uvx twine check dist/*
Publishing
The repository includes a dedicated GitHub Actions workflow at
.github/workflows/publish.yml.
workflow_dispatch: build, validate, and publish the current branch to TestPyPIpushof a tag matchingv*: build, validate, and publish to PyPI
The workflow uses PyPI Trusted Publishing rather than a long-lived API token. Before the first automated release, configure trusted publishers for this project in both PyPI and TestPyPI with:
- owner:
jkatzy - repository:
ML4SE-toolkit - workflow name:
publish.yml - environment:
pypifor PyPI,testpypifor TestPyPI
Release flow:
git switch main
python scripts/check_release_version.py
uv run pytest -m "not optional_dependency"
uv run pytest -m "optional_dependency" --no-cov
uv run ruff check src tests examples
git tag v0.1.0
git push origin main v0.1.0
The publish workflow checks that the package version in pyproject.toml, the
package __version__, and the release tag all agree before uploading.
Minimal example
from ml4setk import CommentQuery, FIMInput
sample = "prefix\n// explain this branch\nsuffix"
match = CommentQuery("java").parse(sample)[0]
model_input, ground_truth = FIMInput(
"<fim_prefix>",
"<fim_suffix>",
"<fim_middle>",
).generate(match)
print(model_input)
print(ground_truth)
Pass FIMInput.from_model("bigcode/starcoder2-3b") instead of the token
strings to use a model's own sentinel tokens. The
input formatting guide
covers every input format and the models each one supports.
The parsing contract is stable across the core query implementations:
prefix: text before the matchsuffix: text after the matchmatch: the extracted region itself
For the comment extraction and cleaning guide, with a runnable quick start, an explanation of how extraction and cleaning work, and the API reference, see docs/comment_extractor.md.
At the moment the comment extractor covers 776 registry keys, including
template and document syntaxes such as astro, coldfusion, jsp, marko,
plantuml, slim, smarty, and restructuredtext, plus nested-comment
languages such as coldfusion, dafny, frege, grammatical_framework,
rexx, tla, and v.
Format-aware coverage includes GNU checksums, ecere_projects, figlet_font,
microsoft_visual_studio_solution, AMPL nl, omgrofl, and pogoscript.
These entries use narrowly scoped structural or syntax-aware guards where
marker-only scanning would misclassify strings, counted records, or binary data.
Development commands
make setup: create and sync the local development environment withuvmake test: run the default unit and integration suite with coveragemake test-optional: run optional-dependency tests without coverage gatingmake comment-fuzz: run deterministic Unicode-heavy parser invariants across every registered languagemake lint: runruffon maintained source, tests, and examples; the legacy EBNF utility tree keeps its existing separate style baselinemake smoke: run the minimal end-to-end smoke testsmake build: create source and wheel distributions indist/make docs: build the MkDocs site intosite/and fail on broken links;make docs-servepreviews it at http://127.0.0.1:8000. TheDocsworkflow publishes the site frommainto GitHub Pages.make check-main-branch: fail if development-only artifacts are still tracked and the branch is not ready to merge tomainmake check-release-version: fail if package version metadata is inconsistent
Git workflow
main is the release branch and dev is the single long-lived integration
branch. Agent instructions, comment-syntax research, adversarial testing
guides, and LLM-judge operations live on dev; release code, deterministic
regressions, and stable user documentation live on main. Promote tested code
from dev to main, then remove any short-lived topic branch used for review.
The permanent rules and the enforced main-branch policy are documented in
docs/git_workflow.md.
Repository map
src/ml4setk/Parsing: query primitives, the comment registry, the sanitizer, and optional Tree-sitter supportsrc/ml4setk/Generation: input formatters and the model token registriessrc/ml4setk/Datasets: the chunked, restartable dataset iteratorsrc/ml4setk/EBNF: grammar-processing and railroad-diagram utilitiestests: regression, unit, integration, and smoke coveragedocs/architecture.md: concise architecture and extension notesdocs/comment_extractor.md: how comment extraction and cleaning work and how to use themdocs/comment_cleaning_policy.md: what cleaning removes and what it keepsdocs/input_formatting.md: every input format and its supported modelsdocs/chunked_datasets.md: iterating over large file-chunked datasetsdocs/git_workflow.md: branch policy, development-only artifacts, and the main-branch guarddevcomment workflow: syntax research, adversarial tests, fuzzing, LLM judges, and regression intake
Metadata
Release files for ML4SE-ToolKit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ml4se_toolkit-0.1.0.tar.gz | 205.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ml4se_toolkit-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 426.6 kB
Release files / ml4se_toolkit-0.1.0.tar.gz
| Download URL | ml4se_toolkit-0.1.0.tar.gz |
|---|---|
| Size | 205.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9a00c9776a795103c1b6b95e72f14041a63ab447f4d5ba72b814544b056e9d9
|
|
BLAKE2b-256 checksum How to use checksums |
c67cd25fc1cf095a3a7f416295f8125c88c8ee9d1bd85eb8da35e2bc5fddb73b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency logRelease files / ml4se_toolkit-0.1.0-py3-none-any.whl
| Download URL | ml4se_toolkit-0.1.0-py3-none-any.whl |
|---|---|
| Size | 221.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bcd43e72813d70b9231cc901ea29ae481301c89d09c8eead5b58ef85fb848a7
|
|
BLAKE2b-256 checksum How to use checksums |
1fc7e8c18e262d12cdc9d73f6b119781801f90910b87de8d57cc3697b674c517
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.
Transparency log