With TensorFlow Transform, we can pre-process data using Apache Beam. One of the requirements when setting up such a pipeline is to define a DatasetMetadata object, which contains the schema that has the information needed to parse the data from its on-disk or in-memory format, into tensors.
In the official documentation, we are given an example of the form:
raw_data_metadata = dataset_metadata.DatasetMetadata(
dataset_schema.from_feature_spec({
's': tf.FixedLenFeature([], tf.string),
'y': tf.FixedLenFeature([], tf.float32),
'x': tf.FixedLenFeature([], tf.float32),
}))
This is all fine if your raw data is a dictionary of the form:
{
's': 'example string',
'y': 32.0,
'x': 35.0
}
However, I am somewhat lost when it comes to defining a schema for a SequenceExample. More specifically, consider that my data has the following format:
{
# context features
'length': 5,
# sequence features
'tokens': [
{
'raw': 'The',
'ner-tag': 'O'
},
{
'raw': 'European',
'ner-tag': 'B-org'
},
{
'raw': 'Union',
'ner-tag': 'I-org'
},
{
'raw': 'is',
'ner-tag': 'O'
},
{
'raw': 'nice',
'ner-tag': 'O'
}
...
]
}
Above I have a sentence with 2 sequences:
- ner-tag sequence which is going to be used as a label for the model
- raw sequence which is going to be used as a feature for the model
How can I create a TFT data schema for such examples?
The documentation is a bit absent for this one. Any help much appreciated!