clip
mindnlp.transformers.models.clip.configuration_clip.CLIPConfig
¶
Bases: PretrainedConfig
[CLIPConfig] is the configuration class to store the configuration of a [CLIPModel]. It is used to instantiate
a CLIP model according to the specified arguments, defining the text model and vision model configs. Instantiating
a configuration with the defaults will yield a similar configuration to that of the CLIP
openai/clip-vit-base-patch32 architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
text_config
|
Dictionary of configuration options used to initialize [
TYPE:
|
vision_config
|
Dictionary of configuration options used to initialize [
TYPE:
|
projection_dim
|
Dimentionality of text and vision projection layers.
TYPE:
|
logit_scale_init_value
|
The inital value of the logit_scale paramter. Default is used as per the original CLIP implementation.
TYPE:
|
kwargs
|
Dictionary of keyword arguments.
TYPE:
|
Example
>>> from transformers import CLIPConfig, CLIPModel
...
>>> # Initializing a CLIPConfig with openai/clip-vit-base-patch32 style configuration
>>> configuration = CLIPConfig()
...
>>> # Initializing a CLIPModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
>>> model = CLIPModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
...
>>> # We can also initialize a CLIPConfig from a CLIPTextConfig and a CLIPVisionConfig
>>> from transformers import CLIPTextConfig, CLIPVisionConfig
...
>>> # Initializing a CLIPText and CLIPVision configuration
>>> config_text = CLIPTextConfig()
>>> config_vision = CLIPVisionConfig()
...
>>> config = CLIPConfig.from_text_vision_configs(config_text, config_vision)
Source code in mindnlp\transformers\models\clip\configuration_clip.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPConfig.__init__(text_config=None, vision_config=None, projection_dim=512, logit_scale_init_value=2.6592, **kwargs)
¶
Initializes a new instance of CLIPConfig.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
text_config
|
The configuration for text inputs. If provided, overrides default values. Default is None.
TYPE:
|
vision_config
|
The configuration for vision inputs. If provided, overrides default values. Default is None.
TYPE:
|
projection_dim
|
The dimension of the projection. Default is 512.
TYPE:
|
logit_scale_init_value
|
The initial value for logit scaling. Default is 2.6592.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If text_config or vision_config are not of type dict. |
ValueError
|
If projection_dim or logit_scale_init_value are not of type int or float respectively. |
KeyError
|
If 'transformers_version' key is present in text_config or vision_config. |
AttributeError
|
If 'id2label' key is not present in vision_config. |
Source code in mindnlp\transformers\models\clip\configuration_clip.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPConfig.from_text_vision_configs(text_config, vision_config, **kwargs)
classmethod
¶
Instantiate a [CLIPConfig] (or a derived class) from clip text model configuration and clip vision model
configuration.
| RETURNS | DESCRIPTION |
|---|---|
|
[ |
Source code in mindnlp\transformers\models\clip\configuration_clip.py
509 510 511 512 513 514 515 516 517 518 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPTextConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [CLIPTextModel]. It is used to instantiate a CLIP
text encoder according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the text encoder of the CLIP
openai/clip-vit-base-patch32 architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_size
|
Vocabulary size of the CLIP text model. Defines the number of different tokens that can be represented by
the
TYPE:
|
hidden_size
|
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
intermediate_size
|
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
projection_dim
|
Dimentionality of text and vision projection layers.
TYPE:
|
num_hidden_layers
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
max_position_embeddings
|
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
hidden_act
|
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
layer_norm_eps
|
The epsilon used by the layer normalization layers.
TYPE:
|
attention_dropout
|
The dropout ratio for the attention probabilities.
TYPE:
|
initializer_range
|
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
initializer_factor
|
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
pad_token_id
|
Padding token id.
TYPE:
|
bos_token_id
|
Beginning of stream token id.
TYPE:
|
eos_token_id
|
End of stream token id.
TYPE:
|
Example
>>> from transformers import CLIPTextConfig, CLIPTextModel
...
>>> # Initializing a CLIPTextConfig with openai/clip-vit-base-patch32 style configuration
>>> configuration = CLIPTextConfig()
...
>>> # Initializing a CLIPTextModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
>>> model = CLIPTextModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\clip\configuration_clip.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPTextConfig.__init__(vocab_size=49408, hidden_size=512, intermediate_size=2048, projection_dim=512, num_hidden_layers=12, num_attention_heads=8, max_position_embeddings=77, hidden_act='quick_gelu', layer_norm_eps=1e-05, attention_dropout=0.0, initializer_range=0.02, initializer_factor=1.0, pad_token_id=1, bos_token_id=49406, eos_token_id=49407, **kwargs)
¶
Initialize CLIPTextConfig.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_size
|
The size of the vocabulary. Default is 49408.
TYPE:
|
hidden_size
|
The size of the hidden layers. Default is 512.
TYPE:
|
intermediate_size
|
The size of the intermediate layers. Default is 2048.
TYPE:
|
projection_dim
|
The projection dimension. Default is 512.
TYPE:
|
num_hidden_layers
|
The number of hidden layers. Default is 12.
TYPE:
|
num_attention_heads
|
The number of attention heads. Default is 8.
TYPE:
|
max_position_embeddings
|
The maximum position embeddings. Default is 77.
TYPE:
|
hidden_act
|
The type of activation function for the hidden layers. Default is 'quick_gelu'.
TYPE:
|
layer_norm_eps
|
Epsilon value for layer normalization. Default is 1e-05.
TYPE:
|
attention_dropout
|
The dropout rate for attention layers. Default is 0.0.
TYPE:
|
initializer_range
|
The range for parameter initializers. Default is 0.02.
TYPE:
|
initializer_factor
|
The factor for parameter initializers. Default is 1.0.
TYPE:
|
pad_token_id
|
The ID of the padding token. Default is 1.
TYPE:
|
bos_token_id
|
The ID of the beginning of sequence token. Default is 49406.
TYPE:
|
eos_token_id
|
The ID of the end of sequence token. Default is 49407.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\clip\configuration_clip.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPTextConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
classmethod
¶
Creates a CLIPTextConfig instance from a pretrained model.
| PARAMETER | DESCRIPTION |
|---|---|
cls
|
The class object.
TYPE:
|
pretrained_model_name_or_path
|
The name or path of the pretrained model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PretrainedConfig
|
A CLIPTextConfig instance initialized with the configuration specified by the pretrained model.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the input parameters are not of the expected types. |
ValueError
|
If the configuration dictionary does not contain the required information. |
Warning
|
If the model type being used for instantiation does not match the class's model type, which may lead to errors. |
Source code in mindnlp\transformers\models\clip\configuration_clip.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPVisionConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [CLIPVisionModel]. It is used to instantiate a
CLIP vision encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the vision encoder of the CLIP
openai/clip-vit-base-patch32 architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
hidden_size
|
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
intermediate_size
|
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
projection_dim
|
Dimentionality of text and vision projection layers.
TYPE:
|
num_hidden_layers
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
num_channels
|
The number of input channels.
TYPE:
|
image_size
|
The size (resolution) of each image.
TYPE:
|
patch_size
|
The size (resolution) of each patch.
TYPE:
|
hidden_act
|
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
layer_norm_eps
|
The epsilon used by the layer normalization layers.
TYPE:
|
attention_dropout
|
The dropout ratio for the attention probabilities.
TYPE:
|
initializer_range
|
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
initializer_factor
|
A factor for initializing all weight matrices (should be kept to 1, used internally for initialization testing).
TYPE:
|
Example
>>> from transformers import CLIPVisionConfig, CLIPVisionModel
...
>>> # Initializing a CLIPVisionConfig with openai/clip-vit-base-patch32 style configuration
>>> configuration = CLIPVisionConfig()
...
>>> # Initializing a CLIPVisionModel (with random weights) from the openai/clip-vit-base-patch32 style configuration
>>> model = CLIPVisionModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\clip\configuration_clip.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPVisionConfig.__init__(hidden_size=768, intermediate_size=3072, projection_dim=512, num_hidden_layers=12, num_attention_heads=12, num_channels=3, image_size=224, patch_size=32, hidden_act='quick_gelu', layer_norm_eps=1e-05, attention_dropout=0.0, initializer_range=0.02, initializer_factor=1.0, **kwargs)
¶
Initialize a CLIPVisionConfig object with the provided configuration parameters.
| PARAMETER | DESCRIPTION |
|---|---|
hidden_size
|
The size of the hidden layers in the network.
TYPE:
|
intermediate_size
|
The size of the intermediate hidden layers in the network.
TYPE:
|
projection_dim
|
The dimension of the projected embeddings.
TYPE:
|
num_hidden_layers
|
The number of hidden layers in the network.
TYPE:
|
num_attention_heads
|
The number of attention heads in the network.
TYPE:
|
num_channels
|
The number of channels in the input image.
TYPE:
|
image_size
|
The size of the input image.
TYPE:
|
patch_size
|
The size of the image patch used in the network.
TYPE:
|
hidden_act
|
The activation function used in the hidden layers.
TYPE:
|
layer_norm_eps
|
The epsilon value for layer normalization.
TYPE:
|
attention_dropout
|
The dropout rate for attention layers.
TYPE:
|
initializer_range
|
The range for parameter initialization.
TYPE:
|
initializer_factor
|
The factor for parameter initialization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any of the input parameters are invalid or out of range. |
Source code in mindnlp\transformers\models\clip\configuration_clip.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
mindnlp.transformers.models.clip.configuration_clip.CLIPVisionConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
classmethod
¶
Load a pretrained configuration from a given model name or path.
| PARAMETER | DESCRIPTION |
|---|---|
cls
|
The class object.
TYPE:
|
pretrained_model_name_or_path
|
The name or path of the pretrained model. It can be either a string representing the name of the model or a path-like object pointing to the model location.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PretrainedConfig
|
The loaded pretrained configuration.
TYPE:
|
This method is a class method that allows loading a pretrained configuration. It takes in the class object 'cls' and the name or path of the pretrained model 'pretrained_model_name_or_path' as parameters. The method returns an instance of type 'PretrainedConfig', which represents the loaded pretrained configuration.
The 'pretrained_model_name_or_path' parameter can be either a string representing the name of the pretrained model or a path-like object pointing to the location of the model. It is used to identify and locate the pretrained model that needs to be loaded.
Note: If the loaded configuration belongs to the 'clip' model type, the 'config_dict' will be updated to use the 'vision_config' sub-dictionary. Additionally, if the 'model_type' attribute is present in the 'cls' class and the loaded configuration's 'model_type' is different from 'cls.model_type', a warning will be logged indicating that instantiating a model of different types may lead to errors.
Example
>>> config = CLIPVisionConfig.from_pretrained("clip_model")
...
Source code in mindnlp\transformers\models\clip\configuration_clip.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
mindnlp.transformers.models.clip.image_processing_clip.CLIPImageProcessor
¶
Bases: BaseImageProcessor
Constructs a CLIP image processor.
| PARAMETER | DESCRIPTION |
|---|---|
do_resize
|
Whether to resize the image's (height, width) dimensions to the specified
TYPE:
|
size
|
224}
TYPE:
|
resample
|
Resampling filter to use if resizing the image. Can be overridden by
TYPE:
|
do_center_crop
|
Whether to center crop the image to the specified
TYPE:
|
crop_size
|
Size of the output image after applying
TYPE:
|
do_rescale
|
Whether to rescale the image by the specified scale
TYPE:
|
rescale_factor
|
Scale factor to use if rescaling the image. Can be overridden by
TYPE:
|
do_normalize
|
Whether to normalize the image. Can be overridden by
TYPE:
|
image_mean
|
Mean to use if normalizing the image. This is a float or list of floats the length of the number of
channels in the image. Can be overridden by the
TYPE:
|
image_std
|
Standard deviation to use if normalizing the image. This is a float or list of floats the length of the
number of channels in the image. Can be overridden by the
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB.
TYPE:
|
Source code in mindnlp\transformers\models\clip\image_processing_clip.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
mindnlp.transformers.models.clip.image_processing_clip.CLIPImageProcessor.__init__(do_resize=True, size=None, resample=PILImageResampling.BICUBIC, do_center_crop=True, crop_size=None, do_rescale=True, rescale_factor=1 / 255, do_normalize=True, image_mean=None, image_std=None, do_convert_rgb=True, **kwargs)
¶
Initializes a CLIPImageProcessor object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The CLIPImageProcessor object itself.
|
do_resize
|
A flag indicating whether to resize the image. Defaults to True.
TYPE:
|
size
|
A dictionary containing the size of the image. Defaults to None.
TYPE:
|
resample
|
The resampling method for resizing the image. Defaults to PILImageResampling.BICUBIC.
TYPE:
|
do_center_crop
|
A flag indicating whether to perform center cropping. Defaults to True.
TYPE:
|
crop_size
|
A dictionary containing the size for cropping. Defaults to None.
TYPE:
|
do_rescale
|
A flag indicating whether to rescale the image. Defaults to True.
TYPE:
|
rescale_factor
|
The factor by which to rescale the image. Defaults to 1 / 255.
TYPE:
|
do_normalize
|
A flag indicating whether to normalize the image. Defaults to True.
TYPE:
|
image_mean
|
The mean value for image normalization. Defaults to None.
TYPE:
|
image_std
|
The standard deviation for image normalization. Defaults to None.
TYPE:
|
do_convert_rgb
|
A flag indicating whether to convert the image to RGB format. Defaults to True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None. |
Source code in mindnlp\transformers\models\clip\image_processing_clip.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
mindnlp.transformers.models.clip.image_processing_clip.CLIPImageProcessor.preprocess(images, do_resize=None, size=None, resample=None, do_center_crop=None, crop_size=None, do_rescale=None, rescale_factor=None, do_normalize=None, image_mean=None, image_std=None, do_convert_rgb=None, return_tensors=None, data_format=ChannelDimension.FIRST, input_data_format=None, **kwargs)
¶
Preprocess an image or batch of images.
| PARAMETER | DESCRIPTION |
|---|---|
images
|
Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
passing in images with pixel values between 0 and 1, set
TYPE:
|
do_resize
|
Whether to resize the image.
TYPE:
|
size
|
Size of the image after resizing. Shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
TYPE:
|
resample
|
Resampling filter to use if resizing the image. This can be one of the enum
TYPE:
|
do_center_crop
|
Whether to center crop the image.
TYPE:
|
crop_size
|
Size of the center crop. Only has an effect if
TYPE:
|
do_rescale
|
Whether to rescale the image.
TYPE:
|
rescale_factor
|
Rescale factor to rescale the image by if
TYPE:
|
do_normalize
|
Whether to normalize the image.
TYPE:
|
image_mean
|
Image mean to use for normalization. Only has an effect if
TYPE:
|
image_std
|
Image standard deviation to use for normalization. Only has an effect if
TYPE:
|
do_convert_rgb
|
Whether to convert the image to RGB.
TYPE:
|
return_tensors
|
The type of tensors to return. Can be one of:
TYPE:
|
data_format
|
The channel dimension format for the output image. Can be one of:
TYPE:
|
input_data_format
|
The channel dimension format for the input image. If unset, the channel dimension format is inferred
from the input image. Can be one of:
-
TYPE:
|
Source code in mindnlp\transformers\models\clip\image_processing_clip.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
mindnlp.transformers.models.clip.image_processing_clip.CLIPImageProcessor.resize(image, size, resample=PILImageResampling.BICUBIC, data_format=None, input_data_format=None, **kwargs)
¶
Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Image to resize.
TYPE:
|
size
|
Size of the output image.
TYPE:
|
resample
|
Resampling filter to use when resiizing the image.
TYPE:
|
data_format
|
The channel dimension format of the image. If not provided, it will be the same as the input image.
TYPE:
|
input_data_format
|
The channel dimension format of the input image. If not provided, it will be inferred.
TYPE:
|
Source code in mindnlp\transformers\models\clip\image_processing_clip.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPModel
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPModel.forward(input_ids=None, pixel_values=None, attention_mask=None, position_ids=None, return_loss=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, CLIPModel
>>> model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(
... text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="ms", padding=True
... )
>>> outputs = model(**inputs)
>>> logits_per_image = outputs.logits_per_image # this is the image-text similarity score
>>> probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
Source code in mindnlp\transformers\models\clip\modeling_clip.py
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPModel.get_image_features(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| RETURNS | DESCRIPTION |
|---|---|
image_features
|
The image embeddings obtained by
TYPE:
|
Tensor
|
applying the projection layer to the pooled output of [ |
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, CLIPModel
>>> model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(images=image, return_tensors="ms")
>>> image_features = model.get_image_features(**inputs)
Source code in mindnlp\transformers\models\clip\modeling_clip.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPModel.get_text_features(input_ids=None, attention_mask=None, position_ids=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| RETURNS | DESCRIPTION |
|---|---|
text_features
|
The text embeddings obtained by
TYPE:
|
Tensor
|
applying the projection layer to the pooled output of [ |
>>> from transformers import AutoTokenizer, CLIPModel
>>> model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
>>> tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32")
>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="ms")
>>> text_features = model.get_text_features(**inputs)
Source code in mindnlp\transformers\models\clip\modeling_clip.py
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp\transformers\models\clip\modeling_clip.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel.forward(input_ids=None, attention_mask=None, position_ids=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from transformers import AutoTokenizer, CLIPTextModel
>>> model = CLIPTextModel.from_pretrained("openai/clip-vit-base-patch32")
>>> tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32")
>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="ms")
>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output # pooled (EOS token) states
Source code in mindnlp\transformers\models\clip\modeling_clip.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection.forward(input_ids=None, attention_mask=None, position_ids=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from transformers import AutoTokenizer, CLIPTextModelWithProjection
>>> model = CLIPTextModelWithProjection.from_pretrained("openai/clip-vit-base-patch32")
>>> tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32")
>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="ms")
>>> outputs = model(**inputs)
>>> text_embeds = outputs.text_embeds
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel.forward(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, CLIPVisionModel
>>> model = CLIPVisionModel.from_pretrained("openai/clip-vit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(images=image, return_tensors="ms")
>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output # pooled CLS states
Source code in mindnlp\transformers\models\clip\modeling_clip.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection.forward(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Examples:
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, CLIPVisionModelWithProjection
>>> model = CLIPVisionModelWithProjection.from_pretrained("openai/clip-vit-base-patch32")
>>> processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)
>>> inputs = processor(images=image, return_tensors="ms")
>>> outputs = model(**inputs)
>>> image_embeds = outputs.image_embeds
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPForImageClassification
¶
Bases: CLIPPreTrainedModel
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 | |
mindnlp.transformers.models.clip.modeling_clip.CLIPForImageClassification.forward(pixel_values=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the image classification/regression loss. Indices should be in [0, ...,
config.num_labels - 1]. If config.num_labels == 1 a regression loss is computed (Mean-Square loss), If
config.num_labels > 1 a classification loss is computed (Cross-Entropy).
Source code in mindnlp\transformers\models\clip\modeling_clip.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 | |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor
¶
Bases: ProcessorMixin
Constructs a CLIP processor which wraps a CLIP image processor and a CLIP tokenizer into a single processor.
[CLIPProcessor] offers all the functionalities of [CLIPImageProcessor] and [CLIPTokenizerFast]. See the
[~CLIPProcessor.__call__] and [~CLIPProcessor.decode] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
image_processor
|
The image processor is a required input.
TYPE:
|
tokenizer
|
The tokenizer is a required input.
TYPE:
|
Source code in mindnlp\transformers\models\clip\processing_clip.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.feature_extractor
property
¶
This method is deprecated. Use image_processor instead.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CLIPProcessor class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
FutureWarning
|
This method raises a FutureWarning to alert users that it is deprecated. |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.feature_extractor_class
property
¶
This method returns the image processor class used for extracting features in the CLIPProcessor class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CLIPProcessor class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
FutureWarning
|
If the method is called, a FutureWarning will be raised to inform the user that
|
Note
The returned image processor class is responsible for extracting features from images in the CLIPProcessor.
Example
>>> clip_processor = CLIPProcessor()
>>> clip_processor.feature_extractor_class
<class 'image_processor.ImageProcessor'>
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.model_input_names
property
¶
This method, 'model_input_names', is a property of the 'CLIPProcessor' class. It returns a list of unique model input names derived from the tokenizer and image processor model input names.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the 'CLIPProcessor' class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
The method returns a list of unique model input names derived from the tokenizer and image processor model input names. |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.__call__(text=None, images=None, return_tensors=None, **kwargs)
¶
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the text
and kwargs arguments to CLIPTokenizerFast's [~CLIPTokenizerFast.__call__] if text is not None to encode
the text. To prepare the image(s), this method forwards the images and kwrags arguments to
CLIPImageProcessor's [~CLIPImageProcessor.__call__] if images is not None. Please refer to the doctsring
of the above two methods for more information.
| PARAMETER | DESCRIPTION |
|---|---|
text
|
The sequence or batch of sequences to be encoded. Each sequence can be a string or a list of strings
(pretokenized string). If the sequences are provided as list of strings (pretokenized), you must set
TYPE:
|
images
|
The image or batch of images to be prepared. Each image can be a PIL image, NumPy array or PyTorch tensor. In case of a NumPy array/PyTorch tensor, each image should be of shape (C, H, W), where C is a number of channels, H and W are image height and width.
TYPE:
|
return_tensors
|
If set, will return tensors of a particular framework. Acceptable values are:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
[
|
Source code in mindnlp\transformers\models\clip\processing_clip.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.__init__(image_processor=None, tokenizer=None, **kwargs)
¶
Initialize a CLIPProcessor object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
TYPE:
|
image_processor
|
An image processor object used for processing images. If not provided, it can be passed as part of the kwargs parameter.
TYPE:
|
tokenizer
|
A tokenizer object used for tokenizing text inputs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If either |
FutureWarning
|
If the deprecated argument |
Source code in mindnlp\transformers\models\clip\processing_clip.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.batch_decode(*args, **kwargs)
¶
This method forwards all its arguments to CLIPTokenizerFast's [~PreTrainedTokenizer.batch_decode]. Please
refer to the docstring of this method for more information.
Source code in mindnlp\transformers\models\clip\processing_clip.py
130 131 132 133 134 135 | |
mindnlp.transformers.models.clip.processing_clip.CLIPProcessor.decode(*args, **kwargs)
¶
This method forwards all its arguments to CLIPTokenizerFast's [~PreTrainedTokenizer.decode]. Please refer to
the docstring of this method for more information.
Source code in mindnlp\transformers\models\clip\processing_clip.py
137 138 139 140 141 142 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer
¶
Bases: PreTrainedTokenizer
Construct a CLIP tokenizer. Based on byte-level Byte-Pair-Encoding.
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
merges_file
|
Path to the merges file.
TYPE:
|
errors
|
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
TYPE:
|
unk_token
|
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
bos_token
|
The beginning of sequence token.
TYPE:
|
eos_token
|
The end of sequence token.
TYPE:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.vocab_size
property
¶
Method to return the vocabulary size of the CLIPTokenizer instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizer class. This parameter refers to the current instance of the CLIPTokenizer for which the vocabulary size is to be calculated.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of unique tokens in the vocabulary. The method returns an integer value representing the size of the vocabulary as the count of unique tokens stored in the encoder. |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.__init__(vocab_file, merges_file, errors='replace', unk_token='<|endoftext|>', bos_token='<|startoftext|>', eos_token='<|endoftext|>', pad_token='<|endoftext|>', **kwargs)
¶
Initializes a CLIPTokenizer object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizer class.
TYPE:
|
vocab_file
|
The path to the vocabulary file containing token encodings.
TYPE:
|
merges_file
|
The path to the file containing BPE merges for tokenization.
TYPE:
|
errors
|
The error handling strategy for text decoding. Defaults to 'replace'.
TYPE:
|
unk_token
|
The token to represent unknown words. Defaults to an empty string.
TYPE:
|
bos_token
|
The beginning of sequence token. Defaults to '<|startoftext|>'.
TYPE:
|
eos_token
|
The end of sequence token. Defaults to an empty string.
TYPE:
|
pad_token
|
The padding token. Defaults to an empty string.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the 'ftfy' package is not installed. |
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.bpe(token)
¶
This method 'bpe' is defined in the class 'CLIPTokenizer'. It processes a given token using Byte Pair Encoding (BPE).
| PARAMETER | DESCRIPTION |
|---|---|
self
|
This parameter represents the instance of the class 'CLIPTokenizer'. It is used to access the attributes and methods of the class.
|
token
|
The input token to be processed using Byte Pair Encoding (BPE). It should be a string representing a single token.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The processed token after applying Byte Pair Encoding (BPE) algorithm. The token is modified based on the algorithm rules. |
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A CLIP sequence has the following format:
- single sequence:
<|startoftext|> X <|endoftext|>
Pairs of sequences are not the expected use case, but they will be handled without a separator.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
592 593 594 595 596 597 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed. CLIP does not make use of token type ids, therefore a list of zeros is returned.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.get_special_tokens_mask(token_ids_0, token_ids_1=None, already_has_special_tokens=False)
¶
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer prepare_for_model method.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
already_has_special_tokens
|
Whether or not the token list is already formatted with special tokens for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.get_vocab()
¶
Method to retrieve the vocabulary of the CLIPTokenizer instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizer class. Represents the current instance of the CLIPTokenizer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary containing the combined vocabulary of the encoder and added_tokens_encoder. The vocabulary includes both the original encoder tokens and any additional tokens added to the tokenizer. |
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
mindnlp.transformers.models.clip.tokenization_clip.CLIPTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to the specified directory with an optional filename prefix.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizer class.
TYPE:
|
save_directory
|
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix
|
An optional prefix to be added to the filename. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths to the saved vocabulary file and merge file. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If the specified save_directory is not a valid directory. |
IOError
|
If there is an issue with writing the vocabulary or merge files. |
Exception
|
If any other unexpected error occurs during the saving process. |
Source code in mindnlp\transformers\models\clip\tokenization_clip.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
mindnlp.transformers.models.clip.tokenization_clip_fast.CLIPTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" CLIP tokenizer (backed by HuggingFace's tokenizers library). Based on byte-level Byte-Pair-Encoding.
This tokenizer inherits from [PreTrainedTokenizerFast] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
merges_file
|
Path to the merges file.
TYPE:
|
tokenizer_file
|
The path to a tokenizer file to use instead of the vocab file.
TYPE:
|
unk_token
|
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
bos_token
|
The beginning of sequence token.
TYPE:
|
eos_token
|
The end of sequence token.
TYPE:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
Source code in mindnlp\transformers\models\clip\tokenization_clip_fast.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
mindnlp.transformers.models.clip.tokenization_clip_fast.CLIPTokenizerFast.__init__(vocab_file=None, merges_file=None, tokenizer_file=None, unk_token='<|endoftext|>', bos_token='<|startoftext|>', eos_token='<|endoftext|>', pad_token='<|endoftext|>', **kwargs)
¶
Initialize the CLIPTokenizerFast class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizerFast class.
TYPE:
|
vocab_file
|
Path to the vocabulary file. Default is None.
TYPE:
|
merges_file
|
Path to the merges file. Default is None.
TYPE:
|
tokenizer_file
|
Path to the tokenizer file. Default is None.
TYPE:
|
unk_token
|
The unknown token. Default is 'endoftext'.
TYPE:
|
bos_token
|
The beginning of sequence token. Default is '<|startoftext|>'.
TYPE:
|
eos_token
|
The end of sequence token. Default is 'endoftext'.
TYPE:
|
pad_token
|
The padding token. Default is 'endoftext'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
Raised if the backend tokenizer pre_tokenizer does not match the expected format.
The CLIP tokenizer in this version has been heavily modified from transformers version 4.17.0. To
resolve this issue, convert the existing tokenizer to be compatible with this version using
|
Source code in mindnlp\transformers\models\clip\tokenization_clip_fast.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
mindnlp.transformers.models.clip.tokenization_clip_fast.CLIPTokenizerFast.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A CLIP sequence has the following format:
- single sequence:
<|startoftext|> X <|endoftext|>
Pairs of sequences are not the expected use case, but they will be handled without a separator.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\clip\tokenization_clip_fast.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
mindnlp.transformers.models.clip.tokenization_clip_fast.CLIPTokenizerFast.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed. CLIP does not make use of token type ids, therefore a list of zeros is returned.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\clip\tokenization_clip_fast.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
mindnlp.transformers.models.clip.tokenization_clip_fast.CLIPTokenizerFast.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary generated by the CLIPTokenizerFast model to the specified directory.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CLIPTokenizerFast class.
TYPE:
|
save_directory
|
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix
|
An optional prefix to be included in the saved filenames. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the filenames of the saved vocabulary files. |
Source code in mindnlp\transformers\models\clip\tokenization_clip_fast.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |