seamless_m4t_v2
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2
¶
MindSpore SeamlessM4Tv2 model.
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock
¶
Bases: Module
This class represents a HiFiGAN residual block, which is used for generating high-fidelity audio waveforms. It inherits from the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
channels |
The number of input and output channels for the convolutional layers.
TYPE:
|
kernel_size |
The size of the convolutional kernel.
TYPE:
|
dilation |
A tuple of dilation factors for the convolutional layers.
TYPE:
|
leaky_relu_slope |
The slope for the leaky ReLU activation function.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a HiFiGAN residual block object. |
get_padding |
Calculates the padding size for the convolutional layers based on the kernel size and dilation factor. |
apply_weight_norm |
Applies weight normalization to the convolutional layers in the residual block. |
remove_weight_norm |
Removes weight normalization from the convolutional layers in the residual block. |
forward |
Constructs the residual block by sequentially applying leaky ReLU activation, convolutional layers, and addition with the residual. Returns the final hidden states after passing through the residual block. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock.__init__(channels, kernel_size=3, dilation=(1, 3, 5), leaky_relu_slope=0.1)
¶
Initializes a HifiGanResidualBlock object.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HifiGanResidualBlock class.
TYPE:
|
channels |
The number of input and output channels for the convolutional layers.
TYPE:
|
kernel_size |
The size of the kernel for the convolutional layers. Defaults to 3.
TYPE:
|
dilation |
A tuple of dilation factors for the convolutional layers. Defaults to (1, 3, 5).
TYPE:
|
leaky_relu_slope |
The slope of the negative part of the leaky ReLU activation function. Defaults to 0.1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock.apply_weight_norm()
¶
Applies weight normalization to the convolutional layers in the HifiGanResidualBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HifiGanResidualBlock class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Description
This method applies weight normalization to the convolutional layers in the HifiGanResidualBlock. Weight normalization is a technique that normalizes the weights of a neural network layer to stabilize training and improve convergence. The method iterates over the convs1 and convs2 lists, which contain the convolutional layers, and applies weight normalization using the nn.utils.weight_norm function.
Note
- The convs1 and convs2 lists must be populated with valid convolutional layers before calling this method.
- Weight normalization modifies the weights of the layers in-place.
Example
>>> block = HifiGanResidualBlock()
>>> block.apply_weight_norm()
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock.forward(hidden_states)
¶
Constructs a single residual block in the HifiGanResidualBlock class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HifiGanResidualBlock class.
TYPE:
|
hidden_states |
The input hidden states of shape (batch_size, channels, height, width).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: The output hidden states of shape (batch_size, channels, height, width). |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock.get_padding(kernel_size, dilation=1)
¶
Returns the amount of padding required for the convolution operation in the HiFi-GAN residual block.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the HifiGanResidualBlock class.
|
kernel_size |
The size of the kernel used in the convolution operation.
TYPE:
|
dilation |
The dilation rate of the convolution operation. Defaults to 1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The amount of padding required for the convolution operation. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If kernel_size or dilation is not an integer, or if the value of dilation is less than or equal to zero. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.HifiGanResidualBlock.remove_weight_norm()
¶
Removes weight normalization from the convolutional layers in a HifiGanResidualBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HifiGanResidualBlock class. It represents the block containing convolutional layers with weight normalization to remove.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value. It modifies the convolutional layers in place by removing weight normalization. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Attention
¶
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Attention.__init__(embed_dim, num_heads, dropout=0.0, is_decoder=False, bias=True, is_causal=False, config=None)
¶
Initializes the SeamlessM4Tv2Attention object.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
embed_dim |
The dimension of the input embeddings.
TYPE:
|
num_heads |
The number of attention heads.
TYPE:
|
dropout |
The dropout probability. Defaults to 0.0.
TYPE:
|
is_decoder |
Indicates if the attention is used in a decoder. Defaults to False.
TYPE:
|
bias |
Indicates if bias is added to the linear transformations. Defaults to True.
TYPE:
|
is_causal |
Indicates if the attention is causal. Defaults to False.
TYPE:
|
config |
The configuration for the attention. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If embed_dim is not divisible by num_heads. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Attention.forward(hidden_states, encoder_hidden_states=None, past_key_value=None, attention_mask=None, output_attentions=False)
¶
Input shape: Batch x Time x Channel
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2CodeHifiGan
¶
Bases: PreTrainedModel
This class represents the SeamlessM4Tv2CodeHifiGan model, which is used for speech synthesis and translation. It inherits from the PreTrainedModel class.
ATTRIBUTE | DESCRIPTION |
---|---|
pad_token_id |
The ID of the padding token in the input sequence.
TYPE:
|
dur_predictor |
The variance predictor module for duration prediction. |
unit_embedding |
The embedding layer for unit tokens.
TYPE:
|
speaker_embedding |
The embedding layer for speaker IDs.
TYPE:
|
language_embedding |
The embedding layer for language IDs.
TYPE:
|
hifi_gan |
The high-fidelity generative adversarial network for speech synthesis.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
_get_dur_output_lengths |
Computes the output length after the duration layer. |
_get_output_hifigan_lengths |
Computes the output length of the hifigan convolutional layers. |
forward |
Constructs the output sequence using the input tokens, speaker ID, and language ID. |
_init_weights |
Initializes the weights of the model. |
apply_weight_norm |
Applies weight normalization to the model. |
remove_weight_norm |
Removes weight normalization from the model. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2CodeHifiGan.__init__(config)
¶
Initializes an instance of SeamlessM4Tv2CodeHifiGan.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A configuration object containing various settings and parameters for the model. It is expected to have the following attributes:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2CodeHifiGan.apply_weight_norm()
¶
Apply weight normalization to the HifiGan model layers.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the SeamlessM4Tv2CodeHifiGan class. Represents the current instance of the class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
None
|
However, if any exceptions occur during the weight normalization process, they will be propagated up the call stack. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2CodeHifiGan.forward(input_ids, speaker_id, lang_id)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [
TYPE:
|
speaker_id |
The id of the speaker used for speech synthesis. Must be lower than
TYPE:
|
tgt_lang |
The language id to use as target language for translation.
TYPE:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2CodeHifiGan.remove_weight_norm()
¶
Removes weight normalization from the specified layers in the HifiGan model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2CodeHifiGan class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Description
This method removes weight normalization from the following layers in the HifiGan model:
- self.hifi_gan.conv_pre: The convolutional layer before upsampling.
- self.hifi_gan.upsampler: A list of upsampling layers.
- self.hifi_gan.resblocks: A list of residual blocks.
- self.hifi_gan.conv_post: The final convolutional layer after upsampling.
Weight normalization is a technique used to normalize the weights of neural network layers. By removing weight normalization, the weights of the specified layers are no longer normalized, which can have an impact on the performance of the model.
Note that this method modifies the layers in-place and does not return any value.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapter
¶
Bases: Module
A class representing a SeamlessM4Tv2ConformerAdapter.
Inherits from nn.Module.
This class initializes an instance of SeamlessM4Tv2ConformerAdapter and forwards the adapter layers. Each adapter layer is a SeamlessM4Tv2ConformerAdapterLayer, and the number of layers is determined by the 'num_adapter_layers' parameter in the configuration.
ATTRIBUTE | DESCRIPTION |
---|---|
layers |
A list of SeamlessM4Tv2ConformerAdapterLayer instances representing the adapter layers.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of SeamlessM4Tv2ConformerAdapter. |
forward |
Constructs the adapter layers by iterating over each layer and applying it to the input hidden states and attention mask. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapter.__init__(config)
¶
Initializes an instance of the 'SeamlessM4Tv2ConformerAdapter' class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the 'SeamlessM4Tv2ConformerAdapter' class.
|
config |
An object of type 'Config' containing configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapter.forward(hidden_states, attention_mask)
¶
Constructs the hidden states of the SeamlessM4Tv2ConformerAdapter by applying the layers in sequence.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2ConformerAdapter class. |
hidden_states |
The input hidden states. The shape is (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor. The shape is (batch_size, sequence_length).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapterLayer
¶
Bases: Module
This class represents a layer for the SeamlessM4Tv2 Conformer Adapter. It inherits from nn.Module and contains methods for computing sub-sample lengths from attention mask and forwarding the adapter layer using the given input and optional attention mask.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration object containing hidden size and adaptor dropout information.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
_compute_sub_sample_lengths_from_attention_mask |
Computes sub-sample lengths from the attention mask. |
forward |
Constructs the adapter layer using the given input hidden_states and optional attention_mask. |
Note
For detailed information on the class methods and attributes, please refer to the class code and comments.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 1041 1042 1043 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 1100 1101 1102 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapterLayer.__init__(config)
¶
This method initializes an instance of the SeamlessM4Tv2ConformerAdapterLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A configuration object containing the parameters for the adapter layer. It is expected to have the following attributes:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerAdapterLayer.forward(hidden_states, attention_mask=None, output_attentions=False)
¶
Constructs the SeamlessM4Tv2ConformerAdapterLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
hidden_states |
The input hidden states. It represents the input data to the layer.
TYPE:
|
attention_mask |
An optional tensor representing the attention mask. Defaults to None. If provided, it restricts the attention of the layer.
TYPE:
|
output_attentions |
A flag indicating whether to output attentions. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mindspore.Tensor: The output hidden states after processing through the layer. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dimensions of input tensors are incompatible. |
RuntimeError
|
If an error occurs during the computation process. |
TypeError
|
If the input parameters are of incorrect type. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerConvolutionModule
¶
Bases: Module
Convolution block used in the conformer block. Uses a causal depthwise convolution similar to that described in Section 2.1 of `https://doi.org/10.48550/arxiv.1609.03499
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 541 542 543 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 614 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerConvolutionModule.__init__(config)
¶
Initializes the SeamlessM4Tv2ConformerConvolutionModule.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object containing various parameters for the module.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raised if the 'config.conv_depthwise_kernel_size' is not an odd number, as it should be for 'SAME' padding. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 541 542 543 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerConvolutionModule.forward(hidden_states, attention_mask=None)
¶
Constructs the SeamlessM4Tv2ConformerConvolutionModule.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4Tv2ConformerConvolutionModule.
|
hidden_states |
The input hidden states tensor of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor of shape (batch_size, sequence_length) indicating which tokens should be attended to and which should not. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
The output hidden states tensor after applying the convolution operations of shape (batch_size, sequence_length, hidden_size). |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 614 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoder
¶
Bases: Module
The class represents a SeamlessM4Tv2ConformerEncoder, which is a neural network cell for encoding speech data. It inherits from the nn.Module class.
The class includes methods for initializing the encoder, applying chunk attention, and forwarding the hidden states. The init method initializes the encoder with the given configuration, dropout, layers, and layer normalization. The _apply_chunk_attention method creates a chunk attention mask to prevent attention across chunks. The forward method processes the hidden states, applies chunk attention if specified, and performs layer-wise computations.
Note
This docstring is a summary based on the provided code and may need additional details from the broader context of the codebase.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 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 950 951 952 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoder.__init__(config)
¶
Initializes an instance of the SeamlessM4Tv2ConformerEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the class.
|
config |
An object of type 'config' containing the configuration settings for the encoder.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoder.forward(hidden_states, attention_mask=None, output_attentions=False, output_hidden_states=False, return_dict=True)
¶
Constructs the SeamlessM4Tv2ConformerEncoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
hidden_states |
The hidden states of the encoder. Shape should be (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor. If provided, it should have the same shape as 'hidden_states'. Masked positions have a value of 'True' and unmasked positions have a value of 'False'. Default is 'None'.
TYPE:
|
output_attentions |
Whether to output the self-attention tensors of each layer. Default is 'False'.
TYPE:
|
output_hidden_states |
Whether to output the hidden states of each layer. Default is 'False'.
TYPE:
|
return_dict |
Whether to return the output as a dictionary. Default is 'True'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.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 950 951 952 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoderLayer
¶
Bases: Module
Conformer block based on https://arxiv.org/abs/2005.08100.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoderLayer.__init__(config)
¶
Initialize a SeamlessM4Tv2ConformerEncoderLayer object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class. |
config |
An object containing the configuration parameters for the encoder layer.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerEncoderLayer.forward(hidden_states, attention_mask=None, output_attentions=False, conv_attention_mask=None)
¶
Constructs a SeamlessM4Tv2ConformerEncoderLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
hidden_states |
The input hidden states. Shape is (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor. Default is None.
If provided, the attention mask tensor must have the same shape as
TYPE:
|
output_attentions |
Whether to output the attention weights. Default is False.
TYPE:
|
conv_attention_mask |
The convolution attention mask tensor. Default is None.
If provided, the convolution attention mask tensor must have the same shape as
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[mindspore.Tensor, Optional[mindspore.Tensor]]: A tuple containing:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeatureProjection
¶
Bases: Module
This class represents a feature projection module for the SeamlessM4Tv2Conformer model. It inherits from the nn.Module class.
The feature projection module is responsible for projecting the input hidden states into a higher-dimensional space, followed by layer normalization and dropout. This helps in capturing complex patterns and enhancing the expressive power of the model.
ATTRIBUTE | DESCRIPTION |
---|---|
layer_norm |
A layer normalization module that normalizes the hidden states.
TYPE:
|
projection |
A dense linear projection layer that projects the hidden states into a higher-dimensional space.
TYPE:
|
dropout |
A dropout module that randomly sets elements of the hidden states to zero.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4Tv2ConformerFeatureProjection module with the given configuration. |
forward |
Applies the feature projection operation on the input hidden states. |
RETURNS | DESCRIPTION |
---|---|
The projected hidden states after applying layer normalization and dropout. |
Note
- The input hidden states should have a shape of [batch_size, sequence_length, input_dim].
-
The configuration should contain the following attributes:
- feature_projection_input_dim: The input dimension of the feature projection layer.
- hidden_size: The output dimension of the feature projection layer.
- layer_norm_eps: The epsilon value for layer normalization.
- speech_encoder_dropout: The dropout probability for the dropout layer.
Example
>>> config = {
... 'feature_projection_input_dim': 512,
... 'hidden_size': 256,
... 'layer_norm_eps': 1e-5,
... 'speech_encoder_dropout': 0.1
...}
>>> feature_projection = SeamlessM4Tv2ConformerFeatureProjection(config)
>>> hidden_states = torch.randn(3, 100, 512)
>>> projected_states = feature_projection.forward(hidden_states)
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 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 390 391 392 393 394 395 396 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeatureProjection.__init__(config)
¶
Initializes an instance of the SeamlessM4Tv2ConformerFeatureProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing configuration parameters for the feature projection.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeatureProjection.forward(hidden_states)
¶
Constructs the feature projection for the SeamlessM4Tv2Conformer model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2ConformerFeatureProjection class. |
hidden_states |
The input hidden states tensor to be projected.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor or None: The projected hidden states tensor. If the input tensor is None, the method returns None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input hidden_states tensor is not a torch.Tensor object. |
ValueError
|
If the input hidden_states tensor is empty or has an incompatible shape. |
RuntimeError
|
If the input hidden_states tensor cannot be cast to the same dtype as the layer_norm weights. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeedForward
¶
Bases: Module
This class represents a feed-forward module for the SeamlessM4Tv2Conformer model, which is used for speech encoding.
Inherits from: nn.Module
ATTRIBUTE | DESCRIPTION |
---|---|
config |
An object containing configuration parameters for the module.
|
act_fn |
The activation function to be applied to the intermediate hidden states.
|
dropout |
The dropout probability to be applied to the intermediate hidden states.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4Tv2ConformerFeedForward module. Args:
|
forward |
Applies the feed-forward operations on the input hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 471 472 473 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeedForward.__init__(config, act_fn=None, dropout=None)
¶
Initializes an instance of the SeamlessM4Tv2ConformerFeedForward class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
An object containing configuration parameters.
|
act_fn |
The activation function to be used for the hidden layers. If not provided, it defaults to the value of config.speech_encoder_hidden_act. It can be either a string specifying a predefined activation function or a custom activation function.
TYPE:
|
dropout |
The dropout probability for the intermediate layers. If not provided, it defaults to the value of config.speech_encoder_dropout.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Note
- The intermediate_dropout attribute is assigned an instance of nn.Dropout with p=dropout.
- The intermediate_dense attribute is assigned an instance of nn.Linear with input size config.hidden_size and output size config.speech_encoder_intermediate_size.
- The intermediate_act_fn attribute is assigned the activation function specified by act_fn. If act_fn is a string, it is mapped to the corresponding activation function from the ACT2FN dictionary. If act_fn is a custom function, it is directly assigned.
- The output_dense attribute is assigned an instance of nn.Linear with input size config.speech_encoder_intermediate_size and output size config.hidden_size.
- The output_dropout attribute is assigned an instance of nn.Dropout with p=dropout.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 471 472 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerFeedForward.forward(hidden_states)
¶
Constructs the feedforward layer in the SeamlessM4Tv2Conformer model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2ConformerFeedForward class. |
hidden_states |
The input hidden states of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Description
This method applies a series of operations to the input hidden states to forward the feedforward layer in the SeamlessM4Tv2Conformer model. The operations include intermediate dense layer, activation function, dropout layer, and output dense layer. The resulting hidden states are returned.
- intermediate_dense: Applies a linear transformation to the hidden states using the intermediate dense layer.
- intermediate_act_fn: Applies the activation function to the intermediate dense outputs.
- intermediate_dropout: Applies dropout to the intermediate outputs.
- output_dense: Applies a linear transformation to the intermediate outputs using the output dense layer.
- output_dropout: Applies dropout to the output dense outputs.
Note: The intermediate dense layer, activation function, dropout layers, and output dense layer must be defined before calling this method.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerSelfAttention
¶
Bases: Module
Construct a SeamlessM4Tv2ConformerSelfAttention object. Can be enhanced with relative position embeddings.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 685 686 687 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerSelfAttention.__init__(config, use_position_embeddings=True)
¶
Initializes a new instance of the SeamlessM4Tv2ConformerSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
An instance of the configuration class that contains the model's configuration parameters.
|
use_position_embeddings |
Whether to use position embeddings or not. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2ConformerSelfAttention.forward(hidden_states, attention_mask=None, output_attentions=False)
¶
Constructs the self-attention mechanism in the SeamlessM4Tv2ConformerSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2ConformerSelfAttention class. |
hidden_states |
The input hidden states tensor of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
An optional attention mask tensor of shape (batch_size, sequence_length, sequence_length). Defaults to None.
TYPE:
|
output_attentions |
Indicates whether to output the attention weights. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Tensor, Optional[Tensor], Optional[Tuple[Tensor]]]
|
Tuple[mindspore.Tensor, Optional[mindspore.Tensor], Optional[Tuple[mindspore.Tensor]]]: A tuple containing:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 685 686 687 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Decoder
¶
Bases: SeamlessM4Tv2PreTrainedModel
A Python class representing the SeamlessM4Tv2Decoder module of the SeamlessM4Tv2 model architecture.
This class inherits from the SeamlessM4Tv2PreTrainedModel class and implements the decoder component of the SeamlessM4Tv2 model. It consists of multiple decoder layers and includes functionality for embedding tokens, calculating positional embeddings, and performing self-attention and cross-attention operations.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration object for the SeamlessM4Tv2Decoder module.
TYPE:
|
dropout |
The dropout probability for the decoder layers.
TYPE:
|
layerdrop |
The layer dropout probability for the decoder layers.
TYPE:
|
padding_idx |
The index of the padding token in the vocabulary.
TYPE:
|
vocab_size |
The size of the vocabulary.
TYPE:
|
max_target_positions |
The maximum number of target positions.
TYPE:
|
embed_scale |
The scale factor for the embedding layer.
TYPE:
|
embed_tokens |
The embedding layer for the input tokens.
TYPE:
|
embed_positions |
The positional embedding layer. |
layers |
The list of decoder layers.
TYPE:
|
layer_norm |
The layer normalization module.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4Tv2Decoder module. |
get_input_embeddings |
Returns the input embeddings. |
set_input_embeddings |
Sets the input embeddings. |
forward |
Constructs the SeamlessM4Tv2Decoder module. |
Please refer to the documentation of the parent class, SeamlessM4Tv2PreTrainedModel, for more details on the inherited attributes and methods.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Decoder.__init__(config, embed_tokens=None)
¶
Initialize the SeamlessM4Tv2Decoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
An instance of SeamlessM4Tv2Config containing configuration parameters for the decoder.
TYPE:
|
embed_tokens |
An optional instance of nn.Embedding for token embedding.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not an instance of SeamlessM4Tv2Config. |
ValueError
|
If the embed_tokens parameter is not None and is not an instance of nn.Embedding. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Decoder.forward(input_ids=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_values=None, inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [
TYPE:
|
attention_mask |
Mask to avoid performing attention on padding token indices. Mask values selected in
TYPE:
|
encoder_hidden_states |
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention of the decoder.
TYPE:
|
encoder_attention_mask |
Mask to avoid performing cross-attention on padding tokens indices of encoder input_ids. Mask values
selected in
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers. See
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Decoder.get_input_embeddings()
¶
Retrieves the input embeddings for the SeamlessM4Tv2Decoder.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4Tv2Decoder class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Decoder.set_input_embeddings(value)
¶
Sets the input embeddings for the SeamlessM4Tv2Decoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4Tv2Decoder class.
TYPE:
|
value |
The input embeddings to be set. This should be a tensor or an instance of the Embedding class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2DecoderLayer
¶
Bases: Module
This class represents a decoder layer of the SeamlessM4Tv2 model. It is used to process the input hidden states and generate the output hidden states for the decoder part of the model.
ATTRIBUTE | DESCRIPTION |
---|---|
`embed_dim` |
The dimension of the hidden states.
|
`self_attn` |
The self-attention mechanism used in the decoder layer.
|
`dropout` |
The dropout probability used in the decoder layer.
|
`activation_fn` |
The activation function used in the decoder layer.
|
`attn_dropout` |
The dropout probability used in the self-attention mechanism.
|
`self_attn_layer_norm` |
The layer normalization applied to the self-attention output.
|
`cross_attention` |
The cross-attention mechanism used in the decoder layer.
|
`cross_attention_layer_norm` |
The layer normalization applied to the cross-attention output.
|
`ffn` |
The feed-forward network used in the decoder layer.
|
`ffn_layer_norm` |
The layer normalization applied to the feed-forward network output.
|
`ffn_dropout` |
The dropout probability used in the feed-forward network.
|
METHOD | DESCRIPTION |
---|---|
`forward` |
Performs the forward pass of the decoder layer. |
PARAMETER | DESCRIPTION |
---|---|
`hidden_states |
The input hidden states of shape
TYPE:
|
`attention_mask |
The attention mask of size
TYPE:
|
`encoder_hidden_states |
The cross-attention input hidden states of shape
TYPE:
|
`encoder_attention_mask |
The encoder attention mask of size
TYPE:
|
`past_key_value |
The cached past key and value projection states.
TYPE:
|
`output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
`use_cache |
Whether or not to use the cached key and value projection states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Note
The attention weights are returned only if output_attentions
is True
.
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 1758 1759 1760 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2DecoderLayer.__init__(config, decoder_ffn_dim=None, decoder_attention_heads=None)
¶
Initialize a decoder layer in the SeamlessM4Tv2 model.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object for the SeamlessM4Tv2 model.
TYPE:
|
decoder_ffn_dim |
The dimension of the feed-forward network in the decoder layer. Defaults to None.
TYPE:
|
decoder_attention_heads |
The number of attention heads to use in the decoder layer. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
1753 1754 1755 1756 1757 1758 1759 1760 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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2DecoderLayer.forward(hidden_states, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_value=None, output_attentions=False, use_cache=True)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
input to the layer of shape
TYPE:
|
attention_mask |
attention mask of size
TYPE:
|
encoder_hidden_states |
cross attention input to the layer of shape
TYPE:
|
encoder_attention_mask |
encoder attention mask of size
TYPE:
|
past_key_value |
cached past key and value projection states
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Encoder
¶
Bases: SeamlessM4Tv2PreTrainedModel
World Class Technical Documentation for SeamlessM4Tv2Encoder:
The SeamlessM4Tv2Encoder
class is a Python class that represents an encoder module in the SeamlessM4Tv2 model.
This class inherits from the SeamlessM4Tv2PreTrainedModel
class.
Summary
The SeamlessM4Tv2Encoder
class implements the encoder module of the SeamlessM4Tv2 model.
It takes input tokens, applies embedding and positional encoding, and passes it through multiple encoder layers
to generate encoded representations of the input.
Constructor
>>> def __init__(self, config: SeamlessM4Tv2Config, embed_tokens: Optional[nn.Embedding] = None, is_t2u_encoder: bool = False):
>>> super().__init__(config)
>>> # Initializes parameters and attributes of the encoder
...
>>> self.post_init()
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Encoder.__init__(config, embed_tokens=None, is_t2u_encoder=False)
¶
Initializes a new instance of the SeamlessM4Tv2Encoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object containing various settings.
TYPE:
|
embed_tokens |
An optional pre-trained embedding layer.
TYPE:
|
is_t2u_encoder |
A boolean value indicating whether the encoder is used for T2U (text-to-unit) conversion.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2Encoder.forward(input_ids=None, attention_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide it. Indices can be obtained using [
TYPE:
|
attention_mask |
Mask to avoid performing attention on padding token indices. Mask values selected in
TYPE:
|
inputs_embeds |
Optionally, instead of passing
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers. See
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers. See
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
|
mindnlp.transformers.models.seamless_m4t_v2.modeling_seamless_m4t_v2.SeamlessM4Tv2EncoderLayer
¶
Bases: Module
This class represents an encoder layer for the SeamlessM4Tv2 model. It inherits from the nn.Module class.
The encoder layer performs multi-head self-attention and feed-forward network operations on the input hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
embed_dim |
The dimension of the hidden states.
TYPE:
|
self_attn |
The self-attention module for the encoder layer.
TYPE:
|
attn_dropout |
Dropout layer for attention weights.
TYPE:
|
self_attn_layer_norm |
Layer normalization for the hidden states after self-attention.
TYPE:
|
ffn |
The feed-forward network module for the encoder layer. |
ffn_layer_norm |
Layer normalization for the hidden states after feed-forward network.
TYPE:
|
ffn_dropout |
Dropout layer for the feed-forward network output.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Performs the forward pass of the encoder layer. Args:
Returns:
|
Source code in mindnlp/transformers/models/seamless_m4t_v2/modeling_seamless_m4t_v2.py
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 |
|