DebertaV3MaskedLMPreprocessor 类keras_nlp.models.DebertaV3MaskedLMPreprocessor(
tokenizer,
sequence_length=512,
truncate="round_robin",
mask_selection_rate=0.15,
mask_selection_length=96,
mask_token_rate=0.8,
random_token_rate=0.1,
**kwargs
)
用于掩码语言建模任务的 DeBERTa 预处理。
此预处理层将为掩码语言建模任务准备输入。它主要用于与 keras_nlp.models.DebertaV3MaskedLM 任务模型一起使用。预处理将分多个步骤进行。
tokenizer 对任意数量的输入段进行分词。"<s>"、"</s>" 和 "<pad>" 符号打包在一起,即在整个序列的开头添加一个 "<s>",在每个段之间添加 "</s></s>",并在整个序列的末尾添加一个 "</s>"。mask_selection_rate 控制。(x, y, sample_weight) 元组,适合使用 keras_nlp.models.DebertaV3MaskedLM 任务模型进行训练。参数
keras_nlp.models.DebertaV3Tokenizer 实例。mask_token_rate 必须介于 0 到 1 之间,表示选择用于掩码的符号时,掩码符号被替换的频率。默认值为 0.8。random_token_rate 必须介于 0 到 1 之间,表示选择用于掩码的符号时,随机符号被替换的频率。注意:mask_token_rate + random_token_rate <= 1,对于 (1 - mask_token_rate - random_token_rate),符号不会被更改。默认值为 0.1。sequence_length 的算法。该值可以是 round_robin 或 waterfall"round_robin": 可用空间每次分配一个符号,以循环的方式分配给仍然需要一些空间的输入,直到达到限制。"waterfall": 预算的分配使用“瀑布”算法,以从左到右的方式分配配额,并填充分配,直到预算用完。它支持任意数量的段。示例
直接在数据上调用该层。
preprocessor = keras_nlp.models.DebertaV3MaskedLMPreprocessor.from_preset(
"deberta_v3_base_en"
)
# Tokenize and mask a single sentence.
preprocessor("The quick brown fox jumped.")
# Tokenize and mask a batch of single sentences.
preprocessor(["The quick brown fox jumped.", "Call me Ishmael."])
# Tokenize and mask sentence pairs.
# In this case, always convert input to tensors before calling the layer.
first = tf.constant(["The quick brown fox jumped.", "Call me Ishmael."])
second = tf.constant(["The fox tripped.", "Oh look, a whale."])
preprocessor((first, second))
使用 tf.data.Dataset 进行映射。
preprocessor = keras_nlp.models.DebertaV3MaskedLMPreprocessor.from_preset(
"deberta_v3_base_en"
)
first = tf.constant(["The quick brown fox jumped.", "Call me Ishmael."])
second = tf.constant(["The fox tripped.", "Oh look, a whale."])
# Map single sentences.
ds = tf.data.Dataset.from_tensor_slices(first)
ds = ds.map(preprocessor, num_parallel_calls=tf.data.AUTOTUNE)
# Map sentence pairs.
ds = tf.data.Dataset.from_tensor_slices((first, second))
# Watch out for tf.data's default unpacking of tuples here!
# Best to invoke the `preprocessor` directly in this case.
ds = ds.map(
lambda first, second: preprocessor(x=(first, second)),
num_parallel_calls=tf.data.AUTOTUNE,
)
from_preset 方法DebertaV3MaskedLMPreprocessor.from_preset(preset, **kwargs)
从模型预设实例化一个 keras_nlp.models.Preprocessor。
预设是一个包含用于保存和加载预训练模型的配置、权重和其他文件资产的目录。preset 可以作为以下之一传递
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''./bert_base_en'对于任何 Preprocessor 子类,您都可以运行 cls.presets.keys() 来列出该类上所有可用的内置预设。
由于通常存在针对给定模型的多个预处理类,因此此方法应在特定子类上调用,例如 keras_nlp.models.BertTextClassifierPreprocessor.from_preset()。
参数
示例
# Load a preprocessor for Gemma generation.
preprocessor = keras_nlp.models.GemmaCausalLMPreprocessor.from_preset(
"gemma_2b_en",
)
# Load a preprocessor for Bert classification.
preprocessor = keras_nlp.models.BertTextClassifierPreprocessor.from_preset(
"bert_base_en",
)
| 预设名称 | 参数 | 描述 |
|---|---|---|
| deberta_v3_extra_small_en | 70.68M | 12 层 DeBERTaV3 模型,保持大小写。在英文维基百科、BookCorpus 和 OpenWebText 上训练。 |
| deberta_v3_small_en | 141.30M | 6 层 DeBERTaV3 模型,保持大小写。在英文维基百科、BookCorpus 和 OpenWebText 上训练。 |
| deberta_v3_base_en | 183.83M | 12 层 DeBERTaV3 模型,保持大小写。在英文维基百科、BookCorpus 和 OpenWebText 上训练。 |
| deberta_v3_large_en | 434.01M | 24 层 DeBERTaV3 模型,保持大小写。在英文维基百科、BookCorpus 和 OpenWebText 上训练。 |
| deberta_v3_base_multi | 278.22M | 12 层 DeBERTaV3 模型,保持大小写。在 2.5TB 多语言 CC100 数据集上训练。 |
tokenizer 属性keras_nlp.models.DebertaV3MaskedLMPreprocessor.tokenizer
用于对字符串进行分词的分词器。