(examples)
| 31 | block_size = args.block_size |
| 32 | # Main data processing function that will concatenate all texts from our dataset and generate chunks of block_size. |
| 33 | def group_texts(examples): |
| 34 | # Concatenate all texts. |
| 35 | concatenated_examples = {k: list(chain(*examples[k])) for k in examples.keys()} |
| 36 | total_length = len(concatenated_examples[list(examples.keys())[0]]) |
| 37 | # We drop the small remainder, we could add padding if the model supported it instead of this drop, you can |
| 38 | # customize this part to your needs. |
| 39 | if total_length >= block_size: |
| 40 | total_length = (total_length // block_size) * block_size |
| 41 | result = { |
| 42 | k: [t[i : i + block_size] for i in range(0, total_length, block_size)] |
| 43 | for k, t in concatenated_examples.items() |
| 44 | } |
| 45 | result["labels"] = result["input_ids"].copy() |
| 46 | return result |
| 47 | |
| 48 | filename = '.'.join(args.input_file.split("/")[-1].split(".")[:-1]) |
| 49 | os.makedirs(args.output_dir, exist_ok=True) |
nothing calls this directly
no outgoing calls
no test coverage detected