MCPcopy Create free account
hub / github.com/Hzfinfdu/Diffusion-BERT / collate_fn

Function collate_fn

predict_downstream_condition.py:118–136  ·  view source on GitHub ↗
(batch_input)

Source from the content-addressed store, hash-verified

116 return wf - wf.mean()
117
118def collate_fn(batch_input):
119 input_ids = pad_sequence([torch.tensor(
120 [tokenizer.cls_token_id] + d['source'] + [tokenizer.mask_token_id] * (args.seq_len - len(d['source']) - 1)
121 ) for d in batch_input], batch_first=True)
122
123 attention_mask = torch.ones_like(input_ids)
124
125 target_mask = torch.stack([torch.cat([
126 torch.zeros(len(d['source']) + 1), torch.ones(input_ids.size(1) - len(d['source']) - 1)
127 ]) for d in batch_input])
128 target_start = torch.tensor([len(d['source']) + 1 for d in batch_input]).long()
129
130 assert input_ids.size() == attention_mask.size() == target_mask.size()
131 return {
132 'input_ids': input_ids.repeat(1, MBR_size).view(-1, input_ids.size(-1)),
133 'attention_mask': attention_mask.repeat(1, MBR_size).view(-1, input_ids.size(-1)),
134 'target_mask': target_mask.repeat(1, MBR_size).view(-1, input_ids.size(-1)),
135 'target_start': target_start
136 }
137
138test_data = Dataloaders[task_name](tokenizer=tokenizer).my_load(splits=['test'])[0]
139test_loader = torch.utils.data.DataLoader(test_data, batch_size=batch_size, collate_fn=collate_fn, num_workers=4, pin_memory=True)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected