Writes given example. The given example is not directly written to the shard, but to a temporary file (or memory). The finalize() method writes all the shards. Args: key (int|bytes): the key associated with the example. Used for shuffling. example: the Example to write to t
(self, key: int | bytes, example: Example)
| 365 | self._example_writer = example_writer |
| 366 | |
| 367 | def write(self, key: int | bytes, example: Example): |
| 368 | """Writes given example. |
| 369 | |
| 370 | The given example is not directly written to the shard, but to a |
| 371 | temporary file (or memory). The finalize() method writes all the shards. |
| 372 | |
| 373 | Args: |
| 374 | key (int|bytes): the key associated with the example. Used for shuffling. |
| 375 | example: the Example to write to the shard. |
| 376 | """ |
| 377 | serialized_example = self._serializer.serialize_example(example=example) |
| 378 | self._shuffler.add(key, serialized_example) |
| 379 | |
| 380 | def finalize(self) -> tuple[list[int], int]: |
| 381 | """Effectively writes examples to the shards.""" |