MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / EvalSidDataset

Class EvalSidDataset

data.py:597–675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595
596
597class EvalSidDataset(CSVBaseDataset):
598
599 def __init__(self, train_file, tokenizer, max_len=2048, sample=-1, test = False, seed=0, category="", K=4, dedup=False):
600 super().__init__(train_file, sample, seed, max_len, category, dedup, tokenizer, test)
601
602 self.get_inputs()
603
604 def generate_example_prompt(self, data_point):
605 return f"""### Example {data_point["idx"]}:
606{data_point["input"]}
607
608### Response:\n{data_point["output"]}
609"""
610
611 def get_history(self, row):
612 row['history_item_sid'] = eval(row['history_item_sid'])
613 L = len(row['history_item_sid'])
614 history = ""
615 for i in range(L):
616 if i == 0:
617 history += row['history_item_sid'][i]
618 else:
619 history += ", " + row['history_item_sid'][i]
620 target_item = str(row['item_sid'])
621 target_item_sid = row["item_sid"]
622 last_history_item_sid = row['history_item_sid'][-1] if row['history_item_sid'] else None
623 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?",
624 f"Can you predict the next possible item the user may expect, given the following chronological interaction history: {history}",
625 "output": target_item + '\n',
626 "dedup": target_item_sid == last_history_item_sid}
627
628
629 def pre(self, idx):
630 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.
631
632### Instruction:
633Can you predict the next possible item that the user may expect?
634
635"""
636 tokens = self.tokenizer.encode(instruction, bos=True, eos=False)
637
638 history = self.get_history(self.data.iloc[idx])
639 target_item = history['output']
640 history['output'] = ''
641 negative_prompt_ids = copy.deepcopy(tokens)
642
643
644
645 prompt = self.generate_prompt(history)
646
647 tokens = tokens + self.tokenizer.encode(prompt, bos=False, eos=False)
648 history["input"] = ""
649
650 attention_mask = [1] * len(tokens)
651
652
653 if self.test:
654 return {

Callers 2

mainFunction · 0.90

Calls

no outgoing calls

Tested by 1