cpmbee
mindnlp.transformers.models.cpmbee.configuration_cpmbee
¶
CpmBee model configuration
mindnlp.transformers.models.cpmbee.configuration_cpmbee.CpmBeeConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [CpmBeeModel]. It is used to instbeeiate an
CPMBee 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 CPMBee
openbmb/cpm-bee-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 CPMBee 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 probabilitiy for all fully connected layers in the embeddings, encoder.
TYPE:
|
position_bias_num_buckets
|
The number of position_bias buckets.
TYPE:
|
position_bias_num_segment_buckets
|
The number of segment 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:
|
use_cache
|
Whether to use cache.
TYPE:
|
distance_scale
|
Scale the rotary embedding.
TYPE:
|
mask_modules
|
Decides which feedforward block or attention block is pruned.
TYPE:
|
half
|
Decides the model parameters are half-precision or not.
TYPE:
|
Example
>>> from transformers import CpmBeeModel, CpmBeeConfig
...
>>> # Initializing a CPMBee cpm-bee-10b style configuration
>>> configuration = CpmBeeConfig()
...
>>> # Initializing a model from the cpm-bee-10b style configuration
>>> model = CpmBeeModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp\transformers\models\cpmbee\configuration_cpmbee.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
mindnlp.transformers.models.cpmbee.configuration_cpmbee.CpmBeeConfig.__init__(vocab_size=30720, hidden_size=4096, num_attention_heads=64, dim_head=64, dim_ff=10240, num_hidden_layers=32, dropout_p=0.0, position_bias_num_buckets=256, position_bias_num_segment_buckets=32, position_bias_max_distance=2048, eps=1e-06, init_std=1.0, use_cache=True, distance_scale=16, mask_modules=None, half=False, **kwargs)
¶
init
Initializes a CpmBeeConfig instance.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_size
|
The size of the vocabulary. Defaults to 30720.
TYPE:
|
hidden_size
|
The size of the hidden layers. Defaults to 4096.
TYPE:
|
num_attention_heads
|
The number of attention heads. Defaults to 64.
TYPE:
|
dim_head
|
The dimension of each attention head. Defaults to 64.
TYPE:
|
dim_ff
|
The dimension of the feed forward network. Defaults to 10240.
TYPE:
|
num_hidden_layers
|
The number of hidden layers. Defaults to 32.
TYPE:
|
dropout_p
|
The dropout probability. Defaults to 0.0.
TYPE:
|
position_bias_num_buckets
|
The number of buckets for position bias. Defaults to 256.
TYPE:
|
position_bias_num_segment_buckets
|
The number of segment buckets for position bias. Defaults to 32.
TYPE:
|
position_bias_max_distance
|
The maximum distance for position bias. Defaults to 2048.
TYPE:
|
eps
|
A small value to avoid division by zero. Defaults to 1e-06.
TYPE:
|
init_std
|
The standard deviation for weight initialization. Defaults to 1.0.
TYPE:
|
use_cache
|
Flag to indicate whether to use cache. Defaults to True.
TYPE:
|
distance_scale
|
The scale factor for distance. Defaults to 16.
TYPE:
|
mask_modules
|
List or Tuple of modules to be masked. Defaults to None.
TYPE:
|
half
|
Flag to indicate whether to use half precision. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\configuration_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee
¶
Tokenization classes for CpmBee.
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer
¶
Bases: PreTrainedTokenizer
Construct a CPMBee tokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
Path to the vocabulary file.
TYPE:
|
bos_token
|
The beginning of sequence token.
TYPE:
|
eos_token
|
The end of sequence token.
TYPE:
|
line_token
|
The line token.
TYPE:
|
space_token
|
The space token.
TYPE:
|
unk_token
|
The unknown token.
TYPE:
|
mask_token
|
The mask token.
TYPE:
|
pad_token
|
The token used for padding.
TYPE:
|
padding_side
|
The padding side. CPM-Bee will use left padding by default.
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 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 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 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 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.bod_token_id
property
¶
Returns the token ID for the beginning of document (BOD) token.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeTokenizer class.
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method returns the token ID corresponding to the BOD token in the encoder dictionary. |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.eod_token_id
property
¶
Method to retrieve the token ID corresponding to the end-of-document token in the CpmBeeTokenizer class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeTokenizer class.
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
The method returns the token ID of the end-of-document token in the tokenizer's encoder. |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.newline_id
property
¶
Returns the ID of the newline token in the CpmBeeTokenizer.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeTokenizer class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.vocab_size: int
property
¶
Returns the size of the vocabulary used by the CpmBeeTokenizer instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The CpmBeeTokenizer instance.
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
An integer representing the size of the vocabulary.
TYPE:
|
Example
>>> tokenizer = CpmBeeTokenizer()
>>> tokenizer.vocab_size()
5000
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.__call__(text, *args, **kwargs)
¶
CPMBee call method will use _tokenize_cpmbee when the input type is dict.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
637 638 639 640 641 642 643 644 645 646 647 648 649 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.__init__(vocab_file, bos_token='<s>', eos_token='</s>', line_token='\n', space_token=' ', unk_token='<unk>', mask_token='<mask>', pad_token='<pad>', padding_side='left', **kwargs)
¶
Initialize a CpmBeeTokenizer object.
| PARAMETER | DESCRIPTION |
|---|---|
vocab_file
|
The path to the file containing the vocabulary.
TYPE:
|
bos_token
|
The beginning of sentence token.
TYPE:
|
eos_token
|
The end of sentence token.
TYPE:
|
line_token
|
The token used to represent a new line.
TYPE:
|
space_token
|
The token used to represent a space.
TYPE:
|
unk_token
|
The token used to represent unknown words.
TYPE:
|
mask_token
|
The token used for masking.
TYPE:
|
pad_token
|
The token used for padding.
TYPE:
|
padding_side
|
The side to apply padding.
TYPE:
|
**kwargs
|
Additional keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the vocab_file does not exist. |
TypeError
|
If any of the arguments are of incorrect type. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.__len__()
¶
Size of the full vocabulary with the added tokens.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
381 382 383 384 385 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.check(token)
¶
Checks if a token is present in the encoder.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeTokenizer class.
TYPE:
|
token
|
The token to be checked in the encoder.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.convert_data_to_id(data, prev_ext_states=None, shuffle_answer=True, max_depth=8)
¶
Parse a dict to data ids. Exclusive for CPMBee. It will
- parse the dict to segments and get segment_rel, which for calculating of position_bias.
- tokenize every segment.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.convert_tokens_to_string(tokens)
¶
Converts a list of tokens into a single string.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeTokenizer class.
TYPE:
|
tokens
|
A list of tokens to be converted into a string.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
A string representation of the tokens.
TYPE:
|
This method takes in two parameters, self and tokens. The self parameter is an instance of the CpmBeeTokenizer class and is used to access the class's attributes and methods. The tokens parameter is a list of strings representing individual tokens.
The function returns a string that is obtained by concatenating all the tokens together using the ''.join() method. This method does not modify the original list of tokens.
No exceptions are raised by this method.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.get_piece(text)
¶
Match with maximum length.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
404 405 406 407 408 409 410 411 412 413 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.get_vocab()
¶
Get the vocabulary of the CpmBeeTokenizer instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeTokenizer class. This parameter represents the current instance of the tokenizer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
A dictionary containing the combined encoder and added tokens encoder. The keys represent tokens, and the values represent their corresponding IDs. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.prepare_for_finetune(data_list, max_length=2048)
¶
Prepares the input data for fine-tuning.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeTokenizer class.
TYPE:
|
data_list
|
A list of dictionaries containing the input data.
TYPE:
|
max_length
|
The maximum length of the input data. Defaults to 2048.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 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 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.prepare_for_model(ids, pair_ids=None, add_special_tokens=True, padding=False, truncation=None, max_length=None, stride=0, pad_to_multiple_of=None, return_tensors=None, return_token_type_ids=None, return_attention_mask=None, return_overflowing_tokens=False, return_special_tokens_mask=False, return_length=False, verbose=True, prepend_batch_axis=False, **kwargs)
¶
Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It
adds special tokens, truncates sequences if overflowing while taking into account the special tokens and
manages a moving window (with user defined stride) for overflowing tokens. Please Note, for pair_ids
different than None and truncation_strategy = longest_first or True, it is not possible to return
overflowing tokens. Such a combination of arguments will raise an error.
| PARAMETER | DESCRIPTION |
|---|---|
ids
|
Tokenized input ids of the first sequence. Can be obtained from a string by chaining the
TYPE:
|
pair_ids
|
Tokenized input ids of the second sequence. Can be obtained from a string by chaining the
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary to a file.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeTokenizer class.
TYPE:
|
save_directory
|
The directory where the vocabulary file will be saved.
TYPE:
|
filename_prefix
|
An optional prefix to prepend to the filename. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[str]
|
Tuple[str]: A tuple containing the path to the saved vocabulary file. |
| RAISES | DESCRIPTION |
|---|---|
IOError
|
If there is an issue with reading or writing the vocabulary file. |
ValueError
|
If the provided save_directory is not a valid directory. |
KeyError
|
If any of the keys used for encoding tokens are not found in the encoder dictionary. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.CpmBeeTokenizer.tokenize(text, **kwargs)
¶
Override the tokenize to meet the needs of CPMBee:
- Mark the special token with
<and>. The<>will be ignored. - Split sentences by the marked special tokens.
- Record the marked special token by
ext_tableandext_table_rev. - Tokenize the sentence without special tokens.
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
mindnlp.transformers.models.cpmbee.tokenization_cpmbee.rel_to_bucket(n_up, n_down, max_depth=8)
¶
Calculates the relative position of an item in a bucket based on the number of items above and below it.
| PARAMETER | DESCRIPTION |
|---|---|
n_up
|
The number of items above the item.
TYPE:
|
n_down
|
The number of items below the item.
TYPE:
|
max_depth
|
The maximum depth of the bucket. Defaults to 8.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The relative position of the item in the bucket. |
Source code in mindnlp\transformers\models\cpmbee\tokenization_cpmbee.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee
¶
MindSpore CpmBee model.
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeAttention
¶
Bases: Module
This class represents the attention mechanism used in the CpmBee model. It inherits from the nn.Module class.
| 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 |
Linear layer for projecting the query.
TYPE:
|
project_k |
Linear layer for projecting the key.
TYPE:
|
project_v |
Linear layer for projecting the value.
TYPE:
|
attention_out |
Linear layer for the output of the attention mechanism.
TYPE:
|
softmax |
Softmax function for computing attention weights.
TYPE:
|
dropout |
Dropout layer for regularization (optional).
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeAttention class. |
forward |
Constructs the attention mechanism. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeAttention.__init__(config)
¶
Initializes an instance of the CpmBeeAttention class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
config
|
The configuration object containing the following attributes:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeAttention.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\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamHypotheses
¶
Bases: BeamHypotheses
This class represents a set of beam hypotheses for the CpmBee model. It is derived from the BeamHypotheses class.
The CpmBeeBeamHypotheses class is used to store and manage a list of beam hypotheses along with their scores and beam indices. Each hypothesis consists of a sequence of predicted tokens and a corresponding sum of log probabilities. The class provides methods to add new hypotheses, update the list of hypotheses, and retrieve the best hypotheses based on their scores.
| ATTRIBUTE | DESCRIPTION |
|---|---|
beams |
A list of tuples representing the beam hypotheses. Each tuple contains the hypothesis score, the predicted token sequence, and the beam indices.
TYPE:
|
worst_score |
The score of the worst hypothesis in the list.
TYPE:
|
num_beams |
The maximum number of beam hypotheses to be stored.
TYPE:
|
length_penalty |
The length penalty factor applied to the hypothesis scores.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
add |
Add a new hypothesis to the list of beam hypotheses. The hypothesis is represented by a sequence of predicted tokens and its sum of log probabilities. Optionally, the beam indices can also be provided. |
update |
Update the list of beam hypotheses by removing the worst hypothesis if the maximum number of hypotheses is exceeded. |
get_best |
Retrieve the best |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamHypotheses.add(hyp, sum_logprobs, beam_indices=None)
¶
Add a new hypothesis to the list.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamSearchScorer
¶
Bases: BeamSearchScorer
Override BeamSearchScorer for CPMBee to support:
- Replace beam_tokens by beam_states, containing
idx,ans,nx_token_id... - The
processwill update the beam_states - The
finalizewill just return the best hypotheses as a list.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamSearchScorer.__init__(batch_size, num_beams, length_penalty=1.0, do_early_stopping=False, num_beam_hyps_to_keep=1, num_beam_groups=1, max_length=None, **model_kwargs)
¶
Initializes the CpmBeeBeamSearchScorer object.
| PARAMETER | DESCRIPTION |
|---|---|
batch_size
|
The batch size for beam search.
TYPE:
|
num_beams
|
The number of beams for beam search.
TYPE:
|
length_penalty
|
The length penalty for beam search. Defaults to 1.0.
TYPE:
|
do_early_stopping
|
Flag to indicate if early stopping should be performed. Defaults to False.
TYPE:
|
num_beam_hyps_to_keep
|
The number of beam hypotheses to keep. Defaults to 1.
TYPE:
|
num_beam_groups
|
The number of beam groups for beam search. Defaults to 1.
TYPE:
|
max_length
|
The maximum length for beam search. Defaults to None.
TYPE:
|
**model_kwargs
|
Additional model-specific keyword arguments.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the provided batch size, num_beams, num_beam_groups, or max_length is not a positive integer. |
TypeError
|
If the provided length_penalty is not a float or if do_early_stopping is not a bool or str. |
RuntimeError
|
If an error occurs during initialization. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamSearchScorer.apply_repetition_penalty(logits, batch_size, num_beams, prev_output_tokens, repetition_penalty, start_idx=None, end_idx=None, window_size=None)
staticmethod
¶
Applies repetition penalty to the logits for beam search in the CpmBeeBeamSearchScorer class.
| PARAMETER | DESCRIPTION |
|---|---|
logits
|
The logits representing the scores for each token in the vocabulary. Shape: (batch_size * num_beams, vocab_size).
TYPE:
|
batch_size
|
The size of the batch.
TYPE:
|
num_beams
|
The number of beams used in the beam search.
TYPE:
|
prev_output_tokens
|
The previously generated tokens. Shape: (batch_size * num_beams, sequence_length).
TYPE:
|
repetition_penalty
|
The coefficient for the repetition penalty. Must be >= 1.
TYPE:
|
start_idx
|
The start index of the window for calculating repetition penalty. Defaults to None.
TYPE:
|
end_idx
|
The end index of the window for calculating repetition penalty. Defaults to None.
TYPE:
|
window_size
|
The size of the window for calculating repetition penalty. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If repetition_penalty is less than 1. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamSearchScorer.finalize()
¶
Finalizes the beam search scoring process and returns the best hypotheses.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeBeamSearchScorer class.
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Tensor]
|
A tuple containing mindspore.Tensor objects representing the best hypotheses. |
This method iterates over the beam hypotheses generated during the beam search process and selects the best hypothesis from each beam. The best hypothesis is determined based on the maximum score assigned to it. The selected best hypotheses are then returned as a tuple of mindspore.Tensor objects.
Note
- The beam hypotheses are internally stored in the _beam_hyps attribute of the CpmBeeBeamSearchScorer instance.
- The best hypothesis is determined by selecting the hypothesis with the maximum score from each beam.
Example
>>> scorer = CpmBeeBeamSearchScorer()
>>> results = scorer.finalize()
>>> # results contains the best hypotheses as mindspore.Tensor objects.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBeamSearchScorer.process(batch_size, cur_len, _next_scores, next_scores, next_tokens, vocab_size=None, pad_token_id=None, bos_token_id=None, eos_token_id=None, max_length=None, ext_table_sub_cpu=None, ext_table_ids_cpu=None, **model_kwargs)
¶
Process the beam search for the CpmBeeBeamSearchScorer.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeBeamSearchScorer class.
|
batch_size
|
The batch size for processing.
TYPE:
|
cur_len
|
The current length of the sequence being processed.
TYPE:
|
_next_scores
|
The scores for the next tokens.
TYPE:
|
next_scores
|
The scores for the next tokens.
TYPE:
|
next_tokens
|
The tokens for the next sequence.
TYPE:
|
vocab_size
|
The size of the vocabulary. Defaults to None.
TYPE:
|
pad_token_id
|
The token ID for padding. Defaults to None.
TYPE:
|
bos_token_id
|
The token ID for the beginning of sequence. Defaults to None.
TYPE:
|
eos_token_id
|
The token ID for the end of sequence. Defaults to None.
TYPE:
|
max_length
|
The maximum length of the sequence. Defaults to None.
TYPE:
|
ext_table_sub_cpu
|
The CPU tensor for extended table sub.
TYPE:
|
ext_table_ids_cpu
|
The CPU tensor for extended table IDs.
TYPE:
|
**model_kwargs
|
Additional keyword arguments for the model.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Tensor]
|
Tuple[mindspore.Tensor]: A tuple containing the next beam scores, next beam states, and next beam indices. |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If the length of next_instance_beam_states is not equal to zero when cur_len is equal to max_length, or not equal to self.num_beams otherwise. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBucketPositionBias
¶
Bases: Module
This class represents a position bias computation module in the CpmBee model. It is used to calculate the relative position buckets for attention mechanism.
| ATTRIBUTE | DESCRIPTION |
|---|---|
num_heads |
The number of attention heads.
TYPE:
|
num_buckets |
The number of position bias buckets.
TYPE:
|
num_segment_bucket |
The number of segment buckets used for position bias.
TYPE:
|
max_distance |
The maximum distance for position bias calculation.
TYPE:
|
relative_attention_bias |
The learnable parameter used for relative attention bias calculation.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeBucketPositionBias instance. |
forward |
Constructs the position bias based on the given query and key positions and relative buckets. |
_position_bucket |
Computes the position bucket for the given relative position. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBucketPositionBias.__init__(config)
¶
Initializes an instance of the CpmBeeBucketPositionBias class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
config
|
The configuration object containing various parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeBucketPositionBias.forward(query_pos, key_pos, rel_buckets)
¶
This method forwards relative position bias embeddings based on the input query positions, key positions, and relative buckets.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeBucketPositionBias class.
TYPE:
|
query_pos
|
A tensor representing the positions of queries in the input sequence.
TYPE:
|
key_pos
|
A tensor representing the positions of keys in the input sequence.
TYPE:
|
rel_buckets
|
A tensor containing relative position buckets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This method does not return any value explicitly. The forwarded embeddings are stored in the 'embeds' variable within the method. |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeDenseGatedACT
¶
Bases: Module
This class represents a dense gated activation module in the CpmBee framework. It performs a nonlinear transformation on an input tensor from one feature space to another using a gated activation function.
The class inherits from the nn.Module class.
| ATTRIBUTE | DESCRIPTION |
|---|---|
w_0 |
An instance of the CpmBeeLinear class representing the first linear transformation.
TYPE:
|
w_1 |
An instance of the CpmBeeLinear class representing the second linear transformation.
TYPE:
|
act |
An instance of the GELU activation function.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeDenseGatedACT class. |
forward |
Transforms an input tensor from one feature space to another via a nonlinear operation. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeDenseGatedACT.__init__(config)
¶
Initializes a new instance of the CpmBeeDenseGatedACT class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The current CpmBeeDenseGatedACT object.
|
config
|
An instance of the CpmBeeConfig class containing configuration parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeDenseGatedACT.forward(hidden_states)
¶
Transform an input tensor from one feature space to another via a nonlinear operation
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
413 414 415 416 417 418 419 420 421 422 423 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEmbeddingExt
¶
Bases: Embedding
Contains a RotaryEmbedding.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEmbeddingExt.__init__(config)
¶
Initialize the CpmBeeEmbeddingExt object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeEmbeddingExt class.
|
config
|
An instance of CpmBeeConfig containing configuration parameters for the embedding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEmbeddingExt.forward(ids, ids_sub)
¶
Construct and return the embeddings of the given input IDs and sub-IDs for the CpmBeeEmbeddingExt class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeEmbeddingExt class.
TYPE:
|
ids
|
The input IDs tensor:
TYPE:
|
ids_sub
|
The sub-IDs tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEmbeddingExt.projection(x, ext_table=None)
¶
This method projects the input tensor 'x' using a dense layer and optionally concatenates it with another tensor 'ext_table'.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
Instance of the class CpmBeeEmbeddingExt.
|
x
|
Input tensor to be projected. It should have a shape compatible with the weight tensor.
TYPE:
|
ext_table
|
Additional tensor to be concatenated with the projected tensor 'x'. It should have a compatible shape with 'x'. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
mindspore.Tensor or None: The projected tensor 'x' after applying the dense layer operation. If 'ext_table' is provided and has a non-zero shape, the concatenated tensor is returned. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEncoder
¶
Bases: Module
CpmBeeEncoder is a class that represents an encoder module for the CpmBeeTransformer model. This class inherits from nn.Module and is responsible for processing input data through multiple transformer blocks.
| ATTRIBUTE | DESCRIPTION |
|---|---|
num_layers |
The number of transformer blocks in the encoder.
TYPE:
|
layers |
List of CpmBeeTransformerBlock instances representing each transformer block in the encoder.
TYPE:
|
output_layernorm |
Layer normalization module for the encoder output.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeEncoder instance with the provided configuration. |
forward |
Processes the input hidden_states through the encoder layers. Args:
Returns:
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEncoder.__init__(config)
¶
Initializes a new instance of the CpmBeeEncoder class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeEncoder class.
|
config
|
An instance of the CpmBeeConfig class containing configuration parameters for the encoder. This parameter is used to configure the encoder's behavior and settings. The config parameter must be of type CpmBeeConfig.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If the length of config.mask_modules does not equal the number of hidden layers specified in config. |
AssertionError
|
If the length of mask_module within config.mask_modules is not 2 for each mask_module in the list. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeEncoder.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\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFFNBlock
¶
Bases: Module
This class represents a feed-forward block in the CpmBee model. It is used to process hidden states before the feed-forward layer.
The CpmBeeFFNBlock class inherits from nn.Module.
| ATTRIBUTE | DESCRIPTION |
|---|---|
layernorm_before_ffn |
An instance of the CpmBeeLayerNorm class that performs layer normalization before the feed-forward layer.
TYPE:
|
ffn |
An instance of the CpmBeeFeedForward class that represents the feed-forward layer.
TYPE:
|
dropout |
An optional dropout layer. If None, no dropout is applied.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeFFNBlock object. |
forward |
Processes the hidden states before the feed-forward layer. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFFNBlock.__init__(config)
¶
Initializes a CpmBeeFFNBlock instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The current object instance.
|
config
|
The configuration object containing the parameters for the CpmBeeFFNBlock. This object must be an instance of CpmBeeConfig class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFFNBlock.forward(hidden_states)
¶
| PARAMETER | DESCRIPTION |
|---|---|
hidden_states
|
Hidden states before feed forward layer.
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFeedForward
¶
Bases: Module
This class represents a feedforward neural network layer for the CpmBee model.
It consists of a dense gated activation layer (CpmBeeDenseGatedACT), optional dropout layer,
and a linear transformation layer (CpmBeeLinear).
| ATTRIBUTE | DESCRIPTION |
|---|---|
w_in |
Instance of
|
dropout |
Optional dropout layer for regularization.
|
w_out |
Instance of
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Constructor method initializing the feedforward layer. |
forward |
Method for processing input hidden states through the feedforward layer. |
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Configuration object of type
TYPE:
|
hidden_states
|
Input tensor of shape
|
| RETURNS | DESCRIPTION |
|---|---|
|
mindspore.Tensor: Transformed hidden states after passing through the feedforward layer. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFeedForward.__init__(config)
¶
Initializes an instance of the CpmBeeFeedForward class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the class.
|
config
|
An object of the CpmBeeConfig class containing configuration parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeFeedForward.forward(hidden_states)
¶
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
472 473 474 475 476 477 478 479 480 481 482 483 484 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM
¶
Bases: CpmBeePreTrainedModel
This class represents a CPMBee model for Causal Language Modeling tasks. It inherits from CpmBeePreTrainedModel and implements methods for model initialization, inference, beam search generation, input embeddings handling, and more.
The class includes methods for initializing the model, forwarding the model for inference, performing inference, getting and setting input embeddings, getting and setting output embeddings, preparing inputs for generation, updating model kwargs for generation, reordering cache during generation, expanding inputs for generation, adjusting logits during generation, performing beam search for generation, and generating outputs based on input data using beam search.
The generate method processes input data using the model to generate responses, filling placeholders in the
input data with generated text. It accepts a dictionary or a list of dictionaries as input and
returns a dictionary or a list of dictionaries with the '
For more details on the methods and their parameters, please refer to the method docstrings within the class implementation.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.__init__(config)
¶
Initializes a new instance of the CpmBeeForCausalLM class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The object instance.
|
config
|
The configuration object for the CpmBee model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.adjust_logits_during_generation(logits, batch_size, beam_size, vocab_size, ext_table_ids, **model_kwargs)
¶
Implement in subclasses of [PreTrainedModel] for custom behavior to adjust the logits in the generate method.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.beam_search(input_ids, beam_scorer, repetition_penalty=1.0, logits_processor=None, max_length=None, pad_token_id=None, eos_token_id=None, bos_token_id=None, vocab_size=None, output_attentions=None, output_hidden_states=None, output_scores=None, return_dict_in_generate=None, synced_gpus=False, **model_kwargs)
¶
Override the beam_search for CPMBee.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.forward(input_ids=None, input_id_sub=None, length=None, context=None, sample_ids=None, num_segments=None, segment=None, segment_rel_offset=None, segment_rel=None, span=None, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None, labels=None, return_dict=None, ext_table_ids=None, ext_table_sub=None, **kwargs)
¶
| PARAMETER | DESCRIPTION |
|---|---|
input_ids
|
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [
TYPE:
|
input_id_sub
|
Subscription of input sequence tokens in the vocabulary. Subscription of normal text will be zero while the special tokens of each group will be the 0, 1, 2,
...
TYPE:
|
length
|
The length of sequences in batch.
TYPE:
|
context
|
Whether this token id is context or not. If is context, the value is 1. If not, the value is 0. If a token id is context, it does not need to be predicted.
TYPE:
|
sample_ids
|
Give a sample id to every token id. The token ids with same sample ids belongs to the same sample.
TYPE:
|
num_segments
|
Total number of segments in the current input.
TYPE:
|
segment
|
Give a segment id to every token id. The token ids with same segment ids belongs to the same sample. Generally, a string key or value in input data will be a segment. For example, input {"input": "hello,
", "
TYPE:
|
segment_rel_offset
|
The offset of segment rel.
TYPE:
|
segment_rel
|
The segment relevance. A relative implementation of measuring the importance of segments.
TYPE:
|
span
|
Span will record every input_ids 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
|
A dummy arguments for CPMBee. The
TYPE:
|
use_cache
|
If set to
TYPE:
|
labels
|
Labels for computing the masked language modeling loss.
TYPE:
|
return_dict
|
Whether or not to return a [
TYPE:
|
ext_table_ids
|
ext_table ids for embedding projection.
TYPE:
|
ext_table_sub
|
ext_table subscriptions for embedding projection.
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.generate(data_list, tokenizer, **kwargs)
¶
Override the generate for CPMBee. It will accept dict or list(dict) as input and returns dict or list(dict)
with <ans> filled.
| PARAMETER | DESCRIPTION |
|---|---|
data_list
|
The sequence used as a prompt for the generation or as model inputs to the encoder. If dict, data_list will be wrapped as a list.
TYPE:
|
tokenizer
|
(
TYPE:
|
generation_config
|
The generation configuration to be used as base parametrization for the generation call.
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.get_input_embeddings()
¶
This method retrieves the input embeddings from the CpmBeeForCausalLM object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeForCausalLM class.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
input_embedding
|
This method returns the input embeddings, which are of type None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.get_output_embeddings()
¶
Returns the output embeddings for the CpmBeeForCausalLM model.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeForCausalLM class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.inference(input_ids=None, input_id_sub=None, position=None, context=None, sample_ids=None, num_segments=None, segment=None, segment_rel_offset=None, segment_rel=None, past_states=None, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None, labels=None, return_dict=None, ext_table_ids=None, ext_table_sub=None, **kwargs)
¶
| PARAMETER | DESCRIPTION |
|---|---|
input_ids
|
Indices of input sequence tokens in the vocabulary. Indices can be obtained using [
TYPE:
|
input_id_sub
|
Subscription of input sequence tokens in the vocabulary. Subscription of normal text will be zero while the special tokens of each group will be the 0, 1, 2,
...
TYPE:
|
position
|
The position of input sequence tokens in the vocabulary for each segment. if segment1 is 0, 1, 2 and segment2 is 0, 1, 2, 3, the position will be 0, 1, 2, 0, 1, 2, 3
TYPE:
|
context
|
Whether this token id is context or not. If is context, the value is 1. If not, the value is 0. If a token id is context, it does not need to be predicted.
TYPE:
|
sample_ids
|
Give a sample id to every token id. The token ids with same sample ids belongs to the same sample.
TYPE:
|
num_segments
|
Total number of segments in the current input.
TYPE:
|
segment
|
Give a segment id to every token id. The token ids with same segment ids belongs to the same sample. Generally, a string key or value in input data will be a segment. For example, input {"input": "hello,
", "
TYPE:
|
segment_rel_offset
|
The offset of segment rel.
TYPE:
|
segment_rel
|
The segment relevance. A relative implementation of measuring the importance of segments.
TYPE:
|
past_states
|
Store the history information including position, context, sample_ids, num_segments, segment and past_key_values.
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
|
A dummy arguments for CPMBee. The
TYPE:
|
use_cache
|
If set to
TYPE:
|
labels
|
Labels for computing the masked language modeling loss.
TYPE:
|
return_dict
|
Whether or not to return a [
TYPE:
|
ext_table_ids
|
ext_table ids for embedding projection.
TYPE:
|
ext_table_sub
|
ext_table subscriptions for embedding projection.
TYPE:
|
Example
Text Generation with CpmBeeForCausalLM.
>>> from transformers import CpmBeeTokenizer, CpmBeeForCausalLM
...
>>> texts = {"input": "今天天气不错,", "<ans>": ""}
>>> model = CpmBeeForCausalLM.from_pretrained("openbmb/cpm-bee-10b")
>>> tokenizer = CPMBeeTokenizer.from_pretrained("openbmb/cpm-bee-10b")
>>> output_texts = model.generate({"input": "今天天气不错,", "<ans>": ""}, tokenizer)
>>> print(output_texts)
{'input': '今天天气不错,', '<ans>': '适合睡觉。'}
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.prepare_inputs_for_generation(input_ids, batch_size, beam_scorer=None, input_id_subs=None, input_pos=None, segment_ids=None, batch_ext_table_ids=None, batch_ext_table_sub=None, other_info=None, **model_kwargs)
¶
Choose the current input according to beam states.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.set_input_embeddings(embeddings)
¶
Sets the input embeddings for the CpmBeeForCausalLM class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeForCausalLM class.
TYPE:
|
embeddings
|
The input embeddings to be set for the CpmBeeForCausalLM instance.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeForCausalLM.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings for the CpmBeeForCausalLM model.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeForCausalLM class.
TYPE:
|
new_embeddings
|
The new embeddings to be set as the output embeddings. This should be a tensor or an object that can be converted to a tensor.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
This method sets the output embeddings of the CpmBeeForCausalLM model to the provided new embeddings. The new embeddings are assigned to the 'lm_head' attribute of the model object.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLayerNorm
¶
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\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLayerNorm.__init__(config)
¶
Initializes a CpmBeeLayerNorm object with the provided configuration.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeLayerNorm class.
|
config
|
An instance of the CpmBeeConfig class containing the configuration parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLayerNorm.forward(hidden_states)
¶
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
129 130 131 132 133 134 135 136 137 138 139 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLinear
¶
Bases: Linear
This class represents a linear layer with a scale operation for CPMBee. It is a subclass of the nn.Linear class.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dim_in |
The input dimension of the linear layer.
TYPE:
|
dim_out |
The output dimension of the linear layer.
TYPE:
|
weight |
The weight parameter of the linear layer.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Construct a linear layer for CPMBee with a scale operation. |
forward |
Apply the linear transformation to the input tensor. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLinear.__init__(dim_in, dim_out, dtype)
¶
Construct a linear for CPMBee. It contains a scale operation.
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
76 77 78 79 80 81 82 83 84 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeLinear.forward(x)
¶
| PARAMETER | DESCRIPTION |
|---|---|
x
|
The input of linear layer
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel
¶
Bases: CpmBeePreTrainedModel
CpmBeeModel
This class represents a CpmBee model for natural language processing tasks. It is a subclass of CpmBeePreTrainedModel and inherits all the functionality from it.
| ATTRIBUTE | DESCRIPTION |
|---|---|
encoder |
An instance of CpmBeeEncoder, responsible for encoding the input sequences.
|
input_embedding |
An instance of CpmBeeEmbeddingExt, used for embedding the input sequences.
|
position_bias |
An instance of CpmBeeBucketPositionBias, used for calculating the position bias.
|
vocab_size |
An integer representing the size of the vocabulary.
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeModel instance with the given configuration. |
get_input_embeddings |
Returns the input embedding instance. |
set_input_embeddings |
Sets the input embeddings to the given value. |
forward |
Constructs the CpmBee model with the provided input and configuration. |
inference |
Performs inference using the CpmBee model with the provided input and configuration. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel.__init__(config)
¶
Initializes an instance of the CpmBeeModel class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The object instance.
|
config
|
The configuration object that contains the model settings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel.forward(input_ids, input_id_sub=None, length=None, context=None, sample_ids=None, num_segments=None, segment=None, segment_rel_offset=None, segment_rel=None, span=None, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None, return_dict=None, **kwargs)
¶
Constructs the CpmBeeModel.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The object itself.
|
input_ids
|
The input tensor of shape (batch, seq_length) containing the input IDs.
TYPE:
|
input_id_sub
|
The optional input tensor of shape (batch, seq_length) containing the sub input IDs. Defaults to None.
TYPE:
|
length
|
The optional input tensor of shape (batch,) containing the length of the input sequences. Defaults to None.
TYPE:
|
context
|
The optional input tensor of shape (batch, seq_length) containing the context. Defaults to None.
TYPE:
|
sample_ids
|
The optional input tensor of shape (batch, seq_length) containing the sample IDs. Defaults to None.
TYPE:
|
num_segments
|
The optional input tensor of shape (batch, seq_length) containing the number of segments. Defaults to None.
TYPE:
|
segment
|
The optional input tensor of shape (batch, seq_length) containing the segments. Defaults to None.
TYPE:
|
segment_rel_offset
|
The optional input tensor of shape (batch, seq_length) containing the segment relative offset. Defaults to None.
TYPE:
|
segment_rel
|
The optional input tensor of shape (batch, seq_length) containing the segment relative. Defaults to None.
TYPE:
|
span
|
The optional input dictionary containing span information. Defaults to None.
TYPE:
|
output_attentions
|
The optional boolean flag indicating whether to output attentions. Defaults to None.
TYPE:
|
output_hidden_states
|
The optional boolean flag indicating whether to output hidden states. Defaults to None.
TYPE:
|
past_key_values
|
The optional list containing past key values. Defaults to None.
TYPE:
|
use_cache
|
The optional boolean flag indicating whether to use cache. Defaults to None.
TYPE:
|
return_dict
|
The optional boolean flag indicating whether to return a dictionary. Defaults to None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel.get_input_embeddings()
¶
This method retrieves the input embeddings for the CpmBeeModel.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeModel class. It is used to access the input embeddings for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
input_embedding
|
The method returns the input embedding associated with the CpmBeeModel instance. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel.inference(input_ids, input_id_sub=None, position=None, context=None, sample_ids=None, num_segments=None, segment=None, segment_rel_offset=None, segment_rel=None, past_states=None, output_attentions=None, output_hidden_states=None, past_key_values=None, use_cache=None, return_dict=None, **kwargs)
¶
Perform inference using the CpmBeeModel.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeModel class.
TYPE:
|
input_ids
|
The input tensor of shape (batch, seq_length) containing the input IDs.
TYPE:
|
input_id_sub
|
The optional input tensor of shape (batch, seq_length) containing the sub input IDs. Default is None.
TYPE:
|
position
|
The optional input tensor of shape (batch, seq_length) containing the position information. Default is None.
TYPE:
|
context
|
The optional input tensor of shape (batch, seq_length) containing the context information. Default is None.
TYPE:
|
sample_ids
|
The optional input tensor of shape (batch, seq_length) containing the sample IDs. Default is None.
TYPE:
|
num_segments
|
The optional input tensor of shape (batch, seq_length) containing the number of segments. Default is None.
TYPE:
|
segment
|
The optional input tensor of shape (batch, seq_length) containing the segment information. Default is None.
TYPE:
|
segment_rel_offset
|
The optional input tensor of shape (batch, seq_length) containing the segment relative offset. Default is None.
TYPE:
|
segment_rel
|
The optional input tensor of shape (batch, seq_length) containing the segment relative information. Default is None.
TYPE:
|
past_states
|
The optional dictionary containing the past states. Default is None.
TYPE:
|
output_attentions
|
Whether to output attentions. If None, it uses the output_attentions from the model configuration. Default is None.
TYPE:
|
output_hidden_states
|
Whether to output hidden states. If None, it uses the output_hidden_states from the model configuration. Default is None.
TYPE:
|
past_key_values
|
The optional list containing the past key values. Default is None.
TYPE:
|
use_cache
|
Whether to use cache. If None, it uses the use_cache from the model configuration. Default is None.
TYPE:
|
return_dict
|
Whether to return a dictionary. If None, it uses the use_return_dict from the model configuration. Default is None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseModelOutputWithPast
|
An instance of BaseModelOutputWithPast containing the last hidden state, past key values, hidden states, and attentions. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeModel.set_input_embeddings(embeddings, **kwargs)
¶
This method sets the input embeddings for the CpmBeeModel.
| PARAMETER | DESCRIPTION |
|---|---|
embeddings
|
The input embeddings to be set for the model. It can be of any type and should contain the necessary information for input embeddings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeOutput
¶
Bases: Module
CpmBeeOutput represents a neural network cell for processing hidden states, including dense transformation, dropout, and layer normalization.
This class inherits from nn.Module and provides methods for initializing the cell and forwarding the output based on the given input tensors.
| ATTRIBUTE | DESCRIPTION |
|---|---|
dense |
A dense layer for transforming the input hidden states.
TYPE:
|
LayerNorm |
A layer normalization module for normalizing the hidden states.
TYPE:
|
dropout |
A dropout module for applying dropout to the hidden states.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__init__ |
Initializes the CpmBeeOutput cell with the given configuration. |
forward |
Constructs the output based on the input hidden states and input tensor. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeOutput.__init__(config)
¶
Initializes a CpmBeeOutput instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeOutput class.
TYPE:
|
config
|
The configuration object containing parameters for the model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the provided config object is not of the expected type. |
ValueError
|
If the config object is missing any required parameters. |
AttributeError
|
If there is an issue with accessing the attributes of the config object. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeOutput.forward(hidden_states, input_tensor)
¶
Constructs the CpmBeeOutput.
This method takes three parameters: self, hidden_states, and input_tensor. It returns a mindspore.Tensor object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeOutput class.
TYPE:
|
hidden_states
|
The hidden states tensor. This tensor contains the hidden states from the previous layer.
TYPE:
|
input_tensor
|
The input tensor. This tensor represents the input to the current layer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
mindspore.Tensor: The forwarded tensor. This tensor is the result of applying the CpmBeeOutput layer operations. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeePreTrainedModel
¶
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\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeRotaryEmbedding
¶
Bases: Module
RotaryEmbedding embeds the unk token and special token. It will embeds the "...
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeRotaryEmbedding.__init__(config)
¶
Initializes a new instance of the CpmBeeRotaryEmbedding class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeRotaryEmbedding class.
|
config
|
An instance of the CpmBeeConfig class containing configuration parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeRotaryEmbedding.forward(x, x_pos)
¶
Constructs a rotary embedding for a given input tensor.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
An instance of the CpmBeeRotaryEmbedding class.
TYPE:
|
x
|
The input tensor for which the rotary embedding is forwarded.
TYPE:
|
x_pos
|
The positional encoding tensor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeSelfAttentionBlock
¶
Bases: Module
Represents a self-attention block in the CpmBee model for transformer-based neural network architectures.
This class inherits from nn.Module.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
The configuration for the self-attention block.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the configuration is invalid. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
layernorm_before_attention |
The layer normalization module before the self-attention block.
TYPE:
|
self_attention |
The self-attention module.
TYPE:
|
dropout |
The dropout layer, if configured.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the input tensors are of invalid shape or type. |
| RETURNS | DESCRIPTION |
|---|---|
|
Tuple[mindspore.Tensor, mindspore.Tensor, mindspore.Tensor]: The updated hidden states, attention weights, and current key-value states. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.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 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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeSelfAttentionBlock.__init__(config)
¶
Initializes a CpmBeeSelfAttentionBlock instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The CpmBeeSelfAttentionBlock instance itself.
|
config
|
An instance of CpmBeeConfig containing configuration parameters for the self-attention block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeSelfAttentionBlock.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\cpmbee\modeling_cpmbee.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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeTransformerBlock
¶
Bases: Module
This class represents a transformer block of the CPM-BEE model, which is a neural network architecture used for natural language processing tasks. The CpmBeeTransformerBlock class inherits from nn.Module and contains two sub-blocks: a self-attention block and a feed-forward neural network (FFN) block.
| ATTRIBUTE | DESCRIPTION |
|---|---|
config |
The configuration object for the CPM-BEE model.
TYPE:
|
mask_att |
A boolean flag indicating whether to apply masking to the self-attention block.
TYPE:
|
mask_ffn |
A boolean flag indicating whether to apply masking to the feed-forward neural network block.
TYPE:
|
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeTransformerBlock.__init__(config, mask_att=False, mask_ffn=False)
¶
init
Initializes a CpmBeeTransformerBlock instance.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the CpmBeeTransformerBlock class.
|
config
|
An instance of the CpmBeeConfig class containing configuration parameters.
TYPE:
|
mask_att
|
A boolean indicating whether to mask attention. Defaults to False.
TYPE:
|
mask_ffn
|
A boolean indicating whether to mask feed-forward network. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\cpmbee\modeling_cpmbee.py
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 | |
mindnlp.transformers.models.cpmbee.modeling_cpmbee.CpmBeeTransformerBlock.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\cpmbee\modeling_cpmbee.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 622 623 624 625 | |