File size: 9,984 Bytes
44fe250 d9938b2 e4b97c7 f27dd68 e4b97c7 22b0876 e4b97c7 22b0876 e4b97c7 d9938b2 22b0876 05aa5d8 22b0876 05aa5d8 e40a03d e4b97c7 e40a03d e4b97c7 e40a03d 11b0604 e40a03d d9938b2 05aa5d8 d9938b2 11b0604 d9938b2 e4b97c7 22b0876 28fd498 e4b97c7 2b4ffe0 e4b97c7 22b0876 e4b97c7 d9938b2 22b0876 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | ---
pretty_name: HAM-Net Datasets
tags:
- code
- software-engineering
- defect-prediction
- multiple-instance-learning
task_categories:
- text-classification
language:
- code
- multilingual
size_categories:
- 10K<n<100K
---
# HAM-Net datasets
This repository provides the processed code datasets used in the HAM-Net
experiments for cross-project software defect prediction.
Each JSONL record represents one source-code file or Java class containing
multiple functions.
For datasets organized by file or class, HAM-Net treats the file/class as a
**bag** and its functions as **instances**, following the multiple-instance
learning (MIL) setting. Each record includes a binary defect label, a project
identifier, and the extracted function-level code and AST information.
## Record format
A simplified MIL record looks like:
```json
{
"id": "stable-sample-id",
"project": "pandas",
"file_path": "pandas/core/example.py",
"label": 1,
"functions": [
{
"name": "example_function",
"code": "def example_function(...): ...",
"func_label": 1,
"ast_nodes": ["DECLARATION", "PARAMETER", "CONTROL", "RETURN"],
"ast_edges": [[0, 1], [0, 2], [2, 3]]
}
]
}
```
`func_label` is present only when it can be derived from patch or line-level
annotations. It is not available for PROMISE.
## Reproducibility release
The repository contains the dataset revision used by the HAM-Net paper's fixed
CPDP experiments. The `main` branch and the immutable `v1.0.0` tag contain the
same four JSONL files and matching split files. To pin the paper revision:
```bash
hf download Scream9371/hamnet-datasets promise_java.jsonl --revision v1.0.0
```
### Reproducibility contract
`v1.0.0` is pinned to the four JSONL files at repository root and the fixed
CPDP files under `splits/cpdp/`. The JSONL files preserve the bag identity and
order used by the original local HAM-Net experiments, while each bag contains
the complete parseable function list. Source text retains comments and AST
graphs are not truncated at 800 nodes.
The paper experiments use the complete function bags. No deterministic
training-time caps are provided or used by this release.
The BugsInPy CPDP split intentionally contains the 2,416 bags used by the
original HAM-Net experiment repository.
## Original data sources
The published JSONL files are derived from the following public datasets. Some
original datasets provide labels for functions, classes, files, or code lines.
During preprocessing, HAM-Net converts several of them into a common
file/class-level MIL format. The table distinguishes the original annotation
level from the released HAM-Net representation.
| Dataset | Original source | Original annotations / content | HAM-Net representation |
|---|---|---|---|
| `promise_java` | [PROMISE repository](https://openscience.us/repo/defect) | Classic Java class-level defect metric datasets with a `bug` count/label | Each Java class forms one MIL bag. The bag is positive when `bug > 0`. |
| `bigvul_c` | [MSR 2020 Big-Vul dataset](https://github.com/ZeoVan/MSR_20_Code_vulnerability_CSV_Dataset) | Large-scale C/C++ vulnerability records containing code changes and CVE-related metadata | Each C/C++ file forms one MIL bag. Functions overlapping buggy-side changed lines are marked as positive. |
| `defactors_python` | [Defactors](https://zenodo.org/records/7708984) | Line-level defect annotations from multiple Python projects | Each Python file forms one MIL bag. Functions overlapping annotated defect lines receive `func_label=1`. |
| `bugsinpy_python` | [BugsInPy](https://github.com/soarsmu/BugsInPy) | Reproducible defects, buggy/fixed commits, and patch information from Python projects | Each Python file forms one MIL bag. Bags are constructed from buggy files and same-project negative files. |
PROMISE, Big-Vul, Defactors, and BugsInPy are converted into class-level or file-level bags for multiple-instance learning. The dataset sources provide the original labels or patch/line annotations; the exact sampling, parsing, AST normalization, and bag construction rules are described below.
## Dataset summary
Percentages are computed from the final JSONL files. `P50/P90/P99` are the numbers of functions per bag. `mixed positive bags` means positive bags containing both at least one `func_label=1` function and at least one `func_label=0` function. `positive functions` is computed only for datasets that retain function-level labels.
| Dataset | Language / granularity | Bags or samples | Positive / negative | Functions per bag P50 / P90 / P99 | Mixed positive bags | Positive functions |
|---|---|---:|---:|---:|---:|---:|
| `promise_java` | Java class-level MIL bag | 1,695 bags | 647 / 1,048 (38.17% / 61.83%) | 8 / 26 / 94.12 | N/A: no function-level labels | N/A |
| `defactors_python` | Python file-level MIL bag | 1,700 bags | 873 / 827 (51.35% / 48.65%) | 18 / 86 / 227.06 | 808 / 873 (92.55%) | 3,190 / 58,028 (5.50%) |
| `bugsinpy_python` | Python file-level MIL bag | 2,416 bags | 525 / 1,891 (21.73% / 78.27%) | 9 / 79 / 205 | 507 / 525 (96.57%) | 1,080 / 63,937 (1.69%) |
| `bigvul_c` | C/C++ file-level MIL bag | 1,700 bags | 733 / 967 (43.12% / 56.88%) | 16 / 64 / 279.01 | 733 / 733 (100.00%) | 1,270 / 51,668 (2.46%) |
`promise_java` uses `bug > 0` as its class/bag label and therefore does not claim function-level defect localization ground truth.
## How the MIL bags are constructed
The following rules define the published MIL samples.
### PROMISE
- Unit of sampling: one target Java class is one bag; methods and constructors in
that class are the bag instances.
- Source candidates: scan the available project/version CSV records and resolve each
class name to its corresponding Java source file. Records without a source file,
unparsable source, or fewer than three parseable methods/constructors are removed.
- Projects: `ant`, `camel`, `ivy`, `jedit`, `log4j`, `lucene`, `poi`, `velocity`, and
`xalan`.
- Label: `label=1` when the source `bug` value is greater than zero; otherwise
`label=0`.
- Function sampling: retain all parseable methods and constructors in the selected
class. No positive/negative function sampling is performed.
### Defactors
- Unit of sampling: one Python source file is one bag and every parseable function
in that file is an instance.
- Projects: `pandas`, `scikit-learn`, `localstack`, `django`, `poetry`, `core`,
`airflow`, `lightning`, `spaCy`, `ansible`, `ray`, `celery`, `sentry`, `cpython`,
and `transformers`.
- Function and bag labels: a function is positive when its span overlaps an annotated
defect line; a bag is positive when it contains at least one positive function.
- Negative bags: sample files from the same project whose functions do not overlap
the annotated defect lines; prefer the same commit and same module when available,
then use other commits from the same project, with duplicate project/commit/file
records removed.
- Function sampling: discard bags with fewer than three parseable functions during
the original candidate construction.
### BugsInPy
- Unit of sampling: one Python file at a buggy commit is one bag; each parseable
function in the file is an instance.
- Projects: `pandas`, `keras`, `youtube-dl`, `scrapy`, `luigi`, `thefuck`, `matplotlib`,
`black`, `ansible`, `fastapi`, `tornado`, `tqdm`, `spacy`, `sanic`, `httpie`,
`cookiecutter`, and `PySnooper`.
- Positive candidates: use the buggy-side files touched by each BugsInPy patch.
A function is positive when its span overlaps a buggy-side patch line, and
the bag is positive when at least one such function exists.
- Negative candidates: for each bug, sample one same-project Python file from the
same buggy snapshot that is not among the patched files. Half of the negative
sampling quota targets files in the same directory or top-level module when such
candidates exist; remaining candidates are sampled from the other files.
- Function sampling: use seed 42, discard files with no parseable function, and
retain the complete parseable function list. This release also excludes bags
that contain no function definition: older
construction artifacts represented them as a single ``<file>`` placeholder,
which is not a valid MIL instance.
### Big-Vul
- Unit of sampling: one C/C++ file at the buggy snapshot is one bag; each parseable
function is an instance.
- Projects: `linux`, `ImageMagick`, `Android`, `tcpdump`, `FFmpeg`, `php-src`, and
`radare2`.
- Positive candidates: use the buggy-side files associated with the vulnerability
patch. A function is positive when it overlaps a removed/changed buggy-side patch
line; the file is a positive bag when at least one function is positive.
- Negative candidates: for each positive file, sample two unmodified same-project
files from the same snapshot. Half of the negative quota targets the same
directory or top-level module when possible; the remainder is sampled from other
files. Sampling uses seed 42, with project and global sample limits applied before
writing the final set.
- Function sampling: discard files with fewer than three parseable functions and
retain all remaining functions in the full-function version.
### AST normalization rules
- To make ASTs from Java, Python, C, and C++ comparable, language-specific node
types are mapped to a shared set of structural roles, such as declarations,
control-flow statements, calls, assignments, returns, and literals.
- This normalization preserves coarse syntactic structure while removing
language-specific lexical details. Identifiers, punctuation, comments, and
documentation text are not retained as structural AST nodes. The normalized
graph contains parent-child structure, reverse edges, and self-loops.
## Files
- `promise_java.jsonl`
- `defactors_python.jsonl`
- `bugsinpy_python.jsonl`
- `bigvul_c.jsonl`
- `splits/cpdp/`: fixed project-disjoint splits used by the paper
|