seamless_m4t
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t
¶
MindSpore SeamlessM4T model.
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock
¶
Bases: Module
This class represents a High Fidelity Generative Adversarial Network (HifiGan) Residual Block. It is a subclass of nn.Module and is used in the forwardion of the HifiGan model.
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 |
The dilation factors to be applied to the convolutional layers.
TYPE:
|
leaky_relu_slope |
The slope of the negative region of the leaky ReLU activation function.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of the HifiGanResidualBlock class. |
get_padding |
Calculates the padding to be applied to the convolutional layers. |
apply_weight_norm |
Applies weight normalization to the convolutional layers. |
remove_weight_norm |
Removes weight normalization from the convolutional layers. |
forward |
Constructs the HifiGanResidualBlock by applying the convolutional layers and residual connections to the input hidden states. |
Note
The HifiGanResidualBlock class inherits from nn.Module, which is a base class for all neural network modules in MindSpore. It provides basic functionalities for forwarding and managing neural networks.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock.__init__(channels, kernel_size=3, dilation=(1, 3, 5), leaky_relu_slope=0.1)
¶
init
Initializes a new instance of the HifiGanResidualBlock class.
PARAMETER | DESCRIPTION |
---|---|
channels |
The number of input and output channels for the convolutional layers.
TYPE:
|
kernel_size |
The size of the convolutional kernel. Defaults to 3.
TYPE:
|
dilation |
The dilation rates for the convolutional layers. Defaults to (1, 3, 5).
TYPE:
|
leaky_relu_slope |
The slope for the Leaky ReLU activation function. Defaults to 0.1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If channels, kernel_size, or any element in the dilation tuple is less than or equal to 0. |
TypeError
|
If the provided values for channels, kernel_size, dilation, or leaky_relu_slope are not of the expected types. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock.apply_weight_norm()
¶
Apply weight normalization to the convolutional layers in the HifiGanResidualBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HifiGanResidualBlock class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock.forward(hidden_states)
¶
Constructs a single residual block in the HifiGan model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the HifiGanResidualBlock class.
TYPE:
|
hidden_states |
The input hidden states for the residual block. Expected shape is [batch_size, channels, sequence_length].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock.get_padding(kernel_size, dilation=1)
¶
Returns the required padding size for a given kernel size and dilation factor.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HifiGanResidualBlock class.
TYPE:
|
kernel_size |
The size of the kernel.
TYPE:
|
dilation |
The dilation factor (default is 1).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The calculated padding size. |
This method calculates the required padding size based on the given kernel size and dilation factor. The padding size is determined by the formula: (kernel_size * dilation - dilation) // 2. The method then returns the calculated padding size as an integer value.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.HifiGanResidualBlock.remove_weight_norm()
¶
Removes weight normalization from the convolutional layers within the HifiGanResidualBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the HifiGanResidualBlock class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TAttention
¶
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 1882 1883 1884 1885 1886 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TAttention.__init__(embed_dim, num_heads, dropout=0.0, is_decoder=False, bias=True, is_causal=False, config=None)
¶
Initialize the SeamlessM4TAttention class.
PARAMETER | DESCRIPTION |
---|---|
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 |
Flag indicating if the attention is used in a decoder context. Defaults to False.
TYPE:
|
bias |
Flag indicating whether to include bias in linear transformations.
TYPE:
|
is_causal |
Flag indicating if the attention is causal.
TYPE:
|
config |
An optional configuration object for the attention mechanism.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If embed_dim is not divisible by num_heads. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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.seamless_m4t.modeling_seamless_m4t.SeamlessM4TAttention.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/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TCodeHifiGan
¶
Bases: PreTrainedModel
This class represents a high fidelity generative adversarial network (HiFi-GAN) model for seamless text-to-speech synthesis in the SeamlessM4T framework. The model includes components for duration prediction, unit embeddings, speaker embeddings, language embeddings, and the HiFi-GAN architecture.
The class includes methods for computing output lengths after the duration layer and the HiFi-GAN convolutional layers. It also provides functionality for forwarding the model using input sequences, speaker IDs, and language IDs, and initializing and applying weight normalization to the model's components.
The class inherits from PreTrainedModel and contains methods for weight initialization, applying weight normalization, and removing weight normalization from the HiFi-GAN components. Additionally, it includes utility functions for weight normalization operations.
For detailed information on each method and its parameters, please refer to the method docstrings within the class definition.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TCodeHifiGan.__init__(config)
¶
Initializes the SeamlessM4TCodeHifiGan class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A configuration object that contains various settings and parameters for the HifiGan model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TCodeHifiGan.apply_weight_norm()
¶
Applies weight normalization to the layers of the SeamlessM4TCodeHifiGan model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TCodeHifiGan class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method modifies the model's layers in-place. |
This method applies weight normalization to the layers of the HifiGan model within the SeamlessM4TCodeHifiGan class. It iterates through each layer and applies weight normalization using the nn.utils.weight_norm() function.
The layers that are subjected to weight normalization are:
- self.hifi_gan.conv_pre: Convolutional layer before upsampling.
- self.hifi_gan.upsampler: List of upsampling layers.
- self.hifi_gan.resblocks: List of residual blocks.
- self.hifi_gan.conv_post: Convolutional layer after upsampling.
The weight normalization technique normalizes the weights of each layer, making the training process more stable and accelerating the convergence. It helps to reduce the internal covariate shift and improves the generalization performance of the model.
Note
The method modifies the original model's layers and does not return any value.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TCodeHifiGan.forward(input_ids, spkr_id, lang_id)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [
TYPE:
|
spkr_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/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TCodeHifiGan.remove_weight_norm()
¶
Removes weight normalization from the specified layers in the SeamlessM4TCodeHifiGan class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TCodeHifiGan class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Description
This method removes weight normalization from the layers in the HifiGan model. The following layers are affected:
- self.hifi_gan.conv_pre: This is the convolutional layer before the upsampling layers.
- self.hifi_gan.upsampler: These are the upsampling layers in the HifiGan model.
- self.hifi_gan.resblocks: These are the residual blocks in the HifiGan model.
- self.hifi_gan.conv_post: This is the convolutional layer after the upsampling layers.
Note
Weight normalization is a technique used in deep learning to normalize the weights of a neural network layer. Removing weight normalization can improve the performance or stability of the model in certain scenarios.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapter
¶
Bases: Module
This class represents a seamless multi-task (M4T) Conformer adapter, designed for adapting transformer-based models for multi-task learning. The adapter consists of multiple adapter layers that can be stacked on top of each other to adapt the model's hidden states for different tasks.
ATTRIBUTE | DESCRIPTION |
---|---|
layers |
A list of SeamlessM4TConformerAdapterLayer instances, each representing an adapter layer in the adapter stack.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4TConformerAdapter instance with the specified configuration. Args:
|
forward |
Constructs the adapter by applying each adapter layer in the stack to the input hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
1495 1496 1497 1498 1499 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapter.__init__(config)
¶
Initializes an instance of the SeamlessM4TConformerAdapter class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself. |
config |
A configuration object containing the necessary parameters for initializing the adapter.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapter.forward(hidden_states, attention_mask)
¶
Constructs the SeamlessM4TConformerAdapter by applying the layers to the input hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerAdapter class. |
hidden_states |
The input hidden states. It should have a shape of [batch_size, sequence_length, hidden_size].
TYPE:
|
attention_mask |
The attention mask tensor. It should have a shape of [batch_size, sequence_length] and is used to mask certain positions in the input sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapterLayer
¶
Bases: Module
The SeamlessM4TConformerAdapterLayer
class is a Python class that represents a layer in the SeamlessM4TConformer
adapter model. This layer is used to adapt the input hidden states using self-attention and feed-forward networks.
This class inherits from the nn.Module
class.
ATTRIBUTE | DESCRIPTION |
---|---|
`kernel_size` |
The size of the kernel used in the convolutional layers.
TYPE:
|
`stride` |
The stride used in the convolutional layers.
TYPE:
|
`residual_layer_norm` |
A layer normalization module applied to the residual hidden states.
TYPE:
|
`residual_conv` |
A 1D convolutional layer used to transform the residual hidden states.
TYPE:
|
`activation` |
The activation function applied to the transformed residual hidden states.
TYPE:
|
`self_attn_layer_norm` |
A layer normalization module applied to the self-attention hidden states.
TYPE:
|
`self_attn_conv` |
A 1D convolutional layer used to transform the self-attention hidden states.
TYPE:
|
`self_attn` |
The self-attention module used to compute attention weights. |
`self_attn_dropout` |
A dropout layer applied to the self-attention hidden states.
TYPE:
|
`ffn_layer_norm` |
A layer normalization module applied to the feed-forward hidden states.
TYPE:
|
`ffn` |
The feed-forward module used to transform the feed-forward hidden states. |
METHOD | DESCRIPTION |
---|---|
`_compute_sub_sample_lengths_from_attention_mask` |
Computes the sub-sampled lengths of the hidden states based on the attention mask. |
`forward` |
Constructs the output hidden states by applying the adapter layer transformations to the input hidden states. |
Note
This class assumes the existence of the following helper functions: _compute_new_attention_mask
,
_prepare_4d_attention_mask
.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 1357 1358 1359 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapterLayer.__init__(config)
¶
Initializes an instance of the SeamlessM4TConformerAdapterLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of the configuration class containing the following attributes:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerAdapterLayer.forward(hidden_states, attention_mask=None, output_attentions=False)
¶
Constructs a SeamlessM4TConformerAdapterLayer.
This method applies the necessary transformations and computations to the input hidden_states
to produce
the final output hidden_states
.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerAdapterLayer class. |
hidden_states |
The input hidden states tensor. It should have a shape of (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
An optional tensor representing the attention mask. It should have a shape of (batch_size, sequence_length).
TYPE:
|
output_attentions |
A flag indicating whether to output attentions. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mindspore.Tensor: The output hidden states tensor. It has the same shape as the input |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerConvolutionModule
¶
Bases: Module
Convolution block used in the conformer block
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerConvolutionModule.__init__(config)
¶
Initializes the SeamlessM4TConformerConvolutionModule.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
An object containing configuration parameters for the module.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
Raised if the 'config.conv_depthwise_kernel_size' is not an odd number, which is required for 'SAME' padding. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerConvolutionModule.forward(hidden_states, attention_mask=None)
¶
Constructs the SeamlessM4TConformerConvolutionModule.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerConvolutionModule class.
|
hidden_states |
The input hidden states. It should have shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
An optional attention mask. It should have the same shape as hidden_states. Each element of the mask should be 0 or 1, indicating whether a token is valid or masked. If provided, the hidden states corresponding to the masked tokens will be set to 0.0. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: The transformed hidden states after passing through the SeamlessM4TConformerConvolutionModule. It has the same shape as the input hidden states. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoder
¶
Bases: Module
This class represents a SeamlessM4TConformerEncoder which is responsible for encoding input sequences using a Conformer model architecture. The encoder consists of multiple ConformerEncoderLayer instances stacked on top of each other. It handles positional embeddings, dropout, layer normalization, and gradient checkpointing.
PARAMETER | DESCRIPTION |
---|---|
config |
An object containing configuration parameters for the encoder.
|
Inherits |
nn.Module
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4TConformerEncoder with the provided configuration. Sets up positional embeddings based on the specified type, dropout, encoder layers, layer normalization, and gradient checkpointing. |
forward |
Constructs the encoder by processing the input hidden states through each encoder layer. It applies dropout, handles attention masks, and computes relative position embeddings. Returns the encoded hidden states, hidden states history if enabled, and attention weights if requested. |
ATTRIBUTE | DESCRIPTION |
---|---|
config |
Configuration parameters for the encoder.
|
embed_positions |
Positional embedding module based on the specified type ('relative' or 'rotary').
|
dropout |
Dropout module for regularization.
|
layers |
List of ConformerEncoderLayer instances representing the stacked encoder layers.
|
layer_norm |
Layer normalization module to normalize the hidden states.
|
gradient_checkpointing |
Flag indicating whether gradient checkpointing is enabled.
|
For detailed usage instructions and examples, refer to the official documentation.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoder.__init__(config)
¶
Initializes an instance of the SeamlessM4TConformerEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerEncoder class.
|
config |
An object of type Config that contains configuration parameters for the SeamlessM4TConformerEncoder.
|
RETURNS | DESCRIPTION |
---|---|
None |
This method initializes the SeamlessM4TConformerEncoder with the given configuration parameters. It sets the configuration parameters for the instance and initializes the positional embedding based on the type of position embedding specified in the configuration. The method also sets the dropout probability, creates a list of encoder layers based on the number of layers specified in the configuration, normalizes the outputs of the encoder layer using LayerNorm, and sets the gradient checkpointing flag to False.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoder.forward(hidden_states, attention_mask=None, output_attentions=False, output_hidden_states=False, return_dict=True)
¶
Construct method in the SeamlessM4TConformerEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerEncoder class.
|
hidden_states |
The input hidden states to be processed by the encoder.
TYPE:
|
attention_mask |
A tensor representing the attention mask to be applied during processing. Defaults to None.
TYPE:
|
output_attentions |
A flag indicating whether to output the attention weights. Defaults to False.
TYPE:
|
output_hidden_states |
A flag indicating whether to output the hidden states of each layer. Defaults to False.
TYPE:
|
return_dict |
A flag indicating whether to return the outputs as a dictionary. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method does not explicitly return a value, but updates hidden_states, all_hidden_states, and all_self_attentions within the class instance. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input arguments are of incorrect types. |
ValueError
|
If the input hidden_states and attention_mask have incompatible shapes. |
RuntimeError
|
If an error occurs during processing or if the input tensors are not well-formed. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
1193 1194 1195 1196 1197 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 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoderLayer
¶
Bases: Module
Conformer block based on https://arxiv.org/abs/2005.08100.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoderLayer.__init__(config)
¶
Initializes a SeamlessM4TConformerEncoderLayer object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself. |
config |
A configuration object containing parameters for the encoder layer. It must have the following attributes:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerEncoderLayer.forward(hidden_states, attention_mask=None, relative_position_embeddings=None, output_attentions=False, conv_attention_mask=None)
¶
The 'forward' method in the 'SeamlessM4TConformerEncoderLayer' class forwards the encoder layer of a Conformer model.
PARAMETER | DESCRIPTION |
---|---|
self |
Reference to the current instance of the class.
|
hidden_states |
The input hidden states for the encoder layer.
TYPE:
|
attention_mask |
An optional tensor representing the attention mask. Default is None.
TYPE:
|
relative_position_embeddings |
Optional tensor for relative position embeddings. Default is None.
TYPE:
|
output_attentions |
A flag indicating whether to output attention weights. Default is False.
TYPE:
|
conv_attention_mask |
An optional tensor representing the convolution attention mask. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[mindspore.Tensor, mindspore.Tensor]: The forwarded hidden states after processing through the encoder layer, along with the attention weights. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeatureProjection
¶
Bases: Module
This class represents a feature projection module for the SeamlessM4TConformer model. It inherits from the nn.Module class.
The feature projection module consists of a layer normalization, a dense projection layer, and a dropout layer. It takes in hidden states as input and applies layer normalization, followed by a projection and dropout operation. The resulting hidden states are returned.
ATTRIBUTE | DESCRIPTION |
---|---|
layer_norm |
A layer normalization module that normalizes the input hidden states.
TYPE:
|
projection |
A dense projection layer that projects the normalized hidden states.
TYPE:
|
dropout |
A dropout layer that applies dropout to the projected hidden states.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Applies the feature projection to the input hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeatureProjection.__init__(config)
¶
Initializes a new instance of the SeamlessM4TConformerFeatureProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the class. |
config |
The configuration parameters for the feature projection.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeatureProjection.forward(hidden_states)
¶
Method to forward the feature projection in the SeamlessM4TConformerFeatureProjection class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerFeatureProjection class. |
hidden_states |
The input hidden states to be processed. Expected to be a tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value directly. The hidden_states are processed and modified in-place. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeedForward
¶
Bases: Module
The SeamlessM4TConformerFeedForward class represents a feed-forward neural network module for the SeamlessM4TConformer model. It inherits from the nn.Module class and contains methods for initializing the network and forwarding the feed-forward operations.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
The configuration parameters for the feed-forward network.
|
act_fn |
The activation function to be used in the network.
|
dropout |
The dropout probability for the network.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4TConformerFeedForward module with the given configuration, activation function, and dropout probability. |
forward |
Constructs the feed-forward operations on the given hidden states, applying intermediate dense layers, activation functions, and dropout. Returns the processed hidden states. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeedForward.__init__(config, act_fn=None, dropout=None)
¶
Initializes the SeamlessM4TConformerFeedForward class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing configuration settings.
|
act_fn |
Activation function to be used.
DEFAULT:
|
dropout |
Dropout rate to be applied.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerFeedForward.forward(hidden_states)
¶
Constructs the feed forward layer for the SeamlessM4TConformerFeedForward class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerFeedForward class. |
hidden_states |
The input hidden states to be processed by the feed forward layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input hidden_states is not a valid tensor. |
ValueError
|
If the input hidden_states is empty or has invalid shape. |
RuntimeError
|
If there is an issue during the feed forward layer forwardion process. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerPositionalConvEmbedding
¶
Bases: Module
A Python class representing a SeamlessM4TConformerPositionalConvEmbedding, which is used for positional convolutional embedding within a Conformer neural network model. This class inherits from nn.Module and includes functionality for applying convolution operations with specific configurations for padding and grouping.
ATTRIBUTE | DESCRIPTION |
---|---|
conv |
nn.Conv1d A 1D convolutional layer with configurable kernel size, padding, and group settings.
|
padding |
SeamlessM4TConformerSamePadLayer A layer for applying padding to the convolutional output based on specified parameters.
|
activation |
function Activation function to be applied to the output of the convolutional layer.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Constructor method for initializing the SeamlessM4TConformerPositionalConvEmbedding instance. |
forward |
Method to perform the sequence of operations on the input hidden states, including convolution, padding, activation, and axis swapping. |
Usage
Instantiate an object of SeamlessM4TConformerPositionalConvEmbedding with a configuration object and utilize the 'forward' method to process input hidden states.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerPositionalConvEmbedding.__init__(config)
¶
Initialize the SeamlessM4TConformerPositionalConvEmbedding.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
Configuration object containing parameters for initializing the positional convolutional embedding.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerPositionalConvEmbedding.forward(hidden_states)
¶
Constructs the positional convolutional embedding for the SeamlessM4TConformerPositionalConvEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerPositionalConvEmbedding class. |
hidden_states |
The input hidden states with shape (batch_size, sequence_length, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method modifies the hidden_states in place. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input hidden_states is not a numpy array. |
ValueError
|
If the input hidden_states does not have the correct shape (batch_size, sequence_length, hidden_size). |
TypeError
|
If the input hidden_states data type is not compatible with numpy array operations. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRelPositionalEmbedding
¶
Bases: Module
Relative positional encoding module.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRelPositionalEmbedding.__init__(config)
¶
Initializes an instance of the SeamlessM4TConformerRelPositionalEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of type 'Config' containing the configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRelPositionalEmbedding.extend_pe(x)
¶
Extends the positional embeddings of the SeamlessM4TConformerRelPositionalEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerRelPositionalEmbedding class. |
x |
The input tensor to extend the positional embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method modifies the positional embeddings in-place. |
Description
This method extends the positional embeddings of the SeamlessM4TConformerRelPositionalEmbedding class based on the shape of the input tensor, 'x'. If the existing positional embeddings (pe) are already larger than or equal to twice the width of 'x', no modifications are made. If the data type of the positional embeddings is different from 'x', the positional embeddings are converted to the data type of 'x'.
The method then calculates positive and negative positional encodings based on the shape of 'x'. The positional encodings are calculated using sine and cosine functions with a positional encoding matrix. The calculated positional encodings are flipped and concatenated to form the final positional embeddings, which are then assigned to the 'pe' attribute of the SeamlessM4TConformerRelPositionalEmbedding instance.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRelPositionalEmbedding.forward(hidden_states)
¶
Constructs the relative positional embeddings for the SeamlessM4TConformer model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerRelPositionalEmbedding class. |
hidden_states |
The hidden states of the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mindspore.Tensor: The relative position embeddings for the given hidden states. |
Description
This method takes the hidden states of the model and forwards the relative position embeddings. It first extends the positional encodings (pe) using the extend_pe() method. Then, it calculates the start and end indices for selecting the relevant portion of the positional encodings based on the length of the hidden states. Finally, it returns the relative position embeddings for the given hidden states.
The positional encodings are extended to ensure that there are sufficient embeddings to cover the entire sequence of hidden states. The start and end indices are calculated to select the relevant portion of the positional encodings that corresponds to the hidden states. This ensures that the relative position embeddings are aligned with the hidden states.
Note
The relative position embeddings are used to capture the positional information between different elements in the hidden states. They help the model understand the relative positions of tokens in the input sequence, which is important for tasks such as machine translation.
Example
>>> rel_pos_emb = SeamlessM4TConformerRelPositionalEmbedding()
>>> hidden_states = mindspore.Tensor(...)
>>> relative_position_embeddings = rel_pos_emb.forward(hidden_states)
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRotaryPositionalEmbedding
¶
Bases: Module
Rotary positional embedding Reference : https://blog.eleuther.ai/rotary-embeddings/ Paper: https://arxiv.org/pdf/2104.09864.pdf
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 329 330 331 332 333 334 335 336 337 338 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRotaryPositionalEmbedding.__init__(config)
¶
init(self, config)
Initialize the SeamlessM4TConformerRotaryPositionalEmbedding instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerRotaryPositionalEmbedding class.
|
config |
A configuration object containing the parameters for the rotary positional embedding, including hidden_size and speech_encoder_attention_heads. It also includes the rotary_embedding_base used for calculating the inverse frequency. It is expected to be a valid configuration object.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerRotaryPositionalEmbedding.forward(hidden_states)
¶
Constructs the rotary positional embeddings for the SeamlessM4TConformerRotaryPositionalEmbedding.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the SeamlessM4TConformerRotaryPositionalEmbedding class.
|
hidden_states |
A tensor representing the hidden states. It should have the shape (batch_size, sequence_length, hidden_size).
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method updates the cached_rotary_positional_embedding attribute of the instance. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSamePadLayer
¶
Bases: Module
This class represents a seamless M4T Conformer layer with same padding.
Inherits from nn.Module.
ATTRIBUTE | DESCRIPTION |
---|---|
num_pad_remove |
The number of padding elements to remove from the input sequence.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4TConformerSamePadLayer instance. |
forward |
Constructs the hidden states of the SeamlessM4TConformerSamePadLayer. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 510 511 512 513 514 515 516 517 518 519 520 521 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSamePadLayer.__init__(num_conv_pos_embeddings)
¶
Initializes an instance of the SeamlessM4TConformerSamePadLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current object instance. |
num_conv_pos_embeddings |
The number of convolutional position embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSamePadLayer.forward(hidden_states)
¶
Constructs the hidden states by removing padding from the input tensor.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerSamePadLayer class. |
hidden_states |
The input tensor containing hidden states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The hidden states tensor with padding removed is modified in-place. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSelfAttention
¶
Bases: Module
Construct a SeamlessM4TConformerSelfAttention object. Can be enhanced with rotary or relative position embeddings.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 1010 1011 1012 1013 1014 1015 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSelfAttention.__init__(config, use_position_embeddings=True)
¶
Initializes a new instance of the SeamlessM4TConformerSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object.
TYPE:
|
use_position_embeddings |
Whether to use position embeddings. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TConformerSelfAttention.forward(hidden_states, attention_mask=None, relative_position_embeddings=None, output_attentions=False)
¶
Constructs the self-attention mechanism in the SeamlessM4TConformerSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the SeamlessM4TConformerSelfAttention 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), where each value is either 0 or 1. It is used to mask positions in the attention scores that should be ignored.
TYPE:
|
relative_position_embeddings |
An optional tensor of shape (sequence_length, sequence_length, hidden_size) used for relative position embeddings. Required when self.position_embeddings_type is 'rotary' or 'relative'.
TYPE:
|
output_attentions |
A flag indicating whether to output attention probabilities. 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:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If self.position_embeddings_type is 'rotary' but relative_position_embeddings is not defined. |
ValueError
|
If self.position_embeddings_type is 'relative' but relative_position_embeddings is not defined. |
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 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 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TDecoder
¶
Bases: SeamlessM4TPreTrainedModel
SeamlessM4TDecoder
This class represents a decoder module for the SeamlessM4T model. It inherits from SeamlessM4TPreTrainedModel and implements methods for initializing the decoder, forwarding the decoder, and getting/setting input embeddings.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
An instance of SeamlessM4TConfig containing the configuration settings for the decoder.
|
dropout |
The dropout rate specified in the configuration.
|
layerdrop |
The layer drop rate specified in the configuration.
|
padding_idx |
The padding token index specified in the configuration.
|
vocab_size |
The size of the vocabulary specified in the configuration.
|
max_target_positions |
The maximum target positions specified in the configuration.
|
embed_scale |
The scaling factor for embedding specified in the configuration.
|
embed_tokens |
An instance of nn.Embedding for embedding tokens.
|
embed_positions |
An instance of SeamlessM4TSinusoidalPositionalEmbedding for embedding positions.
|
layers |
A list of SeamlessM4TDecoderLayer instances representing the decoder layers.
|
layer_norm |
An instance of nn.LayerNorm for layer normalization.
|
gradient_checkpointing |
A boolean specifying whether gradient checkpointing is enabled.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the SeamlessM4TDecoder with the given configuration and embed_tokens. |
get_input_embeddings |
Returns the input embeddings. |
set_input_embeddings |
Sets the input embeddings for the decoder. |
forward |
Constructs the decoder with the given input and optional arguments. |
PARAMETER | DESCRIPTION |
---|---|
input_ids |
A mindspore.Tensor of shape (batch_size, sequence_length) representing input sequence token indices.
|
attention_mask |
A mindspore.Tensor of shape (batch_size, sequence_length) representing attention mask to avoid padding tokens.
|
encoder_hidden_states |
A mindspore.Tensor of shape (batch_size, encoder_sequence_length, hidden_size) representing hidden states of the encoder.
|
encoder_attention_mask |
A mindspore.Tensor of shape (batch_size, encoder_sequence_length) representing attention mask for cross-attention.
|
past_key_values |
A tuple of tuples of mindspore.Tensor representing pre-computed hidden-states for sequential decoding.
|
inputs_embeds |
A mindspore.Tensor of shape (batch_size, sequence_length, hidden_size) representing embedded input representation.
|
use_cache |
A boolean specifying whether to use cache for sequential decoding.
|
output_attentions |
A boolean specifying whether to return attentions tensors of all attention layers.
|
output_hidden_states |
A boolean specifying whether to return hidden states of all layers.
|
return_dict |
A boolean specifying whether to return a ModelOutput instead of a plain tuple.
|
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 |
|
mindnlp.transformers.models.seamless_m4t.modeling_seamless_m4t.SeamlessM4TDecoder.__init__(config, embed_tokens=None)
¶
Initializes an instance of the 'SeamlessM4TDecoder' class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the 'SeamlessM4TDecoder' class.
|
config |
An object containing configuration options for the decoder.
TYPE:
|
embed_tokens |
An optional embedding object to be used for token embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
This method initializes the 'SeamlessM4TDecoder' instance by setting various attributes and creating necessary objects. It takes the following parameters:
- self: An instance of the 'SeamlessM4TDecoder' class.
- config (SeamlessM4TConfig): An object that holds configuration options for the decoder. It provides access to various hyperparameters and settings.
- embed_tokens (Optional[nn.Embedding]): An optional embedding object that can be used for token embeddings. If provided, the 'embed_tokens' attribute of the decoder will be set to this object. Otherwise, a new embedding object will be created using the 'vocab_size' and 'hidden_size' from the 'config' object.
Note
The 'config' parameter is mandatory, while the 'embed_tokens' parameter is optional.
The method performs the following actions:
- Calls the superclass 'init' method with the 'config' parameter.
- Sets the 'dropout' attribute to the 'dropout' value from the 'config' object.
- Sets the 'layerdrop' attribute to the 'decoder_layerdrop' value from the 'config' object.
- Sets the 'padding_idx' attribute to the 'pad_token_id' value from the 'config' object.
- Sets the 'vocab_size' attribute to the 'vocab_size' value from the 'config' object.
- Sets the 'max_target_positions' attribute to the 'max_position_embeddings' value from the 'config' object.
- Sets the 'embed_scale' attribute based on the 'scale_embedding' value from the 'config' object. If 'scale_embedding' is True, it sets 'embed_scale' to the square root of 'hidden_size'; otherwise, it sets 'embed_scale' to 1.0.
-
If 'embed_tokens' is not None:
- Creates a new 'nn.Embedding' object named 'self.embed_tokens' with 'embed_tokens.vocab_size', 'embed_tokens.embedding_size', and 'self.padding_idx' as arguments.
-
Sets the weight of 'self.embed_tokens' to the weight of 'embed_tokens'. 9. If 'embed_tokens' is None:
-
Creates a new 'nn.Embedding' object named 'self.embed_tokens' with 'self.vocab_size', 'config.hidden_size', and 'self.padding_idx' as arguments. 10. Creates a 'SeamlessM4TSinusoidalPositionalEmbedding' object named 'self.embed_positions' with 'self.max_target_positions', 'config.hidden_size', and 'self.padding_idx' as arguments. 11. Creates a list named 'layers'. 12. Iterates 'config.decoder_layers' times and appends a 'SeamlessM4TDecoderLayer' object to 'layers', using 'config', 'config.decoder_attention_heads', and 'config.decoder_ffn_dim' as arguments. 13. Sets the 'layers' attribute to a 'nn.ModuleList' containing the objects in 'layers'. 14. Creates a 'nn.LayerNorm' object named 'self.layer_norm' with a list containing 'config.hidden_size' as the argument. 15. Sets the 'gradient_checkpointing' attribute to False. 16. Calls the 'post_init' method.
Note: The 'post_init' method is not defined in the given code snippet.
Source code in mindnlp/transformers/models/seamless_m4t/modeling_seamless_m4t.py
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 |
|