RECODE-H / annotations /annotation_17 /LESS /less /train /data_arguments.py
mcy98's picture
Upload folder using huggingface_hub
f2cf608 verified
Raw History Blame Contribute Delete
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
@dataclass
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}")