Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for dataset_reader example is wrongly indented #270

Closed
dazcona opened this issue Jun 23, 2021 · 1 comment
Closed

Documentation for dataset_reader example is wrongly indented #270

dazcona opened this issue Jun 23, 2021 · 1 comment
Assignees

Comments

@dazcona
Copy link

dazcona commented Jun 23, 2021

In the documentation for dataset_reader: https://github.com/tensorflow/ranking/blob/master/tensorflow_ranking/g3doc/api_docs/python/tfr/keras/pipeline/DatasetHparams/dataset_reader.md

The following code snippet:

# Write the records to a file.
with tf.io.TFRecordWriter(example_path) as file_writer:
    for _ in range(4):
        x, y = np.random.random(), np.random.random()
    record_bytes = tf.train.Example(features=tf.train.Features(feature={
        "x": tf.train.Feature(float_list=tf.train.FloatList(value=[x])),
        "y": tf.train.Feature(float_list=tf.train.FloatList(value=[y])),
    })).SerializeToString()
    file_writer.write(record_bytes)

should be (see the indentation for record_bytes and its writing to be inside the for loop):

# Write the records to a file.
with tf.io.TFRecordWriter(example_path) as file_writer:
    for _ in range(4):
        x, y = np.random.random(), np.random.random()
        record_bytes = tf.train.Example(features=tf.train.Features(feature={
            "x": tf.train.Feature(float_list=tf.train.FloatList(value=[x])),
            "y": tf.train.Feature(float_list=tf.train.FloatList(value=[y])),
        })).SerializeToString()
        file_writer.write(record_bytes)

Otherwise, only the last two random numbers for x and y are written to the example TFRecord file

@xuanhuiwang xuanhuiwang self-assigned this Jul 13, 2021
@xuanhuiwang
Copy link
Contributor

The documentation is actually derived from the core Tensorflow library and I don't see the issue now.

Feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants