(self, idx)
| 152 | "dedup": target_item_id == last_history_item_id} |
| 153 | |
| 154 | def pre(self, idx): |
| 155 | instruction = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. |
| 156 | |
| 157 | ### Instruction: |
| 158 | {self.instructs[random.randint(0, len(self.instructs)-1)]}\n |
| 159 | """ |
| 160 | tokens = self.tokenizer.encode(instruction, bos=True, eos=False) |
| 161 | |
| 162 | history = self.get_history(self.data.iloc[idx]) |
| 163 | target_item = history['output'] |
| 164 | history['output'] = '' |
| 165 | negative_prompt_ids = copy.deepcopy(tokens) |
| 166 | |
| 167 | |
| 168 | |
| 169 | prompt = self.generate_prompt(history) |
| 170 | |
| 171 | tokens = tokens + self.tokenizer.encode(prompt, bos=False, eos=False) |
| 172 | history["input"] = "" |
| 173 | |
| 174 | attention_mask = [1] * len(tokens) |
| 175 | |
| 176 | |
| 177 | if self.test: |
| 178 | return { |
| 179 | "input_ids": tokens, |
| 180 | "attention_mask": attention_mask, |
| 181 | |
| 182 | } |
| 183 | |
| 184 | golden_tokens = self.tokenizer.encode(target_item, bos=False, eos=True) |
| 185 | input_prompt_len = len(tokens) |
| 186 | tokens = tokens + golden_tokens |
| 187 | attention_mask = [1] * len(tokens) |
| 188 | labels = [-100] * input_prompt_len + tokens[input_prompt_len:] |
| 189 | |
| 190 | if len(tokens) >= self.max_len: |
| 191 | print(len(tokens)) |
| 192 | |
| 193 | |
| 194 | return { |
| 195 | "input_ids": tokens[-self.max_len:], |
| 196 | "attention_mask": attention_mask[-self.max_len:], |
| 197 | "labels": labels[-self.max_len:], |
| 198 | |
| 199 | } |
| 200 | |
| 201 | |
| 202 | class D3Dataset(CSVBaseDataset): |
nothing calls this directly
no test coverage detected