Hey ChatGPT, I'm trying to split a huggingface datasets Dataset class using the usual…
- User
Hey ChatGPT, I'm trying to split a huggingface datasets Dataset class using the usual group_texts function, I will post below. This splits the block size evenly (i.e., given a block size of 1024, it will split the dataset into 1024 token sized chunks). This means that the input_ids and labels returned will be of size 1024.
However, I need the ability to make input_ids and labels of differing sizes, such that I can for example pass input_ids of 128 and labels of 256. Can you please make this happen? (Don't pass any args, as I will be using global variables such as input_block_size and labels_block_size to control the size, similar to how the global variable block_size is used).
def group_texts(examples): # # Concatenate all texts. concatenated_examples = {k: sum(examples[k], []) for k in examples.keys()} total_length = len(concatenated_examples[list(examples.keys())[0]]) # We drop the small remainder, we could add padding if the model supported it instead of this drop, you can # # customize this part to your needs. if total_length >= block_size: total_length = (total_length // block_size) * block_size # # Split by chunks of max_len. result = { k: [t[i : i + block_size] for i in range(0, total_length, block_size)] for k, t in concatenated_examples.items() } result["labels"] = result["input_ids"].copy() return result
- Assistant
- User
Change the function such that there is no overlap whatsoever, as I am using this function primarily under the premise that labels_block_size will always be bigger than input_block_size.
- Assistant