Transformers documentation
VideoPrism
This model was published in HF papers on 2024-02-20 and contributed to Hugging Face Transformers on 2026-06-19.
VideoPrism
The VideoPrism model was proposed in the paper VideoPrism: A Foundational Visual Encoder for Video Understanding by Google DeepMind (blog post).
VideoPrism is a general-purpose video encoder that tackles diverse video understanding tasks with a single frozen model. The model is pretrained on a large-scale heterogeneous corpus containing 36M high-quality video-caption pairs and 582M video clips with noisy parallel text (e.g., ASR transcripts). The pretraining approach improves upon masked autoencoding through global-local distillation of semantic video embeddings and a token shuffling scheme, enabling the model to focus primarily on the video modality while leveraging text associated with videos. VideoPrism achieves state-of-the-art performance on 31 out of 33 video understanding benchmarks across four broad task groups, from web video question answering to computer vision for science.

You can find all original VideoPrism checkpoints under the VideoPrism collection.
Notes:
- VideoPrism uses a factorized spatio-temporal encoder architecture, processing videos through separate spatial and temporal transformers.
- The model supports video-text contrastive learning through
VideoPrismClipModel, which combines a video encoder and a text encoder.VideoPrismConfigmust be used with this model. - For video classification tasks, use
VideoPrismForVideoClassificationwhich adds a classification head on top of the video encoder.VideoPrismVisionConfigmust be used with this model. - The vision encoder can be used standalone via
VideoPrismVisionModelfor extracting video features.VideoPrismVisionConfigmust be used with this model. - The default input resolution is 288x288 pixels with 16 frames per video clip for the base models and 8 frames for the large models. Set interpolate_pos_encoding=True to use the models with custom resolution and frames per clip.
This model was contributed by MHRDYN7 and reviewed by vasqu & zucchini-nlp. The original code can be found here.
Usage example
The snippet below shows how to load the VideoPrismVisionModel for feature extraction using the AutoModel class.
import torch
from transformers import AutoModel, AutoVideoProcessor
processor = AutoVideoProcessor.from_pretrained("google/videoprism-base-f16r288", revision="refs/pr/4")
model = AutoModel.from_pretrained(
"google/videoprism-base-f16r288",
revision="refs/pr/4",
device_map="auto",
# use "flash_attention_2" for faster inference on supported hardware
# attn_implementation="flash_attention_2"
)
video_url = "https://huggingface.co/datasets/nateraw/kinetics-mini/resolve/main/val/archery/-Qz25rXdMjE_000014_000024.mp4"
# when do_sample_frames=True, 16/8 frames will be sampled by default depending on the checkpoint size base/large.
processed_video_inputs = processor(videos=[video_url], return_metadata=True, do_sample_frames=True)
video_metadata = processed_video_inputs["video_metadata"]
video_inputs = processed_video_inputs["pixel_values_videos"].to(model.device)
outputs = model(video_inputs)
# VideoPrism encoder outputs
encoder_outputs = outputs.last_hidden_state
VideoPrismVisionConfig
class transformers.VideoPrismVisionConfig
< source >( transformers_version: str | None = None architectures: list[str] | None = None output_hidden_states: bool | None = False return_dict: bool | None = True dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None chunk_size_feed_forward: int = 0 is_encoder_decoder: bool = False id2label: dict[int, str] | dict[str, str] | None = None label2id: dict[str, int] | dict[str, str] | None = None problem_type: typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None image_size: int | list[int] | tuple[int, int] = 288 num_frames: int = 16 tubelet_size: list[int] | tuple[int, ...] = (1, 18, 18) num_channels: int = 3 hidden_size: int = 768 num_attention_heads: int = 12 intermediate_size: int = 3072 hidden_act: str = 'gelu_python' hidden_dropout_prob: float | int = 0.0 attention_probs_dropout_prob: float | int = 0.0 initializer_range: float = 0.02 layer_norm_eps: float = 1e-06 qkv_bias: bool = True num_spatial_layers: int = 12 num_temporal_layers: int = 4 attn_logit_softcapping: float = 50.0 num_auxiliary_layers: int = 2 apply_l2norm: bool = True )
Parameters
- image_size (
Union[int, list[int], tuple[int, int]], optional, defaults to288) — The size (resolution) of each image. - num_frames (
int, optional, defaults to 16) — The number of frames in the input video. - tubelet_size (
List[int], optional, defaults to[1, 18, 18]) — The size of the tubelet patch. - num_channels (
int, optional, defaults to3) — The number of input channels. - hidden_size (
int, optional, defaults to768) — Dimension of the hidden representations. - num_attention_heads (
int, optional, defaults to12) — Number of attention heads for each attention layer in the Transformer decoder. - intermediate_size (
int, optional, defaults to3072) — Dimension of the MLP representations. - hidden_act (
str, optional, defaults togelu_python) — The non-linear activation function (function or string) in the decoder. For example,"gelu","relu","silu", etc. - hidden_dropout_prob (
Union[float, int], optional, defaults to0.0) — The dropout probability for all fully connected layers in the embeddings, encoder, and pooler. - attention_probs_dropout_prob (
Union[float, int], optional, defaults to0.0) — The dropout ratio for the attention probabilities. - initializer_range (
float, optional, defaults to0.02) — The standard deviation of the truncated_normal_initializer for initializing all weight matrices. - layer_norm_eps (
float, optional, defaults to1e-06) — The epsilon used by the layer normalization layers. - qkv_bias (
bool, optional, defaults toTrue) — Whether to add a bias to the queries, keys and values. - num_spatial_layers (
int, optional, defaults to 12) — Number of spatial transformer blocks. - num_temporal_layers (
int, optional, defaults to 4) — Number of temporal transformer blocks. - attn_logit_softcapping (
float, optional, defaults to 50.0) — Softcapping constant for attention logits. - num_auxiliary_layers (
int, optional, defaults to 2) — Number of auxiliary layers. This is used in the VideoPrismVideoModel that is a part of VideoPrismClipModel. - apply_l2norm (
bool, optional, defaults toTrue) — Whether to apply L2 normalization to the output. This is used in the VideoPrismVideoModel that is a part of VideoPrismClipModel.
This is the configuration class to store the configuration of a VideoPrismClipModel. It is used to instantiate a Videoprism model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the google/videoprism-base-f16r288
Configuration objects inherit from PreTrainedConfig and can be used to control the model outputs. Read the documentation from PreTrainedConfig for more information.
VideoPrismTextConfig
class transformers.VideoPrismTextConfig
< source >( transformers_version: str | None = None architectures: list[str] | None = None output_hidden_states: bool | None = False return_dict: bool | None = True dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None chunk_size_feed_forward: int = 0 is_encoder_decoder: bool = False id2label: dict[int, str] | dict[str, str] | None = None label2id: dict[str, int] | dict[str, str] | None = None problem_type: typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None vocab_size: int = 32000 hidden_size: int = 768 intermediate_size: int = 3072 num_hidden_layers: int = 12 num_attention_heads: int = 12 max_position_embeddings: int = 64 hidden_act: str = 'relu' layer_norm_eps: float = 1e-06 pad_token_id: int | None = 0 bos_token_id: int | None = None eos_token_id: int | list[int] | None = None attention_probs_dropout_prob: float | int = 0.0 apply_l2norm: bool = True qkv_bias: bool = True hidden_dropout_prob: float = 0.0 initializer_range: float = 0.02 attn_logit_softcapping: float = 50.0 )
Parameters
- vocab_size (
int, optional, defaults to32000) — Vocabulary size of the model. Defines the number of different tokens that can be represented by theinput_ids. - hidden_size (
int, optional, defaults to768) — Dimension of the hidden representations. - intermediate_size (
int, optional, defaults to3072) — Dimension of the MLP representations. - num_hidden_layers (
int, optional, defaults to12) — Number of hidden layers in the Transformer decoder. - num_attention_heads (
int, optional, defaults to12) — Number of attention heads for each attention layer in the Transformer decoder. - max_position_embeddings (
int, optional, defaults to64) — The maximum sequence length that this model might ever be used with. - hidden_act (
str, optional, defaults torelu) — The non-linear activation function (function or string) in the decoder. For example,"gelu","relu","silu", etc. - layer_norm_eps (
float, optional, defaults to1e-06) — The epsilon used by the layer normalization layers. - pad_token_id (
int, optional, defaults to0) — Token id used for padding in the vocabulary. - bos_token_id (
int, optional) — Token id used for beginning-of-stream in the vocabulary. - eos_token_id (
Union[int, list[int]], optional) — Token id used for end-of-stream in the vocabulary. - attention_probs_dropout_prob (
Union[float, int], optional, defaults to0.0) — The dropout ratio for the attention probabilities. - apply_l2norm (
bool, optional, defaults toTrue) — Whether to apply L2 normalization to the output of VideoPrismTextEncoder. - qkv_bias (
bool, optional, defaults toTrue) — Whether to add a bias to the queries, keys and values. - hidden_dropout_prob (
float, optional, defaults to0.0) — The dropout probability for all fully connected layers in the embeddings, encoder, and pooler. - initializer_range (
float, optional, defaults to0.02) — The standard deviation of the truncated_normal_initializer for initializing all weight matrices. - attn_logit_softcapping (
float, optional, defaults to 50.0) — Softcapping constant for attention logits.
This is the configuration class to store the configuration of a VideoPrismClipModel. It is used to instantiate a Videoprism model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the google/videoprism-lvt-base-f16r288
Configuration objects inherit from PreTrainedConfig and can be used to control the model outputs. Read the documentation from PreTrainedConfig for more information.
VideoPrismConfig
class transformers.VideoPrismConfig
< source >( transformers_version: str | None = None architectures: list[str] | None = None output_hidden_states: bool | None = False return_dict: bool | None = True dtype: typing.Union[str, ForwardRef('torch.dtype'), NoneType] = None chunk_size_feed_forward: int = 0 is_encoder_decoder: bool = False id2label: dict[int, str] | dict[str, str] | None = None label2id: dict[str, int] | dict[str, str] | None = None problem_type: typing.Optional[typing.Literal['regression', 'single_label_classification', 'multi_label_classification']] = None text_config: dict | transformers.configuration_utils.PreTrainedConfig | None = None vision_config: dict | transformers.configuration_utils.PreTrainedConfig | None = None )
This is the configuration class to store the configuration of a VideoPrismClipModel. It is used to instantiate a Videoprism model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of the google/videoprism-lvt-base-f16r288
Configuration objects inherit from PreTrainedConfig and can be used to control the model outputs. Read the documentation from PreTrainedConfig for more information.
Example:
>>> from transformers import VideoPrismClipModel, VideoPrismConfig
>>> # Initializing a VideoPrismConfig with default values
>>> configuration = VideoPrismConfig()
>>> # Initializing a VideoPrismClipModel with the configuration
>>> model = VideoPrismClipModel(configuration)
>>> # Accessing the model configuration
>>> configuration = model.configVideoPrismTokenizer
class transformers.VideoPrismTokenizer
< source >( vocab: str | list[tuple[str, float]] | None = None eos_token = '</s>' unk_token = '<unk>' pad_token = '<pad>' _spm_precompiled_charsmap = None extra_ids = 100 additional_special_tokens = None **kwargs )
Constructs a VideoPrism tokenizer, which is essentially a T5 tokenizer without its postprocessor (appending an EOS token at the end of the sequence).
This tokenizer inherits from T5Tokenizer which contains most of the main methods. Users should refer to this superclass for more information regarding those methods.
Get the token IDs for sentinel tokens.
Get the list of sentinel tokens (extra_id tokens) from additional_special_tokens.
VideoPrismProcessor
class transformers.VideoPrismProcessor
< source >( video_processor = None tokenizer = None )
Constructs a VideoPrismProcessor which wraps a video processor and a tokenizer into a single processor.
VideoPrismProcessor offers all the functionalities of LlavaOnevisionVideoProcessor and VideoPrismTokenizer. See the ~LlavaOnevisionVideoProcessor and ~VideoPrismTokenizer for more information.
VideoPrismVisionModel
class transformers.VideoPrismVisionModel
< source >( config: VideoPrismVisionConfig )
Parameters
- config (VideoPrismVisionConfig) — Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to load the model weights.
The bare VideoPrism vision encoder outputting raw hidden-states without any specific head on top. This model is the backbone encoder used in VideoPrismVideoModel.
This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
forward
< source >( pixel_values_videos: torch.FloatTensor | None = None interpolate_pos_encoding: bool | None = False **kwargs: typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs] ) → BaseModelOutputWithSpatialAndTemporalStates or tuple(torch.FloatTensor)
Parameters
- pixel_values_videos (
torch.FloatTensorof shape(batch_size, num_frames, num_channels, frame_size, frame_size), optional) — The tensors corresponding to the input video. Pixel values for videos can be obtained using LlavaOnevisionVideoProcessor. SeeLlavaOnevisionVideoProcessor.__call__()for details (VideoPrismProcessor uses LlavaOnevisionVideoProcessor for processing videos). - interpolate_pos_encoding (
bool, optional, defaults toFalse) — Whether to interpolate the pre-trained position encodings.
Returns
BaseModelOutputWithSpatialAndTemporalStates or tuple(torch.FloatTensor)
A BaseModelOutputWithSpatialAndTemporalStates or a tuple of
torch.FloatTensor (if return_dict=False is passed or when config.return_dict=False) comprising various
elements depending on the configuration (VideoPrismConfig) and inputs.
The VideoPrismVisionModel forward method, overrides the __call__ special method.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.
last_hidden_state (
torch.FloatTensorof shape(batch_size, sequence_length, hidden_size)) — Sequence of hidden-states at the output of the last layer of the model.hidden_states (
tuple(torch.FloatTensor), optional, returned whenoutput_hidden_states=Trueis passed or whenconfig.output_hidden_states=True) — Tuple oftorch.FloatTensor(one for the output of the embeddings, if the model has an embedding layer, + one for the output of each layer) of shape(batch_size, sequence_length, hidden_size).Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
attentions (
tuple(torch.FloatTensor), optional, returned whenoutput_attentions=Trueis passed or whenconfig.output_attentions=True) — Tuple oftorch.FloatTensor(one for each layer) of shape(batch_size, num_heads, sequence_length, sequence_length).Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
last_temporal_hidden_state (
torch.FloatTensor, optional) — The last hidden state of the temporal encoder, typically of shape(batch_size * num_patches, num_frames, hidden_size).last_spatial_hidden_state (
torch.FloatTensor, optional) — The last hidden state of the spatial encoder, typically of shape(batch_size * num_frames, num_patches, hidden_size).
VideoPrismVideoModel
class transformers.VideoPrismVideoModel
< source >( config: VideoPrismVisionConfig )
Parameters
- config (VideoPrismVisionConfig) — Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to load the model weights.
VideoPrism video model consisting of the vision encoder backbone with auxiliary encoder layers and an attention pooling head on top. This model is used in VideoPrismClipModel.
This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
forward
< source >( pixel_values_videos: FloatTensor interpolate_pos_encoding: bool | None = False **kwargs: typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs] ) → BaseModelOutputWithPooling or tuple(torch.FloatTensor)
Parameters
- pixel_values_videos (
torch.FloatTensorof shape(batch_size, num_frames, num_channels, frame_size, frame_size)) — The tensors corresponding to the input video. Pixel values for videos can be obtained using LlavaOnevisionVideoProcessor. SeeLlavaOnevisionVideoProcessor.__call__()for details (VideoPrismProcessor uses LlavaOnevisionVideoProcessor for processing videos). - interpolate_pos_encoding (
bool, optional, defaults toFalse) — Whether to interpolate the pre-trained position encodings.
Returns
BaseModelOutputWithPooling or tuple(torch.FloatTensor)
A BaseModelOutputWithPooling or a tuple of
torch.FloatTensor (if return_dict=False is passed or when config.return_dict=False) comprising various
elements depending on the configuration (VideoPrismConfig) and inputs.
The VideoPrismVideoModel forward method, overrides the __call__ special method.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.
last_hidden_state (
torch.FloatTensorof shape(batch_size, sequence_length, hidden_size)) — Sequence of hidden-states at the output of the last layer of the model.pooler_output (
torch.FloatTensorof shape(batch_size, hidden_size)) — Last layer hidden-state of the first token of the sequence (classification token) after further processing through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns the classification token after processing through a linear layer and a tanh activation function. The linear layer weights are trained from the next sentence prediction (classification) objective during pretraining.hidden_states (
tuple(torch.FloatTensor), optional, returned whenoutput_hidden_states=Trueis passed or whenconfig.output_hidden_states=True) — Tuple oftorch.FloatTensor(one for the output of the embeddings, if the model has an embedding layer, + one for the output of each layer) of shape(batch_size, sequence_length, hidden_size).Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
attentions (
tuple(torch.FloatTensor), optional, returned whenoutput_attentions=Trueis passed or whenconfig.output_attentions=True) — Tuple oftorch.FloatTensor(one for each layer) of shape(batch_size, num_heads, sequence_length, sequence_length).Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
VideoPrismTextModel
class transformers.VideoPrismTextModel
< source >( config: VideoPrismTextConfig )
Parameters
- config (VideoPrismTextConfig) — Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to load the model weights.
The bare VideoPrism text encoder outputting last hidden states without any specific head on top. This model is used in VideoPrismClipModel.
This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
forward
< source >( input_ids: torch.LongTensor | None = None attention_mask: torch.Tensor | None = None inputs_embeds: torch.Tensor | None = None position_ids: torch.Tensor | None = None **kwargs: typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs] ) → BaseModelOutputWithPooling or tuple(torch.FloatTensor)
Parameters
- input_ids (
torch.LongTensorof shape(batch_size, sequence_length), optional) — Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
- attention_mask (
torch.Tensorof shape(batch_size, sequence_length), optional) — Mask to avoid performing attention on padding token indices. Mask values selected in[0, 1]:- 1 for tokens that are not masked,
- 0 for tokens that are masked.
- inputs_embeds (
torch.Tensorof shape(batch_size, sequence_length, hidden_size), optional) — Optionally, instead of passinginput_idsyou can choose to directly pass an embedded representation. This is useful if you want more control over how to convertinput_idsindices into associated vectors than the model’s internal embedding lookup matrix. - position_ids (
torch.Tensorof shape(batch_size, sequence_length), optional) — Indices of positions of each input sequence tokens in the position embeddings. Selected in the range[0, config.n_positions - 1].
Returns
BaseModelOutputWithPooling or tuple(torch.FloatTensor)
A BaseModelOutputWithPooling or a tuple of
torch.FloatTensor (if return_dict=False is passed or when config.return_dict=False) comprising various
elements depending on the configuration (VideoPrismConfig) and inputs.
The VideoPrismTextModel forward method, overrides the __call__ special method.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.
last_hidden_state (
torch.FloatTensorof shape(batch_size, sequence_length, hidden_size)) — Sequence of hidden-states at the output of the last layer of the model.pooler_output (
torch.FloatTensorof shape(batch_size, hidden_size)) — Last layer hidden-state of the first token of the sequence (classification token) after further processing through the layers used for the auxiliary pretraining task. E.g. for BERT-family of models, this returns the classification token after processing through a linear layer and a tanh activation function. The linear layer weights are trained from the next sentence prediction (classification) objective during pretraining.hidden_states (
tuple(torch.FloatTensor), optional, returned whenoutput_hidden_states=Trueis passed or whenconfig.output_hidden_states=True) — Tuple oftorch.FloatTensor(one for the output of the embeddings, if the model has an embedding layer, + one for the output of each layer) of shape(batch_size, sequence_length, hidden_size).Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
attentions (
tuple(torch.FloatTensor), optional, returned whenoutput_attentions=Trueis passed or whenconfig.output_attentions=True) — Tuple oftorch.FloatTensor(one for each layer) of shape(batch_size, num_heads, sequence_length, sequence_length).Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.
VideoPrismClipModel
class transformers.VideoPrismClipModel
< source >( config: VideoPrismConfig )
Parameters
- config (VideoPrismConfig) — Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to load the model weights.
VideoPrism model for video-text contrastive learning. This model consists of a VideoPrismVideoModel and a VideoPrismTextModel, and computes similarity scores between video and text inputs.
This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
forward
< source >( pixel_values_videos: FloatTensor input_ids: Tensor attention_mask: torch.Tensor | None = None interpolate_pos_encoding: bool | None = False temperature: float | None = None return_loss: bool | None = None **kwargs: typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs] ) → VideoPrismClipOutput or tuple(torch.FloatTensor)
Parameters
- pixel_values_videos (
torch.FloatTensorof shape(batch_size, num_frames, num_channels, frame_size, frame_size)) — The tensors corresponding to the input video. Pixel values for videos can be obtained using LlavaOnevisionVideoProcessor. SeeLlavaOnevisionVideoProcessor.__call__()for details (VideoPrismProcessor uses LlavaOnevisionVideoProcessor for processing videos). - input_ids (
torch.Tensorof shape(batch_size, sequence_length)) — Indices of input sequence tokens in the vocabulary. Padding will be ignored by default.Indices can be obtained using AutoTokenizer. See PreTrainedTokenizer.encode() and PreTrainedTokenizer.call() for details.
- attention_mask (
torch.Tensorof shape(batch_size, sequence_length), optional) — Mask to avoid performing attention on padding token indices. Mask values selected in[0, 1]:- 1 for tokens that are not masked,
- 0 for tokens that are masked.
- interpolate_pos_encoding (
bool, optional, defaults toFalse) — Whether to interpolate the pre-trained position encodings. - temperature (
float, optional) — A temperature scalar to scale the similarity scores. If not provided, no scaling is applied. - return_loss (
bool, optional) — Whether or not to return the contrastive loss.
Returns
VideoPrismClipOutput or tuple(torch.FloatTensor)
A VideoPrismClipOutput or a tuple of
torch.FloatTensor (if return_dict=False is passed or when config.return_dict=False) comprising various
elements depending on the configuration (VideoPrismConfig) and inputs.
The VideoPrismClipModel forward method, overrides the __call__ special method.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.
- logits_per_video (
torch.FloatTensorof shape(video_batch_size, text_batch_size)) — The scaled dot product scores betweenvideo_embedsandtext_embeds. This represents the video-text similarity scores. - logits_per_text (
torch.FloatTensorof shape(text_batch_size, video_batch_size)) — The scaled dot product scores betweentext_embedsandvideo_embeds. This represents the text-video similarity scores. - video_embeds (
torch.FloatTensorof shape(batch_size, output_dim)) — The video embeddings obtained by applying the projection layer to the pooled output of VideoPrismVideoModel. - text_embeds (
torch.FloatTensorof shape(batch_size, output_dim)) — The text embeddings obtained by applying the projection layer to the pooled output of VideoPrismTextModel. - video_model_output (
~modeling_outputs.BaseModelOutputWithPooling, optional) — The output of VideoPrismVideoModel. - text_model_output (
~modeling_outputs.BaseModelOutputWithPooling, optional) — The output of the VideoPrismTextModel. - loss (
torch.FloatTensorof shape(1,), optional, returned whenreturn_lossisTrue) — Contrastive loss for video-text similarity.
VideoPrismForVideoClassification
class transformers.VideoPrismForVideoClassification
< source >( config: VideoPrismVisionConfig )
Parameters
- config (VideoPrismVisionConfig) — Model configuration class with all the parameters of the model. Initializing with a config file does not load the weights associated with the model, only the configuration. Check out the from_pretrained() method to load the model weights.
VideoPrism Model transformer with a video classification head on top (a linear layer on top of the attention pooler).
This model inherits from PreTrainedModel. Check the superclass documentation for the generic methods the library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads etc.)
This model is also a PyTorch torch.nn.Module subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and behavior.
forward
< source >( pixel_values_videos: FloatTensor labels: torch.LongTensor | None = None interpolate_pos_encoding: bool | None = False **kwargs: typing_extensions.Unpack[transformers.utils.generic.TransformersKwargs] ) → ImageClassifierOutput or tuple(torch.FloatTensor)
Parameters
- pixel_values_videos (
torch.FloatTensorof shape(batch_size, num_frames, num_channels, frame_size, frame_size)) — The tensors corresponding to the input video. Pixel values for videos can be obtained using LlavaOnevisionVideoProcessor. SeeLlavaOnevisionVideoProcessor.__call__()for details (VideoPrismProcessor uses LlavaOnevisionVideoProcessor for processing videos). - labels (
torch.LongTensorof shape(batch_size, sequence_length), optional) — Labels for computing the masked language modeling loss. Indices should either be in[0, ..., config.vocab_size]or -100 (seeinput_idsdocstring). Tokens with indices set to-100are ignored (masked), the loss is only computed for the tokens with labels in[0, ..., config.vocab_size]. - interpolate_pos_encoding (
bool, optional, defaults toFalse) — Whether to interpolate the pre-trained position encodings.
Returns
ImageClassifierOutput or tuple(torch.FloatTensor)
A ImageClassifierOutput or a tuple of
torch.FloatTensor (if return_dict=False is passed or when config.return_dict=False) comprising various
elements depending on the configuration (VideoPrismConfig) and inputs.
The VideoPrismForVideoClassification forward method, overrides the __call__ special method.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.
loss (
torch.FloatTensorof shape(1,), optional, returned whenlabelsis provided) — Classification (or regression if config.num_labels==1) loss.logits (
torch.FloatTensorof shape(batch_size, config.num_labels)) — Classification (or regression if config.num_labels==1) scores (before SoftMax).hidden_states (
tuple(torch.FloatTensor), optional, returned whenoutput_hidden_states=Trueis passed or whenconfig.output_hidden_states=True) — Tuple oftorch.FloatTensor(one for the output of the embeddings, if the model has an embedding layer, + one for the output of each stage) of shape(batch_size, sequence_length, hidden_size). Hidden-states (also called feature maps) of the model at the output of each stage.attentions (
tuple(torch.FloatTensor), optional, returned whenoutput_attentions=Trueis passed or whenconfig.output_attentions=True) — Tuple oftorch.FloatTensor(one for each layer) of shape(batch_size, num_heads, patch_size, sequence_length).Attentions weights after the attention softmax, used to compute the weighted average in the self-attention heads.