TensorFlow Example vs SequenceExample
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
tf.train.Example and tf.train.SequenceExample are both protobuf formats used with TFRecord, but they solve different data-shape problems. Example is for one record with named features. SequenceExample is for data that has per-sequence context plus ordered feature lists over time or steps.
The most useful mental model is simple: if one training instance is just a flat bag of features, use Example. If one training instance contains a sequence, such as tokens in a sentence or frames in a clip, use SequenceExample.
Use Example for Flat Records
An Example stores one set of named features. Each feature can hold bytes, floats, or integers.
This is a good fit for independent examples such as tabular rows, images with one label, or any record where the internal order of values is not the primary structure.
Use SequenceExample for Ordered Features
SequenceExample separates data into:
- context features, which apply to the whole record
- feature lists, which hold ordered per-step values
This is the right choice when each example includes an ordered list of elements and that order matters to the model.
Choose Based on the Model Input Shape
A practical rule:
- use
Examplewhen each record is already one fixed feature set - use
SequenceExamplewhen each record contains a variable-length sequence with shared context
That means:
- image classification datasets often use
Example - language, speech, clickstream, and event-sequence datasets often fit
SequenceExample
You can still store sequences inside an Example if you serialize them yourself, but SequenceExample makes the structure explicit and easier to parse with sequence-aware input pipelines.
Parsing Also Looks Different
The storage choice affects your input pipeline. A flat Example is typically parsed with tf.io.parse_single_example, while sequence-oriented data usually goes through tf.io.parse_single_sequence_example.
If your parsing code naturally wants fixed per-record fields plus ordered per-step fields, that is a strong hint that SequenceExample is the better format.
Common Pitfalls
The biggest mistake is using SequenceExample just because a feature happens to be a list. A list of values is not automatically a sequence problem. The real question is whether the record has ordered step-wise structure.
Another common issue is misunderstanding the split between context and feature lists. Context belongs to the whole example. Feature lists belong to the time or step dimension.
It is also easy to overcomplicate the format. If a plain Example already matches the data shape, adding SequenceExample only makes parsing harder.
Finally, remember that these formats are storage containers, not model types. The model still decides how to interpret the parsed tensors.
One more practical hint: if batching requires heavy padding or ragged handling because lengths vary by step, you are usually in SequenceExample territory already.
Summary
- '
Exampleis for flat per-record features.' - '
SequenceExampleis for records with ordered feature sequences plus shared context.' - Choose based on the actual shape of one training instance.
- Use context for whole-record metadata and feature lists for per-step data.
- Do not pick
SequenceExampleunless sequence structure is really part of the problem.
Related reading
- Tensorflow executing an ops with a specific core of a CPU
- TensorFlow exponential moving average
- TensorFlow ExportOutputs, PredictOuput, and specifying signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY
- Tensorflow fail with Unable to get element from the feed as bytes. when attempting to restore checkpoint
- TensorFlow failed call to cuInit CUDA_ERROR_NO_DEVICE
- Tensorflow feature column for variable list of values
- Tensorflow failed to create a newwriteablefile when retraining inception
- Tensorflow failed to create a newwriteablefile when retraining inception
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.