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.BLOOM_PRETRAINED_MODEL_ARCHIVE_LIST = ['bigscience/bigscience-small-testing', 'bigscience/bloom-560m', 'bigscience/bloom-1b1', 'bigscience/bloom-1b7', 'bigscience/bloom-3b', 'bigscience/bloom-7b1', 'bigscience/bloom']
module-attribute
¶
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM
¶
Bases: BloomPreTrainedModel
The BloomForCausalLM
class is a subclass of BloomPreTrainedModel
and represents a model
for causal language modeling using the BLOOM architecture.
Causal language modeling is the task of predicting the next token in a sequence given the previous tokens. The BLOOM architecture is specifically designed for this task, utilizing a transformer model with an additional language modeling head.
The class has the following methods:
__init__
: Initializes theBloomForCausalLM
instance with a configuration object.get_output_embeddings
: Returns the language modeling head.set_output_embeddings
: Sets the language modeling head to the provided embeddings.prepare_inputs_for_generation
: Prepares the inputs for generation by removing the prefix length from the input sequence and converting the past key values to BLOOM cache format.forward
: Constructs the BLOOM model by passing the inputs through the transformer and language modeling head. Optionally computes the loss if labels are provided._reorder_cache
: Reorders the past key values cache to match the beam indices during beam search or beam sampling.
Additionally, the class inherits all the properties and methods from the BloomPreTrainedModel
class.
Note
The labels
parameter in the forward
method is for language modeling labels, and the position_ids
parameter is deprecated and will be removed in the future.
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 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 1030 1031 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 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 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM.__init__(config)
¶
Initializes a new instance of the BloomForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current object instance.
|
config |
The configuration object containing the model's hyperparameters and settings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 |
|
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, **deprecated_arguments)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for language modeling. Note that the labels are shifted inside the model, i.e. you can set
TYPE:
|
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM.get_output_embeddings()
¶
Returns the output embeddings of the BloomForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomForCausalLM class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
969 970 971 972 973 974 975 976 977 978 979 980 981 982 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM.prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs)
¶
Prepare inputs for generation.
This method takes 5 parameters: self, input_ids, past_key_values, attention_mask, inputs_embeds. It returns a dictionary containing the model inputs.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomForCausalLM class.
TYPE:
|
input_ids |
The input tensor containing the tokenized input sequence.
TYPE:
|
past_key_values |
The optional tensor containing the cached key-value pairs from previous generation steps.
TYPE:
|
attention_mask |
The optional tensor representing the attention mask for the input sequence.
TYPE:
|
inputs_embeds |
The optional tensor containing the embedded input sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the model inputs. It may include either 'input_ids' or 'inputs_embeds' depending on the availability of 'inputs_embeds' and 'past_key_values'. It also includes 'past_key_values', 'use_cache', and 'attention_mask' if provided.
TYPE:
|
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForCausalLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the BloomForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomForCausalLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set for the model's lm_head.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel
¶
Bases: BloomPreTrainedModel
This class represents a custom implementation of a transformer model called BloomModel. It inherits from the BloomPreTrainedModel class and includes functionalities for building the model architecture, setting and getting input embeddings, and forwarding the model for inference or training.
ATTRIBUTE | DESCRIPTION |
---|---|
embed_dim |
The dimension of the word embeddings.
TYPE:
|
num_heads |
The number of attention heads in the model.
TYPE:
|
word_embeddings |
The word embeddings layer.
TYPE:
|
word_embeddings_layernorm |
Layer normalization for word embeddings.
TYPE:
|
h |
List of BloomBlocks representing the hidden layers of the model.
TYPE:
|
ln_f |
Layer normalization for the final hidden states.
TYPE:
|
gradient_checkpointing |
Flag indicating whether gradient checkpointing is enabled.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
build_alibi_tensor |
Builds an alibi tensor for the model. |
get_input_embeddings |
Retrieves the current input embeddings. |
set_input_embeddings |
Updates the input embeddings with new values. |
forward |
Constructs the model for inference or training, handling various input parameters and configurations. |
Note
This class is designed for custom transformer-based models and may require specific configurations and input formats.
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 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 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel.__init__(config)
¶
Initialize the BloomModel with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomModel class.
TYPE:
|
config |
An object containing configuration settings for the BloomModel.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel.build_alibi_tensor(attention_mask, num_heads, dtype)
¶
This method builds an alibi tensor based on the provided attention_mask, number of heads, and data type.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomModel class.
TYPE:
|
attention_mask |
A tensor representing the attention mask.
TYPE:
|
num_heads |
The number of attention heads to use in building the alibi tensor.
TYPE:
|
dtype |
The data type of the tensor.
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: A tensor representing the built alibi tensor. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the attention_mask is not a valid mindspore.Tensor. |
TypeError
|
If the num_heads is not an integer or if the dtype is not a valid data type. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel.forward(input_ids=None, past_key_values=None, attention_mask=None, head_mask=None, inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None, **deprecated_arguments)
¶
Constructs the BLOOM model based on the input parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BloomModel class.
TYPE:
|
input_ids |
Input tensor of shape (batch_size, seq_length) containing the input tokens.
TYPE:
|
past_key_values |
Tuple of length 'n_layer' where each tuple contains two tensors of shape (batch_size, num_heads, seq_length, hidden_size//num_heads) representing the past key and value respectively. If not provided, initialized with None.
TYPE:
|
attention_mask |
Input tensor of shape (batch_size, seq_length) containing the attention mask values. If None, initialized with ones tensor of shape (batch_size, seq_length + past_key_values_length) where past_key_values_length is the length of past_key_values. Default: None.
TYPE:
|
head_mask |
Input tensor of shape (n_layer, num_heads) containing the mask values for each head in each layer. If None, initialized with None. Default: None.
TYPE:
|
inputs_embeds |
Input tensor of shape (batch_size, seq_length, hidden_size) containing the embedded input tokens. If None, initialized with the embeddings of input_ids. Default: None.
TYPE:
|
use_cache |
Whether to use past_key_values for faster decoding. If None, initialized with the value from the model config. Default: None.
TYPE:
|
output_attentions |
Whether to return the attentions tensors of all attention layers. If None, initialized with the value from the model config. Default: None.
TYPE:
|
output_hidden_states |
Whether to return the hidden states tensors of all layers. If None, initialized with the value from the model config. Default: None.
TYPE:
|
return_dict |
Whether to return a BaseModelOutputWithPastAndCrossAttentions object as the output instead of a tuple. If None, initialized with the value from the model config. Default: None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor, ...], BaseModelOutputWithPastAndCrossAttentions]
|
Union[Tuple[mindspore.Tensor, ...], BaseModelOutputWithPastAndCrossAttentions]: A tuple of the following tensors depending on the value of 'return_dict':
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both input_ids and inputs_embeds are provided or neither of them are provided, or if there are any unexpected arguments passed in. |
FutureWarning
|
If position_ids argument is provided (now deprecated), a warning is issued indicating that it has no functionality in BLOOM and will be removed in v5.0.0. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel.get_input_embeddings()
¶
Returns the input embeddings of the BloomModel.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the BloomModel class.
|
RETURNS | DESCRIPTION |
---|---|
Returns the word embeddings of the input tokens. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomModel.set_input_embeddings(new_embeddings)
¶
Sets the input embeddings for the BloomModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the BloomModel class.
TYPE:
|
new_embeddings |
The new embeddings to set as input. It should be a tensor representing the word embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
This method sets the word_embeddings attribute of the BloomModel instance to the provided new_embeddings. The word_embeddings attribute is used as input for the model during forward propagation.
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomPreTrainedModel
¶
Bases: PreTrainedModel
BloomPreTrainedModel is a Python class that extends the functionality of PreTrainedModel. It provides methods for initializing weights and converting cache formats to be compatible with the Bloom model. The class includes functions for initializing weights based on the type of neural network cell and for standardizing or converting cache formats to match specific implementations. Utilize this class to facilitate pre-training tasks in NLP models with MindSpore framework.
Source code in mindnlp/transformers/models/bloom/modeling_bloom.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 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForSequenceClassification
¶
Bases: BloomPreTrainedModel
The 'BloomForSequenceClassification' class represents a fine-tuned sequence classification model based on the Bloom architecture. This class inherits from the 'BloomPreTrainedModel' and includes methods for model initialization and inference. It provides functionality for computing sequence classification/regression loss and handling batch processing. The class also supports different problem types such as regression, single-label classification, and multi-label classification.
The class includes the 'forward' method for generating model outputs and computing loss based on the input data. It also handles deprecated arguments and provides warnings for functionality that will be removed in future versions. Additionally, the method supports the use of padding tokens and provides appropriate error handling for different scenarios.
The 'BloomForSequenceClassification' class is designed to be used for sequence classification tasks and provides flexibility in handling various types of input data and problem types.
For detailed information on the methods and parameters of this class, please refer to the method docstrings and the class code.
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 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 1267 1268 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForSequenceClassification.__init__(config)
¶
Initializes an instance of the BloomForSequenceClassification class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the class.
|
config |
The configuration object for the BloomForSequenceClassification model. It contains various settings and hyperparameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
|
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)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 1267 1268 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForTokenClassification
¶
Bases: BloomPreTrainedModel
The BloomForTokenClassification
class is a Python class that represents a model for token classification using
the BLOOM architecture. This class inherits from the BloomPreTrainedModel
class.
Class Attributes:
num_labels
: The number of labels for the token classification task.transformer
: An instance of theBloomModel
class that represents the BLOOM transformer model.dropout
: An instance of theDropout
class from thenn
module for applying dropout regularization.classifier
: An instance of theDense
class from thenn
module for the final classification layer.
METHOD | DESCRIPTION |
---|---|
`__init__` |
Initializes a new instance of the |
`forward` |
Constructs the BLOOM model for token classification. It takes various input tensors and arguments and returns the model output. Parameters:
Returns:
|
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 1344 1345 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 1395 1396 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForTokenClassification.__init__(config)
¶
Initializes an instance of BloomForTokenClassification.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing settings for the model. It must be an instance of BloomConfig class. This parameter is required.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not an instance of BloomConfig. |
AttributeError
|
If the config object does not contain the required attributes. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
1340 1341 1342 1343 1344 1345 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 |
|
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)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 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 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForQuestionAnswering
¶
Bases: BloomPreTrainedModel
This class represents a Bloom model for question answering tasks. It is a subclass of BloomPreTrainedModel, which provides the basic structure and functionality for pre-trained models. The BloomForQuestionAnswering class includes methods for model forwardion and inference.
ATTRIBUTE | DESCRIPTION |
---|---|
transformer |
An instance of the BloomModel class, which is responsible for the main transformer architecture of the model.
|
qa_outputs |
A neural network layer that takes the output of the transformer and produces logits for start and end positions of the answer span.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the BloomForQuestionAnswering instance with a given configuration. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
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 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 |
|
mindnlp.transformers.models.bloom.modeling_bloom.BloomForQuestionAnswering.__init__(config)
¶
Initializes the BloomForQuestionAnswering class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
A dictionary containing the configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/bloom/modeling_bloom.py
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 |
|
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)
¶
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/bloom/modeling_bloom.py
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 |
|
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 |
|