Architecture¶
Summary¶
ML4SE-toolkit is intentionally small. It centers on one stable contract:
query implementations extract a QueryMatch(prefix, suffix, match), and
generation utilities transform that match into model-ready inputs.
Data flow¶
- A parser scans raw source text and returns one or more
QueryMatchvalues. - An input formatter such as
FIMInput,CausalInput,MaskedLMInput,SpanCorruptionInput, or a diffusion input consumes the match and returns(model_input, ground_truth);generate_manyformats several matches at once (see Input formatting). ml4setk.Generation.IterableQueryLoadercan wrap a dataset to produce those samples lazily; subclasses implementprocess(file, query).
ml4setk.Datasets.ChunkedIterator runs any row function over a dataset stored
as many files, one file at a time, with its progress kept on disk (see
Chunked datasets).
Comment queries and CommentSanitizer read one per-language registry in
ml4setk.Parsing.Comments.registry. Input formatters that support
from_model read the model token registries in ml4setk.Generation.sentinels.
Extension points¶
- Add a new parser by subclassing
Queryand returningQueryMatchvalues in source order. - Add a new generator by subclassing
AbstractInputand documenting its input shape. - Add a comment language by adding registry data, and a model family by adding
an entry to
MODEL_SENTINELS,MODEL_MASK_TOKENS, orMODEL_SPAN_TOKENS. - Keep optional integrations isolated so importing
ml4setkdoes not require every heavy dependency.
Optional dependencies¶
treesitter: enablesml4setk.Parsing.Code.TreeSitterQuery, whoseparse(text, rule)also takes a Tree-sitter query stringdatasets: addspyarrowfor Parquet chunks andhuggingface_hubfor remote chunks inml4setk.Datasets.ChunkedIteratortorch: enables direct interoperability with PyTorch dataset utilities