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

Class SFTData

data.py:108–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107
108class SFTData(CSVBaseDataset):
109 def __init__(self, train_file, tokenizer, max_len=2048, sample=-1, test = False, seed=0, category="", K=4, dedup=False):
110 super().__init__(train_file, sample, seed, max_len, category, dedup, tokenizer, test)
111
112 self.instructs = [
113 f"Given a list of {category} the user recetenly enjoy, please write a new {category} that the user may bought",
114 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.",
115 f"Based on the user's current gaming preference, please draft a list of potential {category} they may have experienced beforehand.",
116 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.",
117 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.",
118 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.",
119 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?",
120 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.",
121 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.",
122 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.",
123 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."
124 ]
125 self.get_inputs()
126
127
128 def generate_example_prompt(self, data_point):
129 return f"""### Example {data_point["idx"]}:
130{data_point["input"]}
131
132### Response:\n{data_point["output"]}
133"""
134
135 def get_history(self, row):
136 row['history_item_title'] = eval(row['history_item_title'])
137 L = len(row['history_item_title'])
138 history = ""
139 history_str = "::".join(row["history_item_title"])
140 for i in range(L):
141 if i == 0:
142 history += "\"" + row['history_item_title'][i] + "\""
143 else:
144 history += ",\t\"" + row['history_item_title'][i] + "\""
145 target_item = str(row['item_title'])
146 target_item = "\"" + target_item + "\"\n"
147 target_item_id = row["item_id"]
148 last_history_item_id = eval(row["history_item_id"])[-1]
149 return {"input": f"The user has palyed the following {self.category}s before: {history}",
150 "output": target_item,
151 "history_str": history_str,
152 "dedup": target_item_id == last_history_item_id}
153
154 def pre(self, idx):
155 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.
156
157### Instruction:
158{self.instructs[random.randint(0, len(self.instructs)-1)]}\n
159"""
160 tokens = self.tokenizer.encode(instruction, bos=True, eos=False)
161
162 history = self.get_history(self.data.iloc[idx])
163 target_item = history['output']
164 history['output'] = ''
165 negative_prompt_ids = copy.deepcopy(tokens)

Callers 2

trainFunction · 0.90

Calls

no outgoing calls

Tested by 1