clip
mindnlp.transformers.models.clip.configuration_clip.CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP = {'openai/clip-vit-base-patch32': 'https://hf-mirror.com/openai/clip-vit-base-patch32/resolve/main/config.json'}
module-attribute
¶
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.CLIP_PRETRAINED_MODEL_ARCHIVE_LIST = ['openai/clip-vit-base-patch32']
module-attribute
¶
mindnlp.transformers.models.clip.modeling_clip.CLIPModel
¶
Bases: CLIPPreTrainedModel
A Python class representing a CLIP (Contrastive Language-Image Pre-training) model that combines text and vision inputs for image-text similarity scoring. This class inherits from CLIPPreTrainedModel and provides methods for extracting text and image features, as well as for forwarding the final CLIP output. The class handles the initialization of model configurations, text and vision embeddings, projectionlayers, and scaling of logits for calculating similarity scores. It also includes examples on how to use the model for text and image inputs.
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPModel.__init__(config)
¶
Initializes an instance of the CLIPModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of the CLIPConfig class which holds the configuration parameters for the CLIPModel.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the 'config.text_config' parameter is not of type CLIPTextConfig. |
ValueError
|
If the 'config.vision_config' parameter is not of type CLIPVisionConfig. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 |
|
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)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CLIPOutput]
|
Union[Tuple, CLIPOutput] |
Example
>>> 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="pt", 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
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 |
|
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
applying the projection layer to the pooled output of [
TYPE:
|
Example
>>> 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="pt")
...
>>> image_features = model.get_image_features(**inputs)
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 |
|
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
applying the projection layer to the pooled output of [
TYPE:
|
Example
>>> 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="pt")
>>> text_features = model.get_text_features(**inputs)
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 |
|
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
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 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel
¶
Bases: CLIPPreTrainedModel
The CLIPTextModel
class represents a model for processing text inputs using the CLIP (Contrastive Language-Image Pretraining) framework.
This class inherits from CLIPPreTrainedModel
and provides methods for initializing the model, obtaining input embeddings,
and forwarding the model for inference.
The CLIPTextModel
class includes methods for initializing the model with a configuration, obtaining input embeddings,
and forwarding the model for inference. The get_input_embeddings
method returns the token embeddings used as input
to the model, while the set_input_embeddings
method allows for updating the token embeddings.
The forward
method forwards the model for performing inference, with options for specifying input tensors,
attention masks, position ids, and return settings.
The forward
method returns the model outputs based on the provided inputs and settings.
Additionally, the docstring includes usage examples for initializing the CLIPTextModel
and performing inference
using the model.
Example
>>> 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="pt")
...
>>> 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
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 1042 1043 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 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel.__init__(config)
¶
Initialize the CLIPTextModel object with the given configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CLIPTextModel class.
TYPE:
|
config |
The configuration object for CLIPTextModel.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
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)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Example
>>> 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="pt")
...
>>> 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
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 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel.get_input_embeddings()
¶
Method to retrieve the input embeddings from the CLIPTextModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CLIPTextModel class. This parameter refers to the current instance of the CLIPTextModel class from which the input embeddings are being retrieved.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Module
|
nn.Module: An instance of the neural network Cell class representing the input embeddings. The return value is the token embedding from the text model, which serves as the input embeddings for further processing within the CLIPTextModel. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModel.set_input_embeddings(value)
¶
Sets the input embeddings for the CLIPTextModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CLIPTextModel.
TYPE:
|
value |
The new input embeddings to be set. It can be of any type.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection
¶
Bases: CLIPPreTrainedModel
This class represents a CLIP text model with a projection layer for embedding text inputs. It inherits from the CLIPPreTrainedModel class.
The CLIPTextModelWithProjection class is designed to process text inputs using the CLIP (Contrastive Language-Image Pretraining) model architecture. It incorporates a CLIPTextTransformer and a text projection layer to generate text embeddings.
The class provides functionality for initializing the model with a CLIPTextConfig, accessing the input embeddings, setting the input embeddings, and forwarding the model's outputs based on input text ids, attention masks, and position ids.
The forward method takes optional input tensors representing text ids, attention masks, position ids, output attentions, output hidden states, and return dictionary flag. It returns a CLIPTextModelOutput object containing the text embeddings and other relevant information.
Example
>>> 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="pt")
...
>>> outputs = model(**inputs)
>>> text_embeds = outputs.text_embeds
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection.__init__(config)
¶
Initializes an instance of the CLIPTextModelWithProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of CLIPTextConfig class that contains the configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 |
|
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)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CLIPTextModelOutput]
|
Union[Tuple, CLIPTextModelOutput] |
Example
>>> 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="pt")
...
>>> outputs = model(**inputs)
>>> text_embeds = outputs.text_embeds
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection.get_input_embeddings()
¶
Method to get the input embeddings from the CLIPTextModelWithProjection instance.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the CLIPTextModelWithProjection class. Represents the current instance of the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Module
|
nn.Module: Returns the input embeddings of type nn.Module. Represents the token embeddings used by the text model. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPTextModelWithProjection.set_input_embeddings(value)
¶
Sets the input embeddings for the CLIPTextModelWithProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CLIPTextModelWithProjection class. |
value |
The input embeddings to be set for the text model.
This should be a tensor or object that can be assigned to the
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method modifies the state of the text model by setting the input embeddings. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel
¶
Bases: CLIPPreTrainedModel
The CLIPVisionModel
class represents a model for vision tasks using the CLIP (Contrastive Language-Image Pre-training)
framework. It is designed to process images and generate visual embeddings using the CLIPVisionTransformer.
PARAMETER | DESCRIPTION |
---|---|
config |
The configuration object that defines the model architecture and behavior.
TYPE:
|
ATTRIBUTE | DESCRIPTION |
---|---|
vision_model |
The CLIPVisionTransformer instance used for image processing.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of the |
get_input_embeddings |
Returns the input embeddings of the vision model. |
forward |
Constructs the vision model and performs image processing. |
RETURNS | DESCRIPTION |
---|---|
The forwarded |
Example
>>> 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="pt")
...
>>> 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
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 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel.__init__(config)
¶
Initializes a new instance of the CLIPVisionModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of CLIPVisionConfig class representing the configuration settings. It is required to initialize the CLIPVisionModel. It must be of type CLIPVisionConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type CLIPVisionConfig. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel.forward(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutputWithPooling]
|
|
Example
>>> 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="pt")
...
>>> 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
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModel.get_input_embeddings()
¶
This method returns the input embeddings from the CLIPVisionModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CLIPVisionModel class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Module
|
nn.Module: The input embeddings from the vision model. This is of type nn.Module. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection
¶
Bases: CLIPPreTrainedModel
Represents a vision model with projection for CLIP (Contrastive Language-Image Pre-training) framework.
This class inherits from CLIPPreTrainedModel and includes methods for initializing the model, retrieving input embeddings, and forwarding the model.
The 'CLIPVisionModelWithProjection' class initializes with a configuration object of type 'CLIPVisionConfig' and sets up the vision model and visual projection. It provides a method to retrieve input embeddings and forwards the vision model with optional parameters for pixel values, attentions, hidden states, and return dictionary. The method returns image embeddings and other model outputs based on the input parameters.
Example
>>> 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="pt")
...
>>> outputs = model(**inputs)
>>> image_embeds = outputs.image_embeds
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection.__init__(config)
¶
Initializes a CLIPVisionModelWithProjection instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance itself.
|
config |
The configuration object for the CLIPVisionModelWithProjection. It contains the necessary parameters for configuring the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection.forward(pixel_values=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CLIPVisionModelOutput]
|
Union[Tuple, CLIPVisionModelOutput] |
Example
>>> 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="pt")
...
>>> outputs = model(**inputs)
>>> image_embeds = outputs.image_embeds
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPVisionModelWithProjection.get_input_embeddings()
¶
Returns the input embeddings of the CLIPVisionModelWithProjection.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of CLIPVisionModelWithProjection class. |
RETURNS | DESCRIPTION |
---|---|
Module
|
nn.Module: A neural network cell representing the input embeddings of the vision model. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPForImageClassification
¶
Bases: CLIPPreTrainedModel
The CLIPForImageClassification class represents a model for image classification using the Contrastive Language-Image Pretraining (CLIP) approach. It inherits from the CLIPPreTrainedModel class and implements the necessary methods for image classification tasks.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration for the CLIP model, containing parameters such as num_labels, vision_model, and classifier.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CLIPForImageClassification model with the provided configuration. |
forward |
Constructs the image classification model using the specified pixel values and labels. It returns the logits, loss, hidden states, and attentions if specified. |
PARAMETER | DESCRIPTION |
---|---|
config |
The configuration for the CLIP model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPForImageClassification.__init__(config)
¶
Initializes an instance of the CLIPForImageClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of the CLIPConfig class containing configuration parameters for CLIP. It specifies the configuration settings needed for initializing the CLIP model. It must be of type CLIPConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type CLIPConfig. |
ValueError
|
If the num_labels attribute in the config is invalid or missing. |
RuntimeError
|
If an error occurs during initialization of the vision model or classifier. |
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 |
|
mindnlp.transformers.models.clip.modeling_clip.CLIPForImageClassification.forward(pixel_values=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the image classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/clip/modeling_clip.py
1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 |
|
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 and will be removed in v5. 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 and will be removed in v5. |
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 |
---|