MCPcopy Create free account
hub / github.com/OpenBMB/ToolBench / SupervisedDataset

Class SupervisedDataset

toolbench/train/train.py:169–191  ·  view source on GitHub ↗

Dataset for supervised fine-tuning.

Source from the content-addressed store, hash-verified

167
168
169class SupervisedDataset(Dataset):
170 """Dataset for supervised fine-tuning."""
171
172 def __init__(self, raw_data, tokenizer: transformers.PreTrainedTokenizer, template="tool-llama"):
173 super(SupervisedDataset, self).__init__()
174
175 rank0_print("Formatting inputs...")
176 sources = [example["conversations"] for example in raw_data]
177 self.template = template
178 data_dict = preprocess(sources, tokenizer, self.template)
179 self.input_ids = data_dict["input_ids"]
180 self.labels = data_dict["labels"]
181 self.attention_mask = data_dict["attention_mask"]
182
183 def __len__(self):
184 return len(self.input_ids)
185
186 def __getitem__(self, i) -> Dict[str, torch.Tensor]:
187 return dict(
188 input_ids=self.input_ids[i],
189 labels=self.labels[i],
190 attention_mask=self.attention_mask[i],
191 )
192
193
194class LazySupervisedDataset(Dataset):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected