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

Function load_lit_format

lit_nlp/api/dataset.py:420–441  ·  view source on GitHub ↗

Load data from LIT jsonl format.

(
    path: str, *args, id_fn=input_hash, **kw
)

Source from the content-addressed store, hash-verified

418
419
420def load_lit_format(
421 path: str, *args, id_fn=input_hash, **kw
422) -> Union[Dataset, IndexedDataset]:
423 """Load data from LIT jsonl format."""
424 with open(path + LIT_SPEC_EXTENSION, 'r') as fd:
425 spec = serialize.from_json(fd.read())
426
427 with open(path, 'r') as fd:
428 examples = [serialize.from_json(line) for line in fd.readlines()]
429
430 first_example_keys = set(ex.keys() if (ex := examples[0]) else [])
431 # TODO(b/294233896): remove this once input representations are consolidated.
432 if first_example_keys.issuperset({'id', 'data'}):
433 return IndexedDataset(
434 spec=spec,
435 indexed_examples=cast(list[lit_types.IndexedInput], examples),
436 id_fn=id_fn,
437 *args,
438 **kw,
439 )
440 else:
441 return Dataset(spec=spec, examples=examples, *args, **kw)
442
443
444# TODO(b/202210900): Remove "NoneDataset" once the LIT front-end constructs its

Callers

nothing calls this directly

Calls 4

IndexedDatasetClass · 0.85
DatasetClass · 0.85
keysMethod · 0.80
from_jsonMethod · 0.45

Tested by

no test coverage detected