I am trying to use someone else's code where it appears they are able to access a feature in a tfrecord example by simply subscripting with a string. Here is a brief version of their code
def foo(example):
text = example["text"]
subtokens = some_other_function(text)
features = {
"my_subtokens": subtokens}
return(features)
input_files = ['test.tfrecord']
d = tf.data.Dataset.from_tensor_slices(tf.constant(input_files))
d = d.map(foo)
The key line in there is text = example["text"]. How were they able to get it so they could access a feature simply by subscripting the example with a string? Every time I try to write a tf record and then use a string as a key, I get the error TypeError: Only integers, slices (':'), ellipsis ('...'), tf.newaxis ('None') and scalar tf.int32/tf.int64 tensors are valid indices
To make my tfrecord, I just copied the code exactly from this website https://www.tensorflow.org/tutorials/load_data/tfrecord