Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the data collator #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions safe/trainer/collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def __call__(self, samples: List[Union[List[int], Any, Dict[str, Any]]]):
tokenizer = self.get_tokenizer()

# examples = samples
examples = copy.deepcopy(samples)
inputs = [example.pop(self.input_key, None) for example in examples]
inputs = [sample.get(self.input_key, None) for sample in samples]
mc_labels = (
torch.tensor([example.pop(self.property_key, None) for example in examples]).float()
if self.property_key in examples[0]
torch.tensor([sample.get(self.property_key, None) for sample in samples]).float()
if self.property_key in samples[0]
else None
)

if "input_ids" not in examples[0] and inputs is not None:
if "input_ids" not in samples[0] and inputs is not None:
batch = tokenizer(
inputs,
return_tensors="pt",
Expand All @@ -86,7 +85,7 @@ def __call__(self, samples: List[Union[List[int], Any, Dict[str, Any]]]):
)
else:
batch = tokenizer.pad(
examples,
samples,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pad will fail if you are not using a copy of samples on which you pop the unused key.

It's designed to either tokenize on the fly or pad a pretokenized data. If the data is pretokenized your changes will raise an error.

return_tensors="pt",
padding=True,
pad_to_multiple_of=self.pad_to_multiple_of,
Expand Down
Loading