Download src/axolotl/utils/samplers/utils.py from Alignment-Lab-AI/axolotl2: direct link, hf CLI and curl.
- Browser
- Download file 559 Bytes
-
https://huggingface.co/datasets/Alignment-Lab-AI/axolotl2/resolve/main/src/axolotl/utils/samplers/utils.py
- Command line
-
hf download hf://datasets/Alignment-Lab-AI/axolotl2/src/axolotl/utils/samplers/utils.py
-
curl -L -o utils.py https://huggingface.co/datasets/Alignment-Lab-AI/axolotl2/resolve/main/src/axolotl/utils/samplers/utils.py
559 Bytes
| """ | |
| helper util to calculate dataset lengths | |
| """ | |
| import numpy as np | |
| def get_dataset_lengths(dataset): | |
| if "length" in dataset.data.column_names: | |
| lengths = np.array(dataset.data.column("length")) | |
| elif "position_ids" in dataset.data.column_names: | |
| position_ids = dataset.data.column("position_ids") | |
| lengths = np.array([x[-1] + 1 for x in position_ids]) | |
| else: | |
| input_ids = dataset.data.column("input_ids") | |
| lengths = np.vectorize(len)(np.array(input_ids, dtype=object)) | |
| return lengths | |
| return lengths | |