MCPcopy Create free account
hub / github.com/PAIR-code/lit / load

Method load

lit_nlp/api/dataset.py:361–409  ·  view source on GitHub ↗

Load and return additional previously-saved datapoints for this dataset. Args: path: The path to the persisted datapoint file. Returns: (IndexedDataset) A dataset containing the loaded data.

(self, path: str)

Source from the content-addressed store, hash-verified

359 return path
360
361 def load(self, path: str):
362 """Load and return additional previously-saved datapoints for this dataset.
363
364 Args:
365 path: The path to the persisted datapoint file.
366
367 Returns:
368 (IndexedDataset) A dataset containing the loaded data.
369
370 """
371 if not path.endswith(LIT_FILE_EXTENSION):
372 # Try to load data using the base load method. If any data is
373 # returned, then use that. Otherwise try loading the lit json extension
374 # data format.
375 base_dataset = self._base
376 new_dataset = base_dataset.load(path) if base_dataset else None
377
378 if new_dataset is not None:
379 description = (f'{len(new_dataset)} examples from '
380 f'{path}\n{self._base.description()}')
381 return IndexedDataset(
382 base=new_dataset, id_fn=self.id_fn, description=description)
383
384 path += LIT_FILE_EXTENSION
385
386 with open(path, 'r') as fd:
387 examples = [
388 cast(IndexedInput, serialize.from_json(line))
389 for line in fd.readlines()
390 ]
391
392 # Load the side-by-side spec if it exists on disk.
393 spec_path = path + LIT_SPEC_EXTENSION
394 if os.path.exists(spec_path):
395 with open(spec_path, 'r') as fd:
396 spec = serialize.from_json(fd.read())
397 else:
398 spec = None
399
400 description = f'{len(examples)} examples from {path}'
401 if self._base is not None:
402 description += '\n' + self._base.description()
403
404 return IndexedDataset(
405 base=self._base,
406 indexed_examples=examples,
407 spec=spec,
408 description=description,
409 id_fn=self.id_fn)
410
411 def __hash__(self):
412 return hash(tuple([ex['id'] for ex in self._indexed_examples]))

Callers

nothing calls this directly

Calls 4

IndexedDatasetClass · 0.85
loadMethod · 0.45
descriptionMethod · 0.45
from_jsonMethod · 0.45

Tested by

no test coverage detected