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

RandomSwap layer

自动蜘蛛 keras.io 正文约 1544 字
RandomSwap layer
Augments input by randomly swapping words.
This layer comes in handy when you need to generate new data using swap augmentations as described in the paper [EDA: Easy Data Augmentation Techniques for Boosting Performance on Text Classification Tasks] (https://arxiv.org/pdf/1901.11196.pdf). The layer expects the inputs to be pre-split into token level inputs. This allows control over the level of augmentation, you can split by character for character level swaps, or by word for word level swaps.
Input data should be passed as tensors, tf.RaggedTensors, or lists. For batched input, inputs should be a list of lists or a rank two tensor. For unbatched inputs, each element should be a list or a rank one tensor.
This layer runs on a pure Python/NumPy code path by default, so it works inside a Grain pipeline and does not require TensorFlow. Randomness is derived from seed together with a stable hash of the record being augmented, so the output does not depend on how many Grain workers are running or on the order records are seen in. The tradeoff is that an identical record is augmented identically on every epoch. To vary the augmentation per epoch, pass your own generator as rng, for example from grain.RandomMapTransform, which derives one from the element index.
Character level usage.
Usage with skip_list.
Usage with skip_py_fn.
Usage in a Grain pipeline, with per epoch variation. Grain derives the generator from its own seed and the element index, so a record that comes round again on the next epoch is augmented differently.
访问原文 返回搜索 https://keras.io/keras_hub/api/preprocessing_layers/random_swap/
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。