Refactor code for generating and writing out examples into a function.
Refactor code for generating and writing out examples into a function.

PiperOrigin-RevId: 451223996

google/deepvariant,google/deepvariant,google/deepvariant