cpmant
mindnlp.transformers.models.cpmant.configuration_cpmant
¶
CPMAnt model configuration
mindnlp.transformers.models.cpmant.configuration_cpmant.CpmAntConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [CpmAntModel
]. It is used to instantiate an
CPMAnt 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 CPMAnt
openbmb/cpm-ant-10b 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 CPMAnt model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size |
Dimension of the encoder layers.
TYPE:
|
num_attention_heads |
Number of attention heads in the Transformer encoder.
TYPE:
|
dim_head |
Dimension of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
dim_ff |
Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
num_hidden_layers |
Number of layers of the Transformer encoder.
TYPE:
|
dropout_p |
The dropout probability for all fully connected layers in the embeddings, encoder.
TYPE:
|
position_bias_num_buckets |
The number of position_bias buckets.
TYPE:
|
position_bias_max_distance |
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:
|
eps |
The epsilon used by the layer normalization layers.
TYPE:
|
init_std |
Initialize parameters with std = init_std.
TYPE:
|
prompt_types |
The type of prompt.
TYPE:
|
prompt_length |
The length of prompt.
TYPE:
|
segment_types |
The type of segment.
TYPE:
|
use_cache |
Whether to use cache.
TYPE:
|
Example
>>> from transformers import CpmAntModel, CpmAntConfig
...
>>> # Initializing a CPMAnt cpm-ant-10b style configuration
>>> configuration = CpmAntConfig()
...
>>> # Initializing a model from the cpm-ant-10b style configuration
>>> model = CpmAntModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/cpmant/configuration_cpmant.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 |
|
mindnlp.transformers.models.cpmant.configuration_cpmant.CpmAntConfig.__init__(vocab_size=30720, hidden_size=4096, num_attention_heads=32, dim_head=128, dim_ff=10240, num_hidden_layers=48, dropout_p=0.0, position_bias_num_buckets=512, position_bias_max_distance=2048, eps=1e-06, init_std=1.0, prompt_types=32, prompt_length=32, segment_types=32, use_cache=True, **kwargs)
¶
Initializes an instance of the CpmAntConfig class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntConfig class.
TYPE:
|
vocab_size |
The size of the vocabulary. Defaults to 30720.
TYPE:
|
hidden_size |
The size of the hidden state. Defaults to 4096.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 32.
TYPE:
|
dim_head |
The dimension of each attention head. Defaults to 128.
TYPE:
|
dim_ff |
The dimension of the feed-forward layer. Defaults to 10240.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 48.
TYPE:
|
dropout_p |
The dropout rate. Defaults to 0.0.
TYPE:
|
position_bias_num_buckets |
The number of buckets for position bias. Defaults to 512.
TYPE:
|
position_bias_max_distance |
The maximum distance for position bias. Defaults to 2048.
TYPE:
|
eps |
The epsilon value for numerical stability. Defaults to 1e-06.
TYPE:
|
init_std |
The standard deviation for weight initialization. Defaults to 1.0.
TYPE:
|
prompt_types |
The number of prompt types. Defaults to 32.
TYPE:
|
prompt_length |
The length of the prompt. Defaults to 32.
TYPE:
|
segment_types |
The number of segment types. Defaults to 32.
TYPE:
|
use_cache |
Whether to use cache. Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/configuration_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant
¶
Tokenization classes for CPMAnt.
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer
¶
Bases: PreTrainedTokenizer
Construct a CPMAnt tokenizer. Based on byte-level Byte-Pair-Encoding.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
bod_token |
The beginning of document token.
TYPE:
|
eod_token |
The end of document token.
TYPE:
|
bos_token |
The beginning of sequence token.
TYPE:
|
eos_token |
The end of sequence token.
TYPE:
|
pad_token |
The token used for padding.
TYPE:
|
unk_token |
The unknown token.
TYPE:
|
line_token |
The line token.
TYPE:
|
space_token |
The space token.
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.bod_token_id
property
¶
This method, 'bod_token_id', is a property method defined in the 'CpmAntTokenizer' class. It takes no external parameters and returns the token ID associated with the 'bod_token'.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.eod_token_id
property
¶
This method 'eod_token_id' in the class 'CpmAntTokenizer' retrieves the token ID of the end-of-document token.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the class CpmAntTokenizer. It is required as this method is part of the class and needs access to its attributes and methods.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns a value of type None. It retrieves the token ID of the end-of-document token from the encoder attribute of the class instance. |
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.newline_id
property
¶
This method, newline_id, in the class CpmAntTokenizer, returns the value associated with the newline character in the encoder.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the newline character |
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.vocab_size: int
property
¶
Returns the size of the vocabulary used by the CpmAntTokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The CpmAntTokenizer instance itself.
|
RETURNS | DESCRIPTION |
---|---|
int
|
The number of unique tokens in the vocabulary.
TYPE:
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.__init__(vocab_file, bod_token='<d>', eod_token='</d>', bos_token='<s>', eos_token='</s>', pad_token='<pad>', unk_token='<unk>', line_token='</n>', space_token='</_>', padding_side='left', **kwargs)
¶
Initialize a CpmAntTokenizer object with the provided parameters.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
The path to the vocabulary file to load.
TYPE:
|
bod_token |
Beginning of document token (default is '
TYPE:
|
eod_token |
End of document token (default is '').
TYPE:
|
bos_token |
Beginning of sentence token (default is '
TYPE:
|
eos_token |
End of sentence token (default is '').
TYPE:
|
pad_token |
Padding token (default is '
TYPE:
|
unk_token |
Token for unknown words (default is '
TYPE:
|
line_token |
Line break token (default is '').
TYPE:
|
space_token |
Space token (default is '</_>').
TYPE:
|
padding_side |
Side for padding (default is 'left').
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
MissingBackendError
|
If required backend 'jieba' is not available. |
FileNotFoundError
|
If the specified 'vocab_file' does not exist. |
KeyError
|
If 'space_token' or 'line_token' are missing in the loaded vocabulary. |
Exception
|
Any other unforeseen error that may occur during initialization. |
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.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 CPMAnt sequence has the following format:
- single sequence:
[BOS] Sequence
.
PARAMETER | DESCRIPTION |
---|---|
token_ids_0 |
The first tokenized sequence that special tokens will be added.
TYPE:
|
token_ids_1 |
The optional second tokenized sequence that special tokens will be added.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.check(token)
¶
Check if a token is present in the encoder of the CpmAntTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntTokenizer class.
TYPE:
|
token |
The token to be checked.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.convert_tokens_to_string(tokens)
¶
Converts a list of tokens into a string representation.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntTokenizer class.
TYPE:
|
tokens |
A list of tokens to be converted into a string representation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of the tokens.
TYPE:
|
Note
- The tokens should be provided as a list of strings.
- The method will join the tokens together using an empty string as a separator.
Example
>>> tokenizer = CpmAntTokenizer()
>>> tokens = ['Hello', 'world', '!']
>>> tokenizer.convert_tokens_to_string(tokens)
'Hello world!'
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.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/cpmant/tokenization_cpmant.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.get_vocab()
¶
Retrieves the vocabulary of the CpmAntTokenizer instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of CpmAntTokenizer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
The vocabulary of the tokenizer, which is a dictionary mapping tokens to their corresponding IDs. |
Example
>>> tokenizer = CpmAntTokenizer()
>>> vocab = tokenizer.get_vocab()
>>> vocab
{'<pad>': 0, '<unk>': 1, '<s>': 2, '</s>': 3, ...}
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.CpmAntTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to a file with the specified directory and filename prefix.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the CpmAntTokenizer class.
|
save_directory |
The directory where the vocabulary file will be saved.
TYPE:
|
filename_prefix |
A string to be prefixed to the filename. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the path to the saved vocabulary file. |
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.WordpieceTokenizer
¶
The WordpieceTokenizer class represents a tokenizer that tokenizes input text into subword tokens using the WordPiece algorithm.
ATTRIBUTE | DESCRIPTION |
---|---|
vocab |
A dictionary containing the vocabulary of subword tokens.
TYPE:
|
unk_token |
The token to be used for out-of-vocabulary or unknown words.
TYPE:
|
max_input_chars_per_word |
The maximum number of input characters per word for tokenization.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
tokenize |
Tokenizes the input token into subword tokens using the WordPiece algorithm and the specified vocabulary. |
Example
>>> vocab = {'hello': 'he', 'world': 'wo', 'hello,': 'hello'}
>>> tokenizer = WordpieceTokenizer(vocab, '<unk>', 200)
>>> tokenized_text = tokenizer.tokenize('helloworld')
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.WordpieceTokenizer.__init__(vocab, unk_token='<unk>', max_input_chars_per_word=200)
¶
Initializes a new instance of the WordpieceTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the WordpieceTokenizer class.
TYPE:
|
vocab |
A list of strings representing the vocabulary for the tokenizer.
TYPE:
|
unk_token |
The token to use for unknown words. Defaults to '
TYPE:
|
max_input_chars_per_word |
The maximum number of characters allowed per word. Defaults to 200.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
This method initializes the WordpieceTokenizer object with the provided vocabulary, unknown token, and maximum input characters per word.
The vocabulary is a list of strings that represents the set of tokens used by the tokenizer.
The unk_token parameter allows customization of the token used to represent unknown words. If not provided, it defaults to '
Example
>>> tokenizer = WordpieceTokenizer(vocab=['hello', 'world'], unk_token='<unk>', max_input_chars_per_word=200)
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.WordpieceTokenizer.tokenize(token)
¶
This method tokenizes a given input token into sub-tokens based on the vocabulary of the WordpieceTokenizer class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the WordpieceTokenizer class. It is used to access the vocabulary and maximum input characters per word.
TYPE:
|
token |
The input token to be tokenized. It represents the word to be broken down into sub-tokens. Must be a string.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
A list of sub-tokens generated from the input token based on the vocabulary. If the length of the input token exceeds the maximum allowed characters per word, it returns a list containing the unknown token (unk_token). Otherwise, it returns a list of sub-tokens that are part of the vocabulary or the unknown token. |
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.tokenization_cpmant.load_vocab(vocab_file)
¶
Loads a vocabulary file into a dictionary.
Source code in mindnlp/transformers/models/cpmant/tokenization_cpmant.py
45 46 47 48 49 50 51 52 53 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant
¶
MindSpore CPMAnt
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntAttention
¶
Bases: Module
This class represents the CpmAntAttention module, which is a component of the CpmAnt model. It performs the self-attention mechanism in the transformer block.
The CpmAntAttention module inherits from the nn.Module class and initializes with a config object of type CpmAntConfig.
ATTRIBUTE | DESCRIPTION |
---|---|
dim_model |
The hidden size of the model.
TYPE:
|
num_heads |
The number of attention heads.
TYPE:
|
dim_head |
The dimension of each attention head.
TYPE:
|
project_q |
The linear transformation layer for query projection.
TYPE:
|
project_k |
The linear transformation layer for key projection.
TYPE:
|
project_v |
The linear transformation layer for value projection.
TYPE:
|
attention_out |
The linear transformation layer for output projection.
TYPE:
|
softmax |
The softmax activation function for attention scores.
TYPE:
|
dropout |
The dropout layer, if configured.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Constructs the self-attention block of the transformer. Args:
Returns:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntAttention.__init__(config)
¶
Initializes an instance of CpmAntAttention.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of CpmAntConfig containing configuration parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method initializes the CpmAntAttention instance with the provided configuration parameters. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntAttention.forward(hidden_q, hidden_kv, attention_mask, position_bias, output_attentions=False, past_key_values=None, use_cache=None)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_q |
Input of transformer block(self-attention block). It can be the raw embedding of a batch of sequences.
TYPE:
|
hidden_kv |
Tensor key_value and query of shape
TYPE:
|
attention_mask |
Avoid invalid areas to participate in the calculation of self-attention.
TYPE:
|
position_bias |
Provide positional information to self-attention block.
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
past_key_values |
Cached past key and value projection states.
TYPE:
|
use_cache |
If set to
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntDenseGatedACT
¶
Bases: Module
A class representing a dense gated activation layer for neural networks in the CPM-ANT model.
This class inherits from nn.Module and provides functionality to transform an input tensor from one feature space to another via a nonlinear operation. The transformation is performed using two dense layers with gated activation.
ATTRIBUTE | DESCRIPTION |
---|---|
w_0 |
The first dense layer for the transformation.
TYPE:
|
w_1 |
The second dense layer for the transformation.
TYPE:
|
act |
The activation function to apply.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntDenseGatedACT instance. |
forward |
Transforms an input tensor using the dense gated activation. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntDenseGatedACT.__init__(config)
¶
Initializes an instance of the CpmAntDenseGatedACT class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object that contains the required parameters for initialization.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntDenseGatedACT.forward(hidden_states)
¶
Transform an input tensor from one feature space to another via a nonlinear operation
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
386 387 388 389 390 391 392 393 394 395 396 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntEncoder
¶
Bases: Module
The CpmAntEncoder class represents a transformer encoder for the CpmAntConfig model. It inherits from nn.Module and contains methods for initializing the encoder and forwarding the encoder layers.
The init method initializes the CpmAntEncoder with the provided CpmAntConfig, setting the number of layers and creating a list of transformer blocks for the encoder.
The forward method takes input hidden_states, attention_mask, position_bias, and optional parameters to perform the encoding process. It iterates through the encoder layers, applying the attention mechanism and caching key and value projection states if specified. The method returns the final hidden_states, current_key_values, hidden_states of all layers, and attention weights of all layers as per the specified optional outputs.
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input to the layer of shape (batch, seq_len, dim_model)
TYPE:
|
attention_mask |
Avoid invalid areas to participate in the calculation of shape (batch, seq_len, seq_len)
TYPE:
|
position_bias |
Provides position information to attention mechanism of shape (num_heads, seq_len, seq_len)
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers.
TYPE:
|
past_key_values |
Cached past key and value projection states
TYPE:
|
use_cache |
If set to True, past_key_values key value states are returned and can be used to speed up decoding (see past_key_values).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
Tuple of mindspore.Tensor, Tuple of mindspore.Tensor, Optional[Tuple[mindspore.Tensor]], Optional[Tuple[mindspore.Tensor]]:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntEncoder.__init__(config)
¶
Initializes a new instance of the CpmAntEncoder class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object for the encoder.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntEncoder.forward(hidden_states, attention_mask, position_bias, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input to the layer of shape
TYPE:
|
attention_mask |
Avoid invalid areas to participate in the calculation of shape
TYPE:
|
position_bias |
Provides position information to attention mechanism of shape
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers.
TYPE:
|
past_key_values |
Cached past key and value projection states
TYPE:
|
use_cache |
If set to
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFFNBlock
¶
Bases: Module
This class represents a feed-forward neural network block used in the CpmAnt model. It is a sub-module of the CpmAnt model and is responsible for applying feed-forward operations to the input hidden states.
The CpmAntFFNBlock class inherits from the nn.Module class, which is a base class for neural network cells in the MindSpore framework.
ATTRIBUTE | DESCRIPTION |
---|---|
layernorm_before_ffn |
An instance of the CpmAntLayerNorm class used for layer normalization before the feed-forward operation.
TYPE:
|
ffn |
An instance of the CpmAntFeedForward class responsible for the actual feed-forward operation.
TYPE:
|
dropout |
An instance of the nn.Dropout class used for applying dropout regularization, if configured. If dropout probability is not specified, it is set to None.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
forward |
Applies the feed-forward operations to the input hidden states and returns the updated hidden states. Args:
Returns:
|
Note
The CpmAntFFNBlock class is typically used as a building block within the CpmAnt model to process intermediate hidden states. It performs layer normalization, feed-forward operations, and optionally applies dropout regularization.
Example
>>> config = CpmAntConfig()
>>> ffn_block = CpmAntFFNBlock(config)
>>> hidden_states = mindspore.Tensor(np.random.randn(batch, len_seq, dim_model), dtype=mindspore.float32)
>>> updated_hidden_states = ffn_block.forward(hidden_states)
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFFNBlock.__init__(config)
¶
Initializes a new instance of the CpmAntFFNBlock class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object for the CpmAntFFNBlock. It contains the parameters and settings for the block.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFFNBlock.forward(hidden_states)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Hidden states before feed forward layer.
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFeedForward
¶
Bases: Module
CpmAntFeedForward represents a feedforward neural network component designed for the CpmAnt model architecture. This class inherits from nn.Module and is used for processing hidden states through a series of transformations.
ATTRIBUTE | DESCRIPTION |
---|---|
w_in |
The first layer of the feedforward network for processing input hidden states.
TYPE:
|
dropout |
Dropout layer for regularization, initialized based on the configuration parameter.
TYPE:
|
w_out |
The output layer of the feedforward network for producing final hidden states.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Constructor method for initializing the CpmAntFeedForward instance with the given configuration. |
forward |
Method for processing the input hidden states through the network layers. |
PARAMETER | DESCRIPTION |
---|---|
config |
Configuration object containing settings for the feedforward network.
TYPE:
|
hidden_states |
Input tensor representing hidden states with shape (batch, seq_len, dim_in).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mindspore.Tensor: Output tensor containing the processed hidden states after passing through the feedforward network. |
Usage
Instantiate an object of CpmAntFeedForward with a CpmAntConfig object and then call the forward method with input hidden_states to obtain the processed output hidden states.
Note
- The dropout layer is optional based on the dropout probability specified in the configuration.
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFeedForward.__init__(config)
¶
Initializes an instance of the CpmAntFeedForward class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object of type CpmAntConfig containing configuration parameters. This parameter is required for configuring the feed-forward network. It should be an instance of CpmAntConfig class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFeedForward.forward(hidden_states)
¶
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM
¶
Bases: CpmAntPreTrainedModel
CpmAntForCausalLM is a class representing a Causal Language Model based on the CPMAnt model for text generation tasks. This class extends the functionality of CpmAntPreTrainedModel and provides methods for model initialization, text generation, and handling embeddings.
The CpmAntForCausalLM class includes methods for model initialization, generating text based on input sequences, accessing and setting input and output embeddings, preparing inputs for text generation, and reordering cache for beam search decoding.
Example
Text Generation with CpmAntForCausalLM:
>>> from transformers import CPMAntTokenizer, CpmAntForCausalLM
...
>>> texts = "Today is a beautiful day, "
>>> model = CpmAntForCausalLM.from_pretrained("openbmb/cpm-ant-10b")
>>> tokenizer = CPMAntTokenizer.from_pretrained("openbmb/cpm-ant-10b")
>>> input_ids = tokenizer(texts, return_tensors="pt")
>>> outputs = model.generate(**input_ids)
>>> output_texts = tokenizer.batch_decode(outputs)
>>> print(output_texts)
['Today is a beautiful day, the sun is shining, and the birds are singing.']
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntForCausalLM model with the provided configuration. |
forward |
Constructs the model for text generation based on the input arguments and returns output in the specified format. |
get_input_embeddings |
Retrieves the input embeddings of the model. |
set_input_embeddings |
Sets new input embeddings for the model. |
get_output_embeddings |
Retrieves the output embeddings of the model. |
set_output_embeddings |
Sets new output embeddings for the model. |
prepare_inputs_for_generation |
Prepares inputs for text generation based on the provided input_ids and keyword arguments. |
_reorder_cache |
Reorders the cache for beam search decoding. |
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary.
TYPE:
|
past_key_values |
Pre-computed hidden states for sequential decoding.
TYPE:
|
use_cache |
Flag to determine if cache should be used for decoding.
TYPE:
|
output_attentions |
Flag to include attention tensors in the output.
TYPE:
|
output_hidden_states |
Flag to include hidden states of all layers in the output.
TYPE:
|
labels |
Labels for computing the masked language modeling loss.
TYPE:
|
return_dict |
Flag to determine the format of the output.
TYPE:
|
attention_mask |
Dummy parameter for text-generation pipeline.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple, CausalLMOutputWithPast]: Tuple or CausalLMOutputWithPast object containing model outputs and past key values. |
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
If a method is not implemented in the subclass. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 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 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.__init__(config)
¶
Initializes an instance of the CpmAntForCausalLM class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object for the CpmAnt model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.forward(input_ids=None, past_key_values=None, use_cache=None, output_attentions=None, output_hidden_states=None, labels=None, return_dict=None, attention_mask=None, **kwargs)
¶
PARAMETER | DESCRIPTION |
---|---|
input_ids |
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [
TYPE:
|
past_key_values |
Contains pre-computed hidden-states (key and values in the self-attention blocks and in the
cross-attention blocks) that can be used (see
TYPE:
|
use_cache |
If set to
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
output_hidden_states |
Whether or not to return the hidden states of all layers.
TYPE:
|
labels |
Labels for computing the masked language modeling loss.
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
attention_mask |
CPMAnt will process attention mask automatically, this parameter is a dummy parameter for text-generation pipeline.
TYPE:
|
Example
Text Generation with CpmAntForCausalLM.
>>> from transformers import CPMAntTokenizer, CpmAntForCausalLM
...
>>> texts = "今天天气不错,"
>>> model = CpmAntForCausalLM.from_pretrained("openbmb/cpm-ant-10b")
>>> tokenizer = CPMAntTokenizer.from_pretrained("openbmb/cpm-ant-10b")
>>> input_ids = tokenizer(texts, return_tensors="pt")
>>> outputs = model.generate(**input_ids)
>>> output_texts = tokenizer.batch_decode(outputs)
>>> print(output_texts)
['今天天气不错,阳光明媚,我和妈妈一起去超市买东西。\n在超市里,我看到了一个很好玩的玩具,它的名字叫“机器人”。它有一个圆圆的脑袋,两只圆圆的眼睛,还有一个圆圆的']
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.get_input_embeddings()
¶
Retrieve the input embeddings used by the CpmAntForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntForCausalLM class. This parameter is required to access the input embeddings specific to this instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the input embeddings associated with the CpmAntForCausalLM model. The input embeddings are used for processing input data within the model. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.get_output_embeddings()
¶
Retrieves the output embeddings of the language model head.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntForCausalLM class.
|
RETURNS | DESCRIPTION |
---|---|
lm_head
|
The method returns the output embeddings of the language model head. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.prepare_inputs_for_generation(input_ids, **kwargs)
¶
Prepare inputs for generation.
This method takes in two parameters: self and input_ids. It modifies the input_ids and returns a dictionary containing the modified input_ids, use_cache, and past_key_values.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntForCausalLM class.
|
input_ids |
The input tensor containing the tokenized input sequence.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary with the following keys:
|
Note
- The input_ids parameter is cast to int.
- If the 'attention_mask' key is present in kwargs, its value is replaced with a zero tensor of shape (1, 1).
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.set_input_embeddings(embeddings)
¶
Set the input embeddings for the CpmAntForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntForCausalLM class.
TYPE:
|
embeddings |
The input embeddings to be set for the model. This parameter should be a valid embeddings object that can be assigned to the input_embedding attribute of the CpmAntForCausalLM instance.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings of the CpmAntForCausalLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntForCausalLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set as the output embeddings of the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
This method sets the output embeddings of the CpmAntForCausalLM model to the provided new embeddings. The new embeddings should be an instance of torch.nn.Module.
Example
>>> model = CpmAntForCausalLM()
>>> new_embeddings = nn.Embedding(1000, 768)
>>> model.set_output_embeddings(new_embeddings)
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntIntermediate
¶
Bases: Module
The CpmAntIntermediate class represents an intermediate layer for the CpmAnt model. This class inherits from nn.Module and is used to perform operations on hidden states, including dense transformations and activation functions.
ATTRIBUTE | DESCRIPTION |
---|---|
dense |
A dense layer used for transforming hidden states.
TYPE:
|
intermediate_act_fn |
The activation function applied to the hidden states.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntIntermediate instance with the provided configuration. |
forward |
Applies dense transformation and activation function to the input hidden states. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntIntermediate.__init__(config)
¶
Initializes an instance of the CpmAntIntermediate class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntIntermediate class.
|
config |
An object of type 'config' containing the configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntIntermediate.forward(hidden_states)
¶
Docstring for method 'forward' in class 'CpmAntIntermediate':
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class CpmAntIntermediate.
TYPE:
|
hidden_states |
A tensor containing the hidden states data to be processed. It should be compatible with the operations performed by the method.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: A tensor representing the processed hidden states data. This tensor is the result of applying the dense layer and intermediate activation function. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntLayerNorm
¶
Bases: Module
We use Root Mean Square (RMS) Layer Normalization, please see https://arxiv.org/abs/1910.07467 for details."
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntLayerNorm.__init__(config)
¶
Initializes a new instance of the CpmAntLayerNorm class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object that the method belongs to.
|
config |
The configuration object used to initialize the instance. The config parameter is of type CpmAntConfig and is required to initialize the instance. It contains the following attributes:
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntLayerNorm.forward(hidden_states)
¶
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
76 77 78 79 80 81 82 83 84 85 86 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntModel
¶
Bases: CpmAntPreTrainedModel
CpmAntModel is a class that represents a model for CPM-ANT (Antecedent-Conditioned Prompting) tasks. It inherits from CpmAntPreTrainedModel and includes methods for initializing the model, preparing attention masks, and forwarding the model output based on input tensors.
ATTRIBUTE | DESCRIPTION |
---|---|
encoder |
CpmAntEncoder object for encoding input data
|
segment_embedding |
nn.Embedding object for segment embeddings
|
input_embedding |
nn.Embedding object for input embeddings
|
position_bias |
CpmAntSegmentPositionEmbedding object for position bias calculations
|
prompt_length |
Length of the prompt in the input data
|
vocab_size |
Size of the vocabulary in the input data
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the model with the given configuration |
get_input_embeddings |
Returns the input embeddings |
set_input_embeddings |
Sets the input embeddings to the given value |
_prepare_attention_mask |
Prepares the attention mask for the input data |
forward |
Constructs the model output based on input tensors and optional configurations |
This class provides functionality for processing input data, calculating attention masks, and generating model outputs for CPM-ANT tasks.
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 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 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntModel.__init__(config)
¶
Initializes a new instance of the CpmAntModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance itself.
|
config |
An instance of CpmAntConfig containing configuration parameters for the model. It specifies the configuration settings required for initializing the model. This parameter is mandatory and must be an instance of CpmAntConfig.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntModel.forward(input_ids=None, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None, return_dict=None, **kwargs)
¶
Constructs the CpmAntModel.
This method initializes and forwards the CpmAntModel. It takes the following parameters:
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
input_ids |
The input tensor of shape [batch_size, seq_length]. It represents the input IDs for the model. Defaults to None.
TYPE:
|
output_attentions |
Whether to output attentions. If set to True, the attentions will be returned. Defaults to None.
TYPE:
|
output_hidden_states |
Whether to output hidden states. If set to True, the hidden states will be returned. Defaults to None.
TYPE:
|
past_key_values |
The past key values. Defaults to None.
TYPE:
|
use_cache |
Whether to use cache. Defaults to None.
TYPE:
|
return_dict |
Whether to return the output as a dictionary. If set to True, the output will be returned as a dictionary. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], BaseModelOutputWithPast]
|
Union[Tuple[mindspore.Tensor], BaseModelOutputWithPast]: The output of the model.
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntModel.get_input_embeddings()
¶
Retrieve the input embeddings from the CpmAntModel.
PARAMETER | DESCRIPTION |
---|---|
self |
CpmAntModel - The instance of the CpmAntModel class.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method returns the input embeddings as an instance of the input_embedding attribute from the CpmAntModel. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntModel.set_input_embeddings(embeddings, **kwargs)
¶
Method to set input embeddings for the CpmAntModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntModel class.
TYPE:
|
embeddings |
The input embeddings to be set for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntOutput
¶
Bases: Module
CpmAntOutput represents a custom module for processing hidden states and input tensors in a CpmAnt model.
This class inherits from nn.Module and includes methods for initializing the module and forwarding the output tensor.
ATTRIBUTE | DESCRIPTION |
---|---|
dense |
A dense layer for processing hidden states.
TYPE:
|
LayerNorm |
A layer normalization module for normalizing hidden states.
TYPE:
|
dropout |
A dropout module for applying dropout to hidden states.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntOutput module with the provided configuration. |
forward |
Constructs the output tensor based on the given hidden states and input tensor. |
Example
>>> config = Config(intermediate_size=256, hidden_size=512, layer_norm_eps=1e-6)
>>> model = CpmAntOutput(config)
>>> output = model.forward(hidden_states, input_tensor)
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntOutput.__init__(config)
¶
Initializes a new instance of the CpmAntOutput class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
config |
An instance of the configuration class containing the model configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntOutput.forward(hidden_states, input_tensor)
¶
Constructs the CpmAntOutput by processing the given hidden states and input tensor.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntOutput class.
TYPE:
|
hidden_states |
A tensor containing the hidden states. Shape: (batch_size, sequence_length, hidden_size) The hidden states represent the intermediate outputs of the model.
TYPE:
|
input_tensor |
A tensor containing the input values. Shape: (batch_size, sequence_length, hidden_size) The input tensor is added to the hidden states after passing through the dense, dropout, and LayerNorm layers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: A tensor representing the processed hidden states. Shape: (batch_size, sequence_length, hidden_size) The processed hidden states are obtained by passing the hidden states through the dense, dropout, and LayerNorm layers, and then adding the input tensor. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntPreTrainedModel
¶
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/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSegmentPositionEmbedding
¶
Bases: Module
This class represents a segment position embedding module for the CPM-ANT model. It is used to generate embeddings that encode the relative positions of segments in the input tensors.
The class inherits from the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
num_heads |
The number of attention heads in the model.
TYPE:
|
num_buckets |
The number of buckets used for segment relative positions.
TYPE:
|
max_distance |
The maximum distance allowed for segment relative positions.
TYPE:
|
num_segments |
The number of segment types in the model.
TYPE:
|
relative_attention_bias |
The parameter used to compute the relative attention bias.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntSegmentPositionEmbedding instance with the provided configuration. |
forward |
Constructs the segment position embeddings based on the input key and query positions and segments. |
_segment_relative_position_bucket |
Computes the segment relative position bucket. |
_position_bucket |
Computes the position bucket. |
Detailed Description
The CpmAntSegmentPositionEmbedding class is used to compute segment position embeddings for the CPM-ANT model. These embeddings encode the relative positions between different segments in the input tensors.
The class takes a configuration object (CpmAntConfig) as input during initialization. This configuration object contains various parameters such as the number of attention heads, the number of buckets for segment relative positions, the maximum distance allowed for segment relative positions, and the number of segment types in the model.
The forward method is the main function of this class. It takes four input tensors: key_pos, query_pos, key_segment, and query_segment. These tensors represent the positions and segments of the key and query elements. The method checks the shapes of the input tensors and raises an AssertionError if they are not compatible. It then performs various operations to compute the relative position bucket and the position bucket. Finally, it uses the computed embeddings to generate the segment position embeddings.
The _segment_relative_position_bucket method computes the segment relative position bucket based on the query and key segments.
The _position_bucket method computes the position bucket based on the relative position, the number of buckets, and the maximum distance.
Note
This class assumes the availability of the following modules: mindspore, math.
Example
>>> config = CpmAntConfig()
>>> segment_embedding = CpmAntSegmentPositionEmbedding(config)
>>> key_pos = mindspore.Tensor(...)
>>> query_pos = mindspore.Tensor(...)
>>> key_segment = mindspore.Tensor(...)
>>> query_segment = mindspore.Tensor(...)
>>> embeddings = segment_embedding.forward(key_pos, query_pos, key_segment, query_segment)
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSegmentPositionEmbedding.__init__(config)
¶
Initializes an instance of the CpmAntSegmentPositionEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing the parameters for the segment position embedding.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSegmentPositionEmbedding.forward(key_pos, query_pos, key_segment, query_segment)
¶
Constructs the segment position embedding for the CpmAntSegmentPositionEmbedding class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the CpmAntSegmentPositionEmbedding class.
|
key_pos |
A tensor representing the positions of the keys. Its shape is (batch, keylen).
TYPE:
|
query_pos |
A tensor representing the positions of the queries. Its shape is (batch, querylen).
TYPE:
|
key_segment |
A tensor representing the segments of the keys. Its shape is (batch, keylen).
TYPE:
|
query_segment |
A tensor representing the segments of the queries. Its shape is (batch, querylen).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If key_pos.shape[0] is not equal to query_pos.shape[0]. |
AssertionError
|
If keylen is not equal to key_segment.shape[1] or querylen is not equal to query_segment.shape[1]. |
AssertionError
|
If querylen is not equal to query_segment.shape[1]. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 952 953 954 955 956 957 958 959 960 961 962 963 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSelfAttentionBlock
¶
Bases: Module
This class represents a self-attention block used in the CpmAnt model. It is a subclass of the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
layernorm_before_attention |
An instance of the CpmAntLayerNorm class that performs layer normalization before the self-attention operation.
TYPE:
|
self_attention |
An instance of the CpmAntAttention class that performs the self-attention operation.
TYPE:
|
dropout |
An optional dropout layer. If configured, it applies dropout to the outputs.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the CpmAntSelfAttentionBlock instance. Args:
|
forward |
Applies the self-attention block to the given hidden states. Args:
Returns:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSelfAttentionBlock.__init__(config)
¶
This method initializes a CpmAntSelfAttentionBlock instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the CpmAntSelfAttentionBlock class.
TYPE:
|
config |
The configuration object containing settings for the self-attention block.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSelfAttentionBlock.forward(hidden_states, attention_mask, position_bias=None, output_attentions=False, past_key_values=None, use_cache=None)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input of transformer block(self-attention block). It can be the raw embedding of a batch of sequences.
TYPE:
|
attention_mask |
Avoid invalid areas to participate in the calculation of self-attention.
TYPE:
|
position_bias |
Provide positional information to self-attention block.
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
past_key_values |
Cached past key and value projection states.
TYPE:
|
use_cache |
If set to
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntTransformerBlock
¶
Bases: Module
This class represents a block of the CpmAntTransformer model, which is a type of transformer used for natural language processing tasks. It inherits from the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
self_att |
The self-attention block of the transformer.
TYPE:
|
ffn |
The feed-forward neural network block of the transformer.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of the CpmAntTransformerBlock class. |
forward |
Constructs the transformer block. |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
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 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntTransformerBlock.__init__(config)
¶
Initializes a new instance of the CpmAntTransformerBlock class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the class.
|
config |
The configuration object for the transformer block.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntTransformerBlock.forward(hidden_states, attention_mask, position_bias=None, output_attentions=False, past_key_values=None, use_cache=None)
¶
PARAMETER | DESCRIPTION |
---|---|
hidden_states |
Input to the layer of shape
TYPE:
|
attention_mask |
Avoid invalid areas to participate in the calculation of shape
TYPE:
|
position_bias |
Provides position information to attention mechanism of shape
TYPE:
|
output_attentions |
Whether or not to return the attentions tensors of all attention layers.
TYPE:
|
past_key_values |
Cached past key and value projection states
TYPE:
|
use_cache |
If set to
TYPE:
|
Source code in mindnlp/transformers/models/cpmant/modeling_cpmant.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|