Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix doc example] FlaxVisionEncoderDecoder #15626

Merged
merged 5 commits into from
Feb 14, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def encode(
Example:

```python
>>> from transformers import FlaxVisionEncoderDecoderModel
>>> from transformers import FlaxVisionEncoderDecoderModel, ViTFeatureExtractor
ydshieh marked this conversation as resolved.
Show resolved Hide resolved
>>> from PIL import Image
>>> import requests

Expand All @@ -403,7 +403,9 @@ def encode(
>>> feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224-in21k")

>>> # initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained("vit", "gpt2")
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
... "google/vit-base-patch16-224-in21k", "gpt2"
... )

>>> pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values
>>> encoder_outputs = model.encode(pixel_values)
Expand Down Expand Up @@ -469,7 +471,7 @@ def decode(
Example:

```python
>>> from transformers import FlaxVisionEncoderDecoderModel
>>> from transformers import FlaxVisionEncoderDecoderModel, ViTFeatureExtractor
ydshieh marked this conversation as resolved.
Show resolved Hide resolved
>>> import jax.numpy as jnp
>>> from PIL import Image
>>> import requests
Expand All @@ -480,7 +482,9 @@ def decode(
>>> feature_extractor = ViTFeatureExtractor.from_pretrained("google/vit-base-patch16-224-in21k")

>>> # initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained("vit", "gpt2")
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
... "google/vit-base-patch16-224-in21k", "gpt2"
... )

>>> pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values
>>> encoder_outputs = model.encode(pixel_values)
Expand Down Expand Up @@ -610,7 +614,9 @@ def __call__(
>>> tokenizer_output = GPT2Tokenizer.from_pretrained("gpt2")

>>> # initialize a vit-gpt2 from pretrained ViT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained("vit", "gpt2")
>>> model = FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
... "google/vit-base-patch16-224-in21k", "gpt2"
... )

>>> pixel_values = feature_extractor(images=image, return_tensors="np").pixel_values

Expand Down