Load data from LIT jsonl format.
(
path: str, *args, id_fn=input_hash, **kw
)
| 418 | |
| 419 | |
| 420 | def 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 |
nothing calls this directly
no test coverage detected