tinybert
mindnlp.transformers.models.tinybert.tinybert
¶
TinyBert Models
mindnlp.transformers.models.tinybert.tinybert.TinyBertAttention
¶
Bases: Module
TinyBertAttention
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertAttention.__init__(config)
¶
Initializes a new instance of the TinyBertAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself.
TYPE:
|
config |
An object containing configuration parameters for the TinyBertAttention class. This parameter is required for configuring the attention mechanism.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertAttention.forward(input_tensor, attention_mask)
¶
Constructs the attention output and layer attention for the TinyBertAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the TinyBertAttention class.
TYPE:
|
input_tensor |
The input tensor for the attention calculation.
TYPE:
|
attention_mask |
The attention mask tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the attention output tensor and the layer attention tensor. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEmbeddings
¶
Bases: Module
Construct the embeddings from word, position and token_type embeddings.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
29 30 31 32 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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEmbeddings.__init__(config)
¶
init BertEmbeddings
Source code in mindnlp/transformers/models/tinybert/tinybert.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEmbeddings.forward(input_ids, token_type_ids=None)
¶
Construct the embeddings from word, position and token_type embeddings.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEncoder
¶
Bases: Module
TinyBertEncoder
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEncoder.__init__(config)
¶
Initializes a TinyBertEncoder object with the given configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertEncoder class.
TYPE:
|
config |
The configuration object containing parameters for the TinyBertEncoder. This object must have the following attributes:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertEncoder.forward(hidden_states, attention_mask)
¶
Method 'forward' in the class 'TinyBertEncoder'.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the 'TinyBertEncoder' class.
TYPE:
|
hidden_states |
The hidden states to be processed by the encoder.
TYPE:
|
attention_mask |
The attention mask to apply during encoding.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple
|
Two lists containing the encoder layers and their respective attentions.
|
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertFitForPreTraining
¶
Bases: TinyBertPreTrainedModel
TinyBertForPreTraining with fit dense
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertFitForPreTraining.__init__(config, fit_size=768)
¶
Initialize a TinyBertFitForPreTraining object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object for the model.
TYPE:
|
fit_size |
The size to fit the dense layer to. Default is 768.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertFitForPreTraining.forward(input_ids, token_type_ids=None, attention_mask=None)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForMaskedLM
¶
Bases: TinyBertPreTrainedModel
BERT model with the masked language modeling head. This module comprises the BERT model followed by the masked language modeling head.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForMaskedLM.__init__(config)
¶
Initializes a new instance of the TinyBertForMaskedLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
An instance of the configuration class, containing various hyperparameters and settings for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForMaskedLM.forward(input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None, output_att=False)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForNextSentencePrediction
¶
Bases: TinyBertPreTrainedModel
BERT model with next sentence prediction head. This module comprises the BERT model followed by the next sentence classification head.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForNextSentencePrediction.__init__(config)
¶
Initializes the TinyBertForNextSentencePrediction class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the TinyBertForNextSentencePrediction class.
|
config |
A configuration object containing various hyperparameters and settings for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForNextSentencePrediction.forward(input_ids, token_type_ids=None, attention_mask=None, next_sentence_label=None)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForPreTraining
¶
Bases: TinyBertPreTrainedModel
BERT model with pre-training heads. This module comprises the BERT model followed by the two pre-training heads:
- the masked language modeling head, and
- the next sentence classification head.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForPreTraining.__init__(config)
¶
Initialize the TinyBertForPreTraining class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertForPreTraining class.
TYPE:
|
config |
The configuration object containing parameters for model initialization.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForPreTraining.forward(input_ids, token_type_ids=None, attention_mask=None, masked_lm_labels=None, next_sentence_label=None)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSentencePairClassification
¶
Bases: TinyBertPreTrainedModel
TinyBertForSentencePairClassification
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSentencePairClassification.__init__(config, num_labels)
¶
Initializes a new instance of the TinyBertForSentencePairClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A configuration object containing various settings and hyperparameters for the model. It is of type 'Config'.
|
num_labels |
An integer representing the number of labels for sentence pair classification.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
AttributeError
|
If the 'config' parameter is missing required attributes. |
ValueError
|
If the 'num_labels' parameter is not a positive integer. |
TypeError
|
If the 'config' parameter is not of type 'Config'. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSentencePairClassification.forward(a_input_ids, b_input_ids, a_token_type_ids=None, b_token_type_ids=None, a_attention_mask=None, b_attention_mask=None, labels=None)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSequenceClassification
¶
Bases: TinyBertPreTrainedModel
TinyBertForSequenceClassification
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSequenceClassification.__init__(config, num_labels, fit_size=768)
¶
Initializes a TinyBertForSequenceClassification instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing model hyperparameters.
TYPE:
|
num_labels |
The number of labels for classification.
TYPE:
|
fit_size |
The size of the hidden layer for fitting. Default is 768.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided 'config' is not of the expected type. |
ValueError
|
If 'num_labels' is not a positive integer. |
ValueError
|
If 'fit_size' is not a positive integer. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertForSequenceClassification.forward(input_ids, token_type_ids=None, attention_mask=None, is_student=False)
¶
forward
Source code in mindnlp/transformers/models/tinybert/tinybert.py
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertIntermediate
¶
Bases: Module
TinyBertIntermediate
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertIntermediate.__init__(config, intermediate_size=-1)
¶
This method initializes a TinyBertIntermediate instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertIntermediate class.
|
config |
An object that holds the configuration settings for the TinyBertIntermediate model.
|
intermediate_size |
An optional integer representing the intermediate size.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided 'config' parameter is not of type 'object'. |
ValueError
|
If the 'intermediate_size' parameter is provided and is a negative integer. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertIntermediate.forward(hidden_states)
¶
This method forwards the intermediate layer of a TinyBERT model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertIntermediate class.
TYPE:
|
hidden_states |
The input hidden states to be processed by the method. Should be a tensor representing the hidden states of the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
hidden_states
|
The processed hidden states are returned as the output of the method. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLMPredictionHead
¶
Bases: Module
TinyBertLMPredictionHead
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLMPredictionHead.__init__(config, bert_model_embedding_weights)
¶
Initializes the TinyBertLMPredictionHead.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
A dictionary containing configuration parameters for the TinyBertPredictionHeadTransform.
|
bert_model_embedding_weights |
A tensor representing the weights of the BERT model's embedding layer.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the provided |
RuntimeError
|
If an error occurs during the initialization process. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLMPredictionHead.forward(hidden_states)
¶
Method to forward the prediction head for TinyBERT LM.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the TinyBertLMPredictionHead class.
TYPE:
|
hidden_states |
Hidden states obtained from the TinyBERT model. The tensor should have the shape [batch_size, sequence_length, hidden_size].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method modifies the hidden_states in place to forward the LM prediction head. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLayer
¶
Bases: Module
TinyBertLayer
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLayer.__init__(config)
¶
Initializes a new instance of the TinyBertLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
An instance of the configuration class that holds various hyperparameters and settings for the TinyBertLayer.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertLayer.forward(hidden_states, attention_mask)
¶
Constructs a TinyBertLayer by applying attention mechanism and generating layer output.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertLayer class.
TYPE:
|
hidden_states |
The input hidden states for the layer, typically a tensor of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask for the input hidden states, typically a tensor of shape (batch_size, 1, sequence_length, sequence_length) with 0s for padding tokens and 1s for non-padding tokens.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the layer output (typically a tensor of shape (batch_size, sequence_length, hidden_size)) and the attention scores (layer_att) generated during the attention computation. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the shape of the hidden_states or attention_mask is not compatible with the expected input shapes. |
TypeError
|
If the input data types are not compatible with the expected types. |
RuntimeError
|
If there is an issue during the computation of attention or output layers. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertModel
¶
Bases: TinyBertPreTrainedModel
TinyBERT model
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertModel.__init__(config)
¶
Initializes a new instance of the TinyBertModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertModel class.
|
config |
A dictionary containing configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the provided 'config' parameter is not a valid dictionary. |
TypeError
|
If any of the required components fail to initialize properly. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertModel.forward(input_ids, token_type_ids=None, attention_mask=None, output_all_encoded_layers=True, output_att=True)
¶
forward.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyMLMHead
¶
Bases: Module
TinyBertOnlyMLMHead
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyMLMHead.__init__(config, bert_model_embedding_weights)
¶
Initializes an instance of the TinyBertOnlyMLMHead class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
A configuration object containing the model's hyperparameters and settings. This parameter is of type 'config' and is required.
|
bert_model_embedding_weights |
The pre-trained BERT model's embedding weights. This parameter is of type 'Tensor' and is required.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyMLMHead.forward(sequence_output)
¶
This method forwards the prediction scores based on the provided sequence output for the TinyBertOnlyMLMHead class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertOnlyMLMHead class.
TYPE:
|
sequence_output |
The output tensor representing the sequence to be used for prediction scores calculation. It should be of type tensor and must contain the sequence information for prediction.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
prediction_scores
|
The prediction scores tensor calculated based on the provided sequence_output. It represents the scores for predicting the masked words in the input sequence.
TYPE:
|
Source code in mindnlp/transformers/models/tinybert/tinybert.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyNSPHead
¶
Bases: Module
TinyBertOnlyNSPHead
Source code in mindnlp/transformers/models/tinybert/tinybert.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyNSPHead.__init__(config)
¶
Initializes the TinyBertOnlyNSPHead class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration settings for the TinyBertOnlyNSPHead. It must have the attribute 'hidden_size' to specify the size of the hidden layer.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOnlyNSPHead.forward(pooled_output)
¶
Description
This method calculates the sequence relationship score using the provided pooled_output.
PARAMETER | DESCRIPTION |
---|---|
self |
(object) The instance of the class TinyBertOnlyNSPHead.
|
pooled_output |
(object) The pooled output from the TinyBERT model.
|
RETURNS | DESCRIPTION |
---|---|
seq_relationship_score
|
(object) The calculated sequence relationship score based on the provided pooled_output. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOutput
¶
Bases: Module
TinyBertOutput
Source code in mindnlp/transformers/models/tinybert/tinybert.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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOutput.__init__(config, intermediate_size=-1)
¶
Initializes an instance of the TinyBertOutput class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
A configuration object containing various parameters.
|
intermediate_size |
The size of the intermediate layer. Defaults to -1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertOutput.forward(hidden_states, input_tensor)
¶
Method 'forward' in the class 'TinyBertOutput'.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the 'TinyBertOutput' class.
TYPE:
|
hidden_states |
The hidden states to be processed.
TYPE:
|
input_tensor |
The input tensor to be combined with the hidden states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The transformation is applied to 'hidden_states' in-place. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPooler
¶
Bases: Module
TinyBertPooler
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPooler.__init__(config)
¶
Initialize the TinyBertPooler class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
An object containing configuration settings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPooler.forward(hidden_states)
¶
Constructs the TinyBertPooler by calculating the pooled output from the given hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the TinyBertPooler class.
TYPE:
|
hidden_states |
A list of hidden states from the TinyBERT model. Each hidden state is a tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
The pooled output tensor obtained after processing the hidden states through dense layers and activation function. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input hidden_states is not a list of tensors. |
ValueError
|
If the hidden_states list is empty or does not contain valid tensors. |
IndexError
|
If the hidden_states list does not have the required elements for pooling. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.__init__(config)
¶
Initializes a TinyBertPreTrainedModel instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertPreTrainedModel class.
|
config |
An instance of the TinyBertConfig class that holds the configuration settings for the model. It should be an instance of TinyBertConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method initializes the TinyBertPreTrainedModel instance with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the config parameter is not an instance of TinyBertConfig, a ValueError is raised with a message specifying the requirement for config to be an instance of TinyBertConfig. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.get_input_embeddings()
¶
Returns the model's input embeddings.
RETURNS | DESCRIPTION |
---|---|
Module
|
|
Source code in mindnlp/transformers/models/tinybert/tinybert.py
858 859 860 861 862 863 864 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.get_position_embeddings()
¶
get the model position embeddings if necessary
Source code in mindnlp/transformers/models/tinybert/tinybert.py
876 877 878 879 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.init_model_weights(module)
¶
Initialize the weights.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.post_init()
¶
post init.
Source code in mindnlp/transformers/models/tinybert/tinybert.py
883 884 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.resize_position_embeddings(new_num_position_embeddings)
¶
resize the model position embeddings if necessary
Source code in mindnlp/transformers/models/tinybert/tinybert.py
872 873 874 875 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.save(save_dir)
¶
save pretrain model
Source code in mindnlp/transformers/models/tinybert/tinybert.py
880 881 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainedModel.set_input_embeddings(new_embeddings)
¶
Set model's input embeddings.
PARAMETER | DESCRIPTION |
---|---|
value |
|
Source code in mindnlp/transformers/models/tinybert/tinybert.py
865 866 867 868 869 870 871 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainingHeads
¶
Bases: Module
TinyBertPreTrainingHeads
Source code in mindnlp/transformers/models/tinybert/tinybert.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainingHeads.__init__(config, bert_model_embedding_weights)
¶
Initializes the TinyBertPreTrainingHeads class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
Configuration object containing settings for the model.
TYPE:
|
bert_model_embedding_weights |
The weights for the BERT model's embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the config parameter is not provided or is of incorrect type. |
ValueError
|
If the bert_model_embedding_weights parameter is not provided or is not a numpy array. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPreTrainingHeads.forward(sequence_output, pooled_output)
¶
This method forwards prediction scores and sequence relationship scores for pre-training heads in TinyBert.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertPreTrainingHeads class.
TYPE:
|
sequence_output |
The output sequence from the TinyBert model, representing the contextualized representations of tokens.
TYPE:
|
pooled_output |
The output at the pooled layer of the TinyBert model, representing the aggregated representation of the entire input sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the prediction scores and sequence relationship score.
|
Source code in mindnlp/transformers/models/tinybert/tinybert.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPredictionHeadTransform
¶
Bases: Module
TinyBertPredictionHeadTransform
Source code in mindnlp/transformers/models/tinybert/tinybert.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPredictionHeadTransform.__init__(config)
¶
Initializes a TinyBertPredictionHeadTransform object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
An object containing configuration parameters for the TinyBertPredictionHeadTransform.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config.hidden_act is not a string or a function. |
ValueError
|
If the config.hidden_act string does not correspond to a valid key in ACT2FN dictionary. |
ValueError
|
If the config.hidden_size is not an integer value. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertPredictionHeadTransform.forward(hidden_states)
¶
Constructs the TinyBertPredictionHeadTransform.
This method takes in the hidden states and performs a series of transformations to predict the next token in the sequence.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the TinyBertPredictionHeadTransform class. |
hidden_states |
The hidden states obtained from the previous layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfAttention
¶
Bases: Module
TinyBertSelfAttention
Source code in mindnlp/transformers/models/tinybert/tinybert.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 151 152 153 154 155 156 157 158 159 160 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfAttention.__init__(config)
¶
Initializes an instance of the TinyBertSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of type 'config' containing the configuration settings for the self-attention mechanism.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the hidden size specified in the configuration is not a multiple of the number of attention heads. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfAttention.forward(hidden_states, attention_mask)
¶
This method forwards the self-attention mechanism for the TinyBERT model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertSelfAttention class.
TYPE:
|
hidden_states |
The input hidden states tensor representing the input sequence.
TYPE:
|
attention_mask |
The attention mask tensor to mask certain positions in the input sequence. It should have the same shape as the input sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tensor
|
The context layer tensor after applying the self-attention mechanism. |
tensor
|
The attention scores tensor generated during the self-attention computation. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dimensions of the input tensors are incompatible for matrix multiplication. |
RuntimeError
|
If an error occurs during the softmax computation. |
AttributeError
|
If the required attributes are missing in the class instance. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfAttention.transpose_for_scores(x)
¶
transpose_for_scores
Source code in mindnlp/transformers/models/tinybert/tinybert.py
104 105 106 107 108 109 110 111 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfOutput
¶
Bases: Module
TinyBertSelfOutput
Source code in mindnlp/transformers/models/tinybert/tinybert.py
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 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfOutput.__init__(config)
¶
Initialize the TinyBertSelfOutput class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TinyBertSelfOutput class.
TYPE:
|
config |
An object containing configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration parameters are missing or incorrect. |
TypeError
|
If the provided configuration is not of the expected type. |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
mindnlp.transformers.models.tinybert.tinybert.TinyBertSelfOutput.forward(hidden_states, input_tensor)
¶
Constructs the output of the TinyBertSelf layer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the TinyBertSelfOutput class.
TYPE:
|
hidden_states |
A tensor representing the hidden states. The shape of the tensor is (batch_size, sequence_length, hidden_size). It contains the input hidden states to be processed.
TYPE:
|
input_tensor |
A tensor representing the input tensor. The shape of the tensor is (batch_size, sequence_length, hidden_size). It serves as the residual connection for the hidden states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: A tensor representing the output of the TinyBertSelf layer. The shape of the tensor is (batch_size, sequence_length, hidden_size). |
Source code in mindnlp/transformers/models/tinybert/tinybert.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
mindnlp.transformers.models.tinybert.tinybert_config
¶
TinyBert Models config
mindnlp.transformers.models.tinybert.tinybert_config.TinyBertConfig
¶
Bases: PretrainedConfig
Configuration class to store the configuration of a BertModel
.
PARAMETER | DESCRIPTION |
---|---|
vocab_size_or_config_json_file |
Vocabulary size of
|
hidden_size |
Size of the encoder layers and the pooler layer.
DEFAULT:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
DEFAULT:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
DEFAULT:
|
intermediate_size |
The size of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
DEFAULT:
|
hidden_act |
The non-linear activation function (function or string) in the encoder and pooler. If string, "gelu", "relu" and "swish" are supported.
DEFAULT:
|
hidden_dropout_prob |
The dropout probabilitiy for all fully connected layers in the embeddings, encoder, and pooler.
DEFAULT:
|
attention_probs_dropout_prob |
The dropout ratio for the attention probabilities.
DEFAULT:
|
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).
DEFAULT:
|
type_vocab_size |
The vocabulary size of the
DEFAULT:
|
initializer_range |
The sttdev of the truncated_normal_initializer for initializing all weight matrices.
DEFAULT:
|
Source code in mindnlp/transformers/models/tinybert/tinybert_config.py
24 25 26 27 28 29 30 31 32 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 |
|
mindnlp.transformers.models.tinybert.tinybert_config.TinyBertConfig.__init__(vocab_size=21128, 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=2, initializer_range=0.02, pre_trained='', training='', **kwargs)
¶
Initializes a new instance of the TinyBertConfig class.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
The size of the vocabulary. Defaults to 21128.
TYPE:
|
hidden_size |
The size of the hidden layers. Defaults to 768.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 12.
TYPE:
|
intermediate_size |
The size of the intermediate layer. Defaults to 3072.
TYPE:
|
hidden_act |
The activation function for the hidden layers. Defaults to 'gelu'.
TYPE:
|
hidden_dropout_prob |
The dropout probability for the hidden layers. Defaults to 0.1.
TYPE:
|
attention_probs_dropout_prob |
The dropout probability for the attention probabilities. Defaults to 0.1.
TYPE:
|
max_position_embeddings |
The maximum number of tokens in a sequence. Defaults to 512.
TYPE:
|
type_vocab_size |
The size of the type vocabulary. Defaults to 2.
TYPE:
|
initializer_range |
The range of the initializer. Defaults to 0.02.
TYPE:
|
pre_trained |
The path to a pre-trained model. Defaults to ''.
TYPE:
|
training |
The training option. Defaults to ''.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/tinybert/tinybert_config.py
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 |
|