ALIGN

## [](#overview)Overview

The ALIGN model was proposed in [Scaling Up Visual and Vision-Language Representation Learning With Noisy Text Supervision](https://arxiv.org/abs/2102.05918) by Chao Jia, Yinfei Yang, Ye Xia, Yi-Ting Chen, Zarana Parekh, Hieu Pham, Quoc V. Le, Yunhsuan Sung, Zhen Li, Tom Duerig. ALIGN is a multi-modal vision and language model. It can be used for image-text similarity and for zero-shot image classification. ALIGN features a dual-encoder architecture with [EfficientNet](efficientnet) as its vision encoder and [BERT](bert) as its text encoder, and learns to align visual and text representations with contrastive learning. Unlike previous work, ALIGN leverages a massive noisy dataset and shows that the scale of the corpus can be used to achieve SOTA representations with a simple recipe.

The abstract from the paper is the following:

_Pre-trained representations are becoming crucial for many NLP and perception tasks. While representation learning in NLP has transitioned to training on raw text without human annotations, visual and vision-language representations still rely heavily on curated training datasets that are expensive or require expert knowledge. For vision applications, representations are mostly learned using datasets with explicit class labels such as ImageNet or OpenImages. For vision-language, popular datasets like Conceptual Captions, MSCOCO, or CLIP all involve a non-trivial data collection (and cleaning) process. This costly curation process limits the size of datasets and hence hinders the scaling of trained models. In this paper, we leverage a noisy dataset of over one billion image alt-text pairs, obtained without expensive filtering or post-processing steps in the Conceptual Captions dataset. A simple dual-encoder architecture learns to align visual and language representations of the image and text pairs using a contrastive loss. We show that the scale of our corpus can make up for its noise and leads to state-of-the-art representations even with such a simple learning scheme. Our visual representation achieves strong performance when transferred to classification tasks such as ImageNet and VTAB. The aligned visual and language representations enables zero-shot image classification and also set new state-of-the-art results on Flickr30K and MSCOCO image-text retrieval benchmarks, even when compared with more sophisticated cross-attention models. The representations also enable cross-modality search with complex text and text + image queries._

## [](#usage)Usage

ALIGN uses EfficientNet to get visual features and BERT to get the text features. Both the text and visual features are then projected to a latent space with identical dimension. The dot product between the projected image and text features is then used as a similarity score.

[AlignProcessor](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignProcessor) wraps [EfficientNetImageProcessor](/docs/transformers/v4.30.0/en/model_doc/efficientnet#transformers.EfficientNetImageProcessor) and [BertTokenizer](/docs/transformers/v4.30.0/en/model_doc/bert#transformers.BertTokenizer) into a single instance to both encode the text and preprocess the images. The following example shows how to get the image-text similarity scores using [AlignProcessor](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignProcessor) and [AlignModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignModel).

```
import requests
import torch
from PIL import Image
from transformers import AlignProcessor, AlignModel

processor = AlignProcessor.from_pretrained("kakaobrain/align-base")
model = AlignModel.from_pretrained("kakaobrain/align-base")

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
candidate_labels = ["an image of a cat", "an image of a dog"]

inputs = processor(text=candidate_labels, images=image, return_tensors="pt")

with torch.no_grad():
    outputs = model(**inputs)


logits_per_image = outputs.logits_per_image


probs = logits_per_image.softmax(dim=1)
print(probs)```

This model was contributed by [Alara Dirik](https://huggingface.co/adirik). The original code is not released, this implementation is based on the Kakao Brain implementation based on the original paper.

## [](#resources)Resources

A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with ALIGN.

-   A blog post on [ALIGN and the COYO-700M dataset](https://huggingface.co/blog/vit-align).
-   A zero-shot image classification [demo](https://huggingface.co/spaces/adirik/ALIGN-zero-shot-image-classification).
-   [Model card](https://huggingface.co/kakaobrain/align-base) of `kakaobrain/align-base` model.

If you’re interested in submitting a resource to be included here, please feel free to open a Pull Request and we will review it. The resource should ideally demonstrate something new instead of duplicating an existing resource.

## [](#transformers.AlignConfig)AlignConfig

### class transformers.AlignConfig

[](#transformers.AlignConfig)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/configuration_align.py#L298)

( text\_config = Nonevision\_config = Noneprojection\_dim = 640temperature\_init\_value = 1.0initializer\_range = 0.02\*\*kwargs )

Parameters

-   [](#transformers.AlignConfig.text_config)**text\_config** (`dict`, _optional_) — Dictionary of configuration options used to initialize [AlignTextConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignTextConfig).
-   [](#transformers.AlignConfig.vision_config)**vision\_config** (`dict`, _optional_) — Dictionary of configuration options used to initialize [AlignVisionConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignVisionConfig).
-   [](#transformers.AlignConfig.projection_dim)**projection\_dim** (`int`, _optional_, defaults to 640) — Dimentionality of text and vision projection layers.
-   [](#transformers.AlignConfig.temperature_init_value)**temperature\_init\_value** (`float`, _optional_, defaults to 1.0) — The inital value of the _temperature_ paramter. Default is used as per the original ALIGN implementation.
-   [](#transformers.AlignConfig.initializer_range)**initializer\_range** (`float`, _optional_, defaults to 0.02) — The standard deviation of the truncated\_normal\_initializer for initializing all weight matrices.
-   [](#transformers.AlignConfig.kwargs)**kwargs** (_optional_) — Dictionary of keyword arguments.

[AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig) is the configuration class to store the configuration of a [AlignModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignModel). It is used to instantiate a ALIGN 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 ALIGN [kakaobrain/align-base](https://huggingface.co/kakaobrain/align-base) architecture.

Configuration objects inherit from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) and can be used to control the model outputs. Read the documentation from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) for more information.

Example:

```
>>> from transformers import AlignConfig, AlignModel

>>> 
>>> configuration = AlignConfig()

>>> 
>>> model = AlignModel(configuration)

>>> 
>>> configuration = model.config

>>> 
>>> from transformers import AlignTextConfig, AlignVisionConfig

>>> 
>>> config_text = AlignTextConfig()
>>> config_vision = AlignVisionConfig()

>>> config = AlignConfig.from_text_vision_configs(config_text, config_vision)```

#### from\_text\_vision\_configs

[](#transformers.AlignConfig.from_text_vision_configs)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/configuration_align.py#L375)

( text\_config: AlignTextConfigvision\_config: AlignVisionConfig\*\*kwargs ) → [AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig)

An instance of a configuration object

Instantiate a [AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig) (or a derived class) from align text model configuration and align vision model configuration.

## [](#transformers.AlignTextConfig)AlignTextConfig

### class transformers.AlignTextConfig

[](#transformers.AlignTextConfig)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/configuration_align.py#L36)

( vocab\_size = 30522hidden\_size = 768num\_hidden\_layers = 12num\_attention\_heads = 12intermediate\_size = 3072hidden\_act = 'gelu'hidden\_dropout\_prob = 0.1attention\_probs\_dropout\_prob = 0.1max\_position\_embeddings = 512type\_vocab\_size = 2initializer\_range = 0.02layer\_norm\_eps = 1e-12pad\_token\_id = 0position\_embedding\_type = 'absolute'use\_cache = True\*\*kwargs )

This is the configuration class to store the configuration of a [AlignTextModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignTextModel). It is used to instantiate a ALIGN 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 ALIGN [kakaobrain/align-base](https://huggingface.co/kakaobrain/align-base) architecture. The default values here are copied from BERT.

Configuration objects inherit from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) and can be used to control the model outputs. Read the documentation from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) for more information.

Example:

```
>>> from transformers import AlignTextConfig, AlignTextModel

>>> 
>>> configuration = AlignTextConfig()

>>> 
>>> model = AlignTextModel(configuration)

>>> 
>>> configuration = model.config```

## [](#transformers.AlignVisionConfig)AlignVisionConfig

### class transformers.AlignVisionConfig

[](#transformers.AlignVisionConfig)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/configuration_align.py#L157)

( num\_channels: int = 3image\_size: int = 600width\_coefficient: float = 2.0depth\_coefficient: float = 3.1depth\_divisor: int = 8kernel\_sizes: typing.List\[int\] = \[3, 3, 5, 3, 5, 5, 3\]in\_channels: typing.List\[int\] = \[32, 16, 24, 40, 80, 112, 192\]out\_channels: typing.List\[int\] = \[16, 24, 40, 80, 112, 192, 320\]depthwise\_padding: typing.List\[int\] = \[\]strides: typing.List\[int\] = \[1, 2, 2, 2, 1, 2, 1\]num\_block\_repeats: typing.List\[int\] = \[1, 2, 2, 3, 3, 4, 1\]expand\_ratios: typing.List\[int\] = \[1, 6, 6, 6, 6, 6, 6\]squeeze\_expansion\_ratio: float = 0.25hidden\_act: str = 'swish'hidden\_dim: int = 2560pooling\_type: str = 'mean'initializer\_range: float = 0.02batch\_norm\_eps: float = 0.001batch\_norm\_momentum: float = 0.99dropout\_rate: float = 0.5drop\_connect\_rate: float = 0.2\*\*kwargs )

This is the configuration class to store the configuration of a [AlignVisionModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignVisionModel). It is used to instantiate a ALIGN 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 ALIGN [kakaobrain/align-base](https://huggingface.co/kakaobrain/align-base) architecture. The default values are copied from EfficientNet (efficientnet-b7)

Configuration objects inherit from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) and can be used to control the model outputs. Read the documentation from [PretrainedConfig](/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig) for more information.

Example:

```
>>> from transformers import AlignVisionConfig, AlignVisionModel

>>> 
>>> configuration = AlignVisionConfig()

>>> 
>>> model = AlignVisionModel(configuration)

>>> 
>>> configuration = model.config```

## [](#transformers.AlignProcessor)AlignProcessor

### class transformers.AlignProcessor

[](#transformers.AlignProcessor)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/processing_align.py#L24)

( image\_processortokenizer )

Parameters

-   [](#transformers.AlignProcessor.image_processor)**image\_processor** ([EfficientNetImageProcessor](/docs/transformers/v4.30.0/en/model_doc/efficientnet#transformers.EfficientNetImageProcessor)) — The image processor is a required input.
-   [](#transformers.AlignProcessor.tokenizer)**tokenizer** (\[`BertTokenizer`, `BertTokenizerFast`\]) — The tokenizer is a required input.

Constructs an ALIGN processor which wraps [EfficientNetImageProcessor](/docs/transformers/v4.30.0/en/model_doc/efficientnet#transformers.EfficientNetImageProcessor) and [BertTokenizer](/docs/transformers/v4.30.0/en/model_doc/bert#transformers.BertTokenizer)/[BertTokenizerFast](/docs/transformers/v4.30.0/en/model_doc/bert#transformers.BertTokenizerFast) into a single processor that interits both the image processor and tokenizer functionalities. See the `__call__()` and [decode()](/docs/transformers/v4.30.0/en/model_doc/owlvit#transformers.OwlViTProcessor.decode) for more information.

This method forwards all its arguments to BertTokenizerFast’s [batch\_decode()](/docs/transformers/v4.30.0/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.batch_decode). Please refer to the docstring of this method for more information.

This method forwards all its arguments to BertTokenizerFast’s [decode()](/docs/transformers/v4.30.0/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.decode). Please refer to the docstring of this method for more information.

## [](#transformers.AlignModel)AlignModel

### class transformers.AlignModel

[](#transformers.AlignModel)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1418)

( config: AlignConfig )

Parameters

-   [](#transformers.AlignModel.config)**config** ([AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig)) — 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()](/docs/transformers/v4.30.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.

This model inherits from [PreTrainedModel](/docs/transformers/v4.30.0/en/main_classes/model#transformers.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](https://pytorch.org/docs/stable/nn.html#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

[](#transformers.AlignModel.forward)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1549)

( input\_ids: typing.Optional\[torch.LongTensor\] = Nonepixel\_values: typing.Optional\[torch.FloatTensor\] = Noneattention\_mask: typing.Optional\[torch.Tensor\] = Nonetoken\_type\_ids: typing.Optional\[torch.Tensor\] = Noneposition\_ids: typing.Optional\[torch.Tensor\] = Nonehead\_mask: typing.Optional\[torch.Tensor\] = Noneinputs\_embeds: typing.Optional\[torch.Tensor\] = Nonereturn\_loss: typing.Optional\[bool\] = Noneoutput\_attentions: typing.Optional\[bool\] = Noneoutput\_hidden\_states: typing.Optional\[bool\] = Nonereturn\_dict: typing.Optional\[bool\] = None )

The [AlignModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignModel) forward method, overrides the `__call__` special method.

Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.

#### get\_text\_features

[](#transformers.AlignModel.get_text_features)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1451)

( input\_ids: typing.Optional\[torch.Tensor\] = Noneattention\_mask: typing.Optional\[torch.Tensor\] = Nonetoken\_type\_ids: typing.Optional\[torch.Tensor\] = Noneposition\_ids: typing.Optional\[torch.Tensor\] = Nonehead\_mask: typing.Optional\[torch.Tensor\] = Noneinputs\_embeds: typing.Optional\[torch.Tensor\] = Noneoutput\_attentions: typing.Optional\[bool\] = Noneoutput\_hidden\_states: typing.Optional\[bool\] = Nonereturn\_dict: typing.Optional\[bool\] = None ) → text\_features (`torch.FloatTensor` of shape `(batch_size, output_dim`)

The [AlignModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignModel) forward method, overrides the `__call__` special method.

Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.

Examples:

```
>>> from transformers import AutoTokenizer, AlignModel

>>> model = AlignModel.from_pretrained("kakaobrain/align-base")
>>> tokenizer = AutoTokenizer.from_pretrained("kakaobrain/align-base")

>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="pt")
>>> text_features = model.get_text_features(**inputs)```

#### get\_image\_features

[](#transformers.AlignModel.get_image_features)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1504)

( pixel\_values: typing.Optional\[torch.FloatTensor\] = Noneoutput\_hidden\_states: typing.Optional\[bool\] = Nonereturn\_dict: typing.Optional\[bool\] = None ) → image\_features (`torch.FloatTensor` of shape `(batch_size, output_dim`)

Parameters

-   [](#transformers.AlignModel.get_image_features.pixel_values)**pixel\_values** (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`) — Pixel values. Padding will be ignored by default should you provide it. Pixel values can be obtained using [AutoImageProcessor](/docs/transformers/v4.30.0/en/model_doc/auto#transformers.AutoImageProcessor). See [EfficientNetImageProcessor.**call**()](/docs/transformers/v4.30.0/en/model_doc/layoutlmv2#transformers.LayoutLMv2FeatureExtractor.__call__) for details.
-   [](#transformers.AlignModel.get_image_features.output_hidden_states)**output\_hidden\_states** (`bool`, _optional_) — Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for more detail.
-   [](#transformers.AlignModel.get_image_features.return_dict)**return\_dict** (`bool`, _optional_) — Whether or not to return a [ModelOutput](/docs/transformers/v4.30.0/en/main_classes/output#transformers.utils.ModelOutput) instead of a plain tuple.

Returns

image\_features (`torch.FloatTensor` of shape `(batch_size, output_dim`)

The image embeddings obtained by applying the projection layer to the pooled output of [AlignVisionModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignVisionModel).

The [AlignModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignModel) forward method, overrides the `__call__` special method.

Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.

Examples:

```
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AlignModel

>>> model = AlignModel.from_pretrained("kakaobrain/align-base")
>>> processor = AutoProcessor.from_pretrained("kakaobrain/align-base")

>>> 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)```

## [](#transformers.AlignTextModel)AlignTextModel

### class transformers.AlignTextModel

[](#transformers.AlignTextModel)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1208)

( config: AlignTextConfigadd\_pooling\_layer: bool = True )

Parameters

-   [](#transformers.AlignTextModel.config)**config** ([AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig)) — 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()](/docs/transformers/v4.30.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.

The text model from ALIGN without any head or projection on top. This model inherits from [PreTrainedModel](/docs/transformers/v4.30.0/en/main_classes/model#transformers.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](https://pytorch.org/docs/stable/nn.html#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

[](#transformers.AlignTextModel.forward)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1229)

( input\_ids: typing.Optional\[torch.Tensor\] = Noneattention\_mask: typing.Optional\[torch.Tensor\] = Nonetoken\_type\_ids: typing.Optional\[torch.Tensor\] = Noneposition\_ids: typing.Optional\[torch.Tensor\] = Nonehead\_mask: typing.Optional\[torch.Tensor\] = Noneinputs\_embeds: typing.Optional\[torch.Tensor\] = Noneoutput\_attentions: typing.Optional\[bool\] = Noneoutput\_hidden\_states: typing.Optional\[bool\] = Nonereturn\_dict: typing.Optional\[bool\] = None ) → [transformers.modeling\_outputs.BaseModelOutputWithPoolingAndCrossAttentions](/docs/transformers/v4.30.0/en/main_classes/output#transformers.modeling_outputs.BaseModelOutputWithPoolingAndCrossAttentions) or `tuple(torch.FloatTensor)`

The [AlignTextModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignTextModel) forward method, overrides the `__call__` special method.

Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.

Examples:

```
>>> from transformers import AutoTokenizer, AlignTextModel

>>> model = AlignTextModel.from_pretrained("kakaobrain/align-base")
>>> tokenizer = AutoTokenizer.from_pretrained("kakaobrain/align-base")

>>> 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  ```

## [](#transformers.AlignVisionModel)AlignVisionModel

### class transformers.AlignVisionModel

[](#transformers.AlignVisionModel)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1333)

( config: AlignVisionConfig )

Parameters

-   [](#transformers.AlignVisionModel.config)**config** ([AlignConfig](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignConfig)) — 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()](/docs/transformers/v4.30.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained) method to load the model weights.

The vision model from ALIGN without any head or projection on top. This model inherits from [PreTrainedModel](/docs/transformers/v4.30.0/en/main_classes/model#transformers.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](https://pytorch.org/docs/stable/nn.html#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

[](#transformers.AlignVisionModel.forward)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/models/align/modeling_align.py#L1357)

( pixel\_values: typing.Optional\[torch.FloatTensor\] = Noneoutput\_hidden\_states: typing.Optional\[bool\] = Nonereturn\_dict: typing.Optional\[bool\] = None ) → `transformers.modeling_outputs.BaseModelOutputWithPoolingAndNoAttention` or `tuple(torch.FloatTensor)`

The [AlignVisionModel](/docs/transformers/v4.30.0/en/model_doc/align#transformers.AlignVisionModel) forward method, overrides the `__call__` special method.

Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the pre and post processing steps while the latter silently ignores them.

Examples:

```
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, AlignVisionModel

>>> model = AlignVisionModel.from_pretrained("kakaobrain/align-base")
>>> processor = AutoProcessor.from_pretrained("kakaobrain/align-base")

>>> 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  ```