Datasets:
hls4ml LHC jets (150p): one row per jet, train/validation/test, shipped loader
Browse files- LICENSE +18 -0
- README.md +196 -0
- configs/config.yaml +21 -0
- configs/data/basis.yaml +40 -0
- configs/paths/default.yaml +12 -0
- data/test-00000-of-00002.parquet +3 -0
- data/test-00001-of-00002.parquet +3 -0
- data/train-00000-of-00004.parquet +3 -0
- data/train-00001-of-00004.parquet +3 -0
- data/train-00002-of-00004.parquet +3 -0
- data/train-00003-of-00004.parquet +3 -0
- data/validation-00000-of-00001.parquet +3 -0
- loader/__init__.py +16 -0
- loader/datamodule.py +133 -0
- loader/physics.py +92 -0
- loader/reading.py +87 -0
- requirements.txt +17 -0
LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Creative Commons Attribution 4.0 International (CC BY 4.0)
|
| 2 |
+
|
| 3 |
+
This dataset is a mirror of
|
| 4 |
+
|
| 5 |
+
Pierini, Maurizio; Duarte, Javier; Tran, Nhan; Freytsis, Marat
|
| 6 |
+
HLS4ML LHC Jet dataset (150 particles)
|
| 7 |
+
Zenodo, 2020
|
| 8 |
+
https://doi.org/10.5281/zenodo.3602260
|
| 9 |
+
|
| 10 |
+
which is published under the Creative Commons Attribution 4.0 International
|
| 11 |
+
licence. The mirror is published under the same licence.
|
| 12 |
+
|
| 13 |
+
You are free to share and adapt the material for any purpose, including
|
| 14 |
+
commercially, provided you give appropriate credit to the original authors,
|
| 15 |
+
link to the licence, and indicate whether changes were made. The rows here are
|
| 16 |
+
the rows of the original HDF5 files, reshaped; no values were recomputed.
|
| 17 |
+
|
| 18 |
+
Licence: https://creativecommons.org/licenses/by/4.0/
|
README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
task_categories:
|
| 6 |
+
- tabular-classification
|
| 7 |
+
pretty_name: hls4ml LHC jet dataset (150 particles)
|
| 8 |
+
size_categories:
|
| 9 |
+
- 100K<n<1M
|
| 10 |
+
tags:
|
| 11 |
+
- physics
|
| 12 |
+
- particle-physics
|
| 13 |
+
- jet-tagging
|
| 14 |
+
- hls4ml
|
| 15 |
+
- lhc
|
| 16 |
+
configs:
|
| 17 |
+
- config_name: default
|
| 18 |
+
data_files:
|
| 19 |
+
- split: train
|
| 20 |
+
path: data/train-*.parquet
|
| 21 |
+
- split: validation
|
| 22 |
+
path: data/validation-*.parquet
|
| 23 |
+
- split: test
|
| 24 |
+
path: data/test-*.parquet
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
# hls4ml LHC jet dataset (150 particles)
|
| 28 |
+
|
| 29 |
+
*A mirror of the Zenodo record
|
| 30 |
+
[10.5281/zenodo.3602260](https://doi.org/10.5281/zenodo.3602260), reshaped to one row
|
| 31 |
+
per jet.*
|
| 32 |
+
|
| 33 |
+
The data are simulated high transverse-momentum (~1 TeV) jets from proton-proton
|
| 34 |
+
collisions at the Large Hadron Collider, labelled by what produced them: a light quark,
|
| 35 |
+
a gluon, a W boson, a Z boson or a top quark. Each jet is constituted of up to 150
|
| 36 |
+
constituents together with a set of jet-level observables, and the set was prepared for
|
| 37 |
+
the hls4ml jet-tagging studies. The mirror holds 880,000 jets.
|
| 38 |
+
|
| 39 |
+
Every value is the value of the original HDF5 files. The jet images from the original
|
| 40 |
+
data files are dropped.
|
| 41 |
+
|
| 42 |
+
## One row is one jet
|
| 43 |
+
|
| 44 |
+
| column | type | holds |
|
| 45 |
+
|---|---|---|
|
| 46 |
+
| the 16 `j1_*` columns | `list<float32>` | one entry per constituent of that jet, so the lists of one row all have the same length |
|
| 47 |
+
| the 53 `j_*` columns | `float32` | jet-level observables, one value per jet |
|
| 48 |
+
| `label` | `int8` | 0 gluon, 1 light quark, 2 W boson, 3 Z boson, 4 top quark |
|
| 49 |
+
| `source_file` | `string` | the HDF5 file the jet was read from, without its extension |
|
| 50 |
+
| `source_row` | `int32` | the jet's row within that file |
|
| 51 |
+
|
| 52 |
+
The constituent features, in the order the original files list them, are `j1_px`,
|
| 53 |
+
`j1_py`, `j1_pz`, `j1_e`, `j1_erel`, `j1_pt`, `j1_ptrel`, `j1_eta`, `j1_etarel`,
|
| 54 |
+
`j1_etarot`, `j1_phi`, `j1_phirel`, `j1_phirot`, `j1_deltaR`, `j1_costheta` and
|
| 55 |
+
`j1_costhetarel`. The jet-level features are `j_ptfrac`, `j_pt`, `j_eta`, `j_mass`,
|
| 56 |
+
`j_tau1_b1`, `j_tau2_b1`, `j_tau3_b1`, `j_tau1_b2`, `j_tau2_b2`, `j_tau3_b2`,
|
| 57 |
+
`j_tau32_b1`, `j_tau32_b2`, `j_zlogz`, `j_c1_b0`, `j_c1_b1`, `j_c1_b2`, `j_c2_b1`,
|
| 58 |
+
`j_c2_b2`, `j_d2_b1`, `j_d2_b2`, `j_d2_a1_b1`, `j_d2_a1_b2`, `j_m2_b1`, `j_m2_b2`,
|
| 59 |
+
`j_n2_b1`, `j_n2_b2`, `j_tau1_b1_mmdt`, `j_tau2_b1_mmdt`, `j_tau3_b1_mmdt`,
|
| 60 |
+
`j_tau1_b2_mmdt`, `j_tau2_b2_mmdt`, `j_tau3_b2_mmdt`, `j_tau32_b1_mmdt`,
|
| 61 |
+
`j_tau32_b2_mmdt`, `j_c1_b0_mmdt`, `j_c1_b1_mmdt`, `j_c1_b2_mmdt`, `j_c2_b1_mmdt`,
|
| 62 |
+
`j_c2_b2_mmdt`, `j_d2_b1_mmdt`, `j_d2_b2_mmdt`, `j_d2_a1_b1_mmdt`, `j_d2_a1_b2_mmdt`,
|
| 63 |
+
`j_m2_b1_mmdt`, `j_m2_b2_mmdt`, `j_n2_b1_mmdt`, `j_n2_b2_mmdt`, `j_mass_trim`,
|
| 64 |
+
`j_mass_mmdt`, `j_mass_prun`, `j_mass_sdb2`, `j_mass_sdm1` and `j_multiplicity`. The
|
| 65 |
+
label is the argmax over the five one-hot columns `j_g`, `j_q`, `j_w`, `j_z`, `j_t` that
|
| 66 |
+
the original `jets` array ends with. The one-hot columns and the always-zero `j_undef`
|
| 67 |
+
beside them are not mirrored, but are replaced by `label`.
|
| 68 |
+
|
| 69 |
+
## Splits
|
| 70 |
+
|
| 71 |
+
`train` and `validation` come from the Zenodo *train* archive. Its files are
|
| 72 |
+
concatenated in sorted-filename order and cut with
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
train_idx, validation_idx = train_test_split(np.arange(n), test_size=0.2, random_state=42)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
`test` is the Zenodo *val* archive, in sorted-filename order.
|
| 79 |
+
|
| 80 |
+
| split | jets | gluon | light quark | W boson | Z boson | top quark |
|
| 81 |
+
|---|---|---|---|---|---|---|
|
| 82 |
+
| `train` | 496,000 | 100,051 | 96,079 | 99,834 | 99,591 | 100,445 |
|
| 83 |
+
| `validation` | 124,000 | 24,797 | 24,132 | 25,103 | 25,063 | 24,905 |
|
| 84 |
+
| `test` | 260,000 | 52,404 | 50,468 | 52,235 | 52,298 | 52,595 |
|
| 85 |
+
|
| 86 |
+
## Layout
|
| 87 |
+
|
| 88 |
+
```
|
| 89 |
+
data/train-NNNNN-of-NNNNN.parquet
|
| 90 |
+
data/validation-NNNNN-of-NNNNN.parquet
|
| 91 |
+
data/test-NNNNN-of-NNNNN.parquet
|
| 92 |
+
loader/ the pipeline described below
|
| 93 |
+
configs/ the Hydra tree that drives it
|
| 94 |
+
requirements.txt what that pipeline needs
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
## Loading
|
| 98 |
+
|
| 99 |
+
The tables need only the `datasets` package:
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
from datasets import load_dataset
|
| 103 |
+
jets = load_dataset("fastmachinelearning/hls4ml_lhc_jets_150p", split="train")
|
| 104 |
+
jets[0]["j1_pt"] # the transverse momenta of that jet's constituents
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
This data record also contains a data processing pipeline that implements a few basic
|
| 108 |
+
recommended processing steps. It reads the parquet files, keeps the leading constituents
|
| 109 |
+
by transverse momentum, normalises each feature by a scale fitted on the training split
|
| 110 |
+
alone, caches the result as `.npy`, and hands back torch tensors:
|
| 111 |
+
|
| 112 |
+
```python
|
| 113 |
+
import sys
|
| 114 |
+
from huggingface_hub import snapshot_download
|
| 115 |
+
from hydra import compose, initialize_config_dir
|
| 116 |
+
from hydra.utils import instantiate
|
| 117 |
+
record = snapshot_download("fastmachinelearning/hls4ml_lhc_jets_150p", repo_type="dataset")
|
| 118 |
+
sys.path.insert(0, record) # the configs name loader.*, so the record has to be importable
|
| 119 |
+
with initialize_config_dir(config_dir=record + "/configs", version_base=None):
|
| 120 |
+
cfg = compose("config", overrides=["paths.root_dir=" + record, "data.nconstituents=32"])
|
| 121 |
+
data = instantiate(cfg.data)
|
| 122 |
+
data.prepare()
|
| 123 |
+
train = data.load("train")
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
The `train.x` object is a `(jets, 32, 16)` float32 tensor of normalised constituents and
|
| 127 |
+
`train.y` a `(jets, 5)` float32 one-hot tensor of the labels. The
|
| 128 |
+
`data.load("validation")` and the `data.load("test")` objects return the other two
|
| 129 |
+
splits, normalised with the scales fitted on `train`. The `data.nconstituents` is used
|
| 130 |
+
to set the maximum number of constituents per jet; `0` or less keeps all 150. Again,
|
| 131 |
+
these are ordered by descending transverse momentum by the data loader. Data that is
|
| 132 |
+
processed in different ways using the record's dataloader are cached on disk in
|
| 133 |
+
different ways; hence, there's no duplicate preprocessing.
|
| 134 |
+
|
| 135 |
+
The `prepare` method writes the caches under the `./cache` folder. Please set the
|
| 136 |
+
`HLS4ML_JETS_CACHE` environment to move this elsewhere. Additionally, `prepare` reads
|
| 137 |
+
the shards from `HLS4ML_JETS_ROOT` when the overrides above are left out. Allow the
|
| 138 |
+
cache a few times the record's size on disk. The pipeline needs python 3.11 or newer
|
| 139 |
+
with `numpy`, `pyarrow`, `torch`, `omegaconf` and `hydra-core`, which `pip install -r
|
| 140 |
+
requirements.txt` at the record's root installs. **If you only want the raw tables, you
|
| 141 |
+
need none of the dataloader functionality. Just call `load_dataset`.**
|
| 142 |
+
|
| 143 |
+
## Caveats
|
| 144 |
+
|
| 145 |
+
**Constituents are stored in descending transverse momentum, the order they sit in the
|
| 146 |
+
original files.** Every jet of all three splits was checked: no list holds a constituent
|
| 147 |
+
with a higher `j1_pt` than the one before it. The loader in this record still
|
| 148 |
+
stable-sorts each jet by descending `j1_pt` before it truncates to `nconstituents` or
|
| 149 |
+
pads up to it, because the reference pipeline does. The sort of the dataloader acts as a
|
| 150 |
+
double-check that constiutents are stored in descending order. Truncating the lists as
|
| 151 |
+
they come therefore keeps the same leading constituents.
|
| 152 |
+
|
| 153 |
+
**The lists have no padding or fixed length.** A jet holds as many entries as it has
|
| 154 |
+
constituents, up to 150. The original files pad every jet to 150 slots with rows of
|
| 155 |
+
zeros; those slots are dropped here and rebuilt by the loader.
|
| 156 |
+
|
| 157 |
+
**The jet images are not mirrored.** The original files carry `jetImage`, `jetImageECAL`
|
| 158 |
+
and `jetImageHCAL`, three 100x100 arrays per jet, which dwarf everything else. Take them
|
| 159 |
+
from Zenodo if you need them.
|
| 160 |
+
|
| 161 |
+
## Provenance
|
| 162 |
+
|
| 163 |
+
Simulated proton-proton collisions at the LHC, produced for the hls4ml jet-tagging
|
| 164 |
+
studies and published on Zenodo in 2020 by Maurizio Pierini, Javier Duarte, Nhan Tran
|
| 165 |
+
and Marat Freytsis. This mirror was built from the two archives of that record,
|
| 166 |
+
`hls4ml_LHCjet_150p_train.tar.gz` and `hls4ml_LHCjet_150p_val.tar.gz`, by the code at
|
| 167 |
+
https://github.com/bb511/jet_tagging_datamaker. The data were produced at commit
|
| 168 |
+
[`1718726`](https://github.com/bb511/jet_tagging_datamaker/tree/1718726) of that
|
| 169 |
+
repository.
|
| 170 |
+
|
| 171 |
+
## Citation
|
| 172 |
+
|
| 173 |
+
Cite the Zenodo record this dataset mirrors.
|
| 174 |
+
|
| 175 |
+
```bibtex
|
| 176 |
+
@dataset{pierini_hls4ml_lhc_jets_150p_2020,
|
| 177 |
+
author = {Pierini, Maurizio and Duarte, Javier and Tran, Nhan and Freytsis, Marat},
|
| 178 |
+
title = {HLS4ML LHC Jet dataset (150 particles)},
|
| 179 |
+
year = {2020},
|
| 180 |
+
publisher = {Zenodo},
|
| 181 |
+
doi = {10.5281/zenodo.3602260},
|
| 182 |
+
url = {https://doi.org/10.5281/zenodo.3602260}
|
| 183 |
+
}
|
| 184 |
+
```
|
| 185 |
+
|
| 186 |
+
## Licence
|
| 187 |
+
|
| 188 |
+
CC BY 4.0, the licence of the original record. See `LICENSE`. Use it for anything,
|
| 189 |
+
including commercially, as long as you credit Pierini, Duarte, Tran and Freytsis, link
|
| 190 |
+
the licence at https://creativecommons.org/licenses/by/4.0/, and say what you changed.
|
| 191 |
+
|
| 192 |
+
## Contact
|
| 193 |
+
|
| 194 |
+
Questions and problems are welcome as a discussion on this dataset's page, or as an
|
| 195 |
+
issue on the repository that produced it:
|
| 196 |
+
https://github.com/bb511/jet_tagging_datamaker.
|
configs/config.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# @package _global_
|
| 2 |
+
|
| 3 |
+
# Root of the configuration tree that ships with the record.
|
| 4 |
+
#
|
| 5 |
+
# import sys
|
| 6 |
+
# from hydra import compose, initialize_config_dir
|
| 7 |
+
# from hydra.utils import instantiate
|
| 8 |
+
#
|
| 9 |
+
# sys.path.insert(0, record) # the _target_ below names loader.*, so it has to import
|
| 10 |
+
# with initialize_config_dir(config_dir=f"{record}/configs", version_base=None):
|
| 11 |
+
# cfg = compose("config", overrides=[f"paths.root_dir={record}"])
|
| 12 |
+
# data = instantiate(cfg.data)
|
| 13 |
+
# data.prepare()
|
| 14 |
+
# train = data.load("train")
|
| 15 |
+
#
|
| 16 |
+
# basis is the configuration the published studies were run with. Change any single
|
| 17 |
+
# setting with, say, data.nconstituents=8.
|
| 18 |
+
|
| 19 |
+
defaults:
|
| 20 |
+
- _self_
|
| 21 |
+
- data: basis
|
configs/data/basis.yaml
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# @package data
|
| 2 |
+
|
| 3 |
+
# The configuration the published studies were run with: the 32 leading constituents by
|
| 4 |
+
# pT of each jet, five flavour classes (g, q, W, Z, t).
|
| 5 |
+
|
| 6 |
+
defaults:
|
| 7 |
+
- /paths: default
|
| 8 |
+
- _self_
|
| 9 |
+
|
| 10 |
+
_target_: loader.datamodule.JetData
|
| 11 |
+
_convert_: all
|
| 12 |
+
|
| 13 |
+
# Where the record is read from and where its caches are built.
|
| 14 |
+
data_dir: ${paths.raw_data_dir}
|
| 15 |
+
cache_root_dir: ${paths.base_data_dir}
|
| 16 |
+
|
| 17 |
+
# 0 or less keeps every slot, up to max_constituents.
|
| 18 |
+
nconstituents: 32
|
| 19 |
+
max_constituents: 150
|
| 20 |
+
n_classes: 5
|
| 21 |
+
|
| 22 |
+
# The 16 constituent columns, in the order the h5 files carry them. The order is what
|
| 23 |
+
# fixes the last axis of the tensors, so it must not be rearranged here.
|
| 24 |
+
constituent_features:
|
| 25 |
+
- j1_px
|
| 26 |
+
- j1_py
|
| 27 |
+
- j1_pz
|
| 28 |
+
- j1_e
|
| 29 |
+
- j1_erel
|
| 30 |
+
- j1_pt
|
| 31 |
+
- j1_ptrel
|
| 32 |
+
- j1_eta
|
| 33 |
+
- j1_etarel
|
| 34 |
+
- j1_etarot
|
| 35 |
+
- j1_phi
|
| 36 |
+
- j1_phirel
|
| 37 |
+
- j1_phirot
|
| 38 |
+
- j1_deltaR
|
| 39 |
+
- j1_costheta
|
| 40 |
+
- j1_costhetarel
|
configs/paths/default.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# @package paths
|
| 2 |
+
|
| 3 |
+
# Root of the downloaded record, the folder holding data/, loader/ and configs/.
|
| 4 |
+
# Override it on the command line with paths.root_dir=/path/to/the/record.
|
| 5 |
+
root_dir: ${oc.env:HLS4ML_JETS_ROOT,.}
|
| 6 |
+
|
| 7 |
+
# The published shards.
|
| 8 |
+
raw_data_dir: ${paths.root_dir}/data
|
| 9 |
+
|
| 10 |
+
# Where the restricted, normalised arrays are cached. They are written to, so they stay
|
| 11 |
+
# outside the downloaded copy.
|
| 12 |
+
base_data_dir: ${oc.env:HLS4ML_JETS_CACHE,./cache}
|
data/test-00000-of-00002.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c5a7cdd43eec8438850f2d52e7a002b9ab6fce997b0e051f827677e8b707396c
|
| 3 |
+
size 534529744
|
data/test-00001-of-00002.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75aa907a5e42e0cbec0c5acfd8b5b56f38b63984ed22943b13b83c95302ec491
|
| 3 |
+
size 388537121
|
data/train-00000-of-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:233a273eeaa6ed3b79488d5c95a8727b46888e809c32411d3d14b45718553ab6
|
| 3 |
+
size 533948666
|
data/train-00001-of-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:723885abf40dbed1f5153d068069001b37a29fa2008efdd3ce3e981a66669792
|
| 3 |
+
size 535060832
|
data/train-00002-of-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6d4da883ffa8dacb318958aba40d6ea2f746ad323d9df292bf06fc6fcb660235
|
| 3 |
+
size 534207019
|
data/train-00003-of-00004.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8afb425656294d1303fb47d566dbfa5e11b42308d7503b22822fda9a0078b154
|
| 3 |
+
size 161003391
|
data/validation-00000-of-00001.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:306ff31b535c7352e9540715b5935559e28de02eb7f4d91d8a0a07d7acf0bbc1
|
| 3 |
+
size 440522352
|
loader/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The loading pipeline that ships with the record.
|
| 2 |
+
#
|
| 3 |
+
# Three stages run in order and the last one caches what it wrote, so a rerun over the
|
| 4 |
+
# same cache directory costs nothing:
|
| 5 |
+
#
|
| 6 |
+
# reading the published parquet shards -> the padded (jets, constituents,
|
| 7 |
+
# features) array the study's own pipeline works on
|
| 8 |
+
# physics keep the leading constituents by pT, fit the scale-only normalisation
|
| 9 |
+
# on the training split, apply it
|
| 10 |
+
# datamodule drive both for a caller who wants tensors and nothing else
|
| 11 |
+
#
|
| 12 |
+
# The stages are configured by the hydra tree under configs/, which names them by their
|
| 13 |
+
# _target_. datamodule.JetData is the only entry point a consumer needs.
|
| 14 |
+
#
|
| 15 |
+
# Nothing is imported here, so that reading and physics can be used without torch
|
| 16 |
+
# installed.
|
loader/datamodule.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Driving the two stages, for a caller who wants tensors and nothing else.
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
from dataclasses import dataclass
|
| 5 |
+
from functools import partial
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
from . import physics, reading
|
| 12 |
+
|
| 13 |
+
log = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
# The record is published pre-split: train and validation are the Zenodo train archive
|
| 16 |
+
# split 80/20, test is the Zenodo validation archive.
|
| 17 |
+
SPLITS = ("train", "validation", "test")
|
| 18 |
+
|
| 19 |
+
CACHE_FILES = (
|
| 20 |
+
*(f"x_{split}.npy" for split in SPLITS),
|
| 21 |
+
*(f"y_{split}.npy" for split in SPLITS),
|
| 22 |
+
"norm_params.npz",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@dataclass(frozen=True)
|
| 27 |
+
class SplitTensors:
|
| 28 |
+
"""One split as a model sees it: the constituents and the one-hot flavour label."""
|
| 29 |
+
|
| 30 |
+
x: torch.Tensor
|
| 31 |
+
y: torch.Tensor
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@dataclass
|
| 35 |
+
class JetData:
|
| 36 |
+
"""Restrict, normalise and cache the published jets, then hand back their tensors.
|
| 37 |
+
|
| 38 |
+
The normalisation is fitted on the training split alone and applied unchanged to
|
| 39 |
+
validation and to test, which is what the study does.
|
| 40 |
+
|
| 41 |
+
:param data_dir: The record's ``data/``, holding the parquet shards.
|
| 42 |
+
:param cache_root_dir: Where the caches are built. They are written to and roughly
|
| 43 |
+
the size of the record, so they stay outside the downloaded copy.
|
| 44 |
+
:param constituent_features: The 16 columns, in the order the h5 files carry them.
|
| 45 |
+
:param nconstituents: How many leading constituents by pT to keep; 0 or less keeps
|
| 46 |
+
all ``max_constituents``.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
data_dir: str
|
| 50 |
+
cache_root_dir: str
|
| 51 |
+
constituent_features: list[str]
|
| 52 |
+
nconstituents: int = 32
|
| 53 |
+
max_constituents: int = 150
|
| 54 |
+
n_classes: int = 5
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def cache_folder(self) -> Path:
|
| 58 |
+
"""One directory per constituent count, so two of them never share a cache."""
|
| 59 |
+
if self.nconstituents <= 0:
|
| 60 |
+
return Path(self.cache_root_dir) / "full"
|
| 61 |
+
|
| 62 |
+
return Path(self.cache_root_dir) / f"nconst_{self.nconstituents}"
|
| 63 |
+
|
| 64 |
+
@property
|
| 65 |
+
def feature_names(self) -> list[str]:
|
| 66 |
+
return list(self.constituent_features)
|
| 67 |
+
|
| 68 |
+
@property
|
| 69 |
+
def pt_idx(self) -> int:
|
| 70 |
+
return self.feature_names.index("j1_pt")
|
| 71 |
+
|
| 72 |
+
@property
|
| 73 |
+
def norm_params(self) -> dict[str, tuple[str, float]] | None:
|
| 74 |
+
"""The fitted scales, once prepare() has written them."""
|
| 75 |
+
path = self.cache_folder / "norm_params.npz"
|
| 76 |
+
|
| 77 |
+
return physics.load_norm_params(path) if path.is_file() else None
|
| 78 |
+
|
| 79 |
+
def prepare(self) -> None:
|
| 80 |
+
"""Build the cache. Cached, so reruns are cheap."""
|
| 81 |
+
if all((self.cache_folder / name).is_file() for name in CACHE_FILES):
|
| 82 |
+
log.info(f"Cache already built in {self.cache_folder}")
|
| 83 |
+
return
|
| 84 |
+
|
| 85 |
+
self.cache_folder.mkdir(parents=True, exist_ok=True)
|
| 86 |
+
params = self._prepare_train()
|
| 87 |
+
for split in SPLITS[1:]:
|
| 88 |
+
self._prepare_split(split, params)
|
| 89 |
+
|
| 90 |
+
def load(self, split: str) -> SplitTensors:
|
| 91 |
+
"""One cached split, x as (jets, constituents, features) and y one-hot."""
|
| 92 |
+
if split not in SPLITS:
|
| 93 |
+
raise ValueError(f"Unknown split '{split}', expected one of {SPLITS}")
|
| 94 |
+
|
| 95 |
+
return SplitTensors(x=self._tensor(f"x_{split}"), y=self._tensor(f"y_{split}"))
|
| 96 |
+
|
| 97 |
+
def _prepare_train(self) -> dict[str, tuple[str, float]]:
|
| 98 |
+
"""The training split, which is also where the normalisation is fitted."""
|
| 99 |
+
x, y = self._read("train")
|
| 100 |
+
params = physics.fit_physics_norm(x, self.feature_names)
|
| 101 |
+
physics.save_norm_params(self.cache_folder / "norm_params.npz", params)
|
| 102 |
+
self._save("train", physics.apply_physics_norm(x, self.feature_names, params), y)
|
| 103 |
+
|
| 104 |
+
return params
|
| 105 |
+
|
| 106 |
+
def _prepare_split(self, split: str, params: dict[str, tuple[str, float]]) -> None:
|
| 107 |
+
x, y = self._read(split)
|
| 108 |
+
self._save(split, physics.apply_physics_norm(x, self.feature_names, params), y)
|
| 109 |
+
|
| 110 |
+
def _read(self, split: str) -> tuple[np.ndarray, np.ndarray]:
|
| 111 |
+
"""The shards of one split, each restricted to the leading constituents."""
|
| 112 |
+
transform = partial(
|
| 113 |
+
physics.restrict_and_sort_by_pt,
|
| 114 |
+
pt_idx=self.pt_idx,
|
| 115 |
+
nconstituents=self.nconstituents,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
return reading.read_split(
|
| 119 |
+
self.data_dir,
|
| 120 |
+
split,
|
| 121 |
+
self.feature_names,
|
| 122 |
+
self.max_constituents,
|
| 123 |
+
self.n_classes,
|
| 124 |
+
transform,
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
def _save(self, split: str, x: np.ndarray, y: np.ndarray) -> None:
|
| 128 |
+
"""float32 on disk: the pipeline runs in float64, the models train in float32."""
|
| 129 |
+
np.save(self.cache_folder / f"x_{split}.npy", x.astype(np.float32))
|
| 130 |
+
np.save(self.cache_folder / f"y_{split}.npy", y.astype(np.float32))
|
| 131 |
+
|
| 132 |
+
def _tensor(self, name: str) -> torch.Tensor:
|
| 133 |
+
return torch.from_numpy(np.load(self.cache_folder / f"{name}.npy")).float()
|
loader/physics.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Restricting to the leading constituents and normalising them.
|
| 2 |
+
#
|
| 3 |
+
# Copied from the study's own data module (jet_tagging_gdl,
|
| 4 |
+
# src/data/hls4ml_datamodule.py) rather than rewritten, so that arrays built from the
|
| 5 |
+
# record and arrays built from the original h5 files agree bit for bit: the same stable
|
| 6 |
+
# argsort over all 150 slots, the same truncate-or-pad, the same python-float scales and
|
| 7 |
+
# the same eps.
|
| 8 |
+
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
# Features that live on both sides of zero, so the scale is half the observed range.
|
| 14 |
+
CENTERED_FEATURES = {
|
| 15 |
+
"j1_px", "j1_py", "j1_pz",
|
| 16 |
+
"j1_eta", "j1_etarel", "j1_etarot",
|
| 17 |
+
"j1_phi", "j1_phirel", "j1_phirot",
|
| 18 |
+
"j1_costheta", "j1_costhetarel",
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
# Features that are non-negative by construction, so the scale is the observed maximum.
|
| 22 |
+
POSITIVE_FEATURES = {
|
| 23 |
+
"j1_pt", "j1_ptrel",
|
| 24 |
+
"j1_e", "j1_erel",
|
| 25 |
+
"j1_deltaR",
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def restrict_and_sort_by_pt(x, pt_idx: int, nconstituents: int | None) -> np.ndarray:
|
| 30 |
+
"""Keep the leading *nconstituents* by pT, in descending pT order.
|
| 31 |
+
|
| 32 |
+
The full constituent list is sorted before truncation, so the constituents kept are
|
| 33 |
+
genuinely the highest-pT ones whatever order they appear in on disk. Negating and
|
| 34 |
+
using a stable sort gives a deterministic order for equal-pT constituents (ties keep
|
| 35 |
+
their on-disk order); ``argsort(...)[::-1]`` would instead reverse an unstable
|
| 36 |
+
ascending sort, making tie order arbitrary run to run. Padded slots carry pT = 0 and
|
| 37 |
+
therefore sort to the end.
|
| 38 |
+
"""
|
| 39 |
+
sort_idx = np.argsort(-x[:, :, pt_idx], axis=1, kind="stable")
|
| 40 |
+
x = np.take_along_axis(x, sort_idx[:, :, np.newaxis], axis=1)
|
| 41 |
+
|
| 42 |
+
target = x.shape[1] if (nconstituents is None or nconstituents <= 0) else nconstituents
|
| 43 |
+
if x.shape[1] < target:
|
| 44 |
+
padding = np.zeros((x.shape[0], target - x.shape[1], x.shape[2]), dtype=x.dtype)
|
| 45 |
+
return np.concatenate((x, padding), axis=1)
|
| 46 |
+
|
| 47 |
+
return x[:, :target, :]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def fit_physics_norm(x_train, feature_names) -> dict[str, tuple[str, float]]:
|
| 51 |
+
"""One scale per feature, fitted on the restricted training array alone."""
|
| 52 |
+
params: dict[str, tuple[str, float]] = {}
|
| 53 |
+
for i, name in enumerate(feature_names):
|
| 54 |
+
vals = x_train[:, :, i]
|
| 55 |
+
vmin, vmax = float(vals.min()), float(vals.max())
|
| 56 |
+
if name in CENTERED_FEATURES:
|
| 57 |
+
params[name] = ("centered", 0.5 * (vmax - vmin))
|
| 58 |
+
elif name in POSITIVE_FEATURES:
|
| 59 |
+
params[name] = ("positive", vmax)
|
| 60 |
+
else:
|
| 61 |
+
raise ValueError(f"Feature '{name}' not categorised in CENTERED or POSITIVE sets.")
|
| 62 |
+
|
| 63 |
+
return params
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def apply_physics_norm(x, feature_names, params, eps: float = 1e-8) -> np.ndarray:
|
| 67 |
+
"""Divide each feature by its scale. Zero padding stays zero, so it survives."""
|
| 68 |
+
x_norm = x.copy()
|
| 69 |
+
for i, name in enumerate(feature_names):
|
| 70 |
+
kind, scale = params[name]
|
| 71 |
+
if kind not in {"centered", "positive"}:
|
| 72 |
+
raise ValueError(f"Unknown normalisation kind '{kind}' for feature '{name}'.")
|
| 73 |
+
x_norm[:, :, i] /= (scale + eps)
|
| 74 |
+
|
| 75 |
+
return x_norm
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def save_norm_params(path, params: dict[str, tuple[str, float]]) -> None:
|
| 79 |
+
"""The study's own npz layout, which its diagnostics and feature lookup read back."""
|
| 80 |
+
names = np.array(list(params.keys()), dtype="U64")
|
| 81 |
+
kinds = np.array([params[n][0] for n in names], dtype="U16")
|
| 82 |
+
scales = np.array([params[n][1] for n in names], dtype=np.float32)
|
| 83 |
+
np.savez(Path(path), feature_names=names, kinds=kinds, scales=scales)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def load_norm_params(path) -> dict[str, tuple[str, float]]:
|
| 87 |
+
npz = np.load(Path(path), allow_pickle=False)
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
str(name): (str(kind), float(scale))
|
| 91 |
+
for name, kind, scale in zip(npz["feature_names"], npz["kinds"], npz["scales"])
|
| 92 |
+
}
|
loader/reading.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reading the published shards back into the padded arrays the study's pipeline works on.
|
| 2 |
+
#
|
| 3 |
+
# One row of the record is one jet and its constituent columns are jagged: only the real
|
| 4 |
+
# constituents are stored, in the order they had on disk. Padding them back out to a
|
| 5 |
+
# fixed width is what the study's normalisation and its models expect.
|
| 6 |
+
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import pyarrow as pa
|
| 11 |
+
import pyarrow.parquet as pq
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def shards(data_dir, split: str) -> list[Path]:
|
| 15 |
+
"""The shards of one split, in the order the record numbers them."""
|
| 16 |
+
found = sorted(Path(data_dir).glob(f"{split}-*.parquet"))
|
| 17 |
+
if not found:
|
| 18 |
+
raise FileNotFoundError(f"No {split} shards under {data_dir}")
|
| 19 |
+
|
| 20 |
+
return found
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def dense(table, names, width: int) -> np.ndarray:
|
| 24 |
+
"""Rebuild the (jets, width, features) array, zero-padding the empty slots.
|
| 25 |
+
|
| 26 |
+
float64 throughout: the study fits its normalisation on the h5 arrays, which numpy
|
| 27 |
+
reads as float64, so anything narrower here would shift the scales.
|
| 28 |
+
"""
|
| 29 |
+
# The 16 columns of a row are one jet's constituents, so they share their offsets and
|
| 30 |
+
# the first column places the values of all of them.
|
| 31 |
+
row, slot, n = _positions(_list_array(table[names[0]]), width)
|
| 32 |
+
out = np.zeros((n, width, len(names)), np.float64)
|
| 33 |
+
for f, name in enumerate(names):
|
| 34 |
+
out[row, slot, f] = np.asarray(_list_array(table[name]).flatten())
|
| 35 |
+
|
| 36 |
+
return out
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def labels(table, n_classes: int) -> np.ndarray:
|
| 40 |
+
"""The label column as one-hot rows, the shape the models are trained against."""
|
| 41 |
+
return np.eye(n_classes, dtype=np.float32)[np.asarray(table["label"]).astype(np.intp)]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def read_split(
|
| 45 |
+
data_dir, split: str, names, width: int, n_classes: int, transform
|
| 46 |
+
) -> tuple[np.ndarray, np.ndarray]:
|
| 47 |
+
"""Every shard of one split, transformed shard by shard and concatenated.
|
| 48 |
+
|
| 49 |
+
*transform* is applied before the concatenation, so peak memory holds one dense shard
|
| 50 |
+
rather than the whole split at full width.
|
| 51 |
+
"""
|
| 52 |
+
x, y = [], []
|
| 53 |
+
for shard in shards(data_dir, split):
|
| 54 |
+
table = pq.read_table(shard, columns=[*names, "label"])
|
| 55 |
+
x.append(transform(dense(table, names, width)))
|
| 56 |
+
y.append(labels(table, n_classes))
|
| 57 |
+
|
| 58 |
+
return np.concatenate(x), np.concatenate(y)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _positions(column, width: int) -> tuple[np.ndarray, np.ndarray, int]:
|
| 62 |
+
"""Row and slot of every constituent within the flattened value array.
|
| 63 |
+
|
| 64 |
+
The offsets of a sliced or combined list array need not start at zero and its
|
| 65 |
+
``.values`` may hold entries the array itself does not own, so the slots are counted
|
| 66 |
+
from ``offsets[0]`` and the values come from ``.flatten()``, which respects the slice.
|
| 67 |
+
"""
|
| 68 |
+
offsets = np.asarray(column.offsets).astype(np.int64)
|
| 69 |
+
counts = np.diff(offsets)
|
| 70 |
+
if counts.size and counts.max() > width:
|
| 71 |
+
raise ValueError(
|
| 72 |
+
f"A jet carries {counts.max()} constituents, more than the width {width}"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
starts = offsets[:-1] - offsets[0]
|
| 76 |
+
row = np.repeat(np.arange(len(counts)), counts)
|
| 77 |
+
slot = np.arange(counts.sum()) - np.repeat(starts, counts)
|
| 78 |
+
|
| 79 |
+
return row, slot, len(counts)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _list_array(column) -> pa.ListArray:
|
| 83 |
+
"""One contiguous list array, whether the table handed over chunks or an array."""
|
| 84 |
+
if isinstance(column, pa.ChunkedArray):
|
| 85 |
+
column = column.combine_chunks()
|
| 86 |
+
|
| 87 |
+
return column.chunk(0) if isinstance(column, pa.ChunkedArray) else column
|
requirements.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# What the pipeline in loader/ needs, on python 3.11 or newer. From the root of the
|
| 2 |
+
# downloaded record:
|
| 3 |
+
#
|
| 4 |
+
# pip install -r requirements.txt
|
| 5 |
+
#
|
| 6 |
+
# These are lower bounds rather than pins, and name the major versions the APIs used
|
| 7 |
+
# here belong to rather than floors anyone has tested. The pipeline was run on python
|
| 8 |
+
# 3.11 with numpy 2.4, pyarrow 25, torch 2.9, omegaconf 2.3 and hydra-core 1.3.
|
| 9 |
+
numpy>=1.24
|
| 10 |
+
pyarrow>=14
|
| 11 |
+
torch>=2.0
|
| 12 |
+
omegaconf>=2.3
|
| 13 |
+
hydra-core>=1.3
|
| 14 |
+
|
| 15 |
+
# Only for fetching the record, as the dataset card's example does. Nothing in loader/
|
| 16 |
+
# imports it, so a record already on disk does not need it.
|
| 17 |
+
huggingface-hub>=1.0
|