MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / MetaPreprocessor

Class MetaPreprocessor

accessory/data/alpaca.py:210–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208
209
210class MetaPreprocessor:
211 def __init__(self):
212 self.routing = {
213 "single_turn_llava": self._preprocess_single_turn_llava,
214 "caption": self._preprocess_caption
215 }
216
217 def preprocess(self, meta_l:List[Dict], recipe: str):
218 return self.routing[recipe](meta_l)
219
220 @ staticmethod
221 def _preprocess_single_turn_llava(meta_l: List[Dict]):
222 new_meta = []
223 for data_item in meta_l:
224 new_meta.append({
225 "image": data_item['image'],
226 "instruction": data_item['conversations'][0]['value'],
227 "output": data_item['conversations'][1]['value']
228 })
229 return new_meta
230
231 @ staticmethod
232 def _preprocess_caption(meta_l: List[Dict]):
233 new_meta = []
234 for data_item in meta_l:
235 caption = data_item['caption']
236 if isinstance(caption, list):
237 caption = random.choice(caption)
238 new_meta.append({
239 "image": data_item['url'],
240 "output": caption
241 })
242
243 return new_meta
244
245
246class FinetuneDistSampler(Sampler):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected