biogpt
mindnlp.transformers.models.biogpt.configuration_biogpt.BioGptConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [BioGptModel]. It is used to instantiate an
BioGPT 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 BioGPT
microsoft/biogpt architecture.
Configuration objects inherit from [PretrainedConfig] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_size
|
Vocabulary size of the BioGPT model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size
|
Dimension of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size
|
Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_act
|
The non-linear activation function (function or string) in the encoder and pooler. If string,
TYPE:
|
hidden_dropout_prob
|
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob
|
The dropout ratio for the attention probabilities.
TYPE:
|
max_position_embeddings
|
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
initializer_range
|
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps
|
The epsilon used by the layer normalization layers.
TYPE:
|
scale_embedding
|
Scale embeddings by diving by sqrt(d_model).
TYPE:
|
use_cache
|
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if
TYPE:
|
layerdrop
|
Please refer to the paper about LayerDrop: https://arxiv.org/abs/1909.11556 for further details
TYPE:
|
activation_dropout
|
The dropout ratio for activations inside the fully connected layer.
TYPE:
|
pad_token_id
|
Padding token id.
TYPE:
|
bos_token_id
|
Beginning of stream token id.
TYPE:
|
eos_token_id
|
End of stream token id.
TYPE:
|
Example
>>> from transformers import BioGptModel, BioGptConfig
...
>>> # Initializing a BioGPT microsoft/biogpt style configuration
>>> configuration = BioGptConfig()
...
>>> # Initializing a model from the microsoft/biogpt style configuration
>>> model = BioGptModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\biogpt\configuration_biogpt.py
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 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 | |
mindnlp.transformers.models.biogpt.configuration_biogpt.BioGptConfig.__init__(vocab_size=42384, hidden_size=1024, num_hidden_layers=24, num_attention_heads=16, intermediate_size=4096, hidden_act='gelu', hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position_embeddings=1024, initializer_range=0.02, layer_norm_eps=1e-12, scale_embedding=True, use_cache=True, layerdrop=0.0, activation_dropout=0.0, pad_token_id=1, bos_token_id=0, eos_token_id=2, **kwargs)
¶
Initializes a new instance of the BioGptConfig class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
vocab_size
|
The size of the vocabulary. Defaults to 42384.
TYPE:
|
hidden_size
|
The size of the hidden layers. Defaults to 1024.
TYPE:
|
num_hidden_layers
|
The number of hidden layers. Defaults to 24.
TYPE:
|
num_attention_heads
|
The number of attention heads. Defaults to 16.
TYPE:
|
intermediate_size
|
The size of the intermediate layers. Defaults to 4096.
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 position embeddings. Defaults to 1024.
TYPE:
|
initializer_range
|
The range for the initializer. Defaults to 0.02.
TYPE:
|
layer_norm_eps
|
The epsilon value for layer normalization. Defaults to 1e-12.
TYPE:
|
scale_embedding
|
Whether to scale the embedding. Defaults to True.
TYPE:
|
use_cache
|
Whether to use caching. Defaults to True.
TYPE:
|
layerdrop
|
The probability of dropping a layer. Defaults to 0.0.
TYPE:
|
activation_dropout
|
The dropout probability for the activation. Defaults to 0.0.
TYPE:
|
pad_token_id
|
The id of the padding token. Defaults to 1.
TYPE:
|
bos_token_id
|
The id of the beginning-of-sentence token. Defaults to 0.
TYPE:
|
eos_token_id
|
The id of the end-of-sentence token. Defaults to 2.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\biogpt\configuration_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForCausalLM
¶
Bases: BioGptPreTrainedModel
Source code in mindnlp\transformers\models\biogpt\modeling_biogpt.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 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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForCausalLM.forward(input_ids=None, attention_mask=None, head_mask=None, inputs_embeds=None, past_key_values=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size, sequence_length), optional):
Labels for language modeling. Note that the labels are shifted inside the model, i.e. you can set
labels = input_ids Indices are selected in [-100, 0, ..., config.vocab_size] All labels set to -100
are ignored (masked), the loss is only computed for labels in [0, ..., config.vocab_size]
Source code in mindnlp\transformers\models\biogpt\modeling_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForTokenClassification
¶
Bases: BioGptPreTrainedModel
Source code in mindnlp\transformers\models\biogpt\modeling_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForTokenClassification.forward(input_ids=None, token_type_ids=None, attention_mask=None, head_mask=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=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\biogpt\modeling_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForSequenceClassification
¶
Bases: BioGptPreTrainedModel
Source code in mindnlp\transformers\models\biogpt\modeling_biogpt.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 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 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptForSequenceClassification.forward(input_ids=None, attention_mask=None, head_mask=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=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\biogpt\modeling_biogpt.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptModel
¶
Bases: BioGptPreTrainedModel
Source code in mindnlp\transformers\models\biogpt\modeling_biogpt.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
mindnlp.transformers.models.biogpt.modeling_biogpt.BioGptPreTrainedModel
¶
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\biogpt\modeling_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer
¶
Bases: PreTrainedTokenizer
Construct an FAIRSEQ Transformer tokenizer. Moses tokenization followed by Byte-Pair Encoding.
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
merges_file
|
Merges file.
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:
|
bos_token
|
The beginning of sequence token that was used during pretraining. 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:
|
pad_token
|
The token used for padding, for example when batching sequences of different lengths.
TYPE:
|
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.cache_moses_detokenizer = {}
instance-attribute
¶
Initialisation
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.vocab_size
property
¶
Returns vocab size
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.__getstate__()
¶
The 'getstate' method in the 'BioGptTokenizer' class is used to retrieve the state of the object for pickling.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the 'BioGptTokenizer' class.
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method does not explicitly return a value, but modifies the state of the object. |
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.__init__(vocab_file, merges_file, unk_token='<unk>', bos_token='<s>', eos_token='</s>', sep_token='</s>', pad_token='<pad>', **kwargs)
¶
Initializes a new instance of the BioGptTokenizer class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
vocab_file
|
The path to the vocabulary file.
TYPE:
|
merges_file
|
The path to the merges file.
TYPE:
|
unk_token
|
The token to represent unknown words. Defaults to '
TYPE:
|
bos_token
|
The token to represent the beginning of a sentence. Defaults to '
TYPE:
|
eos_token
|
The token to represent the end of a sentence. Defaults to ''.
TYPE:
|
sep_token
|
The token to represent sentence separation. Defaults to ''.
TYPE:
|
pad_token
|
The token to represent padding. Defaults to '
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If sacremoses library is not installed. |
IOError
|
If the vocabulary or merges file cannot be read. |
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.__setstate__(d)
¶
Sets the state of the BioGptTokenizer object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the BioGptTokenizer class.
TYPE:
|
d
|
The dictionary containing the state information to be set.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the sacremoses module is not installed, an ImportError is raised. The error message specifies that sacremoses needs to be installed and provides a link to the installation page. |
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.bpe(token)
¶
Performs Byte Pair Encoding (BPE) on a given token.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the BioGptTokenizer class.
|
token
|
The token to be encoded using BPE.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The BPE-encoded representation of the token. |
Description
This method takes a token and applies Byte Pair Encoding (BPE) to it. BPE is a subword tokenization technique that breaks down a token into a sequence of subword units. The BPE algorithm iteratively merges the most frequent pairs of subword units to create a vocabulary of subword units.
The token parameter is the input token to be encoded using BPE. The token is expected to be a string.
The method returns the BPE-encoded representation of the token as a string. The encoded representation is obtained by iteratively merging the most frequent pairs of subword units until no more merges can be made. The resulting subword units are then joined together to form the encoded token.
Note that the method may use a cache to store previously encoded tokens for efficiency.
Example
>>> tokenizer = BioGptTokenizer()
>>> encoded_token = tokenizer.bpe('sequence')
>>> print(encoded_token)
>>> # Output: 'seq uence'</w>'
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.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 BioGPT sequence has the following format:
- single sequence:
</s> X - pair of sequences:
</s> A </s> B
| 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\biogpt\tokenization_biogpt.py
364 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.biogpt.tokenization_biogpt.BioGptTokenizer.convert_tokens_to_string(tokens)
¶
Converts a sequence of tokens (string) in a single string.
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
355 356 357 358 359 360 361 362 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.create_token_type_ids_from_sequences(token_ids_0, token_ids_1=None)
¶
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A FAIRSEQ Transformer sequence pair mask has the following format:
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
| first sequence | second sequence |
If token_ids_1 is None, this method only returns the first portion of the mask (0s).
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.get_special_tokens_mask(token_ids_0, token_ids_1=None, already_has_special_tokens=False)
¶
Retrieve 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 method.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids_0
|
List of IDs.
TYPE:
|
token_ids_1
|
Optional second list of IDs for sequence pairs.
TYPE:
|
already_has_special_tokens
|
Whether or not the token list is already formatted with special tokens for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[int]
|
|
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.get_vocab()
¶
Method to retrieve the vocabulary dictionary consisting of tokens and their corresponding encodings.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the BioGptTokenizer class. It represents the tokenizer object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method returns a vocabulary dictionary that contains tokens and their respective encodings. |
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.moses_detokenize(tokens, lang)
¶
Performs Moses detokenization on a list of tokens for a specified language.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the BioGptTokenizer class.
TYPE:
|
tokens
|
A list of tokens to be detokenized.
TYPE:
|
lang
|
The language of the tokens. Must be a supported language.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method modifies the cache_moses_detokenizer attribute of the BioGptTokenizer instance. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the specified language is not supported. |
TypeError
|
If the tokens parameter is not a list. |
Note
This method utilizes a cache to store MosesDetokenizer objects for each language, ensuring efficient detokenization by reusing previously created instances.
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.moses_tokenize(text, lang)
¶
Perform Moses tokenization on the given text.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the BioGptTokenizer class.
TYPE:
|
text
|
The text to be tokenized.
TYPE:
|
lang
|
The language code for tokenization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the language code is not found in the cache_moses_tokenizer dictionary. |
ValueError
|
If the language code is invalid or unsupported. |
Exception
|
If any other error occurs during tokenization. |
This method utilizes the MosesTokenizer from the nltk.translate.moses package to tokenize the input text. It first checks if the MosesTokenizer for the specified language is already cached. If not, it creates a new MosesTokenizer instance for the language and adds it to the cache. The tokenization is then performed using the cached MosesTokenizer object.
The 'aggressive_dash_splits', 'return_str', and 'escape' parameters are passed to the tokenize method of the MosesTokenizer. 'aggressive_dash_splits' determines whether to perform aggressive dash splitting, 'return_str' specifies whether to return a string or a list of tokens, and 'escape' determines whether to escape XML/HTML characters in the text before tokenization.
Note
This method assumes that the BioGptTokenizer instance has been properly initialized with the necessary resources for tokenization.
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
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 | |
mindnlp.transformers.models.biogpt.tokenization_biogpt.BioGptTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to the specified directory with the given filename prefix.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
Instance of the BioGptTokenizer class.
|
save_directory
|
The directory path where the vocabulary files will be saved. It should already exist, and the method will raise an error if the directory does not exist.
TYPE:
|
filename_prefix
|
An optional prefix to be added to the filenames of the vocabulary files. If provided, the filenames will be prefixed with this value. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the paths to the saved vocabulary file and merge file. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If the specified save_directory is not a valid directory. |
IOError
|
If there is an issue writing the vocabulary files to the disk. |
Source code in mindnlp\transformers\models\biogpt\tokenization_biogpt.py
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 | |