
使用
TensorFlow
加载和预处理数据
|
377
SequenceExample 包含一个用于上下文数据的 Feature 对象和一个 FeatureLists
对象(包含一个或多个命名的 FeatureList 对象(一个名为“ content”,另一个名为
“ comments”)) 。 每 个 FeatureList 包含一个 Feature 对象的列表,每个对象可以是
一个字节字符串列表、一个 64 位整数列表或一个 float 列表(在本示例中,每个 Feature
代表一个句子或一个注释,可能是以字标识符列表的形式)。构建 SequenceExample,
对其进行序列化和解析的过程与构建 Example 对其进行序列化和解析相似,但是你必须
使用tf.io.parse_single_sequence_example() 解析单个SequenceExample
或者使用 tf.io.parse_sequence_example() 来解析批处理。这两个函数都返回一
个包含上下文特征(作为字典)和特征列表(也作为字典)的元组。如果特征列表包含大
小不同的序列(如上例所示),则可能需要使用 tf.RaggedTensor.from_sparse()
将它们转换为不规则的张量(有关完整代码,请参见 notebook):
parsed_context, parsed_feature_lists = tf.io.parse_single_sequence_example(
serialized_sequence_example, ...