Download annotations/annotation_17/LESS/less/train/data_arguments.py from mcy98/RECODE-H: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_17/LESS/less/train/data_arguments.py
- Command line
-
hf download hf://datasets/mcy98/RECODE-H/annotations/annotation_17/LESS/less/train/data_arguments.py
-
curl -L -o data_arguments.py https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_17/LESS/less/train/data_arguments.py
2.27 kB
| import logging | |
| from dataclasses import dataclass, field | |
| from typing import List, Optional | |
| import torch | |
| logger = logging.getLogger(__name__) | |
| def none_or_str(value): | |
| print(value) | |
| if value == "None": | |
| return None | |
| else: | |
| return value | |
| class DataArguments: | |
| train_files: List[str] = field(default_factory=list, metadata={ | |
| "help": "The input training data files (multiple files in glob format)."}) | |
| overwrite_cache: bool = field( | |
| default=False, metadata={"help": "Overwrite the cached training and evaluation sets"} | |
| ) | |
| preprocessing_num_workers: Optional[int] = field( | |
| default=None, | |
| metadata={"help": "The number of processes to use for the preprocessing."}, | |
| ) | |
| max_seq_length: Optional[int] = field( | |
| default=None, | |
| metadata={ | |
| "help": ("The maximum total input sequence length after tokenization. Sequences longer than this will be truncated,") | |
| }, | |
| ) | |
| sample_data_seed: int = field( | |
| default=42, metadata={"help": ("The seed used for data sampling.")}, | |
| ) | |
| percentage: float = field( | |
| default=1.0, metadata={"help": ("Sampling percentage for each dataset")}, | |
| ) | |
| def get_data_statistics(lm_datasets): | |
| """ Get the data statistics of the dataset. """ | |
| def get_length(examples): | |
| lengths = [len(ids) for ids in examples["input_ids"]] | |
| completion_lens = [] | |
| for labels in examples["labels"]: | |
| com_len = (torch.tensor(labels) > -1).sum() | |
| completion_lens.append(com_len) | |
| return {"length": lengths, "c_length": completion_lens} | |
| if not isinstance(lm_datasets, dict): | |
| lm_datasets = {"train": lm_datasets} | |
| for key in lm_datasets: | |
| dataset = lm_datasets[key] | |
| data_size = len(dataset) | |
| dataset = dataset.map(get_length, batched=True) | |
| lengths = dataset["length"] | |
| length = sum(lengths) / len(lengths) | |
| c_lengths = dataset["c_length"] | |
| c_length = sum(c_lengths) / len(c_lengths) | |
| print( | |
| f"[{key} set] examples: {data_size}; # avg tokens: {length}") | |
| print( | |
| f"[{key} set] examples: {data_size}; # avg completion tokens: {c_length}") | |