mpnet
mindnlp.transformers.models.mpnet.configuration_mpnet
¶
MPNet model configuration
mindnlp.transformers.models.mpnet.configuration_mpnet.MPNetConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [MPNetModel
] or a [TFMPNetModel
]. It is used to
instantiate a MPNet 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 MPNet
microsoft/mpnet-base architecture.
```
Source code in mindnlp/transformers/models/mpnet/configuration_mpnet.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 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 |
|
mindnlp.transformers.models.mpnet.configuration_mpnet.MPNetConfig.__init__(vocab_size=30527, 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, initializer_range=0.02, layer_norm_eps=1e-12, relative_attention_num_buckets=32, pad_token_id=1, bos_token_id=0, eos_token_id=2, **kwargs)
¶
Initializes a new instance of the MPNetConfig class.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
The size of the vocabulary. Defaults to 30527.
TYPE:
|
hidden_size |
The size of the hidden states. 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 in the feedforward network. 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 positional embeddings. Defaults to 512.
TYPE:
|
initializer_range |
The range for the random weight initialization. Defaults to 0.02.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization. Defaults to 1e-12.
TYPE:
|
relative_attention_num_buckets |
The number of buckets for relative attention. Defaults to 32.
TYPE:
|
pad_token_id |
The token ID for padding. Defaults to 1.
TYPE:
|
bos_token_id |
The token ID for the beginning of sequence. Defaults to 0.
TYPE:
|
eos_token_id |
The token ID for the end of sequence. Defaults to 2.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/configuration_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet
¶
MindSpore MPNet model.
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetAttention
¶
Bases: Module
Multi-head self-attention mechanism for MPNet.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetAttention.__init__(config)
¶
Initializes an instance of the MPNetAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetAttention class.
|
config |
A configuration object containing the settings for the MPNetAttention.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetAttention.forward(hidden_states, attention_mask=None, head_mask=None, position_bias=None, output_attentions=False, **kwargs)
¶
Constructs the attention layer for the MPNetAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetAttention class.
TYPE:
|
hidden_states |
The input hidden states tensor of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
A tensor of shape (batch_size, sequence_length) indicating which tokens should be attended to and which ones should be ignored. Defaults to None.
TYPE:
|
head_mask |
A tensor of shape (num_heads,) representing the mask to be applied to the attention scores of each head. Defaults to None.
TYPE:
|
position_bias |
A tensor of shape (num_heads, sequence_length, sequence_length) representing the position bias to be added to the attention scores. Defaults to None.
TYPE:
|
output_attentions |
Whether to output the attention scores. Defaults to False.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Union[Tensor, Tuple[Tensor]], ...]: A tuple containing the attention output tensor of shape (batch_size, sequence_length, hidden_size) and any additional outputs returned by the attention layer. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetAttention.prune_heads(heads)
¶
Prunes specified attention heads from the multi-head self-attention layer.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetClassificationHead
¶
Bases: Module
Head for sentence-level classification tasks.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetClassificationHead.__init__(config)
¶
Initializes an instance of the MPNetClassificationHead class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class itself.
|
config |
An object containing configuration parameters for the head, including:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided config parameter is not of the expected type. |
ValueError
|
If any of the configuration parameters are invalid or missing. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetClassificationHead.forward(features, **kwargs)
¶
Constructs the MPNetClassificationHead by performing a series of operations on the input features.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetClassificationHead class.
|
features |
The input features to be processed. It should be a tensor of shape (batch_size, sequence_length, num_features).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEmbeddings
¶
Bases: Module
forward the embeddings from word, position and token_type embeddings.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEmbeddings.__init__(config)
¶
Initializes an instance of the MPNetEmbeddings class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
An object of type 'config' containing the configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEmbeddings.create_position_ids_from_inputs_embeds(inputs_embeds)
¶
We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
PARAMETER | DESCRIPTION |
---|---|
inputs_embeds |
mindspore.Tensor
|
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEmbeddings.forward(input_ids=None, position_ids=None, inputs_embeds=None, **kwargs)
¶
Method 'forward' in the class 'MPNetEmbeddings'.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
input_ids |
The input tensor representing token indices. Defaults to None.
TYPE:
|
position_ids |
The input tensor representing position indices. Defaults to None.
TYPE:
|
inputs_embeds |
The input tensor representing embeddings. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
embeddings
|
The method returns the forwarded embeddings of input data. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both 'input_ids' and 'inputs_embeds' are None. |
ValueError
|
If shape inconsistency is detected between 'input_ids' and 'inputs_embeds'. |
IndexError
|
If an index is out of bounds while accessing tensors. |
TypeError
|
If the input types are not torch tensors. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEncoder
¶
Bases: Module
Encoder module for the MPNet model.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEncoder.__init__(config)
¶
Initializes an instance of the MPNetEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current object instance.
|
config |
The configuration object containing the settings for the MPNetEncoder.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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.mpnet.modeling_mpnet.MPNetEncoder.compute_position_bias(x, position_ids=None, num_buckets=32)
¶
Computes the position bias for relative attention in the MPNet model.
PARAMETER | DESCRIPTION |
---|---|
x |
Input tensor of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
position_ids |
Tensor containing position indices. If provided, the position indices are used to compute relative positions; otherwise, indices are generated based on the input tensor's sequence length. Defaults to None.
TYPE:
|
num_buckets |
Number of buckets for relative position encoding. Defaults to 32.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: Position bias tensor of shape (batch_size, num_heads, sequence_length, sequence_length). |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEncoder.forward(hidden_states, attention_mask=None, head_mask=None, output_attentions=False, output_hidden_states=False, return_dict=False, **kwargs)
¶
Construct method in the MPNetEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetEncoder class.
|
hidden_states |
The input hidden states to be processed by the encoder.
TYPE:
|
attention_mask |
An optional tensor specifying which positions should be attended to. Defaults to None.
TYPE:
|
head_mask |
An optional tensor specifying which heads to mask out. Defaults to None.
TYPE:
|
output_attentions |
A flag indicating whether to output the attention weights. Defaults to False.
TYPE:
|
output_hidden_states |
A flag indicating whether to output hidden states for all layers. Defaults to False.
TYPE:
|
return_dict |
A flag indicating whether to return the outputs as a dictionary. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input parameters are not of the expected types. |
ValueError
|
If the input parameters are not within the expected ranges. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEncoder.relative_position_bucket(relative_position, num_buckets=32, max_distance=128)
staticmethod
¶
Bucketizes relative positions for relative attention in the MPNet model.
PARAMETER | DESCRIPTION |
---|---|
relative_position |
Tensor containing relative positions.
TYPE:
|
num_buckets |
Number of buckets for bucketization. Defaults to 32.
TYPE:
|
max_distance |
Maximum distance for bucketization. Defaults to 128.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: Bucketized relative positions. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM
¶
Bases: MPNetPreTrainedModel
MPNet model for masked language modeling.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM.__init__(config)
¶
Initializes an instance of the MPNetForMaskedLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
The configuration object that defines the model architecture and hyperparameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=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/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM.get_output_embeddings()
¶
Retrieve the output embeddings from the decoder of the language model head.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetForMaskedLM class. Represents the model for Masked Language Modeling.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method returns the output embeddings from the decoder of the language model head. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM.set_output_embeddings(new_embeddings)
¶
Set the output embeddings for MPNetForMaskedLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetForMaskedLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set as the output embeddings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMultipleChoice
¶
Bases: MPNetPreTrainedModel
MPNet model for multiple choice tasks.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMultipleChoice.__init__(config)
¶
Initializes an instance of the MPNetForMultipleChoice class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetForMultipleChoice class.
TYPE:
|
config |
The configuration object for the MPNetModel.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMultipleChoice.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the multiple choice classification loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForQuestionAnswering
¶
Bases: MPNetPreTrainedModel
MPNet model for question answering tasks.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForQuestionAnswering.__init__(config)
¶
Initialize the MPNetForQuestionAnswering class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetForQuestionAnswering class.
TYPE:
|
config |
An object containing configuration settings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
AttributeError
|
If the 'config' object does not have the 'num_labels' attribute. |
TypeError
|
If the 'config' parameter is not of the expected type. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForQuestionAnswering.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=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/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForSequenceClassification
¶
Bases: MPNetPreTrainedModel
MPNet model for sequence classification tasks.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForSequenceClassification.__init__(config)
¶
Initializes an instance of MPNetForSequenceClassification.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
config |
The configuration object containing settings for the model initialization. Must contain the attribute 'num_labels' specifying the number of labels for classification.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the 'config' object does not have the 'num_labels' attribute. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForSequenceClassification.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=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/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForTokenClassification
¶
Bases: MPNetPreTrainedModel
MPNet model for token classification tasks.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForTokenClassification.__init__(config)
¶
Initializes a new instance of the MPNetForTokenClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetForTokenClassification class.
|
config |
An instance of the MPNetConfig class containing the configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForTokenClassification.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=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/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetIntermediate
¶
Bases: Module
Copied from transformers.models.bert.modeling_bert.BertIntermediate
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetIntermediate.__init__(config)
¶
Initializes an instance of the MPNetIntermediate class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetIntermediate class.
|
config |
An object containing configuration parameters for the MPNetIntermediate instance.
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not provided. |
ValueError
|
If the hidden activation function specified in the config is not supported. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetIntermediate.forward(hidden_states)
¶
Constructs the intermediate layer of the MPNet model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetIntermediate class.
TYPE:
|
hidden_states |
The input tensor of shape (batch_size, sequence_length, hidden_size) representing the hidden states.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The output tensor of shape (batch_size, sequence_length, hidden_size) containing the processed hidden states. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input 'hidden_states' is not a mindspore.Tensor. |
ValueError
|
If the shape of 'hidden_states' is not (batch_size, sequence_length, hidden_size). |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLMHead
¶
Bases: Module
MPNet Head for masked and permuted language modeling.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.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 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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLMHead.__init__(config)
¶
This method initializes an instance of the MPNetLMHead class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetLMHead class.
|
config |
An object containing configuration parameters for the MPNetLMHead model.
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration object is invalid or missing required parameters. |
TypeError
|
If the configuration object is not of the expected type. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLMHead.forward(features, **kwargs)
¶
This method forwards the output by processing the input features through various layers.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the MPNetLMHead class.
TYPE:
|
features |
Input features to be processed. Expected to be a tensor data type.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns None after processing the input features through the defined layers. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLayer
¶
Bases: Module
Single layer in the MPNet model architecture.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLayer.__init__(config)
¶
Initializes an instance of the MPNetLayer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetLayer class.
TYPE:
|
config |
The configuration object used to initialize the MPNetLayer. This object contains the settings and parameters required for the MPNetLayer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetLayer.forward(hidden_states, attention_mask=None, head_mask=None, position_bias=None, output_attentions=False, **kwargs)
¶
Constructs an MPNetLayer.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
TYPE:
|
hidden_states |
The input hidden states of shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask of shape (batch_size, sequence_length). Defaults to None.
TYPE:
|
head_mask |
The head mask of shape (num_heads). Defaults to None.
TYPE:
|
position_bias |
The position bias of shape (num_heads, sequence_length, sequence_length). Defaults to None.
TYPE:
|
output_attentions |
Whether to output attentions. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing layer_output of shape (batch_size, sequence_length, hidden_size) and additional optional outputs. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the input dimensions are invalid or incompatible. |
TypeError
|
If the input types are incorrect. |
RuntimeError
|
If there is a runtime error during the execution of the method. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel
¶
Bases: MPNetPreTrainedModel
MPNet model architecture.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel.__init__(config, add_pooling_layer=True)
¶
Initializes an instance of the MPNetModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A dictionary containing the configuration parameters for the model.
TYPE:
|
add_pooling_layer |
A flag indicating whether to include a pooling layer in the model. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, output_attentions=None, output_hidden_states=None, return_dict=None, **kwargs)
¶
Constructs the MPNet model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetModel class.
TYPE:
|
input_ids |
The input tensor containing the indices of input sequence tokens.
TYPE:
|
attention_mask |
The optional attention mask tensor specifying which tokens should be attended to.
TYPE:
|
position_ids |
The optional input tensor containing the position indices of each input token.
TYPE:
|
head_mask |
The optional tensor specifying which heads should be masked in the self-attention layers.
TYPE:
|
inputs_embeds |
The optional input tensor containing the embeddings of each input token.
TYPE:
|
output_attentions |
Whether to return the attentions.
TYPE:
|
output_hidden_states |
Whether to return the hidden states.
TYPE:
|
return_dict |
Whether to return the output as a dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], BaseModelOutputWithPooling]
|
Union[Tuple[mindspore.Tensor], BaseModelOutputWithPooling]: The output of the MPNet model.
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both |
ValueError
|
If neither |
ValueError
|
If the dimensions of |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel.get_input_embeddings()
¶
This method retrieves the input embeddings from the MPNetModel.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetModel class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
The method returns the input embeddings from the MPNetModel. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel.set_input_embeddings(value)
¶
Method to set the input embeddings in the MPNetModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetModel class.
TYPE:
|
value |
The input value representing the embeddings to be set for the model. It should be compatible with the expected format for word embeddings.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetOutput
¶
Bases: Module
Copied from transformers.models.bert.modeling_bert.BertOutput
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetOutput.__init__(config)
¶
Initializes an instance of the MPNetOutput class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetOutput class.
|
config |
An object containing configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of the expected type. |
ValueError
|
If the config parameter does not contain the required attributes. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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.mpnet.modeling_mpnet.MPNetOutput.forward(hidden_states, input_tensor)
¶
Constructs the MPNetOutput.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetOutput class.
TYPE:
|
hidden_states |
A tensor containing the hidden states. This tensor is input to the dense layer, which performs a linear transformation on the hidden states. The shape of this tensor should be compatible with the dense layer's weight matrix.
TYPE:
|
input_tensor |
A tensor containing the input states. This tensor is added to the hidden states after the linear transformation and dropout. The shape of this tensor should be compatible with the hidden states tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: A tensor representing the forwarded MPNetOutput. The shape of the tensor is the same as the hidden_states tensor. The forwarded MPNetOutput is obtained by applying the dense layer, dropout, and LayerNorm operations to the hidden states and adding the input tensor. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetPooler
¶
Bases: Module
Copied from transformers.models.bert.modeling_bert.BertPooler
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetPooler.__init__(config)
¶
Initializes an instance of the MPNetPooler class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the MPNetPooler class.
TYPE:
|
config |
The configuration object containing parameters for initializing the MPNetPooler. The config object should have a 'hidden_size' attribute indicating the size of the hidden layer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetPooler.forward(hidden_states)
¶
This method forwards a pooled output from the hidden states of the MPNet model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetPooler class.
|
hidden_states |
A tensor containing the hidden states of the MPNet model. It is expected to have a shape of (batch_size, sequence_length, hidden_size), where batch_size is the batch size, sequence_length is the length of the input sequence, and hidden_size is the size of the hidden state.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The pooled output tensor generated from the hidden states. It has a shape of (batch_size, hidden_size). |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetPreTrainedModel
¶
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/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetSelfAttention
¶
Bases: Module
SelfAttention Model
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetSelfAttention.__init__(config)
¶
Initializes a new instance of the MPNetSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetSelfAttention class.
|
config |
An object containing configuration parameters for the self-attention mechanism.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the hidden size is not a multiple of the number of attention heads or if the 'embedding_size' attribute is not present in the config object. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetSelfAttention.forward(hidden_states, attention_mask=None, head_mask=None, position_bias=None, output_attentions=False, **kwargs)
¶
This method forwards self-attention mechanism for MPNetSelfAttention.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
hidden_states |
Tensor containing the input hidden states. Shape: (batch_size, sequence_length, hidden_size).
|
attention_mask |
Optional tensor to mask out attention scores. Shape: (batch_size, sequence_length, sequence_length).
DEFAULT:
|
head_mask |
Optional tensor to mask out attention heads. Shape: (num_attention_heads, sequence_length, sequence_length).
DEFAULT:
|
position_bias |
Optional tensor containing positional bias. Shape: (batch_size, num_attention_heads, sequence_length, sequence_length).
DEFAULT:
|
output_attentions |
Boolean indicating whether to output attention probabilities.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Tuple
|
Tuple containing output tensor 'o' and attention probabilities tensor. If output_attentions is False, returns tuple with only 'o'. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dimensions of input tensors are incompatible for matrix operations. |
TypeError
|
If the input parameters are not of expected types. |
RuntimeError
|
If any runtime error occurs during the execution of the method. |
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetSelfAttention.transpose_for_scores(x)
¶
Transposes the input tensor x
to prepare it for multi-head attention scoring.
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
217 218 219 220 221 222 223 |
|
mindnlp.transformers.models.mpnet.modeling_mpnet.create_position_ids_from_input_ids(input_ids, padding_idx)
¶
Replace non-padding symbols with their position numbers. Position numbers begin at padding_idx+1. Padding symbols
are ignored. This is modified from fairseq's utils.make_positions
. :param torch.Tensor x: :return torch.Tensor:
Source code in mindnlp/transformers/models/mpnet/modeling_mpnet.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet
¶
Tokenization classes for MPNet.
mindnlp.transformers.models.mpnet.tokenization_mpnet.BasicTokenizer
¶
Bases: object
Constructs a BasicTokenizer that will run basic tokenization (punctuation splitting, lower casing, etc.).
PARAMETER | DESCRIPTION |
---|---|
do_lower_case |
Whether or not to lowercase the input when tokenizing.
TYPE:
|
never_split |
Collection of tokens which will never be split during tokenization. Only has an effect when
TYPE:
|
tokenize_chinese_chars |
Whether or not to tokenize Chinese characters. This should likely be deactivated for Japanese (see this issue).
TYPE:
|
strip_accents |
Whether or not to strip all accents. If this option is not specified, then it will be determined by the
value for
TYPE:
|
do_split_on_punc |
In some instances we want to skip the basic punctuation splitting so that later tokenization can capture the full context of the words, such as contractions.
TYPE:
|
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.BasicTokenizer.__init__(do_lower_case=True, never_split=None, tokenize_chinese_chars=True, strip_accents=None, do_split_on_punc=True)
¶
Initializes a BasicTokenizer object with the specified parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BasicTokenizer class.
|
do_lower_case |
A flag indicating whether text should be converted to lowercase. Default is True.
TYPE:
|
never_split |
A list of tokens that should never be split during tokenization. Default is an empty list.
TYPE:
|
tokenize_chinese_chars |
A flag indicating whether to tokenize Chinese characters. Default is True.
TYPE:
|
strip_accents |
Not used in the current implementation.
TYPE:
|
do_split_on_punc |
A flag indicating whether to split on punctuation marks. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.BasicTokenizer.tokenize(text, never_split=None)
¶
Basic Tokenization of a piece of text. For sub-word tokenization, see WordPieceTokenizer.
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer
¶
Bases: PreTrainedTokenizer
This tokenizer inherits from [BertTokenizer
] which contains most of the methods. Users should refer to the
superclass for more information regarding methods.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
do_lower_case |
Whether or not to lowercase the input when tokenizing.
TYPE:
|
do_basic_tokenize |
Whether or not to do basic tokenization before WordPiece.
TYPE:
|
never_split |
Collection of tokens which will never be split during tokenization. Only has an effect when
TYPE:
|
bos_token |
The beginning of sequence token that was used during pre-training. Can be used a sequence classifier token. When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the
TYPE:
|
eos_token |
The end of sequence token. When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the
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:
|
tokenize_chinese_chars |
Whether or not to tokenize Chinese characters. This should likely be deactivated for Japanese (see this issue).
TYPE:
|
strip_accents |
Whether or not to strip all accents. If this option is not specified, then it will be determined by the
value for
TYPE:
|
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.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 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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.do_lower_case
property
¶
Method 'do_lower_case' in the class 'MPNetTokenizer'. This method converts the text to lowercase using the basic tokenizer provided by the MPNetTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetTokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.vocab_size
property
¶
Returns the size of the vocabulary.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MPNetTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
The size of the vocabulary. |
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.__init__(vocab_file, do_lower_case=True, do_basic_tokenize=True, never_split=None, bos_token='<s>', eos_token='</s>', sep_token='</s>', cls_token='<s>', unk_token='[UNK]', pad_token='<pad>', mask_token='<mask>', tokenize_chinese_chars=True, strip_accents=None, **kwargs)
¶
This method initializes an instance of the MPNetTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_file |
Path to the vocabulary file.
TYPE:
|
do_lower_case |
Whether to convert tokens to lowercase. Defaults to True.
TYPE:
|
do_basic_tokenize |
Whether to perform basic tokenization. Defaults to True.
TYPE:
|
never_split |
List of tokens that should not be split. Defaults to None.
TYPE:
|
bos_token |
Beginning of sequence token. Defaults to '
TYPE:
|
eos_token |
End of sequence token. Defaults to ''.
TYPE:
|
sep_token |
Separator token. Defaults to ''.
TYPE:
|
cls_token |
Classification token. Defaults to '
TYPE:
|
unk_token |
Token for unknown words. Defaults to '[UNK]'.
TYPE:
|
pad_token |
Padding token. Defaults to '
TYPE:
|
mask_token |
Mask token. Defaults to '
TYPE:
|
tokenize_chinese_chars |
Whether to tokenize Chinese characters. Defaults to True.
TYPE:
|
strip_accents |
Method for stripping accents. Defaults to None.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the vocabulary file specified by 'vocab_file' cannot be found. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.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 MPNet sequence has the following format:
- single sequence:
<s> X </s>
- pair of sequences:
<s> A </s></s> B </s>
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/mpnet/tokenization_mpnet.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
308 309 310 311 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Creates a mask from the two sequences passed to be used in a sequence-pair classification task. MPNet does not make use of token type ids, therefore a list of zeros is returned.
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/mpnet/tokenization_mpnet.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.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
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 |
Set to True if the token list is already formatted with special tokens for the model
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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.mpnet.tokenization_mpnet.MPNetTokenizer.get_vocab()
¶
Method to retrieve the vocabulary from the MPNetTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetTokenizer class.
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the combined vocabulary of added tokens and the original vocabulary. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.MPNetTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to a file in the specified directory with an optional filename prefix.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MPNetTokenizer class.
TYPE:
|
save_directory |
The directory path where the vocabulary file will be saved.
TYPE:
|
filename_prefix |
An optional prefix to be added to the filename. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the path to the saved vocabulary file. |
RAISES | DESCRIPTION |
---|---|
IOError
|
If an error occurs while writing the vocabulary file. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.WordpieceTokenizer
¶
Bases: object
Runs WordPiece tokenization.
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.WordpieceTokenizer.__init__(vocab, unk_token, max_input_chars_per_word=100)
¶
Initializes a new instance of the WordpieceTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the WordpieceTokenizer class.
|
vocab |
A list of vocabulary tokens used for tokenization.
TYPE:
|
unk_token |
The token to be used for representing unknown words.
TYPE:
|
max_input_chars_per_word |
The maximum number of characters allowed per input word. Defaults to 100.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If max_input_chars_per_word is less than or equal to 0. |
TypeError
|
If vocab is not a list or unk_token is not a string. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.WordpieceTokenizer.tokenize(text)
¶
Tokenizes a piece of text into its word pieces. This uses a greedy longest-match-first algorithm to perform tokenization using the given vocabulary.
For example, input = "unaffable"
wil return as output ["un", "##aff", "##able"]
.
PARAMETER | DESCRIPTION |
---|---|
text |
A single token or whitespace separated tokens. This should have already been passed through BasicTokenizer.
|
RETURNS | DESCRIPTION |
---|---|
A list of wordpiece tokens. |
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
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 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.load_vocab(vocab_file)
¶
Loads a vocabulary file into a dictionary.
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
50 51 52 53 54 55 56 57 58 |
|
mindnlp.transformers.models.mpnet.tokenization_mpnet.whitespace_tokenize(text)
¶
Runs basic whitespace cleaning and splitting on a piece of text.
Source code in mindnlp/transformers/models/mpnet/tokenization_mpnet.py
61 62 63 64 65 66 67 |
|