| 352 | |
| 353 | |
| 354 | class SidDataset(CSVBaseDataset): |
| 355 | def __init__(self, train_file, max_len=2048, sample=-1, seed=0, category="", dedup=False): |
| 356 | super().__init__(train_file, sample, seed, max_len, category, dedup, tokenizer=None, test=False) |
| 357 | |
| 358 | self.prompt2history = {} |
| 359 | self.history2target = {} |
| 360 | self.get_inputs() |
| 361 | |
| 362 | def get_history(self, row): |
| 363 | row['history_item_sid'] = eval(row['history_item_sid']) |
| 364 | L = len(row['history_item_sid']) |
| 365 | history = "" |
| 366 | history_str = "::".join(row["history_item_sid"]) |
| 367 | for i in range(L): |
| 368 | if i == 0: |
| 369 | history += row['history_item_sid'][i] |
| 370 | else: |
| 371 | history += ", " + row['history_item_sid'][i] |
| 372 | target_item = str(row['item_sid']) |
| 373 | target_item_sid = row["item_sid"] |
| 374 | last_history_item_sid = row['history_item_sid'][-1] if row['history_item_sid'] else None |
| 375 | return {"input": f"The user has interacted with items {history} in chronological order. Can you predict the next possible item that the user may expect?", |
| 376 | # Analyze user preferences and then predict the semantic ID of the next item. |
| 377 | "output": target_item + "\n", |
| 378 | "history_str": history_str, |
| 379 | "dedup": target_item_sid == last_history_item_sid} |
| 380 | |
| 381 | def pre(self, idx): |
| 382 | history = self.get_history(self.data.iloc[idx]) |
| 383 | target_item = history['output'] |
| 384 | history['output'] = '' |
| 385 | |
| 386 | prompt = self.generate_prompt(history) |
| 387 | self.prompt2history[prompt] = history["history_str"] |
| 388 | self.history2target[history["history_str"]] = target_item |
| 389 | |
| 390 | return { |
| 391 | "prompt": prompt, |
| 392 | "completion": target_item, |
| 393 | |
| 394 | } |
| 395 | |
| 396 | |
| 397 | class SidSFTDataset(CSVBaseDataset): |
no outgoing calls