Returns the number of examples written to the given path.
(
self,
examples: Iterable[KeyExample],
path: epath.Path,
)
| 286 | ) |
| 287 | |
| 288 | def write( |
| 289 | self, |
| 290 | examples: Iterable[KeyExample], |
| 291 | path: epath.Path, |
| 292 | ) -> int: |
| 293 | """Returns the number of examples written to the given path.""" |
| 294 | (for_writing, for_counting) = itertools.tee(examples, 2) |
| 295 | |
| 296 | def serialize_examples() -> Iterator[type_utils.KeySerializedExample]: |
| 297 | for k, v in for_writing: |
| 298 | yield k, self._serialize_example(v) |
| 299 | |
| 300 | self._example_writer.write(path=path, examples=serialize_examples()) |
| 301 | num_examples = sum(1 for _ in for_counting) |
| 302 | |
| 303 | return num_examples |
| 304 | |
| 305 | def write_with_beam( |
| 306 | self, |
no test coverage detected