| 467 | |
| 468 | |
| 469 | class SidSFTDataset_GPR(CSVBaseDataset): |
| 470 | def __init__(self, train_file, tokenizer, max_len=2048, sample=-1, test=False, seed=0, category="", K=4, dedup=False): |
| 471 | super().__init__(train_file, sample, seed, max_len, category, dedup, tokenizer, test) |
| 472 | |
| 473 | # Try to load features from standard location |
| 474 | try: |
| 475 | with open(f'data/{category}/{category}.user.json', 'r') as f: |
| 476 | self.user_features = json.load(f) |
| 477 | except FileNotFoundError: |
| 478 | try: |
| 479 | dataset_dir = os.path.dirname(train_file) |
| 480 | # Assuming structure data/Amazon/train/Sports... -> data/Sports/Sports.user.json |
| 481 | with open(f'data/{category}/{category}.user.json', 'r') as f: |
| 482 | self.user_features = json.load(f) |
| 483 | except: |
| 484 | self.user_features = {} |
| 485 | |
| 486 | try: |
| 487 | with open(f'data/{category}/{category}.item.json', 'r') as f: |
| 488 | self.item_features = json.load(f) |
| 489 | except FileNotFoundError: |
| 490 | self.item_features = {} |
| 491 | |
| 492 | self.get_inputs() |
| 493 | |
| 494 | def get_history(self, row): |
| 495 | row['history_item_sid'] = eval(row['history_item_sid']) |
| 496 | L = len(row['history_item_sid']) |
| 497 | history = "" |
| 498 | history_str = ", ".join(row["history_item_sid"]) |
| 499 | for i in range(L): |
| 500 | if i == 0: |
| 501 | history += row['history_item_sid'][i] |
| 502 | else: |
| 503 | history += ", " + row['history_item_sid'][i] |
| 504 | target_item = str(row['item_sid']) |
| 505 | target_item_sid = row["item_sid"] |
| 506 | last_history_item_sid = row['history_item_sid'][-1] if row['history_item_sid'] else None |
| 507 | 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?", |
| 508 | "output": target_item + "\n", |
| 509 | "history_str": history_str, |
| 510 | "dedup": target_item_sid == last_history_item_sid} |
| 511 | |
| 512 | def pre(self, idx): |
| 513 | instruction = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. |
| 514 | |
| 515 | ### Instruction: |
| 516 | Can you predict the next possible item that the user may expect? |
| 517 | |
| 518 | """ |
| 519 | tokens = self.tokenizer.encode(instruction, bos=True, eos=False) |
| 520 | |
| 521 | row = self.data.iloc[idx] |
| 522 | |
| 523 | # Heterogeneous Prompt Construction |
| 524 | user_id = str(row.get('user_id_original_str', '')) |
| 525 | u_token = self.user_features.get(user_id, '[USER_UNKNOWN]') |
| 526 | e_token = row.get('e_token', '[CTX_HOMEPAGE]') |
nothing calls this directly
no outgoing calls
no test coverage detected