hubert
mindnlp.transformers.models.hubert.configuration_hubert
¶
Hubert model configuration
mindnlp.transformers.models.hubert.configuration_hubert.HubertConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [HubertModel
]. It is used to instantiate an
Hubert model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a similar configuration to that of the Hubert
facebook/hubert-base-ls960 architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
Vocabulary size of the Hubert model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size |
Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout(`float`, |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
activation_dropout |
The dropout ratio for activations inside the fully connected layer.
TYPE:
|
attention_dropout(`float`, |
The dropout ratio for the attention probabilities.
TYPE:
|
final_dropout |
The dropout probabilitiy for the final projection layer of [
TYPE:
|
layerdrop |
The LayerDrop probability. See the LayerDrop paper for more details.
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
feat_extract_norm |
The norm to be applied to 1D convolutional layers in feature encoder. One of
TYPE:
|
feat_proj_dropout |
The dropout probability for output of the feature encoder.
TYPE:
|
feat_proj_layer_norm |
Whether to apply LayerNorm to the output of the feature encoder.
TYPE:
|
feat_extract_activation |
The non-linear activation function (function or string) in the 1D convolutional layers of the feature
extractor. If string,
TYPE:
|
conv_dim |
A tuple of integers defining the number of input and output channels of each 1D convolutional layer in the feature encoder. The length of conv_dim defines the number of 1D convolutional layers.
TYPE:
|
conv_stride |
A tuple of integers defining the stride of each 1D convolutional layer in the feature encoder. The length of conv_stride defines the number of convolutional layers and has to match the length of conv_dim.
TYPE:
|
conv_kernel |
A tuple of integers defining the kernel size of each 1D convolutional layer in the feature encoder. The length of conv_kernel defines the number of convolutional layers and has to match the length of conv_dim.
TYPE:
|
conv_bias |
Whether the 1D convolutional layers have a bias.
TYPE:
|
num_conv_pos_embeddings |
Number of convolutional positional embeddings. Defines the kernel size of 1D convolutional positional embeddings layer.
TYPE:
|
num_conv_pos_embedding_groups |
Number of groups of 1D convolutional positional embeddings layer.
TYPE:
|
do_stable_layer_norm |
Whether do apply stable layer norm architecture of the Transformer encoder.
TYPE:
|
apply_spec_augment |
Whether to apply SpecAugment data augmentation to the outputs of the feature encoder. For reference see SpecAugment: A Simple Data Augmentation Method for Automatic Speech Recognition.
TYPE:
|
mask_time_prob |
Percentage (between 0 and 1) of all feature vectors along the time axis which will be masked. The masking
procecure generates ''mask_time_prob*len(time_axis)/mask_time_length'' independent masks over the axis. If
reasoning from the propability of each feature vector to be chosen as the start of the vector span to be
masked, mask_time_prob should be
TYPE:
|
mask_time_length |
Length of vector span along the time axis.
TYPE:
|
mask_time_min_masks |
The minimum number of masks of length
TYPE:
|
mask_feature_prob |
Percentage (between 0 and 1) of all feature vectors along the feature axis which will be masked. The
masking procecure generates ''mask_feature_prob*len(feature_axis)/mask_time_length'' independent masks over
the axis. If reasoning from the propability of each feature vector to be chosen as the start of the vector
span to be masked, mask_feature_prob should be
TYPE:
|
mask_feature_length |
Length of vector span along the feature axis.
TYPE:
|
mask_feature_min_masks |
The minimum number of masks of length
TYPE:
|
ctc_loss_reduction |
Specifies the reduction to apply to the output of
TYPE:
|
ctc_zero_infinity |
Whether to zero infinite losses and the associated gradients of
TYPE:
|
use_weighted_layer_sum |
Whether to use a weighted average of layer outputs with learned weights. Only relevant when using an
instance of [
TYPE:
|
classifier_proj_size |
Dimensionality of the projection before token mean-pooling for classification.
TYPE:
|
Example
>>> from transformers import HubertModel, HubertConfig
...
>>> # Initializing a Hubert facebook/hubert-base-ls960 style configuration
>>> configuration = HubertConfig()
...
>>> # Initializing a model from the facebook/hubert-base-ls960 style configuration
>>> model = HubertModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/hubert/configuration_hubert.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
mindnlp.transformers.models.hubert.configuration_hubert.HubertConfig.inputs_to_logits_ratio
property
¶
Calculates the ratio of inputs to logits based on the convolutional strides in the Hubert configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of HubertConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The ratio of inputs to logits calculated as the product of convolutional strides. |
mindnlp.transformers.models.hubert.configuration_hubert.HubertConfig.__init__(vocab_size=32, hidden_size=768, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, hidden_act='gelu', hidden_dropout=0.1, activation_dropout=0.1, attention_dropout=0.1, feat_proj_layer_norm=True, feat_proj_dropout=0.0, final_dropout=0.1, layerdrop=0.1, initializer_range=0.02, layer_norm_eps=1e-05, feat_extract_norm='group', feat_extract_activation='gelu', conv_dim=(512, 512, 512, 512, 512, 512, 512), conv_stride=(5, 2, 2, 2, 2, 2, 2), conv_kernel=(10, 3, 3, 3, 3, 2, 2), conv_bias=False, num_conv_pos_embeddings=128, num_conv_pos_embedding_groups=16, do_stable_layer_norm=False, apply_spec_augment=True, mask_time_prob=0.05, mask_time_length=10, mask_time_min_masks=2, mask_feature_prob=0.0, mask_feature_length=10, mask_feature_min_masks=0, ctc_loss_reduction='sum', ctc_zero_infinity=False, use_weighted_layer_sum=False, classifier_proj_size=256, pad_token_id=0, bos_token_id=1, eos_token_id=2, **kwargs)
¶
Initializes a new instance of the HubertConfig class.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
The size of the vocabulary.
TYPE:
|
hidden_size |
The size of the hidden layers.
TYPE:
|
num_hidden_layers |
The number of hidden layers.
TYPE:
|
num_attention_heads |
The number of attention heads.
TYPE:
|
intermediate_size |
The size of the intermediate layers.
TYPE:
|
hidden_act |
The activation function for the hidden layers.
TYPE:
|
hidden_dropout |
The dropout rate for the hidden layers.
TYPE:
|
activation_dropout |
The dropout rate for activations.
TYPE:
|
attention_dropout |
The dropout rate for attention mechanisms.
TYPE:
|
feat_proj_layer_norm |
Whether to apply layer normalization to projection features.
TYPE:
|
feat_proj_dropout |
The dropout rate for feature projection.
TYPE:
|
final_dropout |
The final dropout rate.
TYPE:
|
layerdrop |
The layer drop probability.
TYPE:
|
initializer_range |
The range for parameter initialization.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization.
TYPE:
|
feat_extract_norm |
The normalization type for feature extraction.
TYPE:
|
feat_extract_activation |
The activation function for feature extraction.
TYPE:
|
conv_dim |
The dimensions for convolutional layers.
TYPE:
|
conv_stride |
The stride values for convolutional layers.
TYPE:
|
conv_kernel |
The kernel sizes for convolutional layers.
TYPE:
|
conv_bias |
Whether to use bias in convolutional layers.
TYPE:
|
num_conv_pos_embeddings |
The number of positional embeddings for convolutional layers.
TYPE:
|
num_conv_pos_embedding_groups |
The number of groups for positional embeddings.
TYPE:
|
do_stable_layer_norm |
Whether to use stable layer normalization.
TYPE:
|
apply_spec_augment |
Whether to apply SpecAugment during training.
TYPE:
|
mask_time_prob |
The probability of masking in the time dimension.
TYPE:
|
mask_time_length |
The maximum length of time masking.
TYPE:
|
mask_time_min_masks |
The minimum number of time masks.
TYPE:
|
mask_feature_prob |
The probability of masking in the feature dimension.
TYPE:
|
mask_feature_length |
The maximum length of feature masking.
TYPE:
|
mask_feature_min_masks |
The minimum number of feature masks.
TYPE:
|
ctc_loss_reduction |
The reduction type for CTC loss.
TYPE:
|
ctc_zero_infinity |
Whether to set positive infinity to zero in CTC loss.
TYPE:
|
use_weighted_layer_sum |
Whether to use weighted layer sum for classification.
TYPE:
|
classifier_proj_size |
The size of the classifier projection layer.
TYPE:
|
pad_token_id |
The token ID for padding.
TYPE:
|
bos_token_id |
The token ID for the beginning of sequence.
TYPE:
|
eos_token_id |
The token ID for the end of sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration for convolutional layers is incorrect. |
Source code in mindnlp/transformers/models/hubert/configuration_hubert.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
mindnlp.transformers.models.hubert.modeling_hubert
¶
MindSpore Hubert model.
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttention
¶
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttention.__init__(embed_dim, num_heads, dropout=0.0, is_decoder=False, bias=True, is_causal=False, config=None)
¶
Initializes a HubertAttention object.
PARAMETER | DESCRIPTION |
---|---|
embed_dim |
The dimension of the input embeddings.
TYPE:
|
num_heads |
The number of attention heads to use.
TYPE:
|
dropout |
The dropout probability. Default is 0.0.
TYPE:
|
is_decoder |
Whether the attention mechanism is used in a decoder. Default is False.
TYPE:
|
bias |
Whether to include bias in the linear projections. Default is True.
TYPE:
|
is_causal |
Whether the attention is causal. Default is False.
TYPE:
|
config |
The configuration object for the attention mechanism. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttention.forward(hidden_states, key_value_states=None, past_key_value=None, attention_mask=None, layer_head_mask=None, output_attentions=False)
¶
Input shape: Batch x Time x Channel
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttnAdapterLayer
¶
Bases: Module
Implements an adapter layer for attention modules in the Hubert model, optimizing training throughput by utilizing 3D tensor weights as parameters and bypassing the use of ModuleList.
This class inherits from nn.Module and provides functionality to forward adapter modules directly with 3D tensor weights as parameters, without using ModuleList, resulting in improved training throughput.
ATTRIBUTE | DESCRIPTION |
---|---|
input_dim |
The dimension of the input tensor for the adapter layer.
TYPE:
|
hidden_dim |
The hidden size dimension of the adapter layer.
TYPE:
|
norm |
An instance of LayerNorm for normalizing the hidden states.
TYPE:
|
linear_1 |
An instance of Dense representing the first linear transformation.
TYPE:
|
act_fn |
An instance of ReLU activation function.
TYPE:
|
linear_2 |
An instance of Dense representing the second linear transformation.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Constructs the adapter layer by applying normalization, linear transformations, and activation function to the given hidden_states tensor, and returns the resulting tensor. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttnAdapterLayer.__init__(config)
¶
Implements adapter modules directly with 3D tensor weight as parameters and without using ModuleList to speed up training throughput.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertAttnAdapterLayer.forward(hidden_states)
¶
Method to forward the attention adapter layer in the HubertAttnAdapterLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertAttnAdapterLayer class.
TYPE:
|
hidden_states |
The input hidden states tensor for the layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
hidden_states
|
The forwarded hidden states after passing through the layer operations. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoder
¶
Bases: Module
A class representing the encoder component of the Hubert model. This class is responsible for processing input hidden states through multiple layers of HubertEncoderLayer.
This class inherits from nn.Module.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration object for the Hubert model.
TYPE:
|
pos_conv_embed |
Instance of HubertPositionalConvEmbedding for positional convolutional embeddings. |
layer_norm |
Layer normalization module.
TYPE:
|
dropout |
Dropout module for regularization.
TYPE:
|
layers |
List of HubertEncoderLayer instances representing the encoder layers.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Processes the input hidden states through the encoder layers and returns the final hidden states along with optional hidden states and attentions. |
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
The input hidden states to be processed by the encoder.
TYPE:
|
attention_mask |
Optional attention mask to mask out specific tokens during processing.
TYPE:
|
output_attentions |
Flag indicating whether to output attention weights.
TYPE:
|
output_hidden_states |
Flag indicating whether to output hidden states of each layer.
TYPE:
|
return_dict |
Flag indicating whether to return the output as a BaseModelOutput dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BaseModelOutput or tuple: A BaseModelOutput object containing the last hidden state, hidden states of all layers, and attention weights, or a tuple containing these elements based on the value of 'return_dict'. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoder.__init__(config)
¶
Initializes an instance of the HubertEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing various settings for the HubertEncoder.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoder.forward(hidden_states, attention_mask=None, output_attentions=False, output_hidden_states=False, return_dict=True)
¶
This method forwards the Hubert encoder using the provided parameters and returns the final output.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
hidden_states |
The hidden states input tensor for the encoder.
TYPE:
|
attention_mask |
Optional attention mask tensor to mask certain elements in the hidden states. Default is None.
TYPE:
|
output_attentions |
Flag indicating whether to output attentions. Default is False.
TYPE:
|
output_hidden_states |
Flag indicating whether to output hidden states. Default is False.
TYPE:
|
return_dict |
Flag indicating whether to return the output as a dictionary. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value explicitly, as it updates hidden states and hidden state-related outputs within the class instance. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the attention mask dimensions are incompatible with the hidden states tensor. |
RuntimeError
|
If there is an issue during the execution of the encoder layers. |
TypeError
|
If the input types are incorrect or incompatible with the expected types. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayer
¶
Bases: Module
HubertEncoderLayer represents a single layer of the HubertEncoder.
This class inherits from nn.Module and contains methods to initialize the layer and forward the layer. The init method initializes the layer with the given configuration, while the forward method applies the attention mechanism, dropout, layer normalization, feed forward, and final layer normalization to the input hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
attention |
An instance of HubertAttention representing the attention mechanism with specified parameters.
|
dropout |
An instance of nn.Dropout representing the dropout layer with a specified dropout rate.
|
layer_norm |
An instance of nn.LayerNorm representing the layer normalization with a specified epsilon.
|
feed_forward |
An instance of HubertFeedForward representing the feed forward layer with the given configuration.
|
final_layer_norm |
An instance of nn.LayerNorm representing the final layer normalization with a specified epsilon.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the HubertEncoderLayer instance with the given configuration. |
forward |
Applies the attention mechanism, dropout, layer normalization, feed forward, and final |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayer.__init__(config)
¶
Initializes a HubertEncoderLayer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of HubertEncoderLayer.
|
config |
An instance of HubertConfig containing configuration parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayer.forward(hidden_states, attention_mask=None, output_attentions=False)
¶
Method to forward the Hubert Encoder Layer.
PARAMETER | DESCRIPTION |
---|---|
self |
Reference to the instance of the class.
|
hidden_states |
Input hidden states to be processed.
TYPE:
|
attention_mask |
Mask to avoid attending over padding tokens. Default is None.
TYPE:
|
output_attentions |
Flag to indicate whether to output attention weights. Default is False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple
|
A tuple containing the processed hidden states. If output_attentions is True, the tuple also includes the attention weights. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayerStableLayerNorm
¶
Bases: Module
Represents a stable layer normalization encoder layer for the Hubert model.
This class inherits from nn.Module and contains methods for initializing the layer and forwarding the layer with attention and feed-forward operations. It also includes an optional adapter layer.
ATTRIBUTE | DESCRIPTION |
---|---|
attention |
HubertAttention The attention mechanism for the encoder layer.
|
dropout |
nn.Dropout The dropout layer for the encoder layer.
|
layer_norm |
nn.LayerNorm The layer normalization for the encoder layer.
|
feed_forward |
HubertFeedForward The feed-forward network for the encoder layer.
|
final_layer_norm |
nn.LayerNorm The final layer normalization for the encoder layer.
|
adapter_layer |
HubertAttnAdapterLayer or None The optional adapter layer for the encoder layer.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the encoder layer with the provided configuration. |
forward |
Constructs the encoder layer with attention and feed-forward operations, and an optional adapter layer. |
RETURNS | DESCRIPTION |
---|---|
outputs
|
Tuple[Tensor, ...] The outputs of the encoder layer, including hidden states and optionally attention weights. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayerStableLayerNorm.__init__(config)
¶
Initializes a HubertEncoderLayerStableLayerNorm instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertEncoderLayerStableLayerNorm class.
|
config |
An instance of the HubertConfig class containing configuration parameters for the encoder layer. Parameters:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderLayerStableLayerNorm.forward(hidden_states, attention_mask=None, output_attentions=False)
¶
This method forwards the Hubert encoder layer with stable layer normalization.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertEncoderLayerStableLayerNorm class.
|
hidden_states |
The input tensor representing the hidden states. This parameter is required for the forwardion of the encoder layer.
TYPE:
|
attention_mask |
An optional tensor representing the attention mask. It defaults to None and is used to mask padded tokens during attention computation.
TYPE:
|
output_attentions |
A boolean flag indicating whether to output the attention weights. It defaults to False and is used to control whether the attention weights should be returned.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the forwarded hidden states. If output_attentions is True, the tuple also contains the attention weights. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderStableLayerNorm
¶
Bases: Module
Class representing a Hubert encoder with stable layer normalization.
This class implements an encoder model for the Hubert architecture with stable layer normalization. The encoder consists of multiple layers, each containing positional convolutional embeddings, layer normalization, and dropout, followed by a series of encoder layers. The encoder can process input hidden states, apply attention masks, and optionally output hidden states and self-attentions.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration object for the Hubert model.
TYPE:
|
pos_conv_embed |
Positional convolutional embedding layer. |
layer_norm |
Layer normalization for the hidden states.
TYPE:
|
dropout |
Dropout layer.
TYPE:
|
layers |
List of encoder layers for processing the hidden states.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Processes the input hidden states through the encoder layers. Args:
Returns:
|
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderStableLayerNorm.__init__(config)
¶
Initializes an instance of the HubertEncoderStableLayerNorm class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertEncoderStableLayerNorm class.
|
config |
An instance of HubertConfig containing configuration parameters for the encoder. This parameter specifies the configuration settings for the encoder. It is a required parameter and must be of type HubertConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertEncoderStableLayerNorm.forward(hidden_states, attention_mask=None, output_attentions=False, output_hidden_states=False, return_dict=True)
¶
Constructs the Hubert encoder stable layer norm.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance. |
hidden_states |
The input hidden states of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask of shape (batch_size, sequence_length) or (batch_size, 1, 1, sequence_length) indicating which tokens should be attended to. Defaults to None.
TYPE:
|
output_attentions |
Whether to return the attentions. Defaults to False.
TYPE:
|
output_hidden_states |
Whether to return the hidden states. Defaults to False.
TYPE:
|
return_dict |
Whether to return a dictionary instead of a BaseModelOutput. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value. It operates in place on the hidden_states and other internal buffers. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the shapes of the input tensors are not compatible or if there are issues in the internal computations. |
RuntimeError
|
If there are errors during the computation or if the method is called in an invalid state. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureEncoder
¶
Bases: Module
Construct the features from raw audio waveform
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureEncoder.__init__(config)
¶
Initializes a new instance of HubertFeatureEncoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of HubertConfig containing configuration parameters for the feature encoder. It specifies the normalization type to be used for feature extraction.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the normalization type specified in config.feat_extract_norm is not 'group' or 'layer'. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureEncoder.forward(input_values)
¶
Constructs the hidden states of the HubertFeatureEncoder.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertFeatureEncoder class.
TYPE:
|
input_values |
The input values for forwarding the hidden states. It should be a 2-dimensional array with shape (n_samples, n_features).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureProjection
¶
Bases: Module
Represents a feature projection module for the Hubert model.
This class inherits from nn.Module and implements methods for initializing the feature projection layer and performing feature projection on hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
feat_proj_layer_norm |
Indicates whether feature projection layer normalization is enabled.
TYPE:
|
layer_norm |
If feat_proj_layer_norm is True, this attribute represents the layer normalization module.
TYPE:
|
projection |
The dense layer for feature projection.
TYPE:
|
dropout |
The dropout layer for feature projection.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the feature projection layer with the given configuration. |
forward |
Performs feature projection on the input hidden states and returns the projected hidden states. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureProjection.__init__(config)
¶
Initializes a new instance of HubertFeatureProjection.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertFeatureProjection class.
|
config |
An instance of HubertConfig containing configuration parameters for the feature projection.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type HubertConfig. |
AttributeError
|
If the config object does not contain the required attributes. |
ValueError
|
If the config attributes are not within the specified range or format. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeatureProjection.forward(hidden_states)
¶
Constructs the feature projection for the HubertFeatureProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertFeatureProjection class.
|
hidden_states |
The input hidden states to be projected. It should have a shape of (batch_size, seq_length, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeedForward
¶
Bases: Module
The HubertFeedForward class represents a feedforward neural network layer for the Hubert model. It inherits from nn.Module and implements the feedforward computation for the hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration object for the Hubert model.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the HubertFeedForward instance with the provided configuration. |
forward |
Constructs the feedforward neural network layer using the provided hidden_states. |
Example
Instantiate the HubertFeedForward class with a given configuration:
>>> config = HubertConfig(...)
>>> feed_forward_layer = HubertFeedForward(config)
Perform the feedforward computation using the forwarded layer:
>>> hidden_states = ...
>>> output = feed_forward_layer.forward(hidden_states)
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeedForward.__init__(config)
¶
Initializes the HubertFeedForward class with the specified configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertFeedForward class.
|
config |
An instance of HubertConfig containing the configuration parameters for the feed-forward layer. The config parameter should be of type HubertConfig and is used to set up the feed-forward layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type HubertConfig. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertFeedForward.forward(hidden_states)
¶
Constructs the hidden states of the HubertFeedForward model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertFeedForward class.
|
hidden_states |
The hidden states to be processed by the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC
¶
Bases: HubertPreTrainedModel
A class representing the Hubert model for Connectionist Temporal Classification (CTC).
This class extends the HubertPreTrainedModel class and provides additional methods for freezing the feature encoder and base model, as well as forwarding the model and computing the CTC loss.
ATTRIBUTE | DESCRIPTION |
---|---|
hubert |
The Hubert model for feature extraction.
TYPE:
|
dropout |
Dropout layer for regularization.
TYPE:
|
target_lang |
The target language for the model.
TYPE:
|
lm_head |
Fully connected layer for language modeling.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the HubertForCTC instance with a given configuration and target language. |
tie_weights |
Overwrites the tie_weights method to correctly load adapter weights when passing target_lang to from_pretrained(). |
freeze_feature_encoder |
Disables gradient computation for the feature encoder to prevent parameter updates during training. |
freeze_base_model |
Disables gradient computation for the base model to prevent parameter updates during training. |
forward |
Constructs the model and computes the CTC loss. |
Note
- The target_lang parameter is used for loading adapter weights and should not be passed if config.adapter_attn_dim is not defined.
- The forward method computes the CTC loss for connectionist temporal classification tasks.
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the config.vocab_size is not defined when instantiating the model. |
ValueError
|
If target_lang is passed without config.adapter_attn_dim being defined. |
This class is intended to be used as a language model for CTC tasks, where labels are provided for training and the model outputs logits for each input sequence.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC.__init__(config, target_lang=None)
¶
Initializes a new instance of the HubertForCTC class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object for the Hubert model.
TYPE:
|
target_lang |
The target language for the model. If specified, the model will be trained for the specified language.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration does not define the vocabulary size of the language model head. |
This method initializes the HubertForCTC class by setting up the following components:
- config: The configuration object for the Hubert model.
- hubert: The HubertModel instance based on the provided configuration.
- dropout: A dropout layer with the dropout probability defined in the configuration.
- target_lang: The target language for the model, if specified.
- lm_head: A dense layer with the output hidden size and vocabulary size defined in the configuration.
Note
If the configuration has the 'add_adapter' attribute and it is set to True, the output hidden size will be the value of 'output_hidden_size'. Otherwise, it will be the value of 'hidden_size'.
After initializing these components, the 'post_init' method is called to perform any additional setup tasks.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC.forward(input_values, attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None, labels=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for connectionist temporal classification. Note that
TYPE:
|
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC.freeze_base_model()
¶
Calling this function will disable the gradient computation for the base model so that its parameters will not be updated during training. Only the classification head will be updated.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1875 1876 1877 1878 1879 1880 1881 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC.freeze_feature_encoder()
¶
Calling this function will disable the gradient computation for the feature encoder so that its parameter will not be updated during training.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1868 1869 1870 1871 1872 1873 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForCTC.tie_weights()
¶
This method overwrites [~PreTrainedModel.tie_weights
] so that adapter weights can be correctly loaded when
passing target_lang=...
to from_pretrained(...)
.
This method is not supposed to be called by the user and is prone to be changed in the future.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForSequenceClassification
¶
Bases: HubertPreTrainedModel
HubertForSequenceClassification is a class that represents a sequence classification model based on the Hubert architecture. This class extends the HubertPreTrainedModel and provides functionality for sequence classification tasks.
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the sequence classification model with the provided configuration. |
freeze_feature_encoder |
Disables gradient computation for the feature encoder to prevent parameter updates during training. |
freeze_base_model |
Disables gradient computation for the base model parameters, allowing only the classification head to be updated. |
forward |
Constructs the sequence classification model and computes the loss based on the provided input values and labels. |
ATTRIBUTE | DESCRIPTION |
---|---|
hubert |
HubertModel instance for the sequence classification model.
|
projector |
nn.Linear layer for projecting hidden states to the classifier projection size.
|
classifier |
nn.Linear layer for classification predictions.
|
layer_weights |
Parameter for weighted layer sum computation.
|
Note
- The class assumes a specific structure and functionality based on the provided code snippets.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForSequenceClassification.__init__(config)
¶
Initializes a new instance of HubertForSequenceClassification.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object for the Hubert model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raised if the 'config' object has the attribute 'add_adapter' set to True, |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForSequenceClassification.forward(input_values, attention_mask=None, output_attentions=None, output_hidden_states=None, return_dict=None, labels=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForSequenceClassification.freeze_base_model()
¶
Calling this function will disable the gradient computation for the base model so that its parameters will not be updated during training. Only the classification head will be updated.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
2017 2018 2019 2020 2021 2022 2023 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertForSequenceClassification.freeze_feature_encoder()
¶
Calling this function will disable the gradient computation for the feature encoder so that its parameter will not be updated during training.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
2010 2011 2012 2013 2014 2015 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertGroupNormConvLayer
¶
Bases: Module
A class representing a Group Normalization Convolutional Layer in the Hubert model.
This class inherits from nn.Module and is used to define a single layer of the Hubert model. The layer consists of a 1-dimensional convolutional operation followed by group normalization, an activation function, and returns the output hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
in_conv_dim |
The dimension of the input to the convolutional layer.
TYPE:
|
out_conv_dim |
The dimension of the output from the convolutional layer.
TYPE:
|
conv |
The 1-dimensional convolutional operation.
TYPE:
|
activation |
The activation function applied to the hidden states.
TYPE:
|
layer_norm |
The group normalization operation.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Applies the convolutional operation, group normalization, and activation function to the input hidden states and returns the output. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertGroupNormConvLayer.__init__(config, layer_id=0)
¶
Initializes a HubertGroupNormConvLayer object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertGroupNormConvLayer class.
TYPE:
|
config |
An instance of HubertConfig class containing configuration parameters.
TYPE:
|
layer_id |
The ID of the layer, defaults to 0. Used to access specific convolutional layer configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If layer_id is less than 0. |
KeyError
|
If the specified feature extraction activation function is not found in the ACT2FN dictionary. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertGroupNormConvLayer.forward(hidden_states)
¶
Construct a HubertGroupNormConvLayer by applying a series of operations on the input hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertGroupNormConvLayer class.
TYPE:
|
hidden_states |
The input hidden states to be processed. Expected shape: (batch_size, channels, height, width).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertLayerNormConvLayer
¶
Bases: Module
The HubertLayerNormConvLayer class represents a layer with convolution, layer normalization, and activation functions for the HuBERT model. It inherits from nn.Module.
This class initializes with a HubertConfig instance and a layer ID. It defines a convolutional layer with specified input and output dimensions, kernel size, stride, bias, and padding mode. It also applies layer normalization and an activation function to the input hidden states.
The forward method takes hidden states as input, applies the convolution, layer normalization, and activation function, and returns the processed hidden states.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertLayerNormConvLayer.__init__(config, layer_id=0)
¶
Initializes a new instance of the HubertLayerNormConvLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
The configuration object for the Hubert model.
TYPE:
|
layer_id |
The ID of the layer. Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the provided layer_id is less than 0. |
TypeError
|
If the provided config is not an instance of HubertConfig. |
KeyError
|
If the provided config does not contain required attributes. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertLayerNormConvLayer.forward(hidden_states)
¶
This method forwards a HubertLayerNormConvLayer by applying convolution, layer normalization, and activation functions to the input hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertLayerNormConvLayer class.
|
hidden_states |
A tensor representing the input hidden states that will undergo the transformation. It should have the shape (batch_size, sequence_length, hidden_size).
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value directly. The hidden_states tensor is modified in place and returned after the transformations. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the hidden_states tensor does not have the expected shape. |
RuntimeError
|
If any error occurs during the convolution, layer normalization, or activation operations. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertModel
¶
Bases: HubertPreTrainedModel
A class representing a Hubert model for speech recognition tasks.
This class implements a Hubert model for processing speech input and generating relevant outputs. It includes methods for initializing the model, masking hidden states according to SpecAugment, and forwarding the model's forward pass. The model utilizes a feature extractor, feature projection, and an encoder for processing input data and generating output representations.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
HubertConfig
|
feature_extractor |
HubertFeatureEncoder
|
feature_projection |
HubertFeatureProjection
|
encoder |
HubertEncoder or HubertEncoderStableLayerNorm based on configuration
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the HubertModel with the provided configuration. |
_mask_hidden_states |
Masks hidden states along the time and/or feature axes based on SpecAugment. |
forward |
Constructs the forward pass of the model, processing input values and returning relevant outputs. |
Example
>>> from transformers import AutoProcessor, HubertModel
>>> from datasets import load_dataset
>>> import soundfile as sf
...
>>> processor = AutoProcessor.from_pretrained("facebook/hubert-large-ls960-ft")
>>> model = HubertModel.from_pretrained("facebook/hubert-large-ls960-ft")
...
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.map(map_to_array)
...
>>> input_values = processor(ds["speech"][0], return_tensors="pt").input_values # Batch size 1
>>> hidden_states = model(input_values).last_hidden_state
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertModel.__init__(config)
¶
Initializes the HubertModel with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertModel class.
|
config |
An instance of the HubertConfig class representing the configuration settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertModel.forward(input_values, attention_mask=None, mask_time_indices=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, BaseModelOutput]
|
Union[Tuple, BaseModelOutput] |
Example
>>> from transformers import AutoProcessor, HubertModel
>>> from datasets import load_dataset
>>> import soundfile as sf
...
>>> processor = AutoProcessor.from_pretrained("facebook/hubert-large-ls960-ft")
>>> model = HubertModel.from_pretrained("facebook/hubert-large-ls960-ft")
...
...
>>> def map_to_array(batch):
... speech, _ = sf.read(batch["file"])
... batch["speech"] = speech
... return batch
...
...
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> ds = ds.map(map_to_array)
...
>>> input_values = processor(ds["speech"][0], return_tensors="pt").input_values # Batch size 1
>>> hidden_states = model(input_values).last_hidden_state
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertNoLayerNormConvLayer
¶
Bases: Module
HubertNoLayerNormConvLayer is a Python class representing a convolutional layer without layer normalization. This class inherits from nn.Module.
This class initializes with the following parameters:
- config: A HubertConfig object containing configuration settings.
- layer_id: An integer representing the layer identifier.
The forward method applies a convolutional operation and an activation function to the input hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
in_conv_dim |
Integer representing the input convolutional dimension.
|
out_conv_dim |
Integer representing the output convolutional dimension.
|
conv |
nn.Conv1d object with parameters for the convolutional operation.
|
activation |
Activation function defined in the ACT2FN dictionary based on the config's feat_extract_activation setting.
|
METHOD | DESCRIPTION |
---|---|
forward |
Applies the convolutional operation and activation function to the input hidden_states. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertNoLayerNormConvLayer.__init__(config, layer_id=0)
¶
Initializes a HubertNoLayerNormConvLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
The configuration object containing model hyperparameters.
TYPE:
|
layer_id |
The index of the convolution layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If layer_id is less than 0. |
KeyError
|
If the specified activation function in config is not found in the ACT2FN dictionary. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertNoLayerNormConvLayer.forward(hidden_states)
¶
Constructs the hidden states of the HubertNoLayerNormConvLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertNoLayerNormConvLayer class. |
hidden_states |
The input hidden states to be processed. Expected shape is (batch_size, channels, sequence_length).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
The processed hidden states after applying the convolutional layer and activation function. The shape is (batch_size, channels, sequence_length). |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertPositionalConvEmbedding
¶
Bases: Module
Represents a Positional Convolutional Embedding layer for the Hubert model.
This class inherits from nn.Module and is used to apply positional convolutional embeddings to input hidden states. The layer uses a convolutional neural network to process the input hidden states with configurable parameters such as kernel size, padding, activation function, and bias.
ATTRIBUTE | DESCRIPTION |
---|---|
conv |
Convolutional layer for processing hidden states.
TYPE:
|
padding |
Padding layer to ensure input dimensions match convolutional operations.
TYPE:
|
activation |
Activation function to apply after convolution and padding.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the Positional Convolutional Embedding layer with the specified configuration. |
forward |
Constructs the positional convolutional embedding by applying convolution, padding, and activation functions to the input hidden states. |
RETURNS | DESCRIPTION |
---|---|
The processed hidden states with positional convolutional embeddings applied. |
Note
This class is designed specifically for the Hubert model and should be used within the model architecture for optimal performance.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertPositionalConvEmbedding.__init__(config)
¶
Initializes an instance of the HubertPositionalConvEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing the settings for Hubert model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertPositionalConvEmbedding.forward(hidden_states)
¶
Constructs the HubertPositionalConvEmbedding.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HubertPositionalConvEmbedding class. |
hidden_states |
The input hidden states of shape (batch_size, sequence_length, hidden_size), where batch_size represents the number of input samples, sequence_length represents the length of the input sequence, and hidden_size represents the dimensionality of the hidden states. The hidden states are expected to be in the format (batch_size, hidden_size, sequence_length).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertSamePadLayer
¶
Bases: Module
This class represents a layer in the Hubert model that performs same padding on the input hidden states.
The HubertSamePadLayer class is a subclass of the nn.Module class and provides functionality to remove padding from the input hidden states if necessary. It is specifically designed for the Hubert model and is used to ensure that the input hidden states have the same length as the target sequence for further processing.
ATTRIBUTE | DESCRIPTION |
---|---|
num_pad_remove |
The number of padding elements to remove from the input hidden states. It is determined based on the number of convolutional positional embeddings. If the number is even, num_pad_remove is set to 1, otherwise it is set to 0.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of the HubertSamePadLayer class. Args:
|
forward |
Constructs the output hidden states by removing the padding elements if necessary. Args:
Returns:
|
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertSamePadLayer.__init__(num_conv_pos_embeddings)
¶
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
num_conv_pos_embeddings |
The number of convolutional position embeddings used in the layer. It is used to calculate the value of 'num_pad_remove' based on whether it is even or odd.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
mindnlp.transformers.models.hubert.modeling_hubert.HubertSamePadLayer.forward(hidden_states)
¶
Constructs the hidden states for the HubertSamePadLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HubertSamePadLayer class.
TYPE:
|
hidden_states |
The input hidden states to be processed. Expected shape is (batch_size, sequence_length, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/hubert/modeling_hubert.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|