code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def encode(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
position_ids: Optional[jnp.ndarray] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
t... |
Returns:
Example:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer
>>> # initialize a bert2gpt2 from pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = FlaxEncoderDecoderModel.fro... | encode | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def decode(
self,
decoder_input_ids,
encoder_outputs,
encoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
decoder_position_ids: Optional[jnp.ndarray] = None,
past_key_values: Optional[dict] = None,
ou... |
Returns:
Example:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer
>>> import jax.numpy as jnp
>>> # initialize a bert2gpt2 from pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>>... | decode | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def __call__(
self,
input_ids: jnp.ndarray,
attention_mask: Optional[jnp.ndarray] = None,
decoder_input_ids: Optional[jnp.ndarray] = None,
decoder_attention_mask: Optional[jnp.ndarray] = None,
position_ids: Optional[jnp.ndarray] = None,
decoder_position_ids: Optio... |
Returns:
Examples:
```python
>>> from transformers import FlaxEncoderDecoderModel, BertTokenizer, GPT2Tokenizer
>>> # load a fine-tuned bert2gpt2 model
>>> model = FlaxEncoderDecoderModel.from_pretrained("patrickvonplaten/bert2gpt2-cnn_dailymail-fp16")
>>> # l... | __call__ | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
decoder_pretrained_model_name_or_path: Optional[Union[str, os.PathLike]] = None,
*model_args,
**kwargs,
) -> FlaxPreTrainedModel:
r"""
In... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
Params:
encoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*):
Information necessary to initiate the encoder. Can be either:
... | from_encoder_decoder_pretrained | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_flax_encoder_decoder.py | Apache-2.0 |
def from_encoder_decoder_pretrained(
cls,
encoder_pretrained_model_name_or_path: Optional[str] = None,
decoder_pretrained_model_name_or_path: Optional[str] = None,
*model_args,
**kwargs,
) -> TFPreTrainedModel:
r"""
Instantiate an encoder and a decoder from on... |
Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
checkpoints.
Params:
encoder_pretrained_model_name_or_path (`str`, *optional*):
Information necessary to initiate the encoder. Can be either:
... | from_encoder_decoder_pretrained | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
decoder_input_ids: np.ndarray | tf.Tensor | None = None,
decoder_attention_mask: np.ndarray | tf.Tensor | None = None,
encoder_outputs: np.ndarray | tf.Tensor ... |
Returns:
Examples:
```python
>>> from transformers import TFEncoderDecoderModel, BertTokenizer
>>> # initialize a bert2gpt2 from a pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized
>>> model = TFEncoderDecoderModel.from... | call | python | huggingface/transformers | src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/encoder_decoder/modeling_tf_encoder_decoder.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
task_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optiona... |
task_type_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Task type embedding is a special embedding to represent the characteristic of different tasks, such as
word-aware pre-training task, structure-aware pre-training task and semantic-aware pre-training... | forward | python | huggingface/transformers | src/transformers/models/ernie/modeling_ernie.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/ernie/modeling_ernie.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
encoder_hidden_states: ... |
input_ids (`torch.LongTensor` of shape `((batch_size, sequence_length))`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/esm/modeling_esm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/modeling_esm.py | Apache-2.0 |
def forward(self, x, mask=None, bias=None, indices=None):
"""
Basic self attention with optional mask and external pairwise bias. To handle sequences of different lengths,
use mask.
Inputs:
x: batch of input sequences (.. x L x C) mask: batch of boolean masks where 1=valid, ... |
Basic self attention with optional mask and external pairwise bias. To handle sequences of different lengths,
use mask.
Inputs:
x: batch of input sequences (.. x L x C) mask: batch of boolean masks where 1=valid, 0=padding position (..
x L_k) bias: batch of scalar pairw... | forward | python | huggingface/transformers | src/transformers/models/esm/modeling_esmfold.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(self, residue_index, mask=None):
"""
Input:
residue_index: B x L tensor of indices (dtype=torch.long) mask: B x L tensor of booleans
Output:
pairwise_state: B x L x L x pairwise_state_dim tensor of embeddings
"""
if residue_index.dtype != torch.lo... |
Input:
residue_index: B x L tensor of indices (dtype=torch.long) mask: B x L tensor of booleans
Output:
pairwise_state: B x L x L x pairwise_state_dim tensor of embeddings
| forward | python | huggingface/transformers | src/transformers/models/esm/modeling_esmfold.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def forward(
self,
input_ids: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
masking_pattern: Optional[torch.Tensor] = None,
num_recycles: Optional[int] = None,
output_hidden_states: Optional[bool] = False... |
masking_pattern (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Locations of tokens to mask during training as a form of regularization. Mask values selected in `[0, 1]`.
num_recycles (`int`, *optional*, defaults to `None`):
Number of times to recycle ... | forward | python | huggingface/transformers | src/transformers/models/esm/modeling_esmfold.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/modeling_esmfold.py | Apache-2.0 |
def call(
self,
input_ids: TFModelInputType | None = None,
attention_mask: np.ndarray | tf.Tensor | None = None,
position_ids: np.ndarray | tf.Tensor | None = None,
head_mask: np.ndarray | tf.Tensor | None = None,
inputs_embeds: np.ndarray | tf.Tensor | None = None,
... |
labels (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | call | python | huggingface/transformers | src/transformers/models/esm/modeling_tf_esm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/modeling_tf_esm.py | Apache-2.0 |
def to_tensor_4x4(self) -> torch.Tensor:
"""
Converts a transformation to a homogeneous transformation tensor.
Returns:
A [*, 4, 4] homogeneous transformation tensor
"""
tensor = self._trans.new_zeros((*self.shape, 4, 4))
tensor[..., :3, :3] = self._rots.get_... |
Converts a transformation to a homogeneous transformation tensor.
Returns:
A [*, 4, 4] homogeneous transformation tensor
| to_tensor_4x4 | python | huggingface/transformers | src/transformers/models/esm/openfold_utils/rigid_utils.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/openfold_utils/rigid_utils.py | Apache-2.0 |
def from_tensor_4x4(t: torch.Tensor) -> Rigid:
"""
Constructs a transformation from a homogeneous transformation tensor.
Args:
t: [*, 4, 4] homogeneous transformation tensor
Returns:
T object with shape [*]
"""
if t.shape[-2:] != (4, 4):
... |
Constructs a transformation from a homogeneous transformation tensor.
Args:
t: [*, 4, 4] homogeneous transformation tensor
Returns:
T object with shape [*]
| from_tensor_4x4 | python | huggingface/transformers | src/transformers/models/esm/openfold_utils/rigid_utils.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/esm/openfold_utils/rigid_utils.py | Apache-2.0 |
def _split_heads(self, fused_qkv: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""
Split the last dimension into (num_heads, head_dim), results share same memory storage as `fused_qkv`
Args:
fused_qkv (`torch.tensor`): [batch_size, seq_length, num_heads * 3 * he... |
Split the last dimension into (num_heads, head_dim), results share same memory storage as `fused_qkv`
Args:
fused_qkv (`torch.tensor`): [batch_size, seq_length, num_heads * 3 * head_dim]
Returns:
query: [batch_size, seq_length, num_heads, head_dim] key: [batch_size, se... | _split_heads | python | huggingface/transformers | src/transformers/models/falcon/modeling_falcon.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon/modeling_falcon.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
mamba_attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_value: Optional[FalconHybridMambaAttentionDynamicCache] = None,
... |
Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
`(batch, sequence_length)` where padding elements are indicated by 0.
past_key_value ... | forward | python | huggingface/transformers | src/transformers/models/falcon_h1/modeling_falcon_h1.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_h1/modeling_falcon_h1.py | Apache-2.0 |
def compute_mup_vector(config):
"""
Computes the MuP vector based on model configuration.
FalconH1 applies different MuP multiplier for each dimension of the hidden states.
The MuP vector is partitioned into chunks, and each chunk is multiplied with its
corresponding projected dimension.
Args:... |
Computes the MuP vector based on model configuration.
FalconH1 applies different MuP multiplier for each dimension of the hidden states.
The MuP vector is partitioned into chunks, and each chunk is multiplied with its
corresponding projected dimension.
Args:
config: FalconH1Config object
... | compute_mup_vector | python | huggingface/transformers | src/transformers/models/falcon_h1/modeling_falcon_h1.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_h1/modeling_falcon_h1.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[FalconHybridMambaAttentionDynamicCache] = None,
inputs_embeds: Optional[torch.FloatTensor] = No... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/falcon_h1/modeling_falcon_h1.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_h1/modeling_falcon_h1.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[FalconHybridMambaAttentionDynamicCache] = None,
inputs_embeds: Optional[torch.FloatTensor] = No... |
Example:
```python
>>> from transformers import AutoTokenizer, FalconH1ForCausalLM
>>> model = FalconH1ForCausalLM.from_pretrained("...")
>>> tokenizer = AutoTokenizer.from_pretrained("...")
>>> prompt = "Hey, are you conscious? Can you talk to me?"
>>> inputs... | forward | python | huggingface/transformers | src/transformers/models/falcon_h1/modular_falcon_h1.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_h1/modular_falcon_h1.py | Apache-2.0 |
def rms_forward(hidden_states, variance_epsilon=1e-6):
"""
Calculates simple RMSNorm with no learnable weights. `MambaRMSNorm` will
leverage this in order to multiply the final result with the RMSNorm weight
Args:
hidden_states (`torch.Tensor`):
Hidden states to normalize
va... |
Calculates simple RMSNorm with no learnable weights. `MambaRMSNorm` will
leverage this in order to multiply the final result with the RMSNorm weight
Args:
hidden_states (`torch.Tensor`):
Hidden states to normalize
variance_epsilon (`float`):
The eps value to add in ... | rms_forward | python | huggingface/transformers | src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | Apache-2.0 |
def __init__(self, hidden_size, eps=1e-6):
"""
FalconMambaRMSNorm is equivalent to T5LayerNorm and LlamaRMSNorm
"""
super().__init__()
self.weight = nn.Parameter(torch.ones(hidden_size))
self.variance_epsilon = eps |
FalconMambaRMSNorm is equivalent to T5LayerNorm and LlamaRMSNorm
| __init__ | python | huggingface/transformers | src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.LongTensor] = None,
cache_params: Optional[MambaCache] = None,
use_cache: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool]... |
cache_params (`MambaCache`, *optional*):
If passed along, the model uses the previous state in all the blocks (which will give the output for the
`input_ids` provided as if the model add `state_input_ids + input_ids` as context).
use_cache (`bool`, *optional*):
If se... | forward | python | huggingface/transformers | src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.LongTensor] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
cache_params: Optional[MambaCache] = None,
labels: Optional[torch.LongTensor] = None,
output_hidd... |
cache_params (`MambaCache`, *optional*):
If passed along, the model uses the previous state in all the blocks (which will give the output for the
`input_ids` provided as if the model add `state_input_ids + input_ids` as context).
labels (`torch.LongTensor` of shape `(batch_size,... | forward | python | huggingface/transformers | src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/falcon_mamba/modeling_falcon_mamba.py | Apache-2.0 |
def length_regulator(encoded_embeddings, duration_labels, speaking_speed=1.0):
"""
Length regulator for feed-forward Transformer.
This is the length regulator module described in `FastSpeech: Fast, Robust and Controllable Text to Speech`
https://arxiv.org/pdf/1905.09263.pdf. The length regulator expand... |
Length regulator for feed-forward Transformer.
This is the length regulator module described in `FastSpeech: Fast, Robust and Controllable Text to Speech`
https://arxiv.org/pdf/1905.09263.pdf. The length regulator expands char or phoneme-level embedding features to
frame-level by repeating each featur... | length_regulator | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, encoder_hidden_states):
"""
Args:
hidden_states (`torch.Tensor` of shape `(batch_size, max_text_length, input_dim)`):
Batch of input sequences.
padding_masks (`torch.ByteTensor` of shape `(batch_size, max_text_length)`, *optional*):
... |
Args:
hidden_states (`torch.Tensor` of shape `(batch_size, max_text_length, input_dim)`):
Batch of input sequences.
padding_masks (`torch.ByteTensor` of shape `(batch_size, max_text_length)`, *optional*):
Batch of masks indicating padded part.
Re... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def __init__(
self,
config: FastSpeech2ConformerConfig,
num_layers=2,
num_chans=384,
kernel_size=3,
dropout_rate=0.5,
):
"""
Initialize variance predictor module.
Args:
input_dim (`int`): Input dimension.
num_layers (`i... |
Initialize variance predictor module.
Args:
input_dim (`int`): Input dimension.
num_layers (`int`, *optional*, defaults to 2): Number of convolutional layers.
num_chans (`int`, *optional*, defaults to 384): Number of channels of convolutional layers.
ker... | __init__ | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, encoder_hidden_states, padding_masks=None):
"""
Calculate forward propagation.
Args:
encoder_hidden_states (`torch.Tensor` of shape `(batch_size, max_text_length, input_dim)`):
Batch of input sequences.
padding_masks (`torch.ByteTensor` ... |
Calculate forward propagation.
Args:
encoder_hidden_states (`torch.Tensor` of shape `(batch_size, max_text_length, input_dim)`):
Batch of input sequences.
padding_masks (`torch.ByteTensor` of shape `(batch_size, max_text_length)`, *optional*):
Ba... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def shift_relative_position_tensor(self, pos_tensor):
"""
Args:
pos_tensor (torch.Tensor of shape (batch_size, head, time1, 2*time1-1)): Input tensor.
"""
zero_pad = torch.zeros((*pos_tensor.size()[:3], 1), device=pos_tensor.device, dtype=pos_tensor.dtype)
pos_tensor_... |
Args:
pos_tensor (torch.Tensor of shape (batch_size, head, time1, 2*time1-1)): Input tensor.
| shift_relative_position_tensor | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
pos_emb: Optional[torch.Tensor] = None,
output_attentions: Optional[torch.Tensor] = False,
) -> Tuple[torch.Tensor, torch.Tensor]:
"""
Compute 'Scaled Dot Product At... |
Compute 'Scaled Dot Product Attention' with rel. positional encoding.
Args:
hidden_states (`torch.Tensor` of shape `(batch, time2, size)`): Values of the hidden states
attention_mask (`torch.Tensor` of shape `(batch, time1, time2)`): Mask tensor.
pos_emb (`torch.Ten... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, hidden_states):
"""
Compute convolution module.
Args:
hidden_states (`torch.Tensor` of shape `(batch, time, channels)`): Input tensor.
Returns:
`torch.Tensor`: Output tensor of shape `(batch, time, channels)`.
"""
# exchange th... |
Compute convolution module.
Args:
hidden_states (`torch.Tensor` of shape `(batch, time, channels)`): Input tensor.
Returns:
`torch.Tensor`: Output tensor of shape `(batch, time, channels)`.
| forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
pos_emb: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[torch.Tensor] = False,
):
"""
Compute encoded features.
Args:
hidden_states ... |
Compute encoded features.
Args:
hidden_states (`torch.Tensor` of shape `(batch, time, size)`): Input tensor.
pos_emb (`torch.Tensor` of shape `(1, time, size)`): Positional embeddings tensor.
attention_mask (`torch.Tensor` of shape `(batch, time)`): Attention mask t... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def __init__(self, config: FastSpeech2ConformerConfig, module_config):
"""
Initialize FastSpeech2ConformerMultiLayeredConv1d module.
Args:
input_channels (`int`): Number of input channels.
hidden_channels (`int`): Number of hidden channels.
kernel_size (`int`... |
Initialize FastSpeech2ConformerMultiLayeredConv1d module.
Args:
input_channels (`int`): Number of input channels.
hidden_channels (`int`): Number of hidden channels.
kernel_size (`int`): Kernel size of conv1d.
dropout_rate (`float`): Dropout rate.
... | __init__ | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, hidden_states):
"""
Calculate forward propagation.
Args:
hidden_states (torch.Tensor): Batch of input tensors (batch_size, time, input_channels).
Returns:
torch.Tensor: Batch of output tensors (batch_size, time, hidden_channels).
"""
... |
Calculate forward propagation.
Args:
hidden_states (torch.Tensor): Batch of input tensors (batch_size, time, input_channels).
Returns:
torch.Tensor: Batch of output tensors (batch_size, time, hidden_channels).
| forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, feature_representation):
"""
Args:
feature_representation (`torch.Tensor` of shape (batch_size, time, `*`)):
Input tensor.
Returns:
`torch.Tensor`: Encoded tensor (batch_size, time, `*`).
"""
self.extend_pos_enc(feature_r... |
Args:
feature_representation (`torch.Tensor` of shape (batch_size, time, `*`)):
Input tensor.
Returns:
`torch.Tensor`: Encoded tensor (batch_size, time, `*`).
| forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
input_tensor: torch.LongTensor,
attention_mask: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
output_attentions: Optional[bool] = False,
return_dict: Optional[bool] = None,
):
"""
Args:
input_ids (`t... |
Args:
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you
provide it.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTra... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
outputs_after_postnet,
outputs_before_postnet,
duration_outputs,
pitch_outputs,
energy_outputs,
spectrogram_labels,
duration_labels,
pitch_labels,
energy_labels,
duration_mask,
spectrogram_mask,
):
... |
Args:
outputs_after_postnet (`torch.Tensor` of shape `(batch_size, max_spectrogram_length, num_mel_bins)`):
Batch of outputs after postnet.
outputs_before_postnet (`torch.Tensor` of shape `(batch_size, max_spectrogram_length, num_mel_bins)`):
Batch of out... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor,
attention_mask: Optional[torch.LongTensor] = None,
spectrogram_labels: Optional[torch.FloatTensor] = None,
duration_labels: Optional[torch.LongTensor] = None,
pitch_labels: Optional[torch.FloatTensor] = None,
energy_... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Input sequence of text vectors.
spectrogram_labels (`torch.FloatTensor` of shape `(batch_size, max_spectrogram_length, num_mel_bins)`, *optional*, defaults to `None`):
Batch of padded target features.
... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(self, spectrogram: torch.FloatTensor) -> torch.FloatTensor:
r"""
spectrogram (`torch.FloatTensor`):
Tensor containing the log-mel spectrograms. Can be batched and of shape `(batch_size, sequence_length,
config.model_in_dim)`, or un-batched and of shape `(sequence_leng... |
spectrogram (`torch.FloatTensor`):
Tensor containing the log-mel spectrograms. Can be batched and of shape `(batch_size, sequence_length,
config.model_in_dim)`, or un-batched and of shape `(sequence_length, config.model_in_dim)`.
Returns:
`torch.FloatTensor`: Tensor... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor,
attention_mask: Optional[torch.LongTensor] = None,
spectrogram_labels: Optional[torch.FloatTensor] = None,
duration_labels: Optional[torch.LongTensor] = None,
pitch_labels: Optional[torch.FloatTensor] = None,
energy_... |
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
Input sequence of text vectors.
spectrogram_labels (`torch.FloatTensor` of shape `(batch_size, max_spectrogram_length, num_mel_bins)`, *optional*, defaults to `None`):
Batch of padded target features.
... | forward | python | huggingface/transformers | src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fastspeech2_conformer/modeling_fastspeech2_conformer.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.FloatTensor,
start_positions: Optional[torch.LongTensor] = None,
end_positions: Optional[torch.LongTensor] = None,
cls_index: Optional[torch.LongTensor] = None,
is_impossible: Optional[torch.LongTensor] = None,
p_mask: Optio... |
hidden_states (`torch.FloatTensor` of shape `(batch_size, seq_len, hidden_size)`):
Final hidden states of the model on the sequence tokens.
start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Positions of the first token for the labeled span.
end_p... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.FloatTensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.LongTensor] = None,
position_ids: Optional[torch.LongTensor] = None,
lengths: ... |
lengths (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Length of each sentence that can be used to avoid performing attention on padding token indices. You can
also use `attention_mask` for the same result (see above), kept here for compatibility. Indices selected in
... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
lengths (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Length of each sentence that can be used to avoid performing attention on padding token indices. You can
also use `attention_mask` for the same result (see above), kept here for compatibility. Indices selected in
... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
langs (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
A parallel sequence of tokens to be used to indicate the language of each token in the input. Indices are
languages ids which can be obtained from the language names by using two conversion mappings provide... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
langs (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
A parallel sequence of tokens to be used to indicate the language of each token in the input. Indices are
languages ids which can be obtained from the language names by using two conversion mappings provide... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
langs (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
A parallel sequence of tokens to be used to indicate the language of each token in the input. Indices are
languages ids which can be obtained from the language names by using two conversion mappings provide... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
langs (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
A parallel sequence of tokens to be used to indicate the language of each token in the input. Indices are
languages ids which can be obtained from the language names by using two conversion mappings provide... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
langs: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
lengths: Optional[torch.Te... |
input_ids (`torch.LongTensor` of shape `(batch_size, num_choices, sequence_length)`):
Indices of input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__call__`] for details.
... | forward | python | huggingface/transformers | src/transformers/models/flaubert/modeling_flaubert.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flaubert/modeling_flaubert.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
interpolate_pos_encoding: Optional[bool] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_att... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
| forward | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Opt... |
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`):
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
[`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
... | forward | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def forward(
self,
hidden_states: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
... |
hidden_states (`torch.FloatTensor` of shape `(batch_size, image_num_patches + text_seq_len, hidden_size)`):
The concatenated hidden states of unimodal encoders.
| forward | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def get_text_features(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
output_attentions: Optional[bool] = None,
output_hidde... |
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_length)`):
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
[`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
... | get_text_features | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
interpolate_pos_encoding: Optional[bool] = None,
attention_mask: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, image_num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Returns:
image_features (`torch.FloatTensor` of shape `(batch_size, output_dim`): The image embeddings obtaine... | get_image_features | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
pixel_values: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
bool_masked_pos: Optional[torch.Tensor] = None,
positio... |
input_ids (`torch.LongTensor` of shape `(batch_size, image_num_patches + text_seq_len)`):
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
[`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are i... | forward | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def __init__(self, config: FlavaConfig, image_codebook: Optional[nn.Module] = None):
r"""
image_codebook ([`nn.Module`]):
If passed, the image codebook will be set to this. Otherwise, it will be initialized using the
image_codebook_config defined in the config first as the first ... |
image_codebook ([`nn.Module`]):
If passed, the image codebook will be set to this. Otherwise, it will be initialized using the
image_codebook_config defined in the config first as the first parameter.
| __init__ | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
input_ids_masked: Optional[torch.LongTensor] = None,
pixel_values: Optional[torch.FloatTensor] = None,
codebook_pixel_values: Optional[torch.FloatTensor] = None,
attention_mask: Optional[torch.Tensor] = None... |
input_ids (`torch.LongTensor` of shape `(batch_size, text_seq_len)`):
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`AutoTokenizer`]. See
[`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input
IDs... | forward | python | huggingface/transformers | src/transformers/models/flava/modeling_flava.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/flava/modeling_flava.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
next_sentence_label: Optio... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should be in `[-100, 0, ...,
config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` are ignored (masked), the
... | forward | python | huggingface/transformers | src/transformers/models/fnet/modeling_fnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fnet/modeling_fnet.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_hidden_states: Opti... |
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
Labels for computing the next sequence prediction (classification) loss. Input should be a sequence pair
(see `input_ids` docstring). Indices should be in `[0, 1]`:
- 0 indicates sequence B is a continuation ... | forward | python | huggingface/transformers | src/transformers/models/fnet/modeling_fnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fnet/modeling_fnet.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
bool_masked_pos: Optional[torch.BoolTensor] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple, FocalNetMaskedImageModelingOutput]:
r"""
... |
bool_masked_pos (`torch.BoolTensor` of shape `(batch_size, num_patches)`):
Boolean masked positions. Indicates which patches are masked (1) and which aren't (0).
Examples:
```python
>>> from transformers import AutoImageProcessor, FocalNetConfig, FocalNetForMaskedImageModel... | forward | python | huggingface/transformers | src/transformers/models/focalnet/modeling_focalnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/focalnet/modeling_focalnet.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.Tensor,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> BackboneOutput:
r"""
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> imp... |
Examples:
```python
>>> from transformers import AutoImageProcessor, AutoBackbone
>>> import torch
>>> from PIL import Image
>>> import requests
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, ... | forward | python | huggingface/transformers | src/transformers/models/focalnet/modeling_focalnet.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/focalnet/modeling_focalnet.py | Apache-2.0 |
def forward(
self,
input_ids: torch.Tensor,
attention_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
output_attentions: bool = False,
output_hidden_states: bool = False,
return_d... |
Args:
input_ids (`torch.LongTensor`): tokens in the source language of shape
*(batch, src_len)*
attention_mask (`torch.LongTensor`): indicating which indices are padding tokens
inputs_embeds (`torch.FloatTensor`):
embedding vectors of shape *(... | forward | python | huggingface/transformers | src/transformers/models/fsmt/modeling_fsmt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fsmt/modeling_fsmt.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor,
attention_mask: Optional[torch.Tensor] = None,
decoder_input_ids: Optional[torch.LongTensor] = None,
decoder_attention_mask: Optional[torch.BoolTensor] = None,
head_mask: Optional[torch.Tensor] = None,
decoder_head_m... |
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
Indices of decoder input sequence tokens in the vocabulary.
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
[`PreTrainedTokenizer.__ca... | forward | python | huggingface/transformers | src/transformers/models/fsmt/modeling_fsmt.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fsmt/modeling_fsmt.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
token_type_ids: Optional[torch.Tensor] = None,
inputs_embeds: Optional[torch.Tensor] = None,
labels: Optional[torch.Tensor] = None,
output_attentions: Optio... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the ELECTRA-style loss. Input should be a sequence of tokens (see `input_ids`
docstring) Indices should be in `[0, 1]`:
- 0 indicates the token is an original token,
... | forward | python | huggingface/transformers | src/transformers/models/funnel/modeling_funnel.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/funnel/modeling_funnel.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
image_patches: torch.Tensor = None, # [batch_size, num_total_patches, patch_size_ x patch_size x num_channels ]
image_patches_indices: torch.Tensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids:... |
image_patches (`torch.FloatTensor` of shape `(batch_size, num_total_patches, patch_size_ x patch_size x num_channels)`, *optional*):
Image patches to be used as continuous embeddings. The patches are flattened and then projected to the
hidden size of the model.
image_patches_ind... | forward | python | huggingface/transformers | src/transformers/models/fuyu/modeling_fuyu.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fuyu/modeling_fuyu.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
image_patches: torch.Tensor = None, # [batch_size, num_total_patches, patch_size_ x patch_size x num_channels ]
image_patches_indices: torch.Tensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids:... |
image_patches (`torch.FloatTensor` of shape `(batch_size, num_total_patches, patch_size_ x patch_size x num_channels)`, *optional*):
Image patches to be used as continuous embeddings. The patches are flattened and then projected to the
hidden size of the model.
labels (`torch.Lo... | forward | python | huggingface/transformers | src/transformers/models/fuyu/modeling_fuyu.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fuyu/modeling_fuyu.py | Apache-2.0 |
def __call__(
self,
images: ImageInput = None,
text: Optional[Union[str, List[str], TextInput, PreTokenizedInput]] = None,
audio=None,
videos=None,
**kwargs: Unpack[FuyuProcessorKwargs],
) -> "FuyuBatchFeature":
"""
Main method to prepare for the model... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to LlamaTokenizerFast's [`~LlamaTokenizerFast.__call__`] if `text` is not `None` to
encode the text. To prepare the image(s), this method forwards the `images` a... | __call__ | python | huggingface/transformers | src/transformers/models/fuyu/processing_fuyu.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fuyu/processing_fuyu.py | Apache-2.0 |
def post_process_image_text_to_text(self, generated_outputs, skip_special_tokens=True, **kwargs):
"""
Post-processes the output of `FuyuForConditionalGeneration` to only return the text output.
Args:
generated_outputs (`torch.Tensor` or `np.ndarray`):
The output of t... |
Post-processes the output of `FuyuForConditionalGeneration` to only return the text output.
Args:
generated_outputs (`torch.Tensor` or `np.ndarray`):
The output of the model. The output is expected to be a tensor of shape `(batch_size, sequence_length)`
cont... | post_process_image_text_to_text | python | huggingface/transformers | src/transformers/models/fuyu/processing_fuyu.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/fuyu/processing_fuyu.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/gemma/modeling_gemma.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma/modeling_gemma.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/gemma2/modeling_gemma2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma2/modeling_gemma2.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
Example:
```python
>>> from transformers import AutoTokenizer, Gemma2ForCausalLM
>>> model = Gemma2ForCausalLM.from_pretrained("google/gemma-2-9b")
>>> tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b")
>>> prompt = "What is your favorite condiment?"
... | forward | python | huggingface/transformers | src/transformers/models/gemma2/modular_gemma2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma2/modular_gemma2.py | Apache-2.0 |
def convert(checkpoint_path: str, config: Gemma3Config) -> dict[str, torch.Tensor]:
"""Loads Orbax checkpoint from `input_path` and converts it to HF tree."""
checkpointer = obc.PyTreeCheckpointer()
ckpt = checkpointer.restore(checkpoint_path)
hf_tree: dict[str, torch.Tensor] = {}
def update_tree(p... | Loads Orbax checkpoint from `input_path` and converts it to HF tree. | convert | python | huggingface/transformers | src/transformers/models/gemma3/convert_gemma3_weights_orbax_to_hf.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/convert_gemma3_weights_orbax_to_hf.py | Apache-2.0 |
def pan_and_scan(
self,
image: np.ndarray,
pan_and_scan_min_crop_size: int,
pan_and_scan_max_num_crops: int,
pan_and_scan_min_ratio_to_activate: float,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimens... |
Pan and Scan and image, by cropping into smaller images when the aspect ratio exceeds
minimum allowed ratio.
Args:
image (`np.ndarray`):
Image to resize.
pan_and_scan_min_crop_size (`int`, *optional*):
Minimum size of each crop in pan and... | pan_and_scan | python | huggingface/transformers | src/transformers/models/gemma3/image_processing_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/image_processing_gemma3.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
resample: PILImageResampling = None,
do_rescale: Optional[bool] = None,
rescale_factor: Optional[float] = None,
do_normalize: Optional[bool] ... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
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 `do_rescale=False`.
... | preprocess | python | huggingface/transformers | src/transformers/models/gemma3/image_processing_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/image_processing_gemma3.py | Apache-2.0 |
def pan_and_scan_batched(
self,
images: "torch.Tensor",
pan_and_scan_min_crop_size: int,
pan_and_scan_max_num_crops: int,
pan_and_scan_min_ratio_to_activate: float,
):
"""
Pan and Scan an image, by cropping into smaller images when the aspect ratio exceeds
... |
Pan and Scan an image, by cropping into smaller images when the aspect ratio exceeds
minimum allowed ratio.
Args:
image (`torch.Tensor`):
Image to resize.
pan_and_scan_min_crop_size (`int`, *optional*):
Minimum size of each crop in pan an... | pan_and_scan_batched | python | huggingface/transformers | src/transformers/models/gemma3/image_processing_gemma3_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/image_processing_gemma3_fast.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/gemma3/modeling_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/modeling_gemma3.py | Apache-2.0 |
def get_image_features(self, pixel_values: torch.Tensor) -> torch.Tensor:
"""
Projects the last hidden state from the vision model into language model space.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`)
The tensors corresp... |
Projects the last hidden state from the vision model into language model space.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`)
The tensors corresponding to the input images.
Returns:
image_features (`torch.Tenso... | get_image_features | python | huggingface/transformers | src/transformers/models/gemma3/modeling_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/modeling_gemma3.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[List[torch.FloatTensor], Cache]] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.text_config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are igno... | forward | python | huggingface/transformers | src/transformers/models/gemma3/modeling_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/modeling_gemma3.py | Apache-2.0 |
def forward(
self,
input_ids: torch.LongTensor = None,
pixel_values: torch.FloatTensor = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Union[List[torch.FloatTensor], Cache]] = None,
... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.text_config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are igno... | forward | python | huggingface/transformers | src/transformers/models/gemma3/modeling_gemma3.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/gemma3/modeling_gemma3.py | Apache-2.0 |
def read_video_pyav(container, indices):
"""
Decode the video with PyAV decoder.
Args:
container (`av.container.input.InputContainer`): PyAV container.
indices (`List[int]`): List of frame indices to decode.
Returns:
result (np.ndarray): np array of ... |
Decode the video with PyAV decoder.
Args:
container (`av.container.input.InputContainer`): PyAV container.
indices (`List[int]`): List of frame indices to decode.
Returns:
result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, ... | read_video_pyav | python | huggingface/transformers | src/transformers/models/git/convert_git_to_pytorch.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/git/convert_git_to_pytorch.py | Apache-2.0 |
def forward(
self,
pixel_values: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
interpolate_pos_encoding: bool = False,
return_dict: Optional[bool] = None,
) -> Union[Tuple, BaseModelOutput]:
... |
Examples:
```python
>>> from PIL import Image
>>> import requests
>>> from transformers import AutoProcessor, GitVisionModel
>>> processor = AutoProcessor.from_pretrained("microsoft/git-base")
>>> model = GitVisionModel.from_pretrained("microsoft/git-base")
... | forward | python | huggingface/transformers | src/transformers/models/git/modeling_git.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/git/modeling_git.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
pixel_values: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[... |
Examples:
```python
>>> from transformers import AutoProcessor, AutoModel
>>> import requests
>>> from PIL import Image
>>> processor = AutoProcessor.from_pretrained("microsoft/git-base")
>>> model = AutoModel.from_pretrained("microsoft/git-base")
>>> ... | forward | python | huggingface/transformers | src/transformers/models/git/modeling_git.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/git/modeling_git.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.Tensor] = None,
pixel_values: Optional[torch.Tensor] = None,
head_mask: Optional[torch.Tensor] = None,
inputs_embeds: Optional[... |
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the left-to-right language modeling loss (next word prediction). Indices should be in
`[-100, 0, ..., config.vocab_size]` (see `input_ids` docstring) Tokens with indices set to `-100` ... | forward | python | huggingface/transformers | src/transformers/models/git/modeling_git.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/git/modeling_git.py | Apache-2.0 |
def __call__(
self,
images: Optional[ImageInput] = None,
text: Optional[Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]]] = None,
audio=None,
videos=None,
**kwargs: Unpack[GitProcessorKwargs],
) -> BatchFeature:
"""
Main me... |
Main method to prepare for the model one or several sequences(s) and image(s). This method forwards the `text`
and `kwargs` arguments to BertTokenizerFast's [`~BertTokenizerFast.__call__`] if `text` is not `None` to encode
the text. To prepare the image(s), this method forwards the `images` and... | __call__ | python | huggingface/transformers | src/transformers/models/git/processing_git.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/git/processing_git.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/glm/modeling_glm.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/glm/modeling_glm.py | Apache-2.0 |
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
attention_mask: Optional[torch.Tensor] = None,
position_ids: Optional[torch.LongTensor] = None,
past_key_values: Optional[Cache] = None,
inputs_embeds: Optional[torch.FloatTensor] = None,
labels: Opt... |
labels (`torch.LongTensor` of 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 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
... | forward | python | huggingface/transformers | src/transformers/models/glm4/modeling_glm4.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/glm4/modeling_glm4.py | Apache-2.0 |
def forward(
self,
pixel_values: torch.FloatTensor,
labels: Optional[torch.FloatTensor] = None,
output_attentions: Optional[bool] = None,
output_hidden_states: Optional[bool] = None,
return_dict: Optional[bool] = None,
) -> Union[Tuple[torch.Tensor], DepthEstimatorOut... |
labels (`torch.FloatTensor` of shape `(batch_size, height, width)`, *optional*):
Ground truth depth estimation maps for computing the loss.
Examples:
```python
>>> from transformers import AutoImageProcessor, GLPNForDepthEstimation
>>> import torch
>>> impo... | forward | python | huggingface/transformers | src/transformers/models/glpn/modeling_glpn.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/glpn/modeling_glpn.py | Apache-2.0 |
def get_all_supported_aspect_ratios(min_image_tiles: int, max_image_tiles: int) -> List[Tuple[int, int]]:
"""
Computes all allowed aspect ratios for a given minimum and maximum number of input tiles.
This function calculates all possible arrangements of tiles that can be formed
within the constraint of... |
Computes all allowed aspect ratios for a given minimum and maximum number of input tiles.
This function calculates all possible arrangements of tiles that can be formed
within the constraint of the minimum and maximum number of tiles. Each arrangement is
represented by its aspect ratio (width/height) ... | get_all_supported_aspect_ratios | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2.py | Apache-2.0 |
def get_optimal_tiled_canvas(
original_image_size: Tuple[int, int],
target_tile_size: Tuple[int, int],
min_image_tiles: int,
max_image_tiles: int,
) -> Tuple[int, int]:
"""
Given a minimum and maximum number of tiles, find the canvas with the closest aspect ratio to the
original image aspect... |
Given a minimum and maximum number of tiles, find the canvas with the closest aspect ratio to the
original image aspect ratio.
In case of tie-breaking condition when two canvases have the same aspect ratio difference, we favor the canvas with
more tiles, until the area covered by the tiles is more than... | get_optimal_tiled_canvas | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2.py | Apache-2.0 |
def preprocess(
self,
images: ImageInput,
do_resize: Optional[bool] = None,
size: Optional[Dict[str, int]] = None,
crop_to_patches: Optional[bool] = None,
min_patches: Optional[int] = None,
max_patches: Optional[int] = None,
resample: PILImageResampling = ... |
Preprocess an image or batch of images.
Args:
images (`ImageInput`):
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 `do_rescale=False`.
... | preprocess | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2.py | Apache-2.0 |
def crop_image_to_patches(
self,
images: np.ndarray,
min_patches: int,
max_patches: int,
use_thumbnail: bool = True,
patch_size: Optional[Union[Tuple, int, dict]] = None,
data_format: ChannelDimension = None,
):
"""
Crop the image to patches an... |
Crop the image to patches and return a list of cropped images.
The number of patches and their grid arrangement are determined by the original image size,
the target patch size and the minimum and maximum number of patches.
The aspect ratio of the patches grid is chosen to be the closes... | crop_image_to_patches | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2.py | Apache-2.0 |
def get_number_of_image_patches(self, height: int, width: int, images_kwargs=None):
"""
A utility that returns number patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the input image.... |
A utility that returns number patches for a given image size.
Args:
height (`int`):
Height of the input image.
width (`int`):
Width of the input image.
images_kwargs (`dict`, *optional*)
Any kwargs to override defaults... | get_number_of_image_patches | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2.py | Apache-2.0 |
def crop_image_to_patches(
self,
images: "torch.Tensor",
min_patches: int,
max_patches: int,
use_thumbnail: bool = True,
patch_size: Optional[Union[Tuple, int, dict]] = None,
interpolation: Optional["F.InterpolationMode"] = None,
):
"""
Crop th... |
Crop the images to patches and return a list of cropped images.
The number of patches and their grid arrangement are determined by the original image size,
the target patch size and the minimum and maximum number of patches.
The aspect ratio of the patches grid is chosen to be the close... | crop_image_to_patches | python | huggingface/transformers | src/transformers/models/got_ocr2/image_processing_got_ocr2_fast.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/image_processing_got_ocr2_fast.py | Apache-2.0 |
def get_decomposed_rel_pos(
self,
query: torch.Tensor,
rel_pos_h: torch.Tensor,
rel_pos_w: torch.Tensor,
q_size: Tuple[int, int],
k_size: Tuple[int, int],
) -> torch.Tensor:
"""
Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`.
... |
Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`.
https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py
Args:
query (`torch.Tensor`):
query q in the attention layer with shape (batch_s... | get_decomposed_rel_pos | python | huggingface/transformers | src/transformers/models/got_ocr2/modeling_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/modeling_got_ocr2.py | Apache-2.0 |
def get_image_features(
self,
pixel_values: torch.FloatTensor,
):
"""
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`)
Return... |
Obtains image last hidden states from the vision tower and apply multimodal projection.
Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, channels, height, width)`)
Returns:
image_features (`torch.Tensor`): Image feature tensor of shape `(num_images, image... | get_image_features | python | huggingface/transformers | src/transformers/models/got_ocr2/modeling_got_ocr2.py | https://github.com/huggingface/transformers/blob/master/src/transformers/models/got_ocr2/modeling_got_ocr2.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.