CodeEditSearchTrain / README.md
Paulo de Moura
Update citation to arXiv paper
7577253
|
Raw
History Blame Contribute Delete
48.5 kB
metadata
dataset_info:
  - config_name: batchfile
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2045841
        num_examples: 1232
    download_size: 1001806
    dataset_size: 2045841
  - config_name: bitbake
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 1829963
        num_examples: 924
    download_size: 896539
    dataset_size: 1829963
  - config_name: c
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 9257649
        num_examples: 4415
    download_size: 4722635
    dataset_size: 9257649
  - config_name: clojure
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 5197211
        num_examples: 2191
    download_size: 2355097
    dataset_size: 5197211
  - config_name: coffeescript
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 12309704
        num_examples: 5116
    download_size: 6302961
    dataset_size: 12309704
  - config_name: cpp
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 4221179
        num_examples: 1748
    download_size: 2062159
    dataset_size: 4221179
  - config_name: csharp
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 25876275
        num_examples: 8358
    download_size: 10794984
    dataset_size: 25876275
  - config_name: css
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 7347599
        num_examples: 4705
    download_size: 3329463
    dataset_size: 7347599
  - config_name: elixir
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2220804
        num_examples: 1015
    download_size: 1060494
    dataset_size: 2220804
  - config_name: emacs-lisp
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 1927538
        num_examples: 950
    download_size: 897645
    dataset_size: 1927538
  - config_name: go
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 6201672
        num_examples: 2925
    download_size: 3261068
    dataset_size: 6201672
  - config_name: groovy
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2265571
        num_examples: 832
    download_size: 1044728
    dataset_size: 2265571
  - config_name: haml
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 9185927
        num_examples: 4344
    download_size: 4510228
    dataset_size: 9185927
  - config_name: handlebars
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2961527
        num_examples: 1389
    download_size: 1351557
    dataset_size: 2961527
  - config_name: haskell
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 3615995
        num_examples: 1385
    download_size: 1789317
    dataset_size: 3615995
  - config_name: html
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 41405026
        num_examples: 18169
    download_size: 19752600
    dataset_size: 41405026
  - config_name: htmlperb
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 22052913
        num_examples: 10438
    download_size: 10898322
    dataset_size: 22052913
  - config_name: ini
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 16530607
        num_examples: 10295
    download_size: 8002911
    dataset_size: 16530607
  - config_name: jade
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2362320
        num_examples: 1096
    download_size: 1123028
    dataset_size: 2362320
  - config_name: java
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 29512250
        num_examples: 9831
    download_size: 13118457
    dataset_size: 29512250
  - config_name: javascript
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 119660227
        num_examples: 49310
    download_size: 59815431
    dataset_size: 119660227
  - config_name: json
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 72402143
        num_examples: 38023
    download_size: 32519532
    dataset_size: 72402143
  - config_name: jsx
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 5701814
        num_examples: 2048
    download_size: 2566131
    dataset_size: 5701814
  - config_name: kotlin
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 4328618
        num_examples: 1607
    download_size: 1969473
    dataset_size: 4328618
  - config_name: less
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2397637
        num_examples: 1335
    download_size: 1060965
    dataset_size: 2397637
  - config_name: markdown
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 116029791
        num_examples: 52258
    download_size: 67561822
    dataset_size: 116029791
  - config_name: nix
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 3612197
        num_examples: 1551
    download_size: 1848385
    dataset_size: 3612197
  - config_name: perl
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 3076256
        num_examples: 1435
    download_size: 1616285
    dataset_size: 3076256
  - config_name: php
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 44822098
        num_examples: 17184
    download_size: 20505068
    dataset_size: 44822098
  - config_name: python
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 96055923
        num_examples: 38700
    download_size: 47992077
    dataset_size: 96055923
  - config_name: restructuredtext
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 13900148
        num_examples: 5978
    download_size: 7406376
    dataset_size: 13900148
  - config_name: ruby
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 130463663
        num_examples: 58154
    download_size: 65921990
    dataset_size: 130463663
  - config_name: rust
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 1224510
        num_examples: 533
    download_size: 603023
    dataset_size: 1224510
  - config_name: scala
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 4585699
        num_examples: 1963
    download_size: 2175939
    dataset_size: 4585699
  - config_name: scss
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 11992324
        num_examples: 6733
    download_size: 5456402
    dataset_size: 11992324
  - config_name: shell
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 41069556
        num_examples: 23040
    download_size: 22922635
    dataset_size: 41069556
  - config_name: slim
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2201982
        num_examples: 1032
    download_size: 1055340
    dataset_size: 2201982
  - config_name: sql
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2376727
        num_examples: 1187
    download_size: 1058007
    dataset_size: 2376727
  - config_name: swift
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 5223410
        num_examples: 1870
    download_size: 2323842
    dataset_size: 5223410
  - config_name: text
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 53789856
        num_examples: 44266
    download_size: 28461696
    dataset_size: 53789856
  - config_name: toml
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 5261671
        num_examples: 3368
    download_size: 2432541
    dataset_size: 5261671
  - config_name: twig
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 3569609
        num_examples: 1477
    download_size: 1501079
    dataset_size: 3569609
  - config_name: typescript
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 9139019
        num_examples: 3371
    download_size: 4344755
    dataset_size: 9139019
  - config_name: unknown
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 2663593
        num_examples: 1445
    download_size: 1170410
    dataset_size: 2663593
  - config_name: viml
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 1827434
        num_examples: 1062
    download_size: 940828
    dataset_size: 1827434
  - config_name: xml
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 18438080
        num_examples: 7700
    download_size: 7544989
    dataset_size: 18438080
  - config_name: yaml
    features:
      - name: instruction
        dtype: string
      - name: diff
        dtype: string
      - name: before
        dtype: string
      - name: after
        dtype: string
      - name: commit
        dtype: string
    splits:
      - name: train
        num_bytes: 163395155
        num_examples: 102934
    download_size: 85594626
    dataset_size: 163395155
configs:
  - config_name: batchfile
    data_files:
      - split: train
        path: batchfile/train-*
  - config_name: bitbake
    data_files:
      - split: train
        path: bitbake/train-*
  - config_name: c
    data_files:
      - split: train
        path: c/train-*
  - config_name: clojure
    data_files:
      - split: train
        path: clojure/train-*
  - config_name: coffeescript
    data_files:
      - split: train
        path: coffeescript/train-*
  - config_name: cpp
    data_files:
      - split: train
        path: cpp/train-*
  - config_name: csharp
    data_files:
      - split: train
        path: csharp/train-*
  - config_name: css
    data_files:
      - split: train
        path: css/train-*
  - config_name: elixir
    data_files:
      - split: train
        path: elixir/train-*
  - config_name: emacs-lisp
    data_files:
      - split: train
        path: emacs-lisp/train-*
  - config_name: go
    data_files:
      - split: train
        path: go/train-*
  - config_name: groovy
    data_files:
      - split: train
        path: groovy/train-*
  - config_name: haml
    data_files:
      - split: train
        path: haml/train-*
  - config_name: handlebars
    data_files:
      - split: train
        path: handlebars/train-*
  - config_name: haskell
    data_files:
      - split: train
        path: haskell/train-*
  - config_name: html
    data_files:
      - split: train
        path: html/train-*
  - config_name: htmlperb
    data_files:
      - split: train
        path: htmlperb/train-*
  - config_name: ini
    data_files:
      - split: train
        path: ini/train-*
  - config_name: jade
    data_files:
      - split: train
        path: jade/train-*
  - config_name: java
    data_files:
      - split: train
        path: java/train-*
  - config_name: javascript
    data_files:
      - split: train
        path: javascript/train-*
  - config_name: json
    data_files:
      - split: train
        path: json/train-*
  - config_name: jsx
    data_files:
      - split: train
        path: jsx/train-*
  - config_name: kotlin
    data_files:
      - split: train
        path: kotlin/train-*
  - config_name: less
    data_files:
      - split: train
        path: less/train-*
  - config_name: markdown
    data_files:
      - split: train
        path: markdown/train-*
  - config_name: nix
    data_files:
      - split: train
        path: nix/train-*
  - config_name: perl
    data_files:
      - split: train
        path: perl/train-*
  - config_name: php
    data_files:
      - split: train
        path: php/train-*
  - config_name: python
    data_files:
      - split: train
        path: python/train-*
  - config_name: restructuredtext
    data_files:
      - split: train
        path: restructuredtext/train-*
  - config_name: ruby
    data_files:
      - split: train
        path: ruby/train-*
  - config_name: rust
    data_files:
      - split: train
        path: rust/train-*
  - config_name: scala
    data_files:
      - split: train
        path: scala/train-*
  - config_name: scss
    data_files:
      - split: train
        path: scss/train-*
  - config_name: shell
    data_files:
      - split: train
        path: shell/train-*
  - config_name: slim
    data_files:
      - split: train
        path: slim/train-*
  - config_name: sql
    data_files:
      - split: train
        path: sql/train-*
  - config_name: swift
    data_files:
      - split: train
        path: swift/train-*
  - config_name: text
    data_files:
      - split: train
        path: text/train-*
  - config_name: toml
    data_files:
      - split: train
        path: toml/train-*
  - config_name: twig
    data_files:
      - split: train
        path: twig/train-*
  - config_name: typescript
    data_files:
      - split: train
        path: typescript/train-*
  - config_name: unknown
    data_files:
      - split: train
        path: unknown/train-*
  - config_name: viml
    data_files:
      - split: train
        path: viml/train-*
  - config_name: xml
    data_files:
      - split: train
        path: xml/train-*
  - config_name: yaml
    data_files:
      - split: train
        path: yaml/train-*

CodeEditSearchTrain

A code-edit retrieval training set, derived from bigcode/commitpackft and decontaminated against the cassanof/CodeEditSearch eval.

Each example contains an instruction (the commit message), a unified diff, and the before/after file contents, plus the source commit SHA.

How the dataset is built

We start from bigcode/commitpackft, a large collection of code-edit commits across many programming languages, and keep every language with at least 1,000 commits — 47 languages in total. For each commit we keep the message as the natural-language instruction, render a short unified diff between the file before and after the change, and store the full file contents on both sides. Commits that don't have both a before and an after file, or that have an empty message, are discarded.

The harder problem is making sure none of the kept commits leak into the cassanof/CodeEditSearch evaluation set. We apply three filters, each catching something the previous one would miss:

  1. Same commit. If a commit's SHA already appears in the eval, we drop it, because same git commit means same code change.
  2. Same text after normalization. Two commits can describe the same change with different SHAs (cherry-picks, rebases, mirrored repos). We lowercase, normalize Unicode and collapse whitespace, then hash every text field with xxHash-64 and compare against the same hashes computed over the eval. Anything that collides is dropped.
  3. Near-duplicate text. Even after normalization, paraphrased or partially edited versions slip through. We extract every 13-word sequence from each field and compute what fraction of them also appear in the eval (containment). If any field crosses 50% overlap, the commit is dropped.

Steps 2 and 3 follow the decontamination methodology described in our English models blog post ("Decontaminated BEIR" section) and our multilingual models blog post.

The eval only covers 13 languages, but the contamination index pools everything from those 13 into one big set, and we check every commit in all 47 source languages against it, so a Python snippet that also appears verbatim in a YAML commit message would still be caught.

End result: 678,295 source commits → 599,698 with both file contents → 578,203 after dropping shared SHAs → 573,593 after the exact-text filter → 560,922 kept after the near-duplicate filter. Per-language numbers are in the report below.

Generation code

Python code to build and decontaminate the dataset
"""
Build a code-edit retrieval training set from `bigcode/commitpackft`,
deduped against `cassanof/CodeEditSearch` via (A) commit-SHA exclusion,
(B) normalized xxHash-64, and (C) 13-gram containment.
"""

from __future__ import annotations

import argparse
import difflib
import json
import logging
import os
import re
import sys
import unicodedata
import urllib.request
from pathlib import Path

import xxhash
from datasets import load_dataset, Dataset
from dotenv import load_dotenv
from tqdm import tqdm

logger = logging.getLogger(__name__)


# 13 languages covered by the cassanof/CodeEditSearch eval:
EVAL_LANGUAGES = [
    "c",
    "c++",
    "go",
    "java",
    "javascript",
    "php",
    "python",
    "ruby",
    "rust",
    "scala",
    "shell",
    "swift",
    "typescript",
]

SHUFFLE_SEED = 42
EVAL_DATASET = "cassanof/CodeEditSearch"
SOURCE_DATASET = "bigcode/commitpackft"
SIZE_API = "https://datasets-server.huggingface.co/size?dataset={dataset}"

REPORT_DIR = Path(__file__).resolve().parent / "output"

WHITESPACE_RE = re.compile(r"\s+")


def discover_languages(dataset: str, min_rows: int) -> list[str]:
    """Fetch all configs from HF datasets-server with at least `min_rows` rows."""
    url = SIZE_API.format(dataset=dataset)
    with urllib.request.urlopen(url) as resp:
        data = json.load(resp)
    configs = data["size"]["configs"]
    kept = [c["config"] for c in configs if c["num_rows"] >= min_rows]
    logger.info(
        "discovered %d/%d configs in %s with >= %d rows",
        len(kept), len(configs), dataset, min_rows,
    )
    return sorted(kept)


def collect_eval_shas(languages: list[str]) -> set[str]:
    """Pool every commit SHA appearing in the eval dataset across the given languages."""
    shas: set[str] = set()
    for lang in languages:
        try:
            ds = load_dataset(EVAL_DATASET, lang, split="train")
        except Exception as e:
            logger.warning("could not load eval for lang=%s: %s", lang, e)
            continue
        for row in ds:
            sha = row.get("commit")
            if sha:
                shas.add(sha)
    logger.info("collected %d eval commit SHAs across %d languages", len(shas), len(languages))
    return shas


def has_nonempty_contents(row: dict) -> bool:
    """True if both `old_contents` and `new_contents` are present and non-empty."""
    return bool(row.get("old_contents")) and bool(row.get("new_contents"))


def build_unified_diff(old: str, new: str, old_file: str = "a", new_file: str = "b") -> str:
    """Render a unified diff (3 lines of context) between two file contents."""
    return "".join(difflib.unified_diff(
        old.splitlines(keepends=True),
        new.splitlines(keepends=True),
        fromfile=old_file,
        tofile=new_file,
        n=3,
    ))


def normalize(text: str) -> str:
    """NFKD-fold, lowercase, and collapse whitespace runs to single spaces."""
    text = unicodedata.normalize("NFKD", text).lower()
    return WHITESPACE_RE.sub(" ", text).strip()


def hash64(text: str) -> int:
    """64-bit xxh64 of text bytes."""
    return xxhash.xxh64(text.encode("utf-8", errors="replace")).intdigest()


def word_ngrams(text: str, n: int = 13) -> set[str]:
    """Set of contiguous n-word phrases from whitespace-split text."""
    words = text.split()
    if len(words) < n:
        return set()
    return {" ".join(words[i:i + n]) for i in range(len(words) - n + 1)}


def field_hash(text: str) -> int | None:
    """Normalized hash of one field; None if the field is empty after normalization."""
    norm = normalize(text or "")
    if not norm:
        return None
    return hash64(norm)


def build_eval_overlap_index(languages: list[str], n: int = 13) -> tuple[set[int], set[str]]:
    """Index per-field normalized hashes and pooled per-field n-grams across all eval rows."""
    field_hashes: set[int] = set()
    ngram_set: set[str] = set()
    logger.info("building per-field contamination index over eval rows...")
    total = 0
    for lang in languages:
        try:
            ds = load_dataset(EVAL_DATASET, lang, split="train")
        except Exception:
            raise RuntimeError(f"failed to load eval dataset for lang={lang}; check that EVAL_LANGUAGES is correct and that the dataset is accessible")
        for row in tqdm(ds, desc=f"overlap-index[{lang}]"):
            fields = (
                (row.get("instruction") or "").strip(),
                row.get("diff") or "",
                row.get("before") or "",
                row.get("after") or "",
            )
            if not any(fields):
                continue
            for f in fields:
                h = field_hash(f)
                if h is not None:
                    field_hashes.add(h)
                ngram_set.update(word_ngrams(normalize(f), n=n))
            total += 1
    logger.info(
        "indexed %d eval rows: %d field-hashes, %d %d-grams",
        total, len(field_hashes), len(ngram_set), n,
    )
    return field_hashes, ngram_set


def contamination_reason(
    instruction: str,
    diff: str,
    old_contents: str,
    new_contents: str,
    eval_field_hashes: set[int],
    eval_ngrams: set[str],
    n: int = 13,
    threshold: float = 0.5,
) -> str:
    """Return "hash"/"ngram" if any of the 4 fields matches eval, else "" (clean)."""
    fields = (instruction, diff, old_contents, new_contents)
    for f in fields:
        h = field_hash(f)
        if h is not None and h in eval_field_hashes:
            return "hash"
    for f in fields:
        sample_ngrams = word_ngrams(normalize(f), n=n)
        if not sample_ngrams:
            continue
        if len(sample_ngrams & eval_ngrams) / len(sample_ngrams) >= threshold:
            return "ngram"
    return ""


def build_language(
    lang: str,
    eval_shas: set[str],
    eval_field_hashes: set[int],
    eval_ngrams: set[str],
    output_repo: str,
    max_per_lang: int | None,
    ngram_n: int = 13,
    overlap_threshold: float = 0.5,
) -> dict:
    """Filter one language of the source dataset against the eval, push to the Hub, and return its funnel."""
    logger.info("lang=%s loading source from %s", lang, SOURCE_DATASET)
    ds = load_dataset(
        "json",
        data_files=f"hf://datasets/{SOURCE_DATASET}/data/{lang}/data.jsonl",
        split="train",
    )
    source_rows = len(ds)

    ds = ds.shuffle(seed=SHUFFLE_SEED)
    ds = ds.filter(has_nonempty_contents)
    passed_nonempty = len(ds)
    logger.info(
        "lang=%s %d rows have both old+new contents (from %d)",
        lang, passed_nonempty, source_rows,
    )

    kept_rows: list[dict] = []
    passed_sha = passed_msg = passed_hash = passed_ngram = 0

    for row in tqdm(ds, desc=f"filter[{lang}]"):
        if row.get("commit") in eval_shas:
            continue
        passed_sha += 1

        instruction = (row.get("message") or "").strip()
        if not instruction:
            continue
        passed_msg += 1

        old_contents = row.get("old_contents") or ""
        new_contents = row.get("new_contents") or ""
        diff = build_unified_diff(
            old_contents,
            new_contents,
            old_file=row.get("old_file", "a"),
            new_file=row.get("new_file", "b"),
        )

        reason = contamination_reason(
            instruction, diff, old_contents, new_contents,
            eval_field_hashes, eval_ngrams,
            n=ngram_n, threshold=overlap_threshold,
        )
        if reason == "hash":
            continue
        passed_hash += 1
        if reason == "ngram":
            continue
        passed_ngram += 1

        if max_per_lang and len(kept_rows) >= max_per_lang:
            continue
        kept_rows.append({
            "instruction": instruction,
            "diff": diff,
            "before": old_contents,
            "after": new_contents,
            "commit": row.get("commit"),
        })

    logger.info(
        "lang=%s passed_nonempty=%d passed_sha=%d passed_msg=%d "
        "passed_hash=%d passed_ngram=%d kept=%d",
        lang, passed_nonempty, passed_sha, passed_msg,
        passed_hash, passed_ngram, len(kept_rows),
    )

    config_name = lang.replace("+", "p").replace("#", "sharp")
    logger.info("lang=%s pushing to %s (config=%s)", lang, output_repo, config_name)
    Dataset.from_list(kept_rows).push_to_hub(
        repo_id=output_repo,
        config_name=config_name,
        private=True,
    )

    return {
        "config": config_name,
        "funnel": {
            "source_rows": source_rows,
            "passed_nonempty": passed_nonempty,
            "passed_sha": passed_sha,
            "passed_nonempty_msg": passed_msg,
            "passed_hash": passed_hash,
            "passed_ngram": passed_ngram,
            "kept": len(kept_rows),
        },
    }


def main(argv: list[str] | None = None) -> int:
    """CLI entrypoint: build the decontaminated training set for each language and write the run report."""
    parser = argparse.ArgumentParser(description="Build CodeEditSearch training set.")
    parser.add_argument("--output-repo", default="lightonai/CodeEditSearchTrain",
                        help="HF Hub dataset repo to push to")
    parser.add_argument("--languages", nargs="+", default=None,
                        help="languages to build (default: auto-discover from source via --min-rows)")
    parser.add_argument("--min-rows", type=int, default=1000,
                        help="when auto-discovering, only include configs with >= this many rows (default: 1000)")
    parser.add_argument("--max-per-lang", type=int, default=None,
                        help="cap rows per language (default: no cap)")
    parser.add_argument("--overlap-threshold", type=float, default=0.5,
                        help="13-gram containment threshold (default 0.5)")
    parser.add_argument("--ngram-n", type=int, default=13, help="n-gram size (default 13)")
    args = parser.parse_args(argv)

    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s %(levelname)s %(name)s: %(message)s",
        stream=sys.stderr,
    )

    load_dotenv()
    assert os.environ.get("HF_TOKEN"), "HF_TOKEN not set after load_dotenv(); add it to .env"

    if args.languages is None:
        args.languages = discover_languages(SOURCE_DATASET, args.min_rows)
    logger.info("building %d languages: %s", len(args.languages), args.languages)

    # The eval (cassanof/CodeEditSearch) only has the 13 EVAL_LANGUAGES configs,
    # so only query those — intersected with what the user requested.
    eval_overlap_langs = [l for l in args.languages if l in EVAL_LANGUAGES]
    eval_shas = collect_eval_shas(eval_overlap_langs)
    eval_field_hashes, eval_ngrams = build_eval_overlap_index(
        eval_overlap_langs, n=args.ngram_n,
    )

    report = {
        "source_dataset": SOURCE_DATASET,
        "eval_dataset": EVAL_DATASET,
        "shuffle_seed": SHUFFLE_SEED,
        "overlap_threshold": args.overlap_threshold,
        "ngram_n": args.ngram_n,
        "eval_shas_count": len(eval_shas),
        "eval_field_hashes_count": len(eval_field_hashes),
        "eval_ngrams_count": len(eval_ngrams),
        "languages": [],
    }
    for lang in args.languages:
        report["languages"].append(build_language(
            lang=lang,
            eval_shas=eval_shas,
            eval_field_hashes=eval_field_hashes,
            eval_ngrams=eval_ngrams,
            output_repo=args.output_repo,
            max_per_lang=args.max_per_lang,
            ngram_n=args.ngram_n,
            overlap_threshold=args.overlap_threshold,
        ))

    totals: dict[str, int] = {}
    for entry in report["languages"]:
        for k, v in entry["funnel"].items():
            totals[k] = totals.get(k, 0) + v
    report["totals"] = totals

    REPORT_DIR.mkdir(parents=True, exist_ok=True)
    report_path = REPORT_DIR / "report.json"
    report_path.write_text(json.dumps(report, indent=2))
    logger.info("wrote report to %s", report_path)
    logger.info("totals: %s", json.dumps(totals))
    logger.info("pushed to https://huggingface.co/datasets/%s", args.output_repo)
    return 0


if __name__ == "__main__":
    sys.exit(main())

Filtering report

Per-language decontamination funnel
{
  "source_dataset": "bigcode/commitpackft",
  "eval_dataset": "cassanof/CodeEditSearch",
  "shuffle_seed": 42,
  "overlap_threshold": 0.5,
  "ngram_n": 13,
  "eval_shas_count": 21495,
  "eval_field_hashes_count": 84365,
  "eval_ngrams_count": 2887107,
  "languages": [
    {
      "config": "batchfile",
      "funnel": {
        "source_rows": 1466,
        "passed_nonempty": 1234,
        "passed_sha": 1234,
        "passed_nonempty_msg": 1234,
        "passed_hash": 1234,
        "passed_ngram": 1232,
        "kept": 1232
      }
    },
    {
      "config": "bitbake",
      "funnel": {
        "source_rows": 1308,
        "passed_nonempty": 924,
        "passed_sha": 924,
        "passed_nonempty_msg": 924,
        "passed_hash": 924,
        "passed_ngram": 924,
        "kept": 924
      }
    },
    {
      "config": "c",
      "funnel": {
        "source_rows": 8506,
        "passed_nonempty": 6925,
        "passed_sha": 5335,
        "passed_nonempty_msg": 5335,
        "passed_hash": 5027,
        "passed_ngram": 4415,
        "kept": 4415
      }
    },
    {
      "config": "csharp",
      "funnel": {
        "source_rows": 9346,
        "passed_nonempty": 8472,
        "passed_sha": 8472,
        "passed_nonempty_msg": 8472,
        "passed_hash": 8467,
        "passed_ngram": 8358,
        "kept": 8358
      }
    },
    {
      "config": "cpp",
      "funnel": {
        "source_rows": 4992,
        "passed_nonempty": 3855,
        "passed_sha": 2165,
        "passed_nonempty_msg": 2165,
        "passed_hash": 1967,
        "passed_ngram": 1748,
        "kept": 1748
      }
    },
    {
      "config": "clojure",
      "funnel": {
        "source_rows": 2403,
        "passed_nonempty": 2194,
        "passed_sha": 2194,
        "passed_nonempty_msg": 2194,
        "passed_hash": 2191,
        "passed_ngram": 2191,
        "kept": 2191
      }
    },
    {
      "config": "coffeescript",
      "funnel": {
        "source_rows": 5513,
        "passed_nonempty": 5131,
        "passed_sha": 5131,
        "passed_nonempty_msg": 5131,
        "passed_hash": 5129,
        "passed_ngram": 5116,
        "kept": 5116
      }
    },
    {
      "config": "css",
      "funnel": {
        "source_rows": 5049,
        "passed_nonempty": 4762,
        "passed_sha": 4762,
        "passed_nonempty_msg": 4762,
        "passed_hash": 4762,
        "passed_ngram": 4705,
        "kept": 4705
      }
    },
    {
      "config": "elixir",
      "funnel": {
        "source_rows": 1150,
        "passed_nonempty": 1016,
        "passed_sha": 1016,
        "passed_nonempty_msg": 1016,
        "passed_hash": 1015,
        "passed_ngram": 1015,
        "kept": 1015
      }
    },
    {
      "config": "emacs-lisp",
      "funnel": {
        "source_rows": 1015,
        "passed_nonempty": 950,
        "passed_sha": 950,
        "passed_nonempty_msg": 950,
        "passed_hash": 950,
        "passed_ngram": 950,
        "kept": 950
      }
    },
    {
      "config": "go",
      "funnel": {
        "source_rows": 5004,
        "passed_nonempty": 5001,
        "passed_sha": 3249,
        "passed_nonempty_msg": 3249,
        "passed_hash": 3097,
        "passed_ngram": 2925,
        "kept": 2925
      }
    },
    {
      "config": "groovy",
      "funnel": {
        "source_rows": 1486,
        "passed_nonempty": 1026,
        "passed_sha": 1026,
        "passed_nonempty_msg": 1026,
        "passed_hash": 1026,
        "passed_ngram": 832,
        "kept": 832
      }
    },
    {
      "config": "haml",
      "funnel": {
        "source_rows": 4415,
        "passed_nonempty": 4346,
        "passed_sha": 4346,
        "passed_nonempty_msg": 4346,
        "passed_hash": 4346,
        "passed_ngram": 4344,
        "kept": 4344
      }
    },
    {
      "config": "handlebars",
      "funnel": {
        "source_rows": 1429,
        "passed_nonempty": 1389,
        "passed_sha": 1389,
        "passed_nonempty_msg": 1389,
        "passed_hash": 1389,
        "passed_ngram": 1389,
        "kept": 1389
      }
    },
    {
      "config": "haskell",
      "funnel": {
        "source_rows": 1389,
        "passed_nonempty": 1389,
        "passed_sha": 1389,
        "passed_nonempty_msg": 1389,
        "passed_hash": 1388,
        "passed_ngram": 1385,
        "kept": 1385
      }
    },
    {
      "config": "html",
      "funnel": {
        "source_rows": 20214,
        "passed_nonempty": 18303,
        "passed_sha": 18303,
        "passed_nonempty_msg": 18303,
        "passed_hash": 18287,
        "passed_ngram": 18169,
        "kept": 18169
      }
    },
    {
      "config": "htmlperb",
      "funnel": {
        "source_rows": 10910,
        "passed_nonempty": 10458,
        "passed_sha": 10458,
        "passed_nonempty_msg": 10458,
        "passed_hash": 10456,
        "passed_ngram": 10438,
        "kept": 10438
      }
    },
    {
      "config": "ini",
      "funnel": {
        "source_rows": 11360,
        "passed_nonempty": 10626,
        "passed_sha": 10626,
        "passed_nonempty_msg": 10626,
        "passed_hash": 10553,
        "passed_ngram": 10295,
        "kept": 10295
      }
    },
    {
      "config": "jade",
      "funnel": {
        "source_rows": 1119,
        "passed_nonempty": 1098,
        "passed_sha": 1098,
        "passed_nonempty_msg": 1098,
        "passed_hash": 1097,
        "passed_ngram": 1096,
        "kept": 1096
      }
    },
    {
      "config": "java",
      "funnel": {
        "source_rows": 20635,
        "passed_nonempty": 13579,
        "passed_sha": 11823,
        "passed_nonempty_msg": 11823,
        "passed_hash": 11571,
        "passed_ngram": 9831,
        "kept": 9831
      }
    },
    {
      "config": "javascript",
      "funnel": {
        "source_rows": 52989,
        "passed_nonempty": 52235,
        "passed_sha": 50524,
        "passed_nonempty_msg": 50524,
        "passed_hash": 50124,
        "passed_ngram": 49310,
        "kept": 49310
      }
    },
    {
      "config": "json",
      "funnel": {
        "source_rows": 39777,
        "passed_nonempty": 38065,
        "passed_sha": 38065,
        "passed_nonempty_msg": 38065,
        "passed_hash": 38025,
        "passed_ngram": 38023,
        "kept": 38023
      }
    },
    {
      "config": "jsx",
      "funnel": {
        "source_rows": 2199,
        "passed_nonempty": 2056,
        "passed_sha": 2056,
        "passed_nonempty_msg": 2056,
        "passed_hash": 2056,
        "passed_ngram": 2048,
        "kept": 2048
      }
    },
    {
      "config": "kotlin",
      "funnel": {
        "source_rows": 2214,
        "passed_nonempty": 1838,
        "passed_sha": 1838,
        "passed_nonempty_msg": 1838,
        "passed_hash": 1837,
        "passed_ngram": 1607,
        "kept": 1607
      }
    },
    {
      "config": "less",
      "funnel": {
        "source_rows": 1360,
        "passed_nonempty": 1340,
        "passed_sha": 1340,
        "passed_nonempty_msg": 1340,
        "passed_hash": 1340,
        "passed_ngram": 1335,
        "kept": 1335
      }
    },
    {
      "config": "markdown",
      "funnel": {
        "source_rows": 62518,
        "passed_nonempty": 52850,
        "passed_sha": 52850,
        "passed_nonempty_msg": 52850,
        "passed_hash": 52825,
        "passed_ngram": 52258,
        "kept": 52258
      }
    },
    {
      "config": "nix",
      "funnel": {
        "source_rows": 1593,
        "passed_nonempty": 1551,
        "passed_sha": 1551,
        "passed_nonempty_msg": 1551,
        "passed_hash": 1551,
        "passed_ngram": 1551,
        "kept": 1551
      }
    },
    {
      "config": "perl",
      "funnel": {
        "source_rows": 2288,
        "passed_nonempty": 1453,
        "passed_sha": 1453,
        "passed_nonempty_msg": 1453,
        "passed_hash": 1451,
        "passed_ngram": 1435,
        "kept": 1435
      }
    },
    {
      "config": "php",
      "funnel": {
        "source_rows": 24791,
        "passed_nonempty": 20038,
        "passed_sha": 18293,
        "passed_nonempty_msg": 18293,
        "passed_hash": 17830,
        "passed_ngram": 17184,
        "kept": 17184
      }
    },
    {
      "config": "python",
      "funnel": {
        "source_rows": 56025,
        "passed_nonempty": 42537,
        "passed_sha": 40892,
        "passed_nonempty_msg": 40892,
        "passed_hash": 40393,
        "passed_ngram": 38700,
        "kept": 38700
      }
    },
    {
      "config": "restructuredtext",
      "funnel": {
        "source_rows": 6560,
        "passed_nonempty": 6011,
        "passed_sha": 6011,
        "passed_nonempty_msg": 6011,
        "passed_hash": 6010,
        "passed_ngram": 5978,
        "kept": 5978
      }
    },
    {
      "config": "ruby",
      "funnel": {
        "source_rows": 69413,
        "passed_nonempty": 62121,
        "passed_sha": 60504,
        "passed_nonempty_msg": 60504,
        "passed_hash": 59872,
        "passed_ngram": 58154,
        "kept": 58154
      }
    },
    {
      "config": "rust",
      "funnel": {
        "source_rows": 2996,
        "passed_nonempty": 2341,
        "passed_sha": 646,
        "passed_nonempty_msg": 646,
        "passed_hash": 598,
        "passed_ngram": 533,
        "kept": 533
      }
    },
    {
      "config": "scala",
      "funnel": {
        "source_rows": 5040,
        "passed_nonempty": 4255,
        "passed_sha": 2790,
        "passed_nonempty_msg": 2790,
        "passed_hash": 2287,
        "passed_ngram": 1963,
        "kept": 1963
      }
    },
    {
      "config": "scss",
      "funnel": {
        "source_rows": 6829,
        "passed_nonempty": 6796,
        "passed_sha": 6796,
        "passed_nonempty_msg": 6796,
        "passed_hash": 6796,
        "passed_ngram": 6733,
        "kept": 6733
      }
    },
    {
      "config": "shell",
      "funnel": {
        "source_rows": 31217,
        "passed_nonempty": 26026,
        "passed_sha": 24624,
        "passed_nonempty_msg": 24624,
        "passed_hash": 23969,
        "passed_ngram": 23040,
        "kept": 23040
      }
    },
    {
      "config": "slim",
      "funnel": {
        "source_rows": 1052,
        "passed_nonempty": 1034,
        "passed_sha": 1034,
        "passed_nonempty_msg": 1034,
        "passed_hash": 1033,
        "passed_ngram": 1032,
        "kept": 1032
      }
    },
    {
      "config": "sql",
      "funnel": {
        "source_rows": 2069,
        "passed_nonempty": 1211,
        "passed_sha": 1211,
        "passed_nonempty_msg": 1211,
        "passed_hash": 1206,
        "passed_ngram": 1187,
        "kept": 1187
      }
    },
    {
      "config": "swift",
      "funnel": {
        "source_rows": 4849,
        "passed_nonempty": 3955,
        "passed_sha": 2233,
        "passed_nonempty_msg": 2233,
        "passed_hash": 2079,
        "passed_ngram": 1870,
        "kept": 1870
      }
    },
    {
      "config": "text",
      "funnel": {
        "source_rows": 46588,
        "passed_nonempty": 44799,
        "passed_sha": 44799,
        "passed_nonempty_msg": 44799,
        "passed_hash": 44797,
        "passed_ngram": 44266,
        "kept": 44266
      }
    },
    {
      "config": "toml",
      "funnel": {
        "source_rows": 3424,
        "passed_nonempty": 3380,
        "passed_sha": 3380,
        "passed_nonempty_msg": 3380,
        "passed_hash": 3377,
        "passed_ngram": 3368,
        "kept": 3368
      }
    },
    {
      "config": "twig",
      "funnel": {
        "source_rows": 1610,
        "passed_nonempty": 1479,
        "passed_sha": 1479,
        "passed_nonempty_msg": 1479,
        "passed_hash": 1479,
        "passed_ngram": 1477,
        "kept": 1477
      }
    },
    {
      "config": "typescript",
      "funnel": {
        "source_rows": 5868,
        "passed_nonempty": 5328,
        "passed_sha": 3623,
        "passed_nonempty_msg": 3623,
        "passed_hash": 3488,
        "passed_ngram": 3371,
        "kept": 3371
      }
    },
    {
      "config": "unknown",
      "funnel": {
        "source_rows": 1597,
        "passed_nonempty": 1457,
        "passed_sha": 1457,
        "passed_nonempty_msg": 1457,
        "passed_hash": 1457,
        "passed_ngram": 1445,
        "kept": 1445
      }
    },
    {
      "config": "viml",
      "funnel": {
        "source_rows": 1063,
        "passed_nonempty": 1063,
        "passed_sha": 1063,
        "passed_nonempty_msg": 1063,
        "passed_hash": 1062,
        "passed_ngram": 1062,
        "kept": 1062
      }
    },
    {
      "config": "xml",
      "funnel": {
        "source_rows": 9337,
        "passed_nonempty": 8113,
        "passed_sha": 8113,
        "passed_nonempty_msg": 8113,
        "passed_hash": 8109,
        "passed_ngram": 7700,
        "kept": 7700
      }
    },
    {
      "config": "yaml",
      "funnel": {
        "source_rows": 114320,
        "passed_nonempty": 103688,
        "passed_sha": 103688,
        "passed_nonempty_msg": 103688,
        "passed_hash": 103666,
        "passed_ngram": 102934,
        "kept": 102934
      }
    }
  ],
  "totals": {
    "source_rows": 678295,
    "passed_nonempty": 599698,
    "passed_sha": 578203,
    "passed_nonempty_msg": 578203,
    "passed_hash": 573593,
    "passed_ngram": 560922,
    "kept": 560922
  }
}

Licensing

This dataset is derived from bigcode/commitpackft and we keep all of the original licenses of the source data.

Citation

If you use this dataset, please consider citing our work

@misc{sourty2026denseonlateonfullyopen,
  title         = {DenseOn with the LateOn: Fully Open Dense and Late-Interaction Models for Multilingual, Long-Context, and Code Search},
  author        = {Raphaël Sourty and Antoine Chaffin and Paulo Roberto Moura Junior and Amélie Chatelain},
  year          = {2026},
  eprint        = {2607.27178},
  archivePrefix = {arXiv},
  primaryClass  = {cs.CL},
  url           = {https://arxiv.org/abs/2607.27178},
}