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

Class D3Dataset

data.py:202–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201
202class D3Dataset(CSVBaseDataset):
203 def __init__(self, train_file, max_len=2048, sample=-1, seed=0, category="", dedup=False):
204 super().__init__(train_file, sample, seed, max_len, category, dedup, tokenizer=None, test=False)
205
206 self.prompt2history = {}
207 self.history2target = {}
208 self.instructs = [
209 f"Given a list of {category} the user recetenly enjoy, please write a new {category} that the user may bought",
210 f"Considering the {category} that has recently captured the user's interest, kindly create a compilation of other {category} that the user might have played prior to this.",
211 f"Based on the user's current gaming preference, please draft a list of potential {category} they may have experienced beforehand.",
212 f"Reflecting on the {category} the user has taken pleasure in recently, we request that you formulate a list of {category} that may have preceded the user's current enjoyment.",
213 f"In light of the recent gaming enjoyment expressed by the user, please assemble a list of {category} that could potentially include past titles the user has engaged with.",
214 f"Taking into account the {category} that has lately provided enjoyment to the user, please put together an inventory of {category} the user might have explored previously.",
215 f"Given the user's newfound enjoyment of a particular {category}, would you kindly generate a roster of other {category} that might resonate with their past gaming experiences?",
216 f"In response to the user's recent fondness for a specific {category}, we seek your assistance in listing possible {category} the user may have delighted in earlier.",
217 f"With respect to the {category} currently enjoyed by the user, please compile a suggestive list of {category} they may have played in the past.",
218 f"Bearing in mind the {category} that the user has recently been enthralled by, please construct a catalog of other {category} that the user potentially partook in beforehand.",
219 f"In relation to the user's recent entertainment with a given {category}, it would be appreciated if you could curate a list of {category} that might form part of the user's previous gaming history."
220 ]
221 self.get_inputs()
222
223 def get_history(self, row):
224 row['history_item_title'] = eval(row['history_item_title'])
225 L = len(row['history_item_title'])
226 history = ""
227 history_str = "::".join(row["history_item_title"])
228 for i in range(L):
229 if i == 0:
230 history += "\"" + row['history_item_title'][i] + "\""
231 else:
232 history += ",\t\"" + row['history_item_title'][i] + "\""
233 target_item = str(row['item_title'])
234 target_item = "\"" + target_item + "\"\n"
235 target_item_id = row["item_id"]
236 last_history_item_id = eval(row["history_item_id"])[-1]
237 return {"input": f"The user has palyed the following {self.category}s before: {history}",
238 "output": target_item,
239 "history_str": history_str,
240 "dedup": target_item_id == last_history_item_id}
241
242 def pre(self, idx):
243 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.
244
245### Instruction:
246{self.instructs[random.randint(0, len(self.instructs)-1)]}\n
247"""
248 history = self.get_history(self.data.iloc[idx])
249 target_item = history['output']
250 history['output'] = ''
251
252 prompt = self.generate_prompt(history)
253 self.prompt2history[instruction + prompt] = history["history_str"]
254 self.history2target[history["history_str"]] = target_item
255
256 return {
257 "prompt": instruction + prompt,
258 "completion": target_item,
259 }

Callers 1

Calls

no outgoing calls

Tested by 1