pop2piano
mindnlp.transformers.models.pop2piano.modeling_pop2piano
¶
PyTorch Pop2Piano model.
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention
¶
Bases: Module
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention.compute_bias(query_length, key_length)
¶
Compute binned relative position bias
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention.forward(hidden_states, mask=None, key_value_states=None, position_bias=None, past_key_value=None, layer_head_mask=None, query_length=None, use_cache=False, output_attentions=False)
¶
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoConcatEmbeddingToMel
¶
Bases: Module
Embedding Matrix for composer tokens.
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
868 869 870 871 872 873 874 875 876 877 878 879 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration
¶
Bases: Pop2PianoPreTrainedModel
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.forward(input_ids=None, attention_mask=None, decoder_input_ids=None, decoder_attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, encoder_outputs=None, past_key_values=None, inputs_embeds=None, input_features=None, decoder_inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
labels (mindspore.Tensor of shape (batch_size,), optional):
Labels for computing the sequence classification/regression loss. Indices should be in [-100, 0, ...,
config.vocab_size - 1]. All labels set to -100 are ignored (masked), the loss is only computed for
labels in [0, ..., config.vocab_size]
Returns:
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.generate(input_features, attention_mask=None, composer='composer1', generation_config=None, **kwargs)
¶
Generates token ids for midi outputs.
Most generation-controlling parameters are set in generation_config which, if not passed, will be set to the
model's default generation configuration. You can override any generation_config by passing the corresponding
parameters to generate(), e.g. .generate(inputs, num_beams=4, do_sample=True). For an overview of generation
strategies and code examples, check out the following guide.
| PARAMETER | DESCRIPTION |
|---|---|
input_features
|
This is the featurized version of audio generated by
TYPE:
|
attention_mask
|
For batched generation
DEFAULT:
|
composer
|
This value is passed to
TYPE:
|
generation_config
|
The generation configuration to be used as base parametrization for the generation call.
TYPE:
|
kwargs
|
Ad hoc parametrization of
DEFAULT:
|
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.get_mel_conditioner_outputs(input_features, composer, generation_config, attention_mask=None)
¶
This method is used to concatenate mel conditioner tokens at the front of the input_features in order to control the type of MIDI token generated by the model.
| PARAMETER | DESCRIPTION |
|---|---|
input_features
|
input features extracted from the feature extractor.
TYPE:
|
composer
|
composer token which determines the type of MIDI tokens to be generated.
TYPE:
|
generation_config
|
The generation is used to get the composer-feature_token pair.
TYPE:
|
attention_mask
|
For batched generation
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerNorm
¶
Bases: Module
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerNorm.__init__(hidden_size, eps=1e-06)
¶
Construct a layernorm module in the Pop2Piano style. No bias and no subtraction of mean.
Source code in mindnlp\transformers\models\pop2piano\modeling_pop2piano.py
50 51 52 53 54 55 56 | |
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoPreTrainedModel
¶
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\pop2piano\modeling_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano
¶
Tokenization class for Pop2Piano.
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer
¶
Bases: PreTrainedTokenizer
Constructs a Pop2Piano tokenizer. This tokenizer does not require training.
This tokenizer inherits from [PreTrainedTokenizer] which contains most of the main methods. Users should refer to
this superclass for more information regarding those methods.
| PARAMETER | DESCRIPTION |
|---|---|
vocab
|
Path to the vocab file which contains the vocabulary.
TYPE:
|
default_velocity
|
Determines the default velocity to be used while creating midi Notes.
TYPE:
|
num_bars
|
Determines cutoff_time_idx in for each token.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.vocab_size
property
¶
Returns the vocabulary size of the tokenizer.
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.__call__(notes, padding=False, truncation=None, max_length=None, pad_to_multiple_of=None, return_attention_mask=None, return_tensors=None, verbose=True, **kwargs)
¶
This is the __call__ method for Pop2PianoTokenizer. It converts the midi notes to the transformer generated
token ids.
| PARAMETER | DESCRIPTION |
|---|---|
notes
|
This represents the midi notes. If Each sequence must have 4 values, they are If
TYPE:
|
padding
|
Activates and controls padding. Accepts the following values:
TYPE:
|
truncation
|
Activates and controls truncation. Accepts the following values:
TYPE:
|
max_length
|
Controls the maximum length to use by one of the truncation/padding parameters. If left unset or set to
TYPE:
|
pad_to_multiple_of
|
If set will pad the sequence to a multiple of the provided value. This is especially useful to enable
the use of Tensor Cores on NVIDIA hardware with compute capability
TYPE:
|
return_attention_mask
|
Whether to return the attention mask. If left to the default, will return the attention mask according
to the specific tokenizer's default, defined by the
TYPE:
|
return_tensors
|
If set, will return tensors instead of list of python integers. Acceptable values are:
TYPE:
|
verbose
|
Whether or not to print more information and warnings.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BatchEncoding
|
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.__init__(vocab, default_velocity=77, num_bars=2, unk_token='-1', eos_token='1', pad_token='0', bos_token='2', **kwargs)
¶
This method initializes an instance of the Pop2PianoTokenizer class.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the Pop2PianoTokenizer class.
|
vocab
|
The path to the vocabulary file.
TYPE:
|
default_velocity
|
The default velocity for the tokenizer, default value is 77.
TYPE:
|
num_bars
|
The number of bars.
TYPE:
|
unk_token
|
The unknown token for the tokenizer. If str, it will be converted to an AddedToken.
TYPE:
|
eos_token
|
The end-of-sequence token for the tokenizer. If str, it will be converted to an AddedToken.
TYPE:
|
pad_token
|
The padding token for the tokenizer. If str, it will be converted to an AddedToken.
TYPE:
|
bos_token
|
The beginning-of-sequence token for the tokenizer. If str, it will be converted to an AddedToken.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the 'vocab' file is not found. |
JSONDecodeError
|
If there is an error decoding the JSON data from the 'vocab' file. |
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.batch_decode(token_ids, feature_extractor_output, return_midi=True)
¶
This is the batch_decode method for Pop2PianoTokenizer. It converts the token_ids generated by the
transformer to midi_notes and returns them.
| PARAMETER | DESCRIPTION |
|---|---|
token_ids
|
Output token_ids of
TYPE:
|
feature_extractor_output
|
Denotes the output of
TYPE:
|
return_midi
|
Whether to return midi object or not.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Conditional Return:
If
If
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.batch_encode_plus(notes, truncation_strategy=None, max_length=None, **kwargs)
¶
This is the batch_encode_plus method for Pop2PianoTokenizer. It converts the midi notes to the transformer
generated token ids. It works on multiple batches by calling encode_plus multiple times in a loop.
| PARAMETER | DESCRIPTION |
|---|---|
notes
|
This represents the midi notes. If
If
TYPE:
|
truncation_strategy
|
Indicates the truncation strategy that is going to be used during truncation.
TYPE:
|
max_length
|
Maximum length of the returned list and optionally padding length (see above).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BatchEncoding
|
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.encode_plus(notes, truncation_strategy=None, max_length=None, **kwargs)
¶
This is the encode_plus method for Pop2PianoTokenizer. It converts the midi notes to the transformer
generated token ids. It only works on a single batch, to process multiple batches please use
batch_encode_plus or __call__ method.
| PARAMETER | DESCRIPTION |
|---|---|
notes
|
This represents the midi notes. If
If
TYPE:
|
truncation_strategy
|
Indicates the truncation strategy that is going to be used during truncation.
TYPE:
|
max_length
|
Maximum length of the returned list and optionally padding length (see above).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BatchEncoding
|
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.get_vocab()
¶
Returns the vocabulary of the tokenizer
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
180 181 182 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.notes_to_midi(notes, beatstep, offset_sec=0.0)
¶
Converts notes to Midi.
| PARAMETER | DESCRIPTION |
|---|---|
notes
|
This is used to create Pretty Midi objects.
TYPE:
|
beatstep
|
This is the extrapolated beatstep that we get from feature extractor.
TYPE:
|
offset_sec
|
This represents the offset seconds which is used while creating each Pretty Midi Note.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.relative_batch_tokens_ids_to_midi(tokens, beatstep, beat_offset_idx=0, bars_per_batch=2, cutoff_time_idx=12)
¶
Converts tokens to Midi. This method calls relative_batch_tokens_ids_to_notes method to convert batch tokens
to notes then uses notes_to_midi method to convert them to Midi.
| PARAMETER | DESCRIPTION |
|---|---|
tokens
|
Denotes tokens which alongside beatstep will be converted to Midi.
TYPE:
|
beatstep
|
We get beatstep from feature extractor which is also used to get Midi.
TYPE:
|
beat_offset_idx
|
Denotes beat offset index for each note in generated Midi.
TYPE:
|
bars_per_batch
|
A parameter to control the Midi output generation.
TYPE:
|
cutoff_time_idx
|
Denotes the cutoff time index for each note in generated Midi.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.relative_batch_tokens_ids_to_notes(tokens, beat_offset_idx, bars_per_batch, cutoff_time_idx)
¶
Converts relative tokens to notes which are then used to generate pretty midi object.
| PARAMETER | DESCRIPTION |
|---|---|
tokens
|
Tokens to be converted to notes.
TYPE:
|
beat_offset_idx
|
Denotes beat offset index for each note in generated Midi.
TYPE:
|
bars_per_batch
|
A parameter to control the Midi output generation.
TYPE:
|
cutoff_time_idx
|
Denotes the cutoff time index for each note in generated Midi.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.relative_tokens_ids_to_notes(tokens, start_idx, cutoff_time_idx=None)
¶
Converts relative tokens to notes which will then be used to create Pretty Midi objects.
| PARAMETER | DESCRIPTION |
|---|---|
tokens
|
Relative Tokens which will be converted to notes.
TYPE:
|
start_idx
|
A parameter which denotes the starting index.
TYPE:
|
cutoff_time_idx
|
A parameter used while converting tokens to notes.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.Pop2PianoTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Saves the tokenizer's vocabulary dictionary to the provided save_directory.
| PARAMETER | DESCRIPTION |
|---|---|
save_directory
|
A path to the directory where to saved. It will be created if it doesn't exist.
TYPE:
|
filename_prefix
|
A prefix to add to the names of the files saved by the tokenizer.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.token_note_to_note(number, current_velocity, default_velocity, note_onsets_ready, current_idx, notes)
¶
This function updates the notes list based on the given parameters.
| PARAMETER | DESCRIPTION |
|---|---|
number
|
The number of the note.
TYPE:
|
current_velocity
|
The current velocity of the note.
TYPE:
|
default_velocity
|
The default velocity for the note.
TYPE:
|
note_onsets_ready
|
A list containing the onset index for each note. If an onset index is None, it means that the note has not yet started.
TYPE:
|
current_idx
|
The current index.
TYPE:
|
notes
|
A list containing the notes and their properties.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.tokenization_pop2piano.token_time_to_note(number, cutoff_time_idx, current_idx)
¶
| PARAMETER | DESCRIPTION |
|---|---|
number
|
The amount to increment the current index by.
TYPE:
|
cutoff_time_idx
|
The maximum index value allowed, can be None.
TYPE:
|
current_idx
|
The current index value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
current_idx
|
The updated current index value, respecting the cutoff_time_idx if provided. |
Source code in mindnlp\transformers\models\pop2piano\tokenization_pop2piano.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
mindnlp.transformers.models.pop2piano.processing_pop2piano
¶
Processor class for Pop2Piano.
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor
¶
Bases: ProcessorMixin
Constructs an Pop2Piano processor which wraps a Pop2Piano Feature Extractor and Pop2Piano Tokenizer into a single processor.
[Pop2PianoProcessor] offers all the functionalities of [Pop2PianoFeatureExtractor] and [Pop2PianoTokenizer].
See the docstring of [~Pop2PianoProcessor.__call__] and [~Pop2PianoProcessor.decode] for more information.
| PARAMETER | DESCRIPTION |
|---|---|
feature_extractor
|
An instance of [
TYPE:
|
tokenizer
|
An instance of ['Pop2PianoTokenizer`]. The tokenizer is a required input.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\processing_pop2piano.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor.model_input_names
property
¶
Returns a list of model input names for the Pop2PianoProcessor.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the Pop2PianoProcessor class.
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor.__call__(audio=None, sampling_rate=None, steps_per_beat=2, resample=True, notes=None, padding=False, truncation=None, max_length=None, pad_to_multiple_of=None, verbose=True, **kwargs)
¶
This method uses [Pop2PianoFeatureExtractor.__call__] method to prepare log-mel-spectrograms for the model,
and [Pop2PianoTokenizer.__call__] to prepare token_ids from notes.
Please refer to the docstring of the above two methods for more information.
Source code in mindnlp\transformers\models\pop2piano\processing_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor.batch_decode(token_ids, feature_extractor_output, return_midi=True)
¶
This method uses [Pop2PianoTokenizer.batch_decode] method to convert model generated token_ids to midi_notes.
Please refer to the docstring of the above two methods for more information.
Source code in mindnlp\transformers\models\pop2piano\processing_pop2piano.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor.from_pretrained(pretrained_model_name_or_path, **kwargs)
classmethod
¶
This method creates an instance of the Pop2PianoProcessor class from a pretrained model.
| PARAMETER | DESCRIPTION |
|---|---|
cls
|
The class object itself, automatically passed as the first argument.
TYPE:
|
pretrained_model_name_or_path
|
The name or path of the pretrained model to be used for initialization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\pop2piano\processing_pop2piano.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
mindnlp.transformers.models.pop2piano.processing_pop2piano.Pop2PianoProcessor.save_pretrained(save_directory, **kwargs)
¶
Save the model and its configuration file to a directory. If the directory does not exist, it will be created.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The instance of the Pop2PianoProcessor class.
TYPE:
|
save_directory
|
The directory path where the model and its configuration file will be saved. It should be a directory and not a file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the provided save_directory already exists as a file instead of a directory. |
Source code in mindnlp\transformers\models\pop2piano\processing_pop2piano.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
mindnlp.transformers.models.pop2piano.configuration_pop2piano
¶
Pop2Piano model configuration
mindnlp.transformers.models.pop2piano.configuration_pop2piano.Pop2PianoConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [Pop2PianoForConditionalGeneration]. It is used
to instantiate a Pop2PianoForConditionalGeneration 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
Pop2Piano sweetcocoa/pop2piano 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
TYPE:
|
composer_vocab_size
|
Denotes the number of composers.
TYPE:
|
d_model
|
Size of the encoder layers and the pooler layer.
TYPE:
|
d_kv
|
Size of the key, query, value projections per attention head. The
TYPE:
|
d_ff
|
Size of the intermediate feed forward layer in each
TYPE:
|
num_layers
|
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_decoder_layers
|
Number of hidden layers in the Transformer decoder. Will use the same value as
TYPE:
|
num_heads
|
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
relative_attention_num_buckets
|
The number of buckets to use for each attention layer.
TYPE:
|
relative_attention_max_distance
|
The maximum distance of the longer sequences for the bucket separation.
TYPE:
|
dropout_rate
|
The ratio for all dropout layers.
TYPE:
|
layer_norm_epsilon
|
The epsilon used by the layer normalization layers.
TYPE:
|
initializer_factor
|
A factor for initializing all weight matrices (should be kept to 1.0, used internally for initialization testing).
TYPE:
|
feed_forward_proj
|
Type of feed forward layer to be used. Should be one of
TYPE:
|
use_cache
|
Whether or not the model should return the last key/values attentions (not used by all models).
TYPE:
|
dense_act_fn
|
Type of Activation Function to be used in
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\configuration_pop2piano.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano
¶
Feature extractor class for Pop2Piano
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor
¶
Bases: SequenceFeatureExtractor
Constructs a Pop2Piano feature extractor.
This feature extractor inherits from [~feature_extraction_sequence_utils.SequenceFeatureExtractor] which contains
most of the main methods. Users should refer to this superclass for more information regarding those methods.
This class extracts rhythm and preprocesses the audio before it is passed to the model. First the audio is passed
to RhythmExtractor2013 algorithm which extracts the beat_times, beat positions and estimates their confidence as
well as tempo in bpm, then beat_times is interpolated and to get beatsteps. Later we calculate
extrapolated_beatsteps from it to be used in tokenizer. On the other hand audio is resampled to self.sampling_rate
and preprocessed and then log mel spectogram is computed from that to be used in our transformer model.
| PARAMETER | DESCRIPTION |
|---|---|
sampling_rate
|
Target Sampling rate of audio signal. It's the sampling rate that we forward to the model.
TYPE:
|
padding_value
|
Padding value used to pad the audio. Should correspond to silences.
TYPE:
|
window_size
|
Length of the window in samples to which the Fourier transform is applied.
TYPE:
|
hop_length
|
Step size between each window of the waveform, in samples.
TYPE:
|
min_frequency
|
Lowest frequency that will be used in the log-mel spectrogram.
TYPE:
|
feature_size
|
The feature dimension of the extracted features.
TYPE:
|
num_bars
|
Determines interval between each sequence.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 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 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.__call__(audio, sampling_rate, steps_per_beat=2, resample=True, return_attention_mask=False, return_tensors=None, **kwargs)
¶
Main method to featurize and prepare for the model.
| PARAMETER | DESCRIPTION |
|---|---|
audio
|
The audio or batch of audio to be processed. Each audio can be a numpy array, a list of float values, a list of numpy arrays or a list of list of float values.
TYPE:
|
sampling_rate
|
The sampling rate at which the
TYPE:
|
steps_per_beat
|
This is used in interpolating
TYPE:
|
resample
|
Determines whether to resample the audio to
TYPE:
|
return_attention_mask
|
Denotes if attention_mask for input_features, beatsteps and extrapolated_beatstep will be given as output or not. Automatically set to True for batched inputs.
TYPE:
|
return_tensors
|
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.__init__(sampling_rate=22050, padding_value=0, window_size=4096, hop_length=1024, min_frequency=10.0, feature_size=512, num_bars=2, **kwargs)
¶
Initializes a Pop2PianoFeatureExtractor object.
| PARAMETER | DESCRIPTION |
|---|---|
self
|
The Pop2PianoFeatureExtractor object itself.
|
sampling_rate
|
The sampling rate of the audio signal in Hz. Defaults to 22050.
TYPE:
|
padding_value
|
The value used for padding the audio signal. Defaults to 0.
TYPE:
|
window_size
|
The size of the analysis window in samples. Defaults to 4096.
TYPE:
|
hop_length
|
The number of samples between successive frames. Defaults to 1024.
TYPE:
|
min_frequency
|
The minimum frequency in Hz for the mel filters. Defaults to 10.0.
TYPE:
|
feature_size
|
The size of the output feature representation. Defaults to 512.
TYPE:
|
num_bars
|
The number of bars in each feature representation. Defaults to 2.
TYPE:
|
**kwargs
|
Additional keyword arguments to be passed to the parent class forwardor.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. |
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.extract_rhythm(audio)
¶
This algorithm(RhythmExtractor2013) extracts the beat positions and estimates their confidence as well as
tempo in bpm for an audio signal. For more information please visit
https://essentia.upf.edu/reference/std_RhythmExtractor2013.html .
| PARAMETER | DESCRIPTION |
|---|---|
audio(`numpy.ndarray`)
|
raw audio waveform which is passed to the Rhythm Extractor.
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.interpolate_beat_times(beat_times, steps_per_beat, n_extend)
¶
This method takes beat_times and then interpolates that using scipy.interpolate.interp1d and the output is
then used to convert raw audio to log-mel-spectrogram.
| PARAMETER | DESCRIPTION |
|---|---|
beat_times
|
beat_times is passed into
TYPE:
|
steps_per_beat
|
used as an parameter to control the interpolation.
TYPE:
|
n_extend
|
used as an parameter to control the interpolation.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.mel_spectrogram(sequence)
¶
Generates MelSpectrogram.
| PARAMETER | DESCRIPTION |
|---|---|
sequence
|
The sequence of which the mel-spectrogram will be computed.
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.pad(inputs, is_batched, return_attention_mask, return_tensors=None)
¶
Pads the inputs to same length and returns attention_mask.
| PARAMETER | DESCRIPTION |
|---|---|
inputs
|
Processed audio features.
TYPE:
|
is_batched
|
Whether inputs are batched or not.
TYPE:
|
return_attention_mask
|
Whether to return attention mask or not.
TYPE:
|
return_tensors
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
|
|
|
to it: |
|
|
|
|
|
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
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 | |
mindnlp.transformers.models.pop2piano.feature_extraction_pop2piano.Pop2PianoFeatureExtractor.preprocess_mel(audio, beatstep)
¶
Preprocessing for log-mel-spectrogram
| PARAMETER | DESCRIPTION |
|---|---|
audio
|
Raw audio waveform to be processed.
TYPE:
|
beatstep
|
Interpolated values of the raw audio. If beatstep[0] is greater than 0.0, then it will be shifted by the value at beatstep[0].
TYPE:
|
Source code in mindnlp\transformers\models\pop2piano\feature_extraction_pop2piano.py
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 | |