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_table
andext_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
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 |
|
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
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 |
|
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
process
will update the beam_states - The
finalize
will just return the best hypotheses as a list.
Source code in mindnlp/transformers/models/cpmbee/modeling_cpmbee.py
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 1951 |
|
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
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 |
|
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
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 1951 |
|
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
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 |
|
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
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 |
|
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.
|