text
stringlengths
31
243k
type
stringclasses
1 value
start
int64
36
275k
end
int64
286
280k
depth
int64
0
1
filepath
stringlengths
85
188
parent_class
stringclasses
3 values
class_index
int64
0
10.8k
class MaskFormerSwinModelOutputWithPooling(ModelOutput): """ Class for MaskFormerSwinModel's outputs that also contains the spatial dimensions of the hidden states. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-st...
class_definition
1,419
3,446
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,200
class MaskFormerSwinBaseModelOutput(ModelOutput): """ Class for SwinEncoder's outputs. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-states at the output of the last layer of the model. hidden_states (`tup...
class_definition
3,460
5,212
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,201
class MaskFormerSwinEmbeddings(nn.Module): """ Construct the patch and position embeddings. """ def __init__(self, config): super().__init__() self.patch_embeddings = MaskFormerSwinPatchEmbeddings(config) num_patches = self.patch_embeddings.num_patches self.patch_grid =...
class_definition
7,376
10,590
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,202
class MaskFormerSwinPatchEmbeddings(nn.Module): """ This class turns `pixel_values` of shape `(batch_size, num_channels, height, width)` into the initial `hidden_states` (patch embeddings) of shape `(batch_size, seq_length, hidden_size)` to be consumed by a Transformer. """ def __init__(self, c...
class_definition
10,692
12,882
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,203
class MaskFormerSwinPatchMerging(nn.Module): """ Patch Merging Layer. Args: input_resolution (`Tuple[int]`): Resolution of input feature. dim (`int`): Number of input channels. norm_layer (`nn.Module`, *optional*, defaults to `nn.LayerNorm`): Norm...
class_definition
12,955
15,243
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,204
class MaskFormerSwinDropPath(nn.Module): """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).""" def __init__(self, drop_prob: Optional[float] = None) -> None: super().__init__() self.drop_prob = drop_prob def forward(self, hidden_states: torch.Tensor...
class_definition
15,338
15,826
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,205
class MaskFormerSwinSelfAttention(nn.Module): def __init__(self, config, dim, num_heads, window_size): super().__init__() if dim % num_heads != 0: raise ValueError( f"The hidden size ({dim}) is not a multiple of the number of attention heads ({num_heads})" ) ...
class_definition
15,926
20,813
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,206
class MaskFormerSwinSelfOutput(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(dim, dim) self.dropout = nn.Dropout(config.attention_probs_dropout_prob) def forward(self, hidden_states: torch.Tensor, input_tensor: torch.Tensor) -> torch.Tensor: ...
class_definition
20,910
21,357
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,207
class MaskFormerSwinAttention(nn.Module): def __init__(self, config, dim, num_heads, window_size): super().__init__() self.self = MaskFormerSwinSelfAttention(config, dim, num_heads, window_size) self.output = MaskFormerSwinSelfOutput(config, dim) self.pruned_heads = set() def pr...
class_definition
21,453
23,161
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,208
class MaskFormerSwinIntermediate(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(dim, int(config.mlp_ratio * dim)) if isinstance(config.hidden_act, str): self.intermediate_act_fn = ACT2FN[config.hidden_act] else: self.int...
class_definition
23,260
23,828
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,209
class MaskFormerSwinOutput(nn.Module): def __init__(self, config, dim): super().__init__() self.dense = nn.Linear(int(config.mlp_ratio * dim), dim) self.dropout = nn.Dropout(config.hidden_dropout_prob) def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: hidden_states...
class_definition
23,921
24,350
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,210
class MaskFormerSwinLayer(nn.Module): def __init__(self, config, dim, input_resolution, num_heads, drop_path_rate=0.0, shift_size=0): super().__init__() self.shift_size = shift_size self.window_size = config.window_size self.input_resolution = input_resolution self.layernorm_...
class_definition
24,353
29,402
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,211
class MaskFormerSwinStage(nn.Module): # Copied from transformers.models.swin.modeling_swin.SwinStage.__init__ with Swin->MaskFormerSwin def __init__(self, config, dim, input_resolution, depth, num_heads, drop_path, downsample): super().__init__() self.config = config self.dim = dim ...
class_definition
29,405
31,604
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,212
class MaskFormerSwinEncoder(nn.Module): # Copied from transformers.models.swin.modeling_swin.SwinEncoder.__init__ with Swin->MaskFormerSwin def __init__(self, config, grid_size): super().__init__() self.num_layers = len(config.depths) self.config = config dpr = [x.item() for x in...
class_definition
31,607
34,813
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,213
class MaskFormerSwinPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = MaskFormerSwinConfig base_model_prefix = "model" main_input_name = "pixel_values" support...
class_definition
34,928
35,910
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,214
class MaskFormerSwinModel(MaskFormerSwinPreTrainedModel): def __init__(self, config, add_pooling_layer=True): super().__init__(config) self.config = config self.num_layers = len(config.depths) self.num_features = int(config.embed_dim * 2 ** (self.num_layers - 1)) self.embedd...
class_definition
35,913
39,384
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,215
class MaskFormerSwinBackbone(MaskFormerSwinPreTrainedModel, BackboneMixin): """ MaskFormerSwin backbone, designed especially for the MaskFormer framework. This classes reshapes `hidden_states` from (`batch_size, sequence_length, hidden_size)` to (`batch_size, num_channels, height, width)`). It also add...
class_definition
39,387
42,976
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer_swin.py
null
4,216
class TrackedStateDict: def __init__(self, to_track: Dict): """This class "tracks" a python dictionary by keeping track of which item is accessed. Args: to_track (Dict): The dictionary we wish to track """ self.to_track = to_track self._seen: Set[str] = set() ...
class_definition
1,629
2,624
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/convert_maskformer_original_pytorch_checkpoint_to_pytorch.py
null
4,217
class Args: """Fake command line arguments needed by maskformer/detectron implementation""" config_file: str
class_definition
2,874
2,991
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/convert_maskformer_original_pytorch_checkpoint_to_pytorch.py
null
4,218
class OriginalMaskFormerConfigToOursConverter: def __call__(self, original_config: object) -> MaskFormerConfig: model = original_config.MODEL mask_former = model.MASK_FORMER swin = model.SWIN dataset_catalog = MetadataCatalog.get(original_config.DATASETS.TEST[0]) id2label = ...
class_definition
3,232
5,690
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/convert_maskformer_original_pytorch_checkpoint_to_pytorch.py
null
4,219
class OriginalMaskFormerConfigToImageProcessorConverter: def __call__(self, original_config: object) -> MaskFormerImageProcessor: model = original_config.MODEL model_input = original_config.INPUT dataset_catalog = MetadataCatalog.get(original_config.DATASETS.TEST[0]) return MaskForm...
class_definition
5,693
6,444
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/convert_maskformer_original_pytorch_checkpoint_to_pytorch.py
null
4,220
class OriginalMaskFormerCheckpointToOursConverter: def __init__(self, original_model: nn.Module, config: MaskFormerConfig): self.original_model = original_model self.config = config def pop_all(self, renamed_keys: List[Tuple[str, str]], dst_state_dict: StateDict, src_state_dict: StateDict): ...
class_definition
6,447
25,799
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/convert_maskformer_original_pytorch_checkpoint_to_pytorch.py
null
4,221
class MaskFormerSwinConfig(BackboneConfigMixin, PretrainedConfig): r""" This is the configuration class to store the configuration of a [`MaskFormerSwinModel`]. It is used to instantiate a Donut model according to the specified arguments, defining the model architecture. Instantiating a configuration wi...
class_definition
904
7,215
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/configuration_maskformer_swin.py
null
4,222
class MaskFormerImageProcessor(BaseImageProcessor): r""" Constructs a MaskFormer image processor. The image processor can be used to prepare image(s) and optional targets for the model. This image processor inherits from [`BaseImageProcessor`] which contains most of the main methods. Users should r...
class_definition
12,543
58,148
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/image_processing_maskformer.py
null
4,223
class DetrDecoderOutput(BaseModelOutputWithCrossAttentions): """ Base class for outputs of the DETR decoder. This class adds one attribute to BaseModelOutputWithCrossAttentions, namely an optional stack of intermediate decoder activations, i.e. the output of each decoder layer, each of them gone through...
class_definition
2,046
4,419
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,224
class MaskFormerPixelLevelModuleOutput(ModelOutput): """ MaskFormer's pixel level module output. It returns both the last and (optionally) the hidden states from the `encoder` and `decoder`. By default, the `encoder` is a MaskFormerSwin Transformer and the `decoder` is a Feature Pyramid Network (FPN). ...
class_definition
4,433
6,466
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,225
class MaskFormerPixelDecoderOutput(ModelOutput): """ MaskFormer's pixel decoder module output, practically a Feature Pyramid Network. It returns the last hidden state and (optionally) the hidden states. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, wi...
class_definition
6,480
7,951
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,226
class MaskFormerModelOutput(ModelOutput): """ Class for outputs of [`MaskFormerModel`]. This class returns all the needed hidden states to compute the logits. Args: encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`): Last hidden states (...
class_definition
7,965
11,502
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,227
class MaskFormerForInstanceSegmentationOutput(ModelOutput): """ Class for outputs of [`MaskFormerForInstanceSegmentation`]. This output can be directly passed to [`~MaskFormerImageProcessor.post_process_semantic_segmentation`] or or [`~MaskFormerImageProcessor.post_process_instance_segmentation`] or ...
class_definition
11,516
16,083
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,228
class DetrAttention(nn.Module): """ Multi-headed attention from 'Attention Is All You Need' paper. Here, we add position embeddings to the queries and keys (as explained in the DETR paper). """ def __init__( self, embed_dim: int, num_heads: int, dropout: float = 0.0...
class_definition
22,232
28,107
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,229
class DetrDecoderLayer(nn.Module): def __init__(self, config: DetrConfig): super().__init__() self.embed_dim = config.d_model self.self_attn = DetrAttention( embed_dim=self.embed_dim, num_heads=config.decoder_attention_heads, dropout=config.attention_drop...
class_definition
28,180
32,884
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,230
class DetrDecoder(nn.Module): """ Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`DetrDecoderLayer`]. The decoder updates the query embeddings through multiple self-attention and cross-attention layers. Some small tweaks for DETR: - object_queries and query_pos...
class_definition
32,887
40,297
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,231
class MaskFormerHungarianMatcher(nn.Module): """This class computes an assignment between the labels and the predictions of the network. For efficiency reasons, the labels don't include the no_object. Because of this, in general, there are more predictions than labels. In this case, we do a 1-to-1 matching...
class_definition
40,342
45,375
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,232
class MaskFormerLoss(nn.Module): def __init__( self, num_labels: int, matcher: MaskFormerHungarianMatcher, weight_dict: Dict[str, float], eos_coef: float, ): """ The MaskFormer Loss. The loss is computed very similar to DETR. The process happens in two ste...
class_definition
45,428
56,093
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,233
class MaskFormerFPNConvLayer(nn.Module): def __init__(self, in_features: int, out_features: int, kernel_size: int = 3, padding: int = 1): """ A basic module that executes conv - norm - in sequence used in MaskFormer. Args: in_features (`int`): The number of input...
class_definition
56,096
57,548
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,234
class MaskFormerFPNLayer(nn.Module): def __init__(self, in_features: int, lateral_features: int): """ A Feature Pyramid Network Layer (FPN) layer. It creates a feature map by aggregating features from the previous and backbone layer. Due to the spatial mismatch, the tensor coming from the pr...
class_definition
57,551
58,640
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,235
class MaskFormerFPNModel(nn.Module): def __init__(self, in_features: int, lateral_widths: List[int], feature_size: int = 256): """ Feature Pyramid Network, given an input tensor and a set of feature map of different feature/spatial size, it creates a list of feature maps with the same featur...
class_definition
58,643
59,977
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,236
class MaskFormerPixelDecoder(nn.Module): def __init__(self, *args, feature_size: int = 256, mask_feature_size: int = 256, **kwargs): r""" Pixel Decoder Module proposed in [Per-Pixel Classification is Not All You Need for Semantic Segmentation](https://arxiv.org/abs/2107.06278). It first runs...
class_definition
59,980
61,632
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,237
class MaskFormerSinePositionEmbedding(nn.Module): """ This is a more standard version of the position embedding, very similar to the one used by the Attention is all you need paper, generalized to work on images. """ def __init__( self, num_pos_feats: int = 64, temperature: int = 10000, nor...
class_definition
61,738
63,551
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,238
class PredictionBlock(nn.Module): def __init__(self, in_dim: int, out_dim: int, activation: nn.Module) -> None: super().__init__() self.layers = [nn.Linear(in_dim, out_dim), activation] # Maintain submodule indexing as if part of a Sequential block for i, layer in enumerate(self.laye...
class_definition
63,554
64,108
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,239
class MaskformerMLPPredictionHead(nn.Module): def __init__(self, input_dim: int, hidden_dim: int, output_dim: int, num_layers: int = 3): """ A classic Multi Layer Perceptron (MLP). Args: input_dim (`int`): The input dimensions. hidden_dim (`int`): ...
class_definition
64,111
65,802
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,240
class MaskFormerPixelLevelModule(nn.Module): def __init__(self, config: MaskFormerConfig): """ Pixel Level Module proposed in [Per-Pixel Classification is Not All You Need for Semantic Segmentation](https://arxiv.org/abs/2107.06278). It runs the input image through a backbone and a pixel ...
class_definition
65,805
68,208
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,241
class MaskFormerTransformerModule(nn.Module): """ The MaskFormer's transformer module. """ def __init__(self, in_features: int, config: MaskFormerConfig): super().__init__() hidden_size = config.decoder_config.hidden_size should_project = in_features != hidden_size self....
class_definition
68,211
70,431
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,242
class MaskFormerPreTrainedModel(PreTrainedModel): config_class = MaskFormerConfig base_model_prefix = "model" main_input_name = "pixel_values" def _init_weights(self, module: nn.Module): xavier_std = self.config.init_xavier_std std = self.config.init_std if isinstance(module, Ma...
class_definition
72,227
74,400
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,243
class MaskFormerModel(MaskFormerPreTrainedModel): def __init__(self, config: MaskFormerConfig): super().__init__(config) self.pixel_level_module = MaskFormerPixelLevelModule(config) self.transformer_module = MaskFormerTransformerModule( in_features=self.pixel_level_module.encoder...
class_definition
74,556
78,685
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,244
class MaskFormerForInstanceSegmentation(MaskFormerPreTrainedModel): def __init__(self, config: MaskFormerConfig): super().__init__(config) self.model = MaskFormerModel(config) hidden_size = config.decoder_config.hidden_size # + 1 because we add the "null" class self.class_pre...
class_definition
78,688
90,773
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/modeling_maskformer.py
null
4,245
class MaskFormerConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`MaskFormerModel`]. It is used to instantiate a MaskFormer model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yie...
class_definition
1,009
10,259
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/maskformer/configuration_maskformer.py
null
4,246
class XPathEmbeddings(nn.Module): """Construct the embeddings from xpath tags and subscripts. We drop tree-id in this version, as its info can be covered by xpath. """ def __init__(self, config): super(XPathEmbeddings, self).__init__() self.max_depth = config.max_depth self.xp...
class_definition
1,622
3,573
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,247
class MarkupLMEmbeddings(nn.Module): """Construct the embeddings from word, position and token_type embeddings.""" def __init__(self, config): super(MarkupLMEmbeddings, self).__init__() self.config = config self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, paddi...
class_definition
4,343
8,244
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,248
class MarkupLMSelfOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) d...
class_definition
8,335
8,945
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,249
class MarkupLMIntermediate(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.intermediate_size) if isinstance(config.hidden_act, str): self.intermediate_act_fn = ACT2FN[config.hidden_act] else: self.in...
class_definition
9,018
9,587
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,250
class MarkupLMOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) ...
class_definition
9,674
10,286
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,251
class MarkupLMPooler(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) self.activation = nn.Tanh() def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: # We "pool" the model by simply taking the h...
class_definition
10,353
10,916
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,252
class MarkupLMPredictionHeadTransform(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.hidden_size) if isinstance(config.hidden_act, str): self.transform_act_fn = ACT2FN[config.hidden_act] else: self....
class_definition
11,020
11,724
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,253
class MarkupLMLMPredictionHead(nn.Module): def __init__(self, config): super().__init__() self.transform = MarkupLMPredictionHeadTransform(config) # The output weights are the same as the input embeddings, but there is # an output-only bias for each token. self.decoder = nn....
class_definition
11,821
12,661
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,254
class MarkupLMOnlyMLMHead(nn.Module): def __init__(self, config): super().__init__() self.predictions = MarkupLMLMPredictionHead(config) def forward(self, sequence_output: torch.Tensor) -> torch.Tensor: prediction_scores = self.predictions(sequence_output) return prediction_scor...
class_definition
12,753
13,075
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,255
class MarkupLMSelfAttention(nn.Module): def __init__(self, config, position_embedding_type=None): super().__init__() if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"): raise ValueError( f"The hidden size ({config.hidden_size...
class_definition
13,169
20,519
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,256
class MarkupLMAttention(nn.Module): def __init__(self, config, position_embedding_type=None): super().__init__() self.self = MARKUPLM_SELF_ATTENTION_CLASSES[config._attn_implementation]( config, position_embedding_type=position_embedding_type ) self.output = MarkupLMSelfO...
class_definition
20,700
22,834
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,257
class MarkupLMLayer(nn.Module): def __init__(self, config): super().__init__() self.chunk_size_feed_forward = config.chunk_size_feed_forward self.seq_len_dim = 1 self.attention = MarkupLMAttention(config) self.is_decoder = config.is_decoder self.add_cross_attention = ...
class_definition
22,920
26,847
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,258
class MarkupLMEncoder(nn.Module): def __init__(self, config): super().__init__() self.config = config self.layer = nn.ModuleList([MarkupLMLayer(config) for _ in range(config.num_hidden_layers)]) self.gradient_checkpointing = False def forward( self, hidden_states...
class_definition
26,935
30,733
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,259
class MarkupLMPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = MarkupLMConfig base_model_prefix = "markuplm" # Copied from transformers.models.bert.modeling_bert...
class_definition
30,736
32,200
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,260
class MarkupLMModel(MarkupLMPreTrainedModel): # Copied from transformers.models.clap.modeling_clap.ClapTextModel.__init__ with ClapText->MarkupLM def __init__(self, config, add_pooling_layer=True): super().__init__(config) self.config = config self.embeddings = MarkupLMEmbeddings(config...
class_definition
35,995
42,099
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,261
class MarkupLMForQuestionAnswering(MarkupLMPreTrainedModel): # Copied from transformers.models.bert.modeling_bert.BertForQuestionAnswering.__init__ with bert->markuplm, Bert->MarkupLM def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self.markuplm ...
class_definition
42,394
47,821
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,262
class MarkupLMForTokenClassification(MarkupLMPreTrainedModel): # Copied from transformers.models.bert.modeling_bert.BertForTokenClassification.__init__ with bert->markuplm, Bert->MarkupLM def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self.marku...
class_definition
47,937
51,951
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,263
class MarkupLMForSequenceClassification(MarkupLMPreTrainedModel): # Copied from transformers.models.bert.modeling_bert.BertForSequenceClassification.__init__ with bert->markuplm, Bert->MarkupLM def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self....
class_definition
52,181
57,126
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/modeling_markuplm.py
null
4,264
class MarkupLMTokenizer(PreTrainedTokenizer): r""" Construct a MarkupLM tokenizer. Based on byte-level Byte-Pair-Encoding (BPE). [`MarkupLMTokenizer`] can be used to turn HTML strings into to token-level `input_ids`, `attention_mask`, `token_type_ids`, `xpath_tags_seq` and `xpath_tags_seq`. This tokeniz...
class_definition
6,591
70,107
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/tokenization_markuplm.py
null
4,265
class MarkupLMConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`MarkupLMModel`]. It is used to instantiate a MarkupLM model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a s...
class_definition
788
7,310
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/configuration_markuplm.py
null
4,266
class MarkupLMProcessor(ProcessorMixin): r""" Constructs a MarkupLM processor which combines a MarkupLM feature extractor and a MarkupLM tokenizer into a single processor. [`MarkupLMProcessor`] offers all the functionalities you need to prepare data for the model. It first uses [`MarkupLMFeatureEx...
class_definition
856
6,348
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/processing_markuplm.py
null
4,267
class MarkupLMFeatureExtractor(FeatureExtractionMixin): r""" Constructs a MarkupLM feature extractor. This can be used to get a list of nodes and corresponding xpaths from HTML strings. This feature extractor inherits from [`~feature_extraction_utils.PreTrainedFeatureExtractor`] which contains most ...
class_definition
924
6,407
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/feature_extraction_markuplm.py
null
4,268
class MarkupLMTokenizerFast(PreTrainedTokenizerFast): r""" Construct a MarkupLM tokenizer. Based on byte-level Byte-Pair-Encoding (BPE). [`MarkupLMTokenizerFast`] can be used to turn HTML strings into to token-level `input_ids`, `attention_mask`, `token_type_ids`, `xpath_tags_seq` and `xpath_tags_seq`....
class_definition
2,829
43,285
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/markuplm/tokenization_markuplm_fast.py
null
4,269
class WordpieceTokenizer: def __init__(self, vocab, unk_token="<unk>", max_input_chars_per_word=200): self.vocab = vocab self.unk_token = unk_token self.max_input_chars_per_word = max_input_chars_per_word def tokenize(self, token): chars = list(token) if len(chars) > sel...
class_definition
1,387
2,351
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/tokenization_cpmant.py
null
4,270
class CpmAntTokenizer(PreTrainedTokenizer): """ Construct a CPMAnt tokenizer. Based on byte-level Byte-Pair-Encoding. Args: vocab_file (`str`): Path to the vocabulary file. bod_token (`str`, *optional*, defaults to `"<d>"`): The beginning of document token. e...
class_definition
2,354
9,703
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/tokenization_cpmant.py
null
4,271
class CpmAntConfig(PretrainedConfig): r""" This is the configuration class to store the configuration of a [`CpmAntModel`]. It is used to instantiate an CPMAnt model according to the specified arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a simila...
class_definition
804
5,115
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/configuration_cpmant.py
null
4,272
class CpmAntLayerNorm(nn.Module): """ We use Root Mean Square (RMS) Layer Normalization, please see https://arxiv.org/abs/1910.07467 for details." """ def __init__(self, config: CpmAntConfig): super().__init__() self.eps = config.eps self.dim_norm = config.hidden_size s...
class_definition
1,352
2,285
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,273
class CpmAntAttention(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.dim_model = config.hidden_size self.num_heads = config.num_attention_heads self.dim_head = config.dim_head self.project_q = nn.Linear(self.dim_model, self.num_heads * self.dim...
class_definition
2,288
6,866
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,274
class CpmAntSelfAttentionBlock(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.layernorm_before_attention = CpmAntLayerNorm(config) self.self_attention = CpmAntAttention(config) if config.dropout_p: self.dropout = torch.nn.Dropout(config.drop...
class_definition
6,869
9,093
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,275
class CpmAntDenseGatedACT(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.w_0 = nn.Linear(config.hidden_size, config.dim_ff, bias=False) self.w_1 = nn.Linear(config.hidden_size, config.dim_ff, bias=False) self.act = torch.nn.GELU() def forward(self,...
class_definition
9,096
9,833
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,276
class CpmAntFeedForward(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.w_in = CpmAntDenseGatedACT(config) if config.dropout_p is not None: self.dropout = torch.nn.Dropout(config.dropout_p) else: self.dropout = None self....
class_definition
9,836
10,614
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,277
class CpmAntFFNBlock(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.layernorm_before_ffn = CpmAntLayerNorm(config) self.ffn = CpmAntFeedForward(config) if config.dropout_p: self.dropout = torch.nn.Dropout(config.dropout_p) else: ...
class_definition
10,617
11,477
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,278
class CpmAntTransformerBlock(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.self_att = CpmAntSelfAttentionBlock(config) self.ffn = CpmAntFFNBlock(config) def forward( self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, ...
class_definition
11,480
13,448
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,279
class CpmAntEncoder(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.num_layers = config.num_hidden_layers self.layers = nn.ModuleList([CpmAntTransformerBlock(config) for ith in range(self.num_layers)]) self.output_layernorm = CpmAntLayerNorm(config) ...
class_definition
13,451
16,364
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,280
class CpmAntIntermediate(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.hidden_size, config.intermediate_size) if isinstance(config.hidden_act, str): self.intermediate_act_fn = ACT2FN[config.hidden_act] else: self.inte...
class_definition
16,455
17,022
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,281
class CpmAntSegmentPositionEmbedding(nn.Module): def __init__(self, config: CpmAntConfig): super().__init__() self.num_heads = config.num_attention_heads self.num_buckets = config.position_bias_num_buckets self.max_distance = config.position_bias_max_distance self.num_segmen...
class_definition
17,025
21,055
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,282
class CpmAntOutput(nn.Module): def __init__(self, config): super().__init__() self.dense = nn.Linear(config.intermediate_size, config.hidden_size) self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps) self.dropout = nn.Dropout(config.hidden_dropout_prob) d...
class_definition
21,140
21,750
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,283
class CpmAntPreTrainedModel(PreTrainedModel): """ An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models. """ config_class = CpmAntConfig base_model_prefix = "cpmant" def _init_weights(self, module): """Initialize the...
class_definition
21,753
22,889
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,284
class CpmAntModel(CpmAntPreTrainedModel): def __init__(self, config: CpmAntConfig): super().__init__(config) self.encoder = CpmAntEncoder(config) self.segment_embedding = nn.Embedding(config.segment_types, config.hidden_size) self.input_embedding = nn.Embedding( config.vo...
class_definition
24,991
31,282
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,285
class CpmAntForCausalLM(CpmAntPreTrainedModel, GenerationMixin): _tied_weights_keys = ["lm_head.weight"] def __init__(self, config: CpmAntConfig): super().__init__(config) self.cpmant = CpmAntModel(config) # lm_head.weight is tied to cpmant.input_embedding.weight self.lm_head =...
class_definition
31,471
37,037
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/cpmant/modeling_cpmant.py
null
4,286
class TFLEDLearnedPositionalEmbedding(keras.layers.Embedding): """ This module learns positional embeddings up to a fixed maximum size. """ def __init__(self, num_embeddings: int, embedding_dim: int, **kwargs): super().__init__(num_embeddings, embedding_dim, **kwargs) def call(self, input_...
class_definition
4,036
4,686
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,287
class TFLEDEncoderSelfAttention(keras.layers.Layer): def __init__(self, config, layer_id, **kwargs): super().__init__(**kwargs) self.config = config if config.hidden_size % config.num_attention_heads != 0: raise ValueError( f"The hidden size ({config.hidden_size}...
class_definition
4,815
41,333
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,288
class TFLEDEncoderAttention(keras.layers.Layer): def __init__(self, config, layer_id, **kwargs): super().__init__(**kwargs) self.longformer_self_attn = TFLEDEncoderSelfAttention(config, layer_id=layer_id, name="longformer_self_attn") self.output_dense = keras.layers.Dense(config.d_model, use...
class_definition
41,336
42,817
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,289
class TFLEDDecoderAttention(keras.layers.Layer): """Multi-headed attention from "Attention Is All You Need""" def __init__( self, embed_dim: int, num_heads: int, dropout: float = 0.0, is_decoder: bool = False, bias: bool = True, **kwargs, ): s...
class_definition
42,820
50,224
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,290
class TFLEDEncoderLayer(keras.layers.Layer): def __init__(self, config: LEDConfig, layer_id: int, **kwargs): super().__init__(**kwargs) self.embed_dim = config.d_model self.self_attn = TFLEDEncoderAttention(config, layer_id, name="self_attn") self.self_attn_layer_norm = keras.layers....
class_definition
50,227
53,991
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,291
class TFLEDDecoderLayer(keras.layers.Layer): def __init__(self, config: LEDConfig, **kwargs): super().__init__(**kwargs) self.embed_dim = config.d_model self.self_attn = TFLEDDecoderAttention( embed_dim=self.embed_dim, num_heads=config.decoder_attention_heads, ...
class_definition
53,994
60,789
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,292
class TFLEDPreTrainedModel(TFPreTrainedModel): config_class = LEDConfig base_model_prefix = "led" @property def input_signature(self): sig = super().input_signature sig["global_attention_mask"] = tf.TensorSpec((None, None), tf.int32, name="global_attention_mask") return sig
class_definition
60,792
61,107
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,293
class TFLEDEncoderBaseModelOutput(ModelOutput): """ Base class for Longformer's outputs, with potential hidden states, local and global attentions. Args: last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-states at the output of the...
class_definition
61,249
64,403
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,294
class TFLEDSeq2SeqModelOutput(ModelOutput): """ Base class for model encoder's outputs that also contains : pre-computed hidden states that can speed up sequential decoding. Args: last_hidden_state (`tf.Tensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidd...
class_definition
64,417
69,024
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,295
class TFLEDSeq2SeqLMOutput(ModelOutput): """ Base class for sequence-to-sequence language models outputs. Args: loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided): Language modeling loss. logits (`tf.Tensor` of shape `(batch_size, sequence_length,...
class_definition
69,038
73,582
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,296
class TFLEDEncoder(keras.layers.Layer): config_class = LEDConfig """ Transformer encoder consisting of *config.encoder_layers* self-attention layers. Each layer is a [`TFLEDEncoderLayer`]. Args: config: LEDConfig """ def __init__(self, config: LEDConfig, embed_tokens: Optional[kera...
class_definition
80,384
92,528
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,297
class TFLEDDecoder(keras.layers.Layer): config_class = LEDConfig """ Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`TFLEDDecoderLayer`] Args: config: LEDConfig embed_tokens: output embedding """ def __init__(self, config: LEDConfig, embed_to...
class_definition
92,551
103,515
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,298
class TFLEDMainLayer(keras.layers.Layer): config_class = LEDConfig def __init__(self, config: LEDConfig, **kwargs): super().__init__(**kwargs) self.config = config self.shared = keras.layers.Embedding( input_dim=config.vocab_size, output_dim=config.d_model, ...
class_definition
103,538
108,618
0
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/led/modeling_tf_led.py
null
4,299