网页 综合 更新时间 2026-11-15 00:14:16

MultiSegmentPacker layer

自动蜘蛛 keras.io 正文约 1565 字
MultiSegmentPacker layer
Packs multiple sequences into a single fixed width model input.
This layer packs multiple input sequences into a single fixed width sequence containing start and end delimeters, forming a dense input suitable for a classification task for BERT and BERT-like models.
Takes as input a tuple of token segments. Each tuple element should contain the tokens for a segment, passed as tensors, tf.RaggedTensors, or lists. For batched input, each element in the tuple of segments should be a list of lists or a rank two tensor. For unbatched inputs, each element should be a list or rank one tensor.
The layer will process inputs as follows: - Truncate all input segments to fit within sequence_length according to the truncate strategy. - Concatenate all input segments, adding a single start_value at the start of the entire sequence, and multiple end_values at the end of each segment. - Pad the resulting sequence to sequence_length using pad_tokens. - Calculate a separate tensor of "segment ids", with integer type and the same shape as the packed token output, where each integer index of the segment the token originated from. The segment id of the start_value is always 0, and the segment id of each end_value is the segment that precedes it.
A tuple with two elements. The first is the dense, packed token sequence. The second is an integer tensor of the same shape, containing the segment ids.
Pack a single input for classification.
Pack multiple inputs for classification.
Pack multiple inputs for classification with different sep tokens.
Devlin et al., 2018.
访问原文 返回搜索 https://keras.io/keras_hub/api/preprocessing_layers/multi_segment_packer/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。