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
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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
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 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntDenseGatedACT
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
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
223 224 225 226 227 228 229 230 231 232 233 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntEncoder
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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
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 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFFNBlock
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFeedForward
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntFeedForward.forward(hidden_states)
¶
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
247 248 249 250 251 252 253 254 255 256 257 258 259 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntForCausalLM
¶
Bases: CpmAntPreTrainedModel
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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:
|
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
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 | |
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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntLayerNorm.forward(hidden_states)
¶
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
50 51 52 53 54 55 56 57 58 59 60 | |
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
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntSelfAttentionBlock
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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
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 | |
mindnlp.transformers.models.cpmant.modeling_cpmant.CpmAntTransformerBlock
¶
Bases: Module
Source code in mindnlp\transformers\models\cpmant\modeling_cpmant.py
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 | |
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
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 | |