PaliGemmaCausalLMPreprocessor
类keras_hub.models.PaliGemmaCausalLMPreprocessor(
tokenizer,
image_converter=None,
sequence_length=1024,
add_start_token=True,
add_end_token=True,
**kwargs
)
因果语言建模预处理层的基类。
CausalLMPreprocessor
任务封装了一个 keras_hub.tokenizer.Tokenizer
,以创建一个用于因果语言建模任务的预处理层。它旨在与 keras.models.CausalLM
任务配对使用。
所有 CausalLMPreprocessor
接受单个输入。这可以是单个字符串或一批字符串。请参阅以下示例。这些输入将被分词并填充/截断为固定的序列长度。
此层将始终输出一个 (x, y, sample_weight)
元组,其中 x
是一个包含分词输入的字典,y
包含来自 x
偏移 1 的标记,而 sample_weight
标记 y
包含填充值的位置。x
的确切内容将根据所使用的模型而有所不同。
CausalLMPreprocessor
包含两个额外的方法,generate_preprocess
和 generate_postprocess
,用于生成。请参阅以下示例。
所有 CausalLMPreprocessor
任务都包含一个 from_preset()
构造函数,可用于加载预训练的配置和词汇表。您可以直接在此基类上调用 from_preset()
构造函数,在这种情况下,将自动实例化适合您模型的正确类。
示例。
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
"bert_base_en_uncased",
sequence_length=256, # Optional.
)
# Tokenize, mask and pack a single sentence.
x = "The quick brown fox jumped."
x, y, sample_weight = preprocessor(x)
# Tokenize and pad/truncate a batch of labeled sentences.
x = ["The quick brown fox jumped.", "Call me Ishmael."]
x, y, sample_weight = preprocessor(x)
# With a [`tf.data.Dataset`](https://tensorflowcn.cn/api_docs/python/tf/data/Dataset).
ds = tf.data.Dataset.from_tensor_slices(x)
ds = ds.map(preprocessor, num_parallel_calls=tf.data.AUTOTUNE)
# Generate preprocess and postprocess.
x = preprocessor.generate_preprocess(x) # Tokenized numeric inputs.
x = preprocessor.generate_postprocess(x) # Detokenized string outputs.
from_preset
方法PaliGemmaCausalLMPreprocessor.from_preset(
preset, config_file="preprocessor.json", **kwargs
)
从模型预设实例化一个 keras_hub.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_hub.models.BertTextClassifierPreprocessor.from_preset()
)上调用此方法。
参数
示例
# Load a preprocessor for Gemma generation.
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
"gemma_2b_en",
)
# Load a preprocessor for Bert classification.
preprocessor = keras_hub.models.TextClassifierPreprocessor.from_preset(
"bert_base_en",
)
预设 | 参数 | 描述 |
---|---|---|
pali_gemma_3b_mix_224 | 2.92B | 图像大小 224,混合微调,文本序列长度为 256 |
pali_gemma_3b_224 | 2.92B | 图像大小 224,预训练,文本序列长度为 128 |
pali_gemma_3b_mix_448 | 2.92B | 图像大小 448,混合微调,文本序列长度为 512 |
pali_gemma_3b_448 | 2.92B | 图像大小 448,预训练,文本序列长度为 512 |
pali_gemma_3b_896 | 2.93B | 图像大小 896,预训练,文本序列长度为 512 |
pali_gemma2_mix_3b_224 | 3.03B | 30 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_pt_3b_224 | 3.03B | 30 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma_2_ft_docci_3b_448 | 3.03B | 30 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在 DOCCI 数据集上进行了微调,以改进具有精细细节的描述。 |
pali_gemma2_mix_3b_448 | 3.03B | 30 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_pt_3b_448 | 3.03B | 30 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_pt_3b_896 | 3.04B | 30 亿参数,图像大小 896,SigLIP-So400m 视觉编码器为 27 层,Gemma2 2B 语言模型为 26 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_mix_10b_224 | 9.66B | 100 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_pt_10b_224 | 9.66B | 100 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_ft_docci_10b_448 | 9.66B | 100 亿参数,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在 DOCCI 数据集上进行了微调,以改进具有精细细节的描述。 |
pali_gemma2_mix_10b_448 | 9.66B | 100 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_pt_10b_448 | 9.66B | 100 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_pt_10b_896 | 9.67B | 100 亿参数,图像大小 896,SigLIP-So400m 视觉编码器为 27 层,Gemma2 9B 语言模型为 42 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_mix_28b_224 | 27.65B | 280 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 27B 语言模型为 46 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_mix_28b_448 | 27.65B | 280 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 27B 语言模型为 46 层。此模型已在各种视觉-语言任务和领域上进行了微调。 |
pali_gemma2_pt_28b_224 | 27.65B | 280 亿参数,图像大小 224,SigLIP-So400m 视觉编码器为 27 层,Gemma2 27B 语言模型为 46 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_pt_28b_448 | 27.65B | 280 亿参数,图像大小 448,SigLIP-So400m 视觉编码器为 27 层,Gemma2 27B 语言模型为 46 层。此模型已在混合数据集上进行了预训练。 |
pali_gemma2_pt_28b_896 | 27.65B | 280 亿参数,图像大小 896,SigLIP-So400m 视觉编码器为 27 层,Gemma2 27B 语言模型为 46 层。此模型已在混合数据集上进行了预训练。 |
tokenizer
属性keras_hub.models.PaliGemmaCausalLMPreprocessor.tokenizer
用于分词字符串的分词器。