CLIPPreprocessor 类keras_hub.models.CLIPPreprocessor(
tokenizer,
sequence_length=77,
add_start_token=True,
add_end_token=True,
to_lower=True,
**kwargs
)
CLIP 预处理层,用于对输入进行分词和打包。
此预处理层将执行 2 项操作
tokenizer 对输入进行分词。"token_ids" 和 "padding_mask" 的字典。此层可以直接与 tf.data.Dataset.map 结合使用,以预处理 keras.Model.fit 使用的 (x, y, sample_weight) 格式的字符串数据。
此层的调用方法接受三个参数:x、y 和 sample_weight。x 可以是表示单个段的 Python 字符串或张量,表示一批单个段的 Python 字符串列表,或表示要打包在一起的多个段的张量列表。y 和 sample_weight 都是可选的,可以有任何格式,并且将原样传递。
CLIPPreprocessor 强制输入只有一个段,因为 CLIP 主要用于生成任务。对于具有多段输入(如“glue/mnli”)的任务,请使用为分类目的设计的模型,例如 BERT 或 RoBERTa。
参数
keras_hub.models.CLIPTokenizer 实例。True,预处理器将在每个输入序列前添加分词器的起始词元。True,预处理器将在每个输入序列后附加分词器的结束词元。调用参数
tf.Tensor 或 Python 字符串列表。sequence_length。from_preset 方法CLIPPreprocessor.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",
)
tokenizer 属性keras_hub.models.CLIPPreprocessor.tokenizer
用于对字符串进行分词的分词器。