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

Method pre

ts_rec_data.py:79–124  ·  view source on GitHub ↗
(self, idx)

Source from the content-addressed store, hash-verified

77 "dedup": target_item_sid == last_history_item_sid}
78
79 def pre(self, idx):
80 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.
81
82### Instruction:
83Can you predict the next possible item that the user may expect?
84
85"""
86 tokens = self.tokenizer.encode(instruction, bos=True, eos=False)
87
88 history = self.get_history(self.data.iloc[idx])
89 # print("**********************")
90 # print("history: ", history)
91 target_item = history['output']
92 history['output'] = ''
93 negative_prompt_ids = copy.deepcopy(tokens)
94
95 prompt = self.generate_prompt(history)
96 # print("prompt: ", prompt)
97
98 tokens = tokens + self.tokenizer.encode(prompt, bos=False, eos=False)
99 # print("tokens: ", tokens)
100 # print("**********************")
101 history["input"] = ""
102
103 attention_mask = [1] * len(tokens)
104
105 if self.test:
106 return {
107 "input_ids": tokens,
108 "attention_mask": attention_mask,
109 }
110
111 golden_tokens = self.tokenizer.encode(target_item, bos=False, eos=True)
112 input_prompt_len = len(tokens)
113 tokens = tokens + golden_tokens
114 attention_mask = [1] * len(tokens)
115 labels = [-100] * input_prompt_len + tokens[input_prompt_len:]
116
117 if len(tokens) >= self.max_len:
118 print(f"Sequence length {len(tokens)} exceeds max_len {self.max_len}")
119
120 return {
121 "input_ids": tokens[-self.max_len:],
122 "attention_mask": attention_mask[-self.max_len:],
123 "labels": labels[-self.max_len:],
124 }
125
126 def get_inputs(self):
127 inputs = []

Callers 1

get_inputsMethod · 0.95

Calls 3

get_historyMethod · 0.95
generate_promptMethod · 0.95
encodeMethod · 0.45

Tested by

no test coverage detected