Hey ChatGPT, I just need some small small array slicing code. result["inputids"] has a…
- User
Hey ChatGPT, I just need some small small array slicing code. result["input_ids"] has a total size of input_block_size + label_block_size. I want to break this down such that result["input_ids"] has the first input_block_size elements and result["labels"] has the remaining elements that were not part of the slicing (aka has the last label_block_size elements).
If you're confused, I also have the code I used to make the giant array I need to slice:
input_block_size = 128 label_block_size = 256 def group_texts_uneven(examples): # # Concatenate all texts. combined_block_size = input_block_size + label_block_size 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 >= combined_block_size: total_length = (total_length // combined_block_size) * combined_block_size # # Split by chunks of max_len. result = { k: [t[i : i + combined_block_size] for i in range(0, total_length, combined_block_size)] for k, t in concatenated_examples.items() } result["labels"] = result["input_ids"].copy() return result
- Assistant
To adjust the
group_texts_unevenfunction to slice theinput_idsandlabelsappropriately according to your description, you should follow these steps after creating thecombined_block_sizechunks. You need to separate the firstinput_block_sizeelements for and the last elements for within each chunk of . Here's how you can adjust your function to accomplish this: