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.MPNetClassificationHead
¶
Bases: Module
Head for sentence-level classification tasks.
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetEmbeddings
¶
Bases: Module
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.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 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMaskedLM
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 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 | |
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)
¶
labels (mindspore.Tensor of shape (batch_size, sequence_length), optional):
Labels for computing the masked language modeling loss. Indices should be in [-100, 0, ...,
config.vocab_size] (see input_ids docstring) Tokens with indices set to -100 are ignored (masked), the
loss is only computed for the tokens with labels in [0, ..., config.vocab_size]
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForMultipleChoice
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
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)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the multiple choice classification loss. Indices should be in [0, ...,
num_choices-1] where num_choices is the size of the second dimension of the input tensors. (See
input_ids above)
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForQuestionAnswering
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | |
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)
¶
start_positions (mindspore.Tensor of shape (batch_size,), optional):
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 (sequence_length). Position outside of the sequence
are not taken into account for computing the loss.
end_positions (mindspore.Tensor of shape (batch_size,), optional):
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 (sequence_length). Position outside of the sequence
are not taken into account for computing the loss.
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
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 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetForSequenceClassification
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
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 | |
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)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the sequence classification/regression loss. Indices should be in [0, ...,
config.num_labels - 1]. If config.num_labels == 1 a regression loss is computed (Mean-Square loss), If
config.num_labels > 1 a classification loss is computed (Cross-Entropy).
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
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.modeling_mpnet.MPNetForTokenClassification
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
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)
¶
labels (mindspore.Tensor of shape (batch_size, sequence_length), optional):
Labels for computing the token classification loss. Indices should be in [0, ..., config.num_labels - 1].
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
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 | |
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
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 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetModel
¶
Bases: MPNetPreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
mindnlp.transformers.models.mpnet.modeling_mpnet.MPNetPreTrainedModel
¶
Bases: PreTrainedModel
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
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 mindspore.Tensor x: :return mindspore.Tensor:
Source code in mindnlp\transformers\models\mpnet\modeling_mpnet.py
915 916 917 918 919 920 921 922 923 | |
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 | |