deberta
mindnlp.transformers.models.deberta.modeling_deberta
¶
MindSpore DeBERTa model.
mindnlp.transformers.models.deberta.modeling_deberta.ContextPooler
¶
Bases: Module
Represents a ContextPooler module used for pooling contextual embeddings in a neural network architecture.
This class inherits from nn.Module and provides methods for initializing the pooler, forwarding the pooled output based on hidden states, and retrieving the output dimension. The pooler consists of a dense layer and dropout mechanism for processing hidden states.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dense |
A dense layer for transforming input hidden states to pooler hidden size.
TYPE:
|
dropout |
A dropout layer for stable dropout operations.
TYPE:
|
config |
Configuration object containing pooler settings.
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the ContextPooler with the given configuration. |
forward |
Constructs the pooled output by processing hidden states. |
output_dim |
Property that returns the output dimension based on the hidden size in the configuration. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
mindnlp.transformers.models.deberta.modeling_deberta.ContextPooler.output_dim
property
¶
Method to retrieve the output dimension of the ContextPooler.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the ContextPooler class. This parameter is required to access the configuration information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method does not perform any computation but simply returns the output dimension. |
mindnlp.transformers.models.deberta.modeling_deberta.ContextPooler.__init__(config)
¶
Initializes a new instance of the ContextPooler class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the ContextPooler class.
|
config |
An object of type 'config' that contains the configuration parameters for the ContextPooler.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
mindnlp.transformers.models.deberta.modeling_deberta.ContextPooler.forward(hidden_states)
¶
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the ContextPooler class.
TYPE:
|
hidden_states |
A tensor containing hidden states. It is expected to have a specific shape and format for processing.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pooled_output
|
The output tensor after the pooling operation. It represents the pooled context information.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the hidden_states tensor does not meet the expected shape or format requirements. |
RuntimeError
|
If an error occurs during the pooling operation. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaAttention
¶
Bases: Module
This class represents the DebertaAttention module, which is a component of the DeBERTa model. It inherits from the nn.Module class.
DebertaAttention applies self-attention mechanism on the input hidden states, allowing the model to focus on different parts of the input sequence. It consists of a DisentangledSelfAttention layer and a DebertaSelfOutput layer.
| PARAMETER | DESCRIPTION |
|---|---|
config |
A dictionary containing the configuration parameters for the DebertaAttention module.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes a new instance of DebertaAttention. Args:
|
forward |
Applies the DebertaAttention mechanism on the input hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaAttention.__init__(config)
¶
Initializes a new instance of the DebertaAttention class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The current instance of the DebertaAttention class.
TYPE:
|
config |
The configuration object containing the settings for the attention module. It should provide the necessary parameters for initializing the DisentangledSelfAttention and DebertaSelfOutput instances.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaAttention.forward(hidden_states, attention_mask, output_attentions=False, query_states=None, relative_pos=None, rel_embeddings=None)
¶
Constructs the DebertaAttention layer with the given parameters.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The DebertaAttention instance.
|
hidden_states |
The input hidden states with shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask with shape (batch_size, sequence_length).
TYPE:
|
output_attentions |
Whether to output attention matrices.
TYPE:
|
query_states |
The query states with shape (batch_size, sequence_length, hidden_size). If not provided, defaults to hidden_states.
TYPE:
|
relative_pos |
The relative position encoding with shape (batch_size, sequence_length, sequence_length).
TYPE:
|
rel_embeddings |
The relative position embeddings with shape (num_relative_distances, hidden_size).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEmbeddings
¶
Bases: Module
Construct the embeddings from word, position and token_type embeddings.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEmbeddings.__init__(config)
¶
Initializes the DebertaEmbeddings class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
Instance of the DebertaEmbeddings class.
TYPE:
|
config |
An object containing configuration parameters for the Deberta model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEmbeddings.forward(input_ids=None, token_type_ids=None, position_ids=None, mask=None, inputs_embeds=None)
¶
Constructs the embeddings for the Deberta model.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaEmbeddings class.
TYPE:
|
input_ids |
A tensor of shape (batch_size, sequence_length) representing the input token IDs. Default is None.
TYPE:
|
token_type_ids |
A tensor of shape (batch_size, sequence_length) representing the token type IDs. Default is None.
TYPE:
|
position_ids |
A tensor of shape (batch_size, sequence_length) representing the position IDs. Default is None.
TYPE:
|
mask |
A tensor of shape (batch_size, sequence_length) representing the attention mask. Default is None.
TYPE:
|
inputs_embeds |
A tensor of shape (batch_size, sequence_length, embedding_size) representing the input embeddings. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
A tensor of shape (batch_size, sequence_length, embedding_size) representing the forwarded embeddings. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder
¶
Bases: Module
Modified BertEncoder with relative position bias support
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder.__init__(config)
¶
Initialize the DebertaEncoder class with the provided configuration.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaEncoder class.
TYPE:
|
config |
An object containing configuration settings for the DebertaEncoder.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder.forward(hidden_states, attention_mask, output_hidden_states=True, output_attentions=False, query_states=None, relative_pos=None, return_dict=True)
¶
This method forwards the DebertaEncoder by processing the input hidden states and attention mask.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaEncoder class.
TYPE:
|
hidden_states |
The input hidden states for the encoder. It can be a Sequence of hidden states or a single hidden state object.
TYPE:
|
attention_mask |
The attention mask to be applied to the input hidden states.
TYPE:
|
output_hidden_states |
Indicates whether to return all hidden states. Defaults to True.
TYPE:
|
output_attentions |
Indicates whether to return attentions. Defaults to False.
TYPE:
|
query_states |
The query states for the encoder. Defaults to None.
TYPE:
|
relative_pos |
The relative position information. Defaults to None.
TYPE:
|
return_dict |
Indicates whether to return the output as a BaseModelOutput instance. Defaults to True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input parameters are invalid or incompatible. |
RuntimeError
|
If there is a runtime error during the execution of the method. |
TypeError
|
If the input types are incorrect or incompatible. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder.get_attention_mask(attention_mask)
¶
This method calculates the attention mask for the DebertaEncoder.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaEncoder class.
TYPE:
|
attention_mask |
The attention mask tensor. It can be of dimension 2 or 3. For a 2-dimensional tensor, it is expected to be of shape (batch_size, sequence_length) representing the attention mask for each token in the input sequence. For a 3-dimensional tensor, it is expected to be of shape (batch_size, num_heads, sequence_length) representing the attention mask for each head in the multi-head attention mechanism.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method does not return any value. The attention_mask parameter is modified in place. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the attention_mask tensor is not of dimension 2 or 3, a ValueError is raised. |
RuntimeError
|
If there is a runtime error during the calculation, a RuntimeError may be raised. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder.get_rel_embedding()
¶
Retrieve the relative embeddings from the DebertaEncoder.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaEncoder class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
Returns the relative embeddings if self.relative_attention is True, otherwise returns None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaEncoder.get_rel_pos(hidden_states, query_states=None, relative_pos=None)
¶
Method
get_rel_pos
Description
This method calculates and returns the relative position tensor used for relative attention in the DebertaEncoder class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaEncoder class.
TYPE:
|
hidden_states |
The input tensor representing the hidden states.
TYPE:
|
query_states |
The input tensor representing the query states. Default is None.
TYPE:
|
relative_pos |
The input tensor representing the relative positions. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Note
The 'query_states' and 'relative_pos' parameters are optional. If 'relative_attention' is True and 'relative_pos' is not provided, this method will automatically build the relative position tensor using 'query_states' or 'hidden_states' shape.
Example
>>> # Create an instance of DebertaEncoder class
>>> encoder = DebertaEncoder()
...
>>> # Call the get_rel_pos method
>>> encoder.get_rel_pos(hidden_states, query_states, relative_pos)
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForMaskedLM
¶
Bases: DebertaPreTrainedModel
DebertaForMaskedLM is a class that represents a DeBERTa model for masked language modeling. This class is designed to be used for generating predictions and computing loss in a masked language modeling task. It inherits from DebertaPreTrainedModel, providing additional functionality specific to masked language modeling tasks.
| ATTRIBUTE | DESCRIPTION |
|---|---|
deberta |
A DebertaModel instance used for processing input sequences.
|
cls |
A DebertaOnlyMLMHead instance responsible for generating prediction scores for masked tokens.
|
| METHOD | DESCRIPTION |
|---|---|
get_output_embeddings |
Retrieves the decoder embeddings used for output predictions. |
set_output_embeddings |
Sets new decoder embeddings for output predictions. |
forward |
Constructs the DeBERTa model for masked language modeling, including processing input data, generating predictions, and computing the masked language modeling loss. |
The 'forward' method takes various input parameters such as input_ids, attention_mask, labels, etc., and returns a MaskedLMOutput object containing the loss, prediction scores, hidden states, and attentions. It also allows for customization of return types based on the 'return_dict' parameter.
Note
Ensure proper input data formatting as described in the docstring of the 'forward' method for accurate predictions and loss computation.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForMaskedLM.__init__(config)
¶
Initialize the DebertaForMaskedLM class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForMaskedLM class.
TYPE:
|
config |
The configuration object containing parameters for the Deberta model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the config parameter is not provided or is of an incorrect type. |
ValueError
|
If the config object is missing required attributes. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForMaskedLM.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| PARAMETER | DESCRIPTION |
|---|---|
labels |
Labels for computing the masked language modeling loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForMaskedLM.get_output_embeddings()
¶
Retrieve the output embeddings from the DebertaForMaskedLM model.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForMaskedLM class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
decoder
|
This method returns the output embeddings obtained from the predictions decoder of the model. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForMaskedLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the DebertaForMaskedLM model.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForMaskedLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set as the output embeddings. It should be of shape (vocab_size, hidden_size).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForQuestionAnswering
¶
Bases: DebertaPreTrainedModel
This class represents a Deberta model for question answering tasks. It inherits functionality from the DebertaPreTrainedModel class. The DebertaForQuestionAnswering class includes methods for initializing the model with configuration, and for forwarding the model by processing input data and producing question answering model outputs. The forward method takes various input tensors such as input_ids, attention_mask, token_type_ids, position_ids, and inputs_embeds, and returns QuestionAnsweringModelOutput. It also supports optional parameters for controlling the output format and behavior. The class provides detailed documentation for the forward method, including explanations of the input and output parameters and their respective shapes and types. Additionally, the class handles the computation of total loss for question answering tasks based on start and end positions, and returns the final model outputs as a QuestionAnsweringModelOutput object.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForQuestionAnswering.__init__(config)
¶
Initializes a new instance of the DebertaForQuestionAnswering class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the class.
|
config |
An instance of the configuration class containing the model configuration.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForQuestionAnswering.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, inputs_embeds=None, start_positions=None, end_positions=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| PARAMETER | DESCRIPTION |
|---|---|
start_positions |
Labels for position (index) of the start of the labelled span for computing the token classification loss.
Positions are clamped to the length of the sequence (
TYPE:
|
end_positions |
Labels for position (index) of the end of the labelled span for computing the token classification loss.
Positions are clamped to the length of the sequence (
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForSequenceClassification
¶
Bases: DebertaPreTrainedModel
DebertaForSequenceClassification is a class that represents a DeBERTa model for sequence classification tasks. It inherits from DebertaPreTrainedModel and provides functionalities for sequenceclassification using the DeBERTa model architecture.
The class includes methods for initializing the model, getting and setting input embeddings, and forwarding the model for sequence classification tasks. The 'forward' method takes input tensors such as input_ids, attention_mask, token_type_ids, position_ids, inputs_embeds, and labels to perform sequence classification. It utilizes the DeBERTa model, a context pooler, and a classifier to generate logits for the input sequences and compute the loss based on the specified problem type.
The 'forward' method also handles different problem types such as regression, single-label classification, and multi-label classification by adjusting the loss computation accordingly. The class provides flexibility in handling various types of sequence classification tasks and supports configurable return options.
For more detailed information on the methods and parameters of DebertaForSequenceClassification, refer to the class implementation and the DeBERTa documentation.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForSequenceClassification.__init__(config)
¶
Initializes the DebertaForSequenceClassification class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForSequenceClassification class. |
config |
The configuration object containing various settings for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
AttributeError
|
If the 'num_labels' attribute is missing in the configuration object. |
TypeError
|
If the 'num_labels' attribute in the configuration object is not an integer. |
ValueError
|
If the 'cls_dropout' attribute is not a valid dropout value. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForSequenceClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| PARAMETER | DESCRIPTION |
|---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForSequenceClassification.get_input_embeddings()
¶
Method to retrieve the input embeddings from the Deberta model for sequence classification.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForSequenceClassification class. This parameter is used to access the Deberta model's input embeddings. |
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method returns None as it simply delegates the call to the Deberta model to retrieve the input embeddings. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForSequenceClassification.set_input_embeddings(new_embeddings)
¶
Sets the input embeddings for the Deberta model in the DebertaForSequenceClassification class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaForSequenceClassification class. |
new_embeddings |
The new input embeddings to be set for the Deberta model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForTokenClassification
¶
Bases: DebertaPreTrainedModel
This class represents a token classification model based on the DeBERTa architecture. It is designed to perform token-level classification tasks such as named entity recognition or part-of-speech tagging.
The DebertaForTokenClassification class extends the DebertaPreTrainedModel class and inherits its functionality
and attributes.
| ATTRIBUTE | DESCRIPTION |
|---|---|
`num_labels` |
The number of labels for token classification.
|
`deberta` |
The DeBERTa model used for feature extraction.
|
`dropout` |
A dropout layer for regularization.
|
`classifier` |
A fully connected layer for classification.
|
| METHOD | DESCRIPTION |
|---|---|
`__init__ |
Initializes the |
`forward |
Performs the forward pass of the model and returns the output. Args:
Returns:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForTokenClassification.__init__(config)
¶
init
Initializes an instance of the DebertaForTokenClassification class. Args: self: DebertaForTokenClassification The instance of the DebertaForTokenClassification class. config: DebertaConfig The configuration object containing the model configuration settings. It is used to set up the model architecture and hyperparameters. Required and must be an instance of DebertaConfig.
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaForTokenClassification.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
| PARAMETER | DESCRIPTION |
|---|---|
labels |
Labels for computing the token classification loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaIntermediate
¶
Bases: Module
DebertaIntermediate represents an intermediate layer in the DeBERTa neural network architecture for natural language processing tasks. This class inherits from nn.Module and contains methods for initializing the layer and performing computations on hidden states. The layer consists of a dense transformation followed by an activation function specified in the configuration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dense |
A dense layer with hidden size and intermediate size specified in the configuration.
TYPE:
|
intermediate_act_fn |
The activation function applied to the hidden states.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaIntermediate layer with the provided configuration. |
forward |
Applies the dense transformation and activation function to the input hidden states. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaIntermediate.__init__(config)
¶
Initializes a new instance of the DebertaIntermediate class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The object itself.
|
config |
An object containing the configuration parameters for the DebertaIntermediate class. It should have the following properties:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaIntermediate.forward(hidden_states)
¶
Constructs the intermediate layer of the Deberta model. This method takes in the hidden states tensor and applies a series of transformations to it in order to forward the intermediate layer of the Deberta model. The hidden states tensor is first passed through a dense layer, followed by an activation function specified by 'intermediate_act_fn'. The resulting tensor represents the intermediate hidden states and is returned as the output of this method.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaIntermediate class.
TYPE:
|
hidden_states |
The input hidden states tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
mindspore.Tensor: The tensor representing the output hidden states. |
| RAISES | DESCRIPTION |
|---|---|
None
|
|
Note
The 'intermediate_act_fn' attribute should be set prior to calling this method to specify the desired activation function.
Example
>>> intermediate_layer = DebertaIntermediate()
>>> hidden_states = mindspore.Tensor([0.1, 0.2, 0.3])
>>> output = intermediate_layer.forward(hidden_states)
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLMPredictionHead
¶
Bases: Module
DebertaLMPredictionHead represents the prediction head for language model tasks in a DeBERTa model. This class inherits from nn.Module.
| ATTRIBUTE | DESCRIPTION |
|---|---|
transform |
An instance of DebertaPredictionHeadTransform for transforming hidden states. |
embedding_size |
The size of the embedding layer, defaults to the hidden size if not specified in config.
TYPE:
|
decoder |
A fully connected layer for decoding hidden states to predict the next token.
TYPE:
|
bias |
The bias parameter for the decoder layer.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaLMPredictionHead with the provided configuration. |
forward |
Constructs the prediction head by applying transformations and decoding the hidden states. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLMPredictionHead.__init__(config)
¶
Initializes an instance of the DebertaLMPredictionHead class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The current object instance.
|
config |
An object containing configuration parameters for the DebertaLMPredictionHead.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLMPredictionHead.forward(hidden_states)
¶
This method forwards the prediction head for DebertaLM model.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaLMPredictionHead class.
TYPE:
|
hidden_states |
The hidden states to be processed for prediction.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The processed hidden states after passing through the transformation and decoder layers. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayer
¶
Bases: Module
Represents a single layer in the DeBERTa model, containing modules for attention, intermediate processing, and output computation.
This class inherits from nn.Module and is responsible for processing input hidden states through attention mechanisms, intermediate processing, and final output computation. It provides a 'forward' method to perform these operations and return the final layer output.
| ATTRIBUTE | DESCRIPTION |
|---|---|
attention |
Module for performing attention mechanism computation.
TYPE:
|
intermediate |
Module for intermediate processing of attention output.
TYPE:
|
output |
Module for computing final output based on intermediate processed data.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
forward |
Process the input hidden states through attention, intermediate, and output modules to compute the final layer output. Args:
Returns:
|
Note
If 'output_attentions' is set to True, the 'forward' method will return both the final layer output and the attention matrix.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayer.__init__(config)
¶
Initialize a DebertaLayer instance.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaLayer class.
TYPE:
|
config |
An object containing configuration settings for the DebertaLayer. It is used to customize the behavior of the layer during initialization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayer.forward(hidden_states, attention_mask, query_states=None, relative_pos=None, rel_embeddings=None, output_attentions=False)
¶
Constructs the DebertaLayer by performing attention, intermediate, and output operations.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The class instance.
TYPE:
|
hidden_states |
The input hidden states tensor.
TYPE:
|
attention_mask |
The attention mask tensor to mask out padded tokens.
TYPE:
|
query_states |
The tensor representing query states for attention computation. Defaults to None.
TYPE:
|
relative_pos |
The tensor representing relative positions for attention computation. Defaults to None.
TYPE:
|
rel_embeddings |
The tensor containing relative embeddings for attention computation. Defaults to None.
TYPE:
|
output_attentions |
Flag indicating whether to output attention matrices. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the dimensions of the input tensors are incompatible. |
TypeError
|
If the input parameters are not of the expected types. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayerNorm
¶
Bases: Module
LayerNorm module in the TF style (epsilon inside the square root).
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayerNorm.__init__(size, eps=1e-12)
¶
Initializes an instance of the DebertaLayerNorm class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the class.
|
size |
The size of the layer normalization parameters. It determines the shape of the weight and bias tensors.
TYPE:
|
eps |
The epsilon value used for numerical stability. It prevents division by zero. Default is 1e-12.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaLayerNorm.forward(hidden_states)
¶
This method forwards layer normalization for hidden states in a Deberta model.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaLayerNorm class.
TYPE:
|
hidden_states |
The input hidden states tensor to be normalized. Should be a tensor of dtype float32.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method performs layer normalization on the hidden_states tensor in place. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input hidden_states tensor is not of dtype float32. |
RuntimeError
|
If any runtime error occurs during the normalization process. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaModel
¶
Bases: DebertaPreTrainedModel
DebertaModel class represents a DeBERTa model for natural language processing tasks. This class inherits functionalities from DebertaPreTrainedModel and implements methods for initializing the model, getting and setting input embeddings, and forwarding the model output.
| ATTRIBUTE | DESCRIPTION |
|---|---|
embeddings |
The embeddings module of the DeBERTa model.
TYPE:
|
encoder |
The encoder module of the DeBERTa model.
TYPE:
|
z_steps |
Number of Z steps used in the model.
TYPE:
|
config |
Configuration object for the model.
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaModel with the provided configuration. |
get_input_embeddings |
Retrieves the word embeddings from the input embeddings. |
set_input_embeddings |
Sets new word embeddings for the input embeddings. |
_prune_heads |
Prunes heads of the model based on the provided dictionary. |
forward |
Constructs the model output based on the input parameters. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If the prune function is called as it is not implemented in the DeBERTa model. |
ValueError
|
If both input_ids and inputs_embeds are specified simultaneously, or if neither input_ids nor inputs_embeds are provided. |
| RETURNS | DESCRIPTION |
|---|---|
|
Tuple or BaseModelOutput: Depending on the configuration settings, returns either a tuple or a BaseModelOutput object containing the model output. |
Note
This class is designed for use in natural language processing tasks and leverages the DeBERTa architecture for efficient modeling.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaModel.__init__(config)
¶
Initializes a new instance of the DebertaModel class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the class.
|
config |
The configuration object containing the model configuration parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaModel.forward(input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
This method forwards a DebertaModel based on the provided input parameters.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaModel class.
TYPE:
|
input_ids |
The input tensor containing token indices. Default is None.
TYPE:
|
attention_mask |
The attention mask tensor to specify which tokens should be attended to. Default is None.
TYPE:
|
token_type_ids |
The tensor specifying the type of each token. Default is None.
TYPE:
|
position_ids |
The tensor containing position indices of tokens. Default is None.
TYPE:
|
inputs_embeds |
The tensor containing precomputed embeddings for input tokens. Default is None.
TYPE:
|
output_attentions |
Flag to indicate whether to output attentions. Default is None.
TYPE:
|
output_hidden_states |
Flag to indicate whether to output hidden states. Default is None.
TYPE:
|
return_dict |
Flag to indicate whether to return output as a dictionary. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[Tuple, BaseModelOutput]
|
Union[Tuple, BaseModelOutput]: The output value, which can either be a tuple or a BaseModelOutput object, containing the forwarded DebertaModel. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
Raised if both input_ids and inputs_embeds are specified simultaneously. |
ValueError
|
Raised if neither input_ids nor inputs_embeds are specified. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaModel.get_input_embeddings()
¶
Retrieve the input embeddings from the DebertaModel.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaModel class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaModel.set_input_embeddings(new_embeddings)
¶
Method to set the input embeddings for a DebertaModel instance.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaModel class.
TYPE:
|
new_embeddings |
New input embeddings to be set for the model. It should be of the appropriate type compatible with the model's word_embeddings attribute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the new_embeddings parameter is not of the expected type. |
ValueError
|
If the new_embeddings parameter is invalid or incompatible with the model. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOnlyMLMHead
¶
Bases: Module
This class represents a Deberta Masked Language Model (MLM) head for generating prediction scores from sequence output. It inherits from nn.Module and contains methods for initializing the MLM head and forwarding prediction scores.
| ATTRIBUTE | DESCRIPTION |
|---|---|
predictions |
A DebertaLMPredictionHead object for generating prediction scores.
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaOnlyMLMHead with the given configuration. |
forward |
Constructs prediction scores from the provided sequence output. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOnlyMLMHead.__init__(config)
¶
Initializes an instance of the DebertaOnlyMLMHead class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the class.
|
config |
A configuration object containing the necessary settings for the DebertaOnlyMLMHead.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOnlyMLMHead.forward(sequence_output)
¶
Class
DebertaOnlyMLMHead
Method
forward
Description
This method forwards prediction scores based on the given sequence output.
| PARAMETER | DESCRIPTION |
|---|---|
self |
(object) The instance of the DebertaOnlyMLMHead class.
|
sequence_output |
(object) The sequence output from the model for which prediction scores need to be generated.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOutput
¶
Bases: Module
This class represents the output layer of the Deberta model. It inherits from the nn.Module class and is responsible for applying the final transformations to the hidden states.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dense |
A dense layer that transforms the hidden states to an intermediate size.
TYPE:
|
LayerNorm |
A layer normalization module that normalizes the hidden states.
TYPE:
|
dropout |
A dropout layer that applies dropout to the hidden states.
TYPE:
|
config |
The configuration object for the Deberta model.
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaOutput instance. Args:
|
forward |
Applies the final transformations to the hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOutput.__init__(config)
¶
Initializes a new instance of the DebertaOutput class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaOutput class.
|
config |
An instance of the configuration class containing the parameters for the DebertaOutput layer.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaOutput.forward(hidden_states, input_tensor)
¶
Constructs the output of the Deberta model by performing a series of operations.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaOutput class.
TYPE:
|
hidden_states |
The input hidden states. This tensor represents the intermediate outputs of the model.
TYPE:
|
input_tensor |
The input tensor to be added to the hidden states.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaPredictionHeadTransform
¶
Bases: Module
Represents a prediction head transformation module for the DeBERTa model.
This class defines a prediction head transformation module for the DeBERTa model, which includes operations such as dense layer, activation function transformation, and layer normalization.
| ATTRIBUTE | DESCRIPTION |
|---|---|
embedding_size |
The size of the embedding used in the transformation.
TYPE:
|
dense |
The dense layer used for transformation.
TYPE:
|
transform_act_fn |
The activation function used for transformation.
TYPE:
|
LayerNorm |
The layer normalization module applied to the hidden states.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the DebertaPredictionHeadTransform instance with the given configuration. |
forward |
Constructs the prediction head transformation on the input hidden states. |
Note
This class inherits from nn.Module and is designed specifically for the DeBERTa model.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaPredictionHeadTransform.__init__(config)
¶
Initializes the DebertaPredictionHeadTransform class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaPredictionHeadTransform class. |
config |
The configuration object containing parameters for the prediction head. It should include the following attributes:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the config parameter is not of the expected type. |
KeyError
|
If the config.hidden_act is a string that does not match any key in the ACT2FN dictionary. |
ValueError
|
If the config does not contain the required attributes. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaPredictionHeadTransform.forward(hidden_states)
¶
This method 'forward' is defined within the class 'DebertaPredictionHeadTransform' and is responsible for processing the hidden states.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the 'DebertaPredictionHeadTransform' class.
|
hidden_states |
A tensor representing the hidden states to be processed. It is of type 'Tensor' and is expected to contain the information to be transformed.
|
| RETURNS | DESCRIPTION |
|---|---|
hidden_states
|
A tensor containing the transformed hidden states after processing. It is of type 'Tensor' and represents the result of the transformation operation. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaSelfOutput
¶
Bases: Module
Represents the output layer for the DeBERTa model, responsible for transforming hidden states and applying normalization and dropout.
This class inherits from nn.Module and contains methods to initialize the output layer components, including dense transformation, layer normalization, and dropout. The 'forward' method takes hidden states and input tensor, applies transformations, and returns the final hidden states after normalization and dropout.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dense |
A fully connected layer for transforming hidden states.
TYPE:
|
LayerNorm |
Layer normalization applied to the hidden states.
TYPE:
|
dropout |
Dropout regularization to prevent overfitting.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the output layer components with the given configuration. |
forward |
Applies transformations to hidden states and input tensor to produce final hidden states. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaSelfOutput.__init__(config)
¶
Initializes an instance of the DebertaSelfOutput class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The current instance of the class.
TYPE:
|
config |
The configuration object containing the settings for the Deberta model.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
mindnlp.transformers.models.deberta.modeling_deberta.DebertaSelfOutput.forward(hidden_states, input_tensor)
¶
Method 'forward' in the class 'DebertaSelfOutput'.
This method forwards the hidden states by applying a series of operations on the input hidden states and the input tensor.
| PARAMETER | DESCRIPTION |
|---|---|
self |
Instance of the DebertaSelfOutput class.
|
hidden_states |
Hidden states that need to be processed.
|
input_tensor |
Input tensor to be added to the processed hidden states.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DisentangledSelfAttention
¶
Bases: Module
Disentangled self-attention module
| PARAMETER | DESCRIPTION |
|---|---|
config |
A model config class instance with the configuration to build a new model. The schema is similar to
BertConfig, for more details, please refer [
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 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 1493 1494 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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DisentangledSelfAttention.__init__(config)
¶
Initializes a DisentangledSelfAttention object with the given configuration.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The object itself. |
config |
A configuration object that contains various parameters for the self-attention mechanism.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the hidden size is not a multiple of the number of attention heads. |
Note
The hidden size should be a multiple of the number of attention heads in order to ensure proper functioning of the self-attention mechanism.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 | |
mindnlp.transformers.models.deberta.modeling_deberta.DisentangledSelfAttention.disentangled_att_bias(query_layer, key_layer, relative_pos, rel_embeddings, scale_factor)
¶
Perform disentangled attention bias calculation in the DisentangledSelfAttention class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DisentangledSelfAttention class. |
query_layer |
Input tensor representing the query layer of shape [batch_size, seq_length, hidden_size].
TYPE:
|
key_layer |
Input tensor representing the key layer of shape [batch_size, seq_length, hidden_size].
TYPE:
|
relative_pos |
Optional input tensor representing the relative positions of shape [batch_size, seq_length, seq_length] or [seq_length, seq_length]. If None, relative positions are calculated using the build_relative_position function.
TYPE:
|
rel_embeddings |
Input tensor representing the relative position embeddings of shape [2 * max_relative_positions, hidden_size].
TYPE:
|
scale_factor |
Scaling factor for the calculation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
score
|
Output tensor representing the disentangled attention bias score of shape [batch_size, seq_length, seq_length].
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the dimension of relative_pos is not 2 or 3 or 4. |
Note
- The method calculates the disentangled attention bias score using the query and key layers, relative positions, and relative position embeddings.
- The attention bias score is calculated based on the 'c2p' and 'p2c' types of positional attention specified in the pos_att_type attribute of the DisentangledSelfAttention instance.
- The score is returned as a Tensor.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 | |
mindnlp.transformers.models.deberta.modeling_deberta.DisentangledSelfAttention.forward(hidden_states, attention_mask, output_attentions=False, query_states=None, relative_pos=None, rel_embeddings=None)
¶
Call the module
| PARAMETER | DESCRIPTION |
|---|---|
hidden_states |
Input states to the module usually the output from previous layer, it will be the Q,K and V in Attention(Q,K,V)
TYPE:
|
attention_mask |
An attention mask matrix of shape [B, N, N] where B is the batch size, N is the maximum sequence length in which element [i,j] = 1 means the i th token in the input can attend to the j th token.
TYPE:
|
output_attentions |
Whether return the attention matrix.
TYPE:
|
query_states |
The Q state in Attention(Q,K,V).
TYPE:
|
relative_pos |
The relative position encoding between the tokens in the sequence. It's of shape [B, N, N] with values ranging in [-max_relative_positions, max_relative_positions].
TYPE:
|
rel_embeddings |
The embedding of relative distances. It's a tensor of shape [\(2 \times \text{max_relative_positions}\), hidden_size].
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DisentangledSelfAttention.swapaxes_for_scores(x)
¶
Performs a swap axis operation on the input tensor for scores in the DisentangledSelfAttention class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DisentangledSelfAttention class. |
x |
The input tensor to be operated on. It should have a shape of (batch_size, seq_length, hidden_size).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
torch.Tensor: The transformed tensor after swapping the axes. The shape of the returned tensor is (batch_size, num_attention_heads, seq_length, -1). |
Note
- The method assumes that the input tensor has a rank of at least 3.
- The parameter 'self.num_attention_heads' is expected to be a positive integer representing the number of attention heads.
- The last dimension in the returned tensor is determined by the shape of the input tensor.
Example
>>> attention = DisentangledSelfAttention()
>>> input_tensor = torch.randn(32, 10, 512)
>>> output_tensor = attention.swapaxes_for_scores(input_tensor)
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.DropoutContext
¶
Represents a context for managing dropout operations within a neural network.
This class defines a context for managing dropout operations, including setting the dropout rate, mask, scaling factor, and reusing masks across iterations. It is designed to be used within a neural network framework to control dropout behavior during training.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dropout |
The dropout rate to be applied.
TYPE:
|
mask |
The mask array used for applying dropout.
TYPE:
|
scale |
The scaling factor applied to the output.
TYPE:
|
reuse_mask |
Flag indicating whether to reuse the mask across iterations.
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
mindnlp.transformers.models.deberta.modeling_deberta.DropoutContext.__init__()
¶
Initialize a DropoutContext object.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DropoutContext class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout
¶
Bases: Module
Optimized dropout module for stabilizing the training
| PARAMETER | DESCRIPTION |
|---|---|
drop_prob |
the dropout probabilities
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 465 466 467 468 469 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout.__init__(drop_prob)
¶
Initialize the StableDropout object.
This method is called when a new instance of the StableDropout class is created. It initializes the object with the given drop probability and sets the count and context_stack attributes to their initial values.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the StableDropout class.
TYPE:
|
drop_prob |
The probability of dropping a value during dropout. Must be between 0 and 1 (inclusive).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout.clear_context()
¶
Clears the context of the StableDropout class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the StableDropout class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout.forward(x)
¶
Call the module
| PARAMETER | DESCRIPTION |
|---|---|
x |
The input tensor to apply dropout
TYPE:
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
401 402 403 404 405 406 407 408 409 410 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout.get_context()
¶
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the StableDropout class invoking the method. This parameter is required for accessing the instance attributes and methods.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
mindnlp.transformers.models.deberta.modeling_deberta.StableDropout.init_context(reuse_mask=True, scale=1)
¶
Initializes the context stack for the StableDropout class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the StableDropout class.
|
reuse_mask |
Indicates whether the dropout mask should be reused or not. Defaults to True.
TYPE:
|
scale |
The scaling factor applied to the dropout mask. Defaults to 1.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
mindnlp.transformers.models.deberta.modeling_deberta.XDropout
¶
Bases: Module
Optimized dropout function to save computation and memory by using mask operation instead of multiplication.
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.XDropout.__init__(local_ctx)
¶
Initialize a new instance of the XDropout class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the XDropout class.
TYPE:
|
local_ctx |
The local context for the XDropout instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
mindnlp.transformers.models.deberta.modeling_deberta.XDropout.forward(inputs)
¶
Constructs a masked and scaled version of the input tensor using the XDropout method.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the XDropout class.
TYPE:
|
inputs |
The input tensor to be masked and scaled.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
mindnlp.transformers.models.deberta.modeling_deberta.XSoftmax
¶
Bases: Module
Masked Softmax which is optimized for saving memory
| PARAMETER | DESCRIPTION |
|---|---|
input |
The input tensor that will apply softmax.
TYPE:
|
mask |
The mask matrix where 0 indicate that element will be ignored in the softmax calculation.
TYPE:
|
dim |
The dimension that will apply softmax
TYPE:
|
Example
>>> import torch
>>> from transformers.models.deberta.modeling_deberta import XSoftmax
...
>>> # Make a tensor
>>> x = torch.randn([4, 20, 100])
...
>>> # Create a mask
>>> mask = (x > 0).int()
...
>>> # Specify the dimension to apply softmax
>>> dim = -1
...
>>> y = XSoftmax.apply(x, mask, dim)
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
mindnlp.transformers.models.deberta.modeling_deberta.XSoftmax.__init__(dim=-1)
¶
Initializes an instance of the XSoftmax class.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the XSoftmax class.
|
dim |
The dimension along which the softmax operation is performed. Default is -1. The value of dim must be a non-negative integer or -1. If -1, the operation is performed along the last dimension of the input tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
mindnlp.transformers.models.deberta.modeling_deberta.XSoftmax.brop(input, mask, output, grad_output)
¶
This method, 'brop', is a member of the 'XSoftmax' class and performs a specific operation on the given input, mask, output, and grad_output parameters.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the 'XSoftmax' class.
|
input |
The input parameter of type
|
mask |
The mask parameter of type
|
output |
The output parameter of type
|
grad_output |
The grad_output parameter of type
|
| RETURNS | DESCRIPTION |
|---|---|
dx
|
A value of type |
|
None. |
| RAISES | DESCRIPTION |
|---|---|
<Exception1>
|
|
<Exception2>
|
|
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.XSoftmax.forward(input, mask)
¶
Constructs a softmax operation with masking for a given input tensor.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the XSoftmax class.
TYPE:
|
input |
The input tensor on which the softmax operation is performed.
TYPE:
|
mask |
A tensor representing the mask used for masking certain elements in the input tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method modifies the input tensor in-place and does not return any value. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the input tensor or the mask tensor is not of the expected type. |
ValueError
|
If the dimensions of the input tensor and the mask tensor do not match. |
RuntimeError
|
If an error occurs during the softmax operation or masking process. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
mindnlp.transformers.models.deberta.modeling_deberta.build_relative_position(query_size, key_size)
¶
Build relative position according to the query and key
We assume the absolute position of query \(P_q\) is range from (0, query_size) and the absolute position of key \(P_k\) is range from (0, key_size), The relative positions from query to key is \(R_{q \rightarrow k} = P_q - P_k\)
| PARAMETER | DESCRIPTION |
|---|---|
query_size |
the length of query
TYPE:
|
key_size |
the length of key
TYPE:
|
Return
torch.LongTensor: A tensor with shape [1, query_size, key_size]
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | |
mindnlp.transformers.models.deberta.modeling_deberta.c2p_dynamic_expand(c2p_pos, query_layer, relative_pos)
¶
Converts the input Cartesian coordinates to polar coordinates by dynamically expanding the Cartesian coordinates based on the shape of the query layer and relative positions.
| PARAMETER | DESCRIPTION |
|---|---|
c2p_pos |
The input Cartesian coordinates. Expected shape is [batch_size, height, width, num_features].
TYPE:
|
query_layer |
The query layer. Used to determine the shape of the expanded Cartesian coordinates. Expected shape is [batch_size, query_height, query_width, query_features].
TYPE:
|
relative_pos |
The relative positions. Used to determine the shape of the expanded Cartesian coordinates. Expected shape is [relative_features].
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 | |
mindnlp.transformers.models.deberta.modeling_deberta.get_mask(input, local_context)
¶
| PARAMETER | DESCRIPTION |
|---|---|
input |
The input tensor for which the dropout mask is generated.
TYPE:
|
local_context |
The local context containing information about dropout parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The function returns the generated dropout mask, or None if no mask is generated. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the local_context is not of type DropoutContext. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
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 | |
mindnlp.transformers.models.deberta.modeling_deberta.p2c_dynamic_expand(c2p_pos, query_layer, key_layer)
¶
Transforms the given c2p_pos tensor into a dynamic expanded tensor.
| PARAMETER | DESCRIPTION |
|---|---|
c2p_pos |
The tensor representing the c2p position.
TYPE:
|
query_layer |
The tensor representing the query layer.
TYPE:
|
key_layer |
The tensor representing the key layer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
torch.Tensor: The dynamic expanded tensor obtained by expanding the c2p_pos tensor. The shape of the returned tensor is [query_layer.shape[0], query_layer.shape[1], key_layer.shape[-2], key_layer.shape[-2]]. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 | |
mindnlp.transformers.models.deberta.modeling_deberta.pos_dynamic_expand(pos_index, p2c_att, key_layer)
¶
| PARAMETER | DESCRIPTION |
|---|---|
pos_index |
A tensor representing positional indices.
TYPE:
|
p2c_att |
A tensor containing attention weights.
TYPE:
|
key_layer |
A tensor representing key layer values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/modeling_deberta.py
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 | |
mindnlp.transformers.models.deberta.configuration_deberta
¶
DeBERTa model configuration
mindnlp.transformers.models.deberta.configuration_deberta.DebertaConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [DebertaModel] or a [TFDebertaModel]. It is
used to instantiate a DeBERTa model according to the specified arguments, defining the model architecture.
Instantiating a configuration with the defaults will yield a similar configuration to that of the DeBERTa
microsoft/deberta-base architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_size |
Vocabulary size of the DeBERTa model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size |
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob |
The dropout ratio for the attention probabilities.
TYPE:
|
max_position_embeddings |
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
type_vocab_size |
The vocabulary size of the
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
relative_attention |
Whether use relative position encoding.
TYPE:
|
max_relative_positions |
The range of relative positions
TYPE:
|
pad_token_id |
The value used to pad input_ids.
TYPE:
|
position_biased_input |
Whether add absolute position embedding to content embedding.
TYPE:
|
pos_att_type |
The type of relative position attention, it can be a combination of
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
Example
>>> from transformers import DebertaConfig, DebertaModel
...
>>> # Initializing a DeBERTa microsoft/deberta-base style configuration
>>> configuration = DebertaConfig()
...
>>> # Initializing a model (with random weights) from the microsoft/deberta-base style configuration
>>> model = DebertaModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/deberta/configuration_deberta.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
mindnlp.transformers.models.deberta.configuration_deberta.DebertaConfig.__init__(vocab_size=50265, hidden_size=768, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, hidden_act='gelu', hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position_embeddings=512, type_vocab_size=0, initializer_range=0.02, layer_norm_eps=1e-07, relative_attention=False, max_relative_positions=-1, pad_token_id=0, position_biased_input=True, pos_att_type=None, pooler_dropout=0, pooler_hidden_act='gelu', **kwargs)
¶
Initialize a DebertaConfig object.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The object instance.
|
vocab_size |
The size of the vocabulary. Default is 50265.
TYPE:
|
hidden_size |
The size of the hidden layers. Default is 768.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Default is 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Default is 12.
TYPE:
|
intermediate_size |
The size of the intermediate layers. Default is 3072.
TYPE:
|
hidden_act |
The activation function for hidden layers. Default is 'gelu'.
TYPE:
|
hidden_dropout_prob |
The dropout probability for hidden layers. Default is 0.1.
TYPE:
|
attention_probs_dropout_prob |
The dropout probability for attention probabilities. Default is 0.1.
TYPE:
|
max_position_embeddings |
The maximum position embeddings. Default is 512.
TYPE:
|
type_vocab_size |
The size of the type vocabulary. Default is 0.
TYPE:
|
initializer_range |
The range for parameter initialization. Default is 0.02.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization. Default is 1e-07.
TYPE:
|
relative_attention |
Whether to use relative attention. Default is False.
TYPE:
|
max_relative_positions |
The maximum relative positions for relative attention. Default is -1.
TYPE:
|
pad_token_id |
The token ID for padding. Default is 0.
TYPE:
|
position_biased_input |
Whether to use position-biased input. Default is True.
TYPE:
|
pos_att_type |
The type of positional attention. Default is None.
TYPE:
|
pooler_dropout |
The dropout probability for the pooler layer. Default is 0.
TYPE:
|
pooler_hidden_act |
The activation function for the pooler layer. Default is 'gelu'.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/configuration_deberta.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
mindnlp.transformers.models.deberta.tokenization_deberta
¶
Tokenization class for model DeBERTa.
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer
¶
Bases: PreTrainedTokenizer
Construct a DeBERTa tokenizer. Based on byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import DebertaTokenizer
...
>>> tokenizer = DebertaTokenizer.from_pretrained("microsoft/deberta-base")
>>> tokenizer("Hello world")["input_ids"]
[1, 31414, 232, 2]
>>> tokenizer(" Hello world")["input_ids"]
[1, 20920, 232, 2]
You can get around that behavior by passing add_prefix_space=True when instantiating this tokenizer or when you
call it on some text, but since the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True, this tokenizer will add a space before each word (even the first one).
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
merges_file |
Path to the merges file.
TYPE:
|
errors |
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
TYPE:
|
bos_token |
The beginning of sequence token.
TYPE:
|
eos_token |
The end of sequence token.
TYPE:
|
sep_token |
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for sequence classification or for a text and a question for question answering. It is also used as the last token of a sequence built with special tokens.
TYPE:
|
cls_token |
The classifier token which is used when doing sequence classification (classification of the whole sequence instead of per-token classification). It is the first token of the sequence when built with special tokens.
TYPE:
|
unk_token |
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
pad_token |
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
mask_token |
The token used for masking values. This is the token used when training this model with masked language modeling. This is the token which the model will try to predict.
TYPE:
|
add_prefix_space |
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (Deberta tokenizer detect beginning of words by the preceding space).
TYPE:
|
add_bos_token |
Whether or not to add an initial <|endoftext|> to the input. This allows to treat the leading word just as any other word.
TYPE:
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 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 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 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.vocab_size
property
¶
Returns the size of the vocabulary used by the DebertaTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaTokenizer class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of unique tokens in the vocabulary. |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.__init__(vocab_file, merges_file, errors='replace', bos_token='[CLS]', eos_token='[SEP]', sep_token='[SEP]', cls_token='[CLS]', unk_token='[UNK]', pad_token='[PAD]', mask_token='[MASK]', add_prefix_space=False, add_bos_token=False, **kwargs)
¶
Initialize a DebertaTokenizer object.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the class.
|
vocab_file |
The path to the vocabulary file.
TYPE:
|
merges_file |
The path to the merges file.
TYPE:
|
errors |
The error handling strategy. Default is 'replace'.
TYPE:
|
bos_token |
Beginning of sentence token. Default is '[CLS]'.
TYPE:
|
eos_token |
End of sentence token. Default is '[SEP]'.
TYPE:
|
sep_token |
Separator token. Default is '[SEP]'.
TYPE:
|
cls_token |
Classification token. Default is '[CLS]'.
TYPE:
|
unk_token |
Token for unknown words. Default is '[UNK]'.
TYPE:
|
pad_token |
Token for padding. Default is '[PAD]'.
TYPE:
|
mask_token |
Token for masking. Default is '[MASK]'.
TYPE:
|
add_prefix_space |
Whether to add prefix space. Default is False.
TYPE:
|
add_bos_token |
Whether to add beginning of sentence token. Default is False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
IOError
|
If there is an issue with opening the vocab_file or merges_file. |
Exception
|
Any other unexpected error that may occur during initialization. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.bpe(token)
¶
Performs Byte Pair Encoding (BPE) on the given token.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaTokenizer class.
TYPE:
|
token |
The token to be encoded using BPE.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The encoded token after applying BPE. |
This method applies BPE to the given token by iteratively replacing the most frequent pairs of characters in the token with a single character. If the token is already present in the cache, the cached value is returned. Otherwise, the token is converted to a tuple of characters. Pairs of characters in the tuple are obtained using the 'get_pairs' function. If no pairs are found, the original token is returned.
The method then enters a loop where it selects the most frequent pair from the pairs obtained. If the selected pair is not present in the 'bpe_ranks' dictionary, the loop is terminated. Otherwise, the first and second characters of the pair are extracted.
A new word list, 'new_word', is created to store the modified characters of the token. The method iterates over the characters of the token and checks if the current character matches the first character of the selected pair. If it does, and the next character is the second character of the pair, the pair is replaced with a single character by appending it to 'new_word' and incrementing the index by 2. Otherwise, the current character is appended to 'new_word' and the index is incremented by 1.
The modified 'new_word' is converted back to a tuple and assigned to 'word'. If the length of 'word' becomes 1, indicating that the BPE process is complete, the loop is terminated. Otherwise, new pairs are obtained from 'word' and the process is repeated until 'word' is of length 1.
Finally, 'word' is converted to a string by joining the characters with spaces. The encoded token is stored in the cache for future use and returned.
Note
- This method assumes the presence of the 'get_pairs' function and the 'bpe_ranks' dictionary.
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
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 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 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A DeBERTa sequence has the following format:
- single sequence: [CLS] X [SEP]
- pair of sequences: [CLS] A [SEP] B [SEP]
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0 |
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
482 483 484 485 486 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A DeBERTa sequence pair mask has the following format:
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If token_ids_1 is None, this method only returns the first portion of the mask (0s).
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0 |
List of IDs.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
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 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.get_special_tokens_mask(token_ids_0, token_ids_1=None, already_has_special_tokens=False)
¶
Retrieves sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer prepare_for_model or encode_plus methods.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0 |
List of IDs.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
already_has_special_tokens |
Whether or not the token list is already formatted with special tokens for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
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 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.get_vocab()
¶
Returns the vocabulary of the DebertaTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaTokenizer class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The vocabulary of the tokenizer, which is a dictionary containing the encoder mappings of the tokenizer's tokens and any added tokens. |
| RAISES | DESCRIPTION |
|---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.prepare_for_tokenization(text, is_split_into_words=False, **kwargs)
¶
This method prepares the input text for tokenization by potentially adding a prefix space based on the provided parameters.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaTokenizer class.
|
text |
The input text to be tokenized.
TYPE:
|
is_split_into_words |
A flag indicating whether the text is already split into words. Default is False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method modifies the input text in place and does not return any value. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
mindnlp.transformers.models.deberta.tokenization_deberta.DebertaTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to files in the specified directory with an optional filename prefix.
| PARAMETER | DESCRIPTION |
|---|---|
self |
The instance of the DebertaTokenizer class.
TYPE:
|
save_directory |
The directory path where the vocabulary files will be saved.
TYPE:
|
filename_prefix |
An optional prefix to be added to the filenames. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths to the saved vocabulary file and merge file. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the specified save_directory does not exist. |
IOError
|
If there is an issue encountered while writing to the vocabulary or merge files. |
RuntimeError
|
If the BPE merge indices are not consecutive, indicating a potential corruption in the tokenizer. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | |
mindnlp.transformers.models.deberta.tokenization_deberta.bytes_to_unicode()
¶
Returns list of utf-8 byte and a mapping to unicode strings. We specifically avoids mapping to whitespace/control characters the bpe code barfs on.
The reversible bpe codes work on unicode strings. This means you need a large # of unicode characters in your vocab if you want to avoid UNKs. When you're at something like a 10B token dataset you end up needing around 5K for decent coverage. This is a significant percentage of your normal, say, 32K bpe vocab. To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
mindnlp.transformers.models.deberta.tokenization_deberta.get_pairs(word)
¶
Return set of symbol pairs in a word.
Word is represented as tuple of symbols (symbols being variable-length strings).
Source code in mindnlp/transformers/models/deberta/tokenization_deberta.py
96 97 98 99 100 101 102 103 104 105 106 107 | |
mindnlp.transformers.models.deberta.tokenization_deberta_fast
¶
Fast Tokenization class for model DeBERTa.
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" DeBERTa tokenizer (backed by HuggingFace's tokenizers library). Based on byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import DebertaTokenizerFast
...
>>> tokenizer = DebertaTokenizerFast.from_pretrained("microsoft/deberta-base")
>>> tokenizer("Hello world")["input_ids"]
[1, 31414, 232, 2]
>>> tokenizer(" Hello world")["input_ids"]
[1, 20920, 232, 2]
You can get around that behavior by passing add_prefix_space=True when instantiating this tokenizer, but since
the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True, this tokenizer needs to be instantiated with add_prefix_space=True.
This tokenizer inherits from [PreTrainedTokenizerFast] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
merges_file |
Path to the merges file.
TYPE:
|
tokenizer_file |
The path to a tokenizer file to use instead of the vocab file.
TYPE:
|
errors |
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
TYPE:
|
bos_token |
The beginning of sequence token.
TYPE:
|
eos_token |
The end of sequence token.
TYPE:
|
sep_token |
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for sequence classification or for a text and a question for question answering. It is also used as the last token of a sequence built with special tokens.
TYPE:
|
cls_token |
The classifier token which is used when doing sequence classification (classification of the whole sequence instead of per-token classification). It is the first token of the sequence when built with special tokens.
TYPE:
|
unk_token |
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this token instead.
TYPE:
|
pad_token |
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
mask_token |
The token used for masking values. This is the token used when training this model with masked language modeling. This is the token which the model will try to predict.
TYPE:
|
add_prefix_space |
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (Deberta tokenizer detect beginning of words by the preceding space).
TYPE:
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta_fast.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast.mask_token: str
property
writable
¶
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Deberta tokenizer has a special mask token to be used in the fill-mask pipeline. The mask token will greedily comprise the space before the [MASK].
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast.__init__(vocab_file=None, merges_file=None, tokenizer_file=None, errors='replace', bos_token='[CLS]', eos_token='[SEP]', sep_token='[SEP]', cls_token='[CLS]', unk_token='[UNK]', pad_token='[PAD]', mask_token='[MASK]', add_prefix_space=False, **kwargs)
¶
Initialize a DebertaTokenizerFast object.
| PARAMETER | DESCRIPTION |
|---|---|
self |
An instance of the DebertaTokenizerFast class.
TYPE:
|
vocab_file |
The path to the vocabulary file. Defaults to None.
TYPE:
|
merges_file |
The path to the merges file. Defaults to None.
TYPE:
|
tokenizer_file |
The path to the tokenizer file. Defaults to None.
TYPE:
|
errors |
Specifies how to handle encoding and decoding errors. Defaults to 'replace'.
TYPE:
|
bos_token |
The beginning of sentence token. Defaults to '[CLS]'.
TYPE:
|
eos_token |
The end of sentence token. Defaults to '[SEP]'.
TYPE:
|
sep_token |
The separator token. Defaults to '[SEP]'.
TYPE:
|
cls_token |
The classification token. Defaults to '[CLS]'.
TYPE:
|
unk_token |
The unknown token. Defaults to '[UNK]'.
TYPE:
|
pad_token |
The padding token. Defaults to '[PAD]'.
TYPE:
|
mask_token |
The mask token. Defaults to '[MASK]'.
TYPE:
|
add_prefix_space |
Whether to add a space before each token. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta_fast.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A DeBERTa sequence has the following format:
- single sequence: [CLS] X [SEP]
- pair of sequences: [CLS] A [SEP] B [SEP]
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0 |
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta_fast.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A DeBERTa sequence pair mask has the following format:
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If token_ids_1 is None, this method only returns the first portion of the mask (0s).
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0 |
List of IDs.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/deberta/tokenization_deberta_fast.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
mindnlp.transformers.models.deberta.tokenization_deberta_fast.DebertaTokenizerFast.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary files of the tokenizer model to a specified directory.
| PARAMETER | DESCRIPTION |
|---|---|
self |
Instance of the DebertaTokenizerFast class.
|
save_directory |
The directory path where the vocabulary files will be saved.
TYPE:
|
filename_prefix |
An optional prefix to be added to the saved filenames. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths of the saved vocabulary files. |
Source code in mindnlp/transformers/models/deberta/tokenization_deberta_fast.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |