MCPcopy Create free account
hub / github.com/SkyworkAI/Skywork / group_texts

Function group_texts

train/pt_data_preprocess.py:33–46  ·  view source on GitHub ↗
(examples)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected