bloom
mindnlp.transformers.models.bloom.configuration_bloom.BloomConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [BloomModel]. It is used to instantiate a Bloom
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to the Bloom architecture
bigscience/bloom.
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 Bloom model. Defines the maximum number of different tokens that can be represented
by the
TYPE:
|
hidden_size
|
Dimensionality of the embeddings and hidden states.
TYPE:
|
n_layer
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
n_head
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
layer_norm_epsilon
|
The epsilon to use in the layer normalization layers.
TYPE:
|
initializer_range
|
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
apply_residual_connection_post_layernorm
|
If enabled, use the layer norm of the hidden states as the residual in the transformer blocks
TYPE:
|
hidden_dropout
|
Dropout rate of the dropout function on the bias dropout.
TYPE:
|
attention_dropout
|
Dropout rate applied to the attention probs
TYPE:
|
use_cache
|
Whether or not the model should return the last key/values attentions (not used by all models).
TYPE:
|
pretraining_tp
|
Experimental feature. Tensor parallelism rank used during pretraining with Megatron. Please refer to this
document to understand more about it. This value is
necessary to ensure exact reproducibility of the pretraining results. Please refer to this
issue. Note also that this is enabled only when
TYPE:
|
slow_but_exact
|
Experimental feature. Whether to use slow but exact implementation of the attention mechanism. While merging the TP rank tensors, due to slicing operations the results may be slightly different between the model trained on Megatron and our model. Please refer to this issue. A solution to obtain more accurate results is to enable this feature. Enabling this will hurt the computational time of the inference. Will be probably resolved in the future once the main model has been fine-tuned with TP_rank=1.
TYPE:
|
Example
>>> from transformers import BloomConfig, BloomModel
...
>>> # Initializing a Bloom configuration
>>> configuration = BloomConfig()
...
>>> # Initializing a model (with random weights) from the configuration
>>> model = BloomModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\bloom\configuration_bloom.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
mindnlp.transformers.models.bloom.configuration_bloom.BloomConfig.__init__(vocab_size=250880, hidden_size=64, n_layer=2, n_head=8, layer_norm_epsilon=1e-05, initializer_range=0.02, use_cache=True, bos_token_id=1, eos_token_id=2, apply_residual_connection_post_layernorm=False, hidden_dropout=0.0, attention_dropout=0.0, pretraining_tp=1, slow_but_exact=False, **kwargs)
¶
Initializes a new instance of the BloomConfig class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The object itself.
|
vocab_size
|
The size of the vocabulary. Default is 250880.
TYPE:
|
hidden_size
|
The size of the hidden layer. Default is 64.
TYPE:
|
n_layer
|
The number of layers. Default is 2.
TYPE:
|
n_head
|
The number of attention heads. Default is 8.
TYPE:
|
layer_norm_epsilon
|
The epsilon value for layer normalization. Default is 1e-05.
TYPE:
|
initializer_range
|
The range for the initializer. Default is 0.02.
TYPE:
|
use_cache
|
Determines if caching is used. Default is True.
TYPE:
|
bos_token_id
|
The ID of the beginning-of-sentence token. Default is 1.
TYPE:
|
eos_token_id
|
The ID of the end-of-sentence token. Default is 2.
TYPE:
|
apply_residual_connection_post_layernorm
|
Determines if residual connection is applied after layer normalization. Default is False.
TYPE:
|
hidden_dropout
|
The dropout rate for hidden layers. Default is 0.0.
TYPE:
|
attention_dropout
|
The dropout rate for attention layers. Default is 0.0.
TYPE:
|
pretraining_tp
|
The pretraining TP value. Default is 1.
TYPE:
|
slow_but_exact
|
Determines if the method should prioritize accuracy over speed. Default is False.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\bloom\configuration_bloom.py
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 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM
¶
Bases: BloomPreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
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 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 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM.forward(input_ids=None, past_key_values=None, attention_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, cache_position=None, **deprecated_arguments)
¶
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\bloom\modeling_bloom.py
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 813 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel
¶
Bases: BloomPreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
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 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 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomPreTrainedModel
¶
Bases: PreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForSequenceClassification
¶
Bases: BloomPreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
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 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForSequenceClassification.forward(input_ids=None, past_key_values=None, attention_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, **deprecated_arguments)
¶
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\bloom\modeling_bloom.py
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 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForTokenClassification
¶
Bases: BloomPreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
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 1030 1031 1032 1033 1034 1035 1036 1037 1038 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForTokenClassification.forward(input_ids=None, past_key_values=None, attention_mask=None, head_mask=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, **deprecated_arguments)
¶
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\bloom\modeling_bloom.py
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 1030 1031 1032 1033 1034 1035 1036 1037 1038 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForQuestionAnswering
¶
Bases: BloomPreTrainedModel
Source code in mindnlp\transformers\models\bloom\modeling_bloom.py
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | |
mindnlp.transformers.models.bloom.modeling_bloom.BloomForQuestionAnswering.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\bloom\modeling_bloom.py
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 | |
mindnlp.transformers.models.bloom.tokenization_bloom_fast.BloomTokenizerFast
¶
Bases: PreTrainedTokenizerFast
Construct a "fast" Bloom tokenizer (backed by HuggingFace's tokenizers library). Based on byte-level Byte-Pair-Encoding.
This tokenizer has been trained to treat spaces like parts of the tokens (a bit like sentencepiece) so a word will be encoded differently whether it is at the beginning of the sentence (without space) or not:
Example
>>> from transformers import BloomTokenizerFast
...
>>> tokenizer = BloomTokenizerFast.from_pretrained("bigscience/bloom")
>>> tokenizer("Hello world")["input_ids"]
[59414, 8876]
...
>>> tokenizer(" Hello world")["input_ids"]
[86153, 8876]
You can get around that behavior by passing add_prefix_space=True when instantiating this tokenizer, but since
the model was not pretrained this way, it might yield a decrease in performance.
When used with is_split_into_words=True, this tokenizer needs to be instantiated with add_prefix_space=True.
This tokenizer inherits from [PreTrainedTokenizerFast] which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
merges_file
|
Path to the merges file.
TYPE:
|
errors
|
Paradigm to follow when decoding bytes to UTF-8. See bytes.decode for more information.
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.
TYPE:
|
eos_token
|
The end of sequence token.
TYPE:
|
add_prefix_space
|
Whether or not to add an initial space to the input. This allows to treat the leading word just as any other word. (Bloom tokenizer detect beginning of words by the preceding space).
TYPE:
|
trim_offsets
|
Whether or not the post-processing step should trim offsets to avoid including whitespaces.
TYPE:
|
Source code in mindnlp\transformers\models\bloom\tokenization_bloom_fast.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 | |
mindnlp.transformers.models.bloom.tokenization_bloom_fast.BloomTokenizerFast.default_chat_template
property
¶
A simple chat template that ignores role information and just concatenates messages with EOS tokens.
mindnlp.transformers.models.bloom.tokenization_bloom_fast.BloomTokenizerFast.__init__(vocab_file=None, merges_file=None, tokenizer_file=None, unk_token='<unk>', bos_token='<s>', eos_token='</s>', pad_token='<pad>', add_prefix_space=False, clean_up_tokenization_spaces=False, **kwargs)
¶
Initialize a BloomTokenizerFast object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
vocab_file
|
Path to a vocabulary file.
TYPE:
|
merges_file
|
Path to a merges file.
TYPE:
|
tokenizer_file
|
Path to a tokenizer file.
TYPE:
|
unk_token
|
The unknown token.
TYPE:
|
bos_token
|
The beginning of sequence token.
TYPE:
|
eos_token
|
The end of sequence token.
TYPE:
|
pad_token
|
The padding token.
TYPE:
|
add_prefix_space
|
Flag indicating whether to add prefix space.
TYPE:
|
clean_up_tokenization_spaces
|
Flag indicating whether to clean up tokenization spaces.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\bloom\tokenization_bloom_fast.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 | |
mindnlp.transformers.models.bloom.tokenization_bloom_fast.BloomTokenizerFast.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the tokenizer's vocabulary to a specified directory.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the BloomTokenizerFast class.
TYPE:
|
save_directory
|
The directory where the vocabulary files will be saved.
TYPE:
|
filename_prefix
|
A prefix to prepend to the vocabulary file names. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple of file names that were saved in the specified directory. |
The 'save_vocabulary' method saves the tokenizer's vocabulary to the specified 'save_directory'. The vocabulary files are saved using the 'filename_prefix' if provided, or a default name if not specified.
Example
>>> tokenizer = BloomTokenizerFast()
>>> tokenizer.save_vocabulary('/path/to/save', 'vocab_')
Source code in mindnlp\transformers\models\bloom\tokenization_bloom_fast.py
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 | |