pop2piano
mindnlp.transformers.models.pop2piano.modeling_pop2piano
¶
Mindspore Pop2Piano model.
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention
¶
Bases: Module
This class represents a self-attention mechanism with optional relative attention bias for the Pop2Piano model. It inherits from nn.Module and provides functionalities for attention computation and head pruning.
ATTRIBUTE | DESCRIPTION |
---|---|
config |
Pop2PianoConfig, the configuration for the attention mechanism
|
has_relative_attention_bias |
bool, flag indicating whether relative attention bias is enabled
|
relative_attention_num_buckets |
int, the number of buckets for relative attention
|
relative_attention_max_distance |
int, the maximum distance for relative attention
|
d_model |
int, the model dimension
|
key_value_proj_dim |
int, the dimension of projected key and value
|
n_heads |
int, the number of attention heads
|
dropout |
float, dropout rate
|
inner_dim |
int, the inner dimension for multi-head attention
|
q |
nn.Linear, query projection layer
|
k |
nn.Linear, key projection layer
|
v |
nn.Linear, value projection layer
|
o |
nn.Linear, output projection layer
|
relative_attention_bias |
nn.Embedding, embedding layer for relative attention bias
|
pruned_heads |
set, set of pruned attention heads
|
gradient_checkpointing |
bool, flag for gradient checkpointing
|
METHOD | DESCRIPTION |
---|---|
prune_heads |
Prunes specified attention heads from the model |
_relative_position_bucket |
Computes relative position buckets |
compute_bias |
Computes binned relative position bias |
forward |
Constructs attention mechanism |
Note
For detailed information on each method and attribute, refer to the method and attribute documentation in the class implementation.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention.__init__(config, has_relative_attention_bias=False)
¶
Initializes an instance of the Pop2PianoAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoAttention class.
|
config |
An instance of Pop2PianoConfig containing the configuration parameters.
TYPE:
|
has_relative_attention_bias |
A boolean indicating whether relative attention bias is enabled.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
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
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
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
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoAttention.prune_heads(heads)
¶
This method 'prune_heads' is defined within the class 'Pop2PianoAttention' and is responsible for pruning the attention heads based on the provided criteria.
PARAMETER | DESCRIPTION |
---|---|
self |
Represents the instance of the class 'Pop2PianoAttention'. It is used to access the class attributes and methods.
|
heads |
A list containing the indices of attention heads to be pruned. The indices should be within the range of the total number of attention heads. If the list is empty, no action will be taken.
|
RETURNS | DESCRIPTION |
---|---|
None
|
However, it modifies the internal state of the 'Pop2PianoAttention' instance by pruning the attention heads and updating the relevant attributes. |
Source code in mindnlp/transformers/models/pop2piano/modeling_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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoBlock
¶
Bases: Module
This class represents a block of the Pop2Piano model. It is a subclass of nn.Module and contains layers for self-attention, cross-attention (if applicable), and feed-forward processing.
ATTRIBUTE | DESCRIPTION |
---|---|
is_decoder |
Indicates whether the block is a decoder block or not.
TYPE:
|
layer |
List of layers in the block, including self-attention, cross-attention, and feed-forward layers.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes a new instance of the Pop2PianoBlock class. |
forward |
Constructs the block by applying the layers sequentially to the input hidden states. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoBlock.__init__(config, has_relative_attention_bias=False)
¶
Initializes a new instance of the Pop2PianoBlock class.
PARAMETER | DESCRIPTION |
---|---|
self |
The class instance that the method operates on.
|
config |
An instance of the configuration class that contains the model configuration.
|
has_relative_attention_bias |
A boolean value indicating whether the model has relative attention bias. Defaults to False.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoBlock.forward(hidden_states, attention_mask=None, position_bias=None, encoder_hidden_states=None, encoder_attention_mask=None, encoder_decoder_position_bias=None, layer_head_mask=None, cross_attn_layer_head_mask=None, past_key_value=None, use_cache=False, output_attentions=False)
¶
Constructs the Pop2PianoBlock.
This method forwards the Pop2PianoBlock by performing self-attention and cross-attention operations on the given input hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoBlock class.
TYPE:
|
hidden_states |
The input hidden states. It has shape (batch_size, sequence_length, hidden_size).
TYPE:
|
attention_mask |
The attention mask tensor. It has shape (batch_size, sequence_length) and each element is either 0 or 1. Defaults to None.
TYPE:
|
position_bias |
The position bias tensor. It has shape (batch_size, num_heads, sequence_length, sequence_length). Defaults to None.
TYPE:
|
encoder_hidden_states |
The encoder hidden states tensor. It has shape (batch_size, sequence_length, hidden_size). Defaults to None.
TYPE:
|
encoder_attention_mask |
The encoder attention mask tensor. It has shape (batch_size, sequence_length) and each element is either 0 or 1. Defaults to None.
TYPE:
|
encoder_decoder_position_bias |
The encoder-decoder position bias tensor. It has shape (batch_size, num_heads, sequence_length, sequence_length). Defaults to None.
TYPE:
|
layer_head_mask |
The layer head mask tensor. It has shape (num_hidden_layers, num_heads) and each element is either 0 or 1. Defaults to None.
TYPE:
|
cross_attn_layer_head_mask |
The cross-attention layer head mask tensor. It has shape (num_hidden_layers, num_heads) and each element is either 0 or 1. Defaults to None.
TYPE:
|
past_key_value |
The tuple of past key-value state tensors. The tuple contains two tensors for self-attention and four tensors for cross-attention. Defaults to None.
TYPE:
|
use_cache |
Whether to use cache for the attention outputs. Defaults to False.
TYPE:
|
output_attentions |
Whether to output attentions. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Tensor]: The tuple containing the output hidden states tensor and other optional tensors, depending on the value of use_cache. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the length of past_key_value is not equal to the expected number of past states. |
Warning
|
If past_key_values is passed to the encoder instead of the decoder. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoConcatEmbeddingToMel
¶
Bases: Module
Embedding Matrix for composer
tokens.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoConcatEmbeddingToMel.__init__(config)
¶
Initializes the Pop2PianoConcatEmbeddingToMel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoConcatEmbeddingToMel class.
|
config |
A configuration object containing parameters for the initialization.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoConcatEmbeddingToMel.forward(feature, index_value, embedding_offset)
¶
This method forwards inputs_embeds for Pop2PianoConcatEmbeddingToMel model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class Pop2PianoConcatEmbeddingToMel.
TYPE:
|
feature |
The input feature array to be concatenated with composer_embedding.
TYPE:
|
index_value |
The index value used for embedding lookup.
TYPE:
|
embedding_offset |
The offset value to adjust the index_value for embedding lookup.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseActDense
¶
Bases: Module
This class represents a Pop2PianoDenseActDense layer, which is used in neural network models. It inherits from the nn.Module class.
The Pop2PianoDenseActDense layer consists of two dense linear transformations (wi and wo), an activation function (act), and a dropout layer (dropout). The layer takes a tensor of hidden states as input and applies the following operations to the input:
- The input tensor is passed through the wi dense linear transformation.
- The result is then passed through the activation function specified by the Pop2PianoConfig's dense_act_fn attribute.
- The output of the activation function is then passed through the dropout layer, which randomly sets elements of the tensor to zero with a probability specified by the Pop2PianoConfig's dropout_rate attribute.
- If the weight of the wo dense linear transformation is a tensor and the input tensor's dtype is different from the weight's dtype, and the weight's dtype is not int8, the input tensor is converted to the same dtype as the weight.
- The converted input tensor is then passed through the wo dense linear transformation.
- The final output of the layer is returned.
Please note that this class assumes the existence of the Pop2PianoConfig class, which should be passed as an argument to the class's forwardor.
Example
>>> config = Pop2PianoConfig(...)
>>> layer = Pop2PianoDenseActDense(config)
>>> hidden_states = ...
>>> output = layer.forward(hidden_states)
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseActDense.__init__(config)
¶
Initializes the Pop2PianoDenseActDense class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An instance of the Pop2PianoConfig class containing the configuration parameters for the model. It specifies the model's dimensions and activation function for the dense layers.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the 'config' parameter is not of type Pop2PianoConfig. |
ValueError
|
If the 'config' parameter does not contain valid configuration parameters. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseActDense.forward(hidden_states)
¶
Constructs the Pop2PianoDenseActDense object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoDenseActDense class.
|
hidden_states |
The hidden states to be processed. It should have a shape of (batch_size, feature_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
mindspore.Tensor: The processed hidden states. It has the same shape as the input hidden_states. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the hidden_states parameter is not of type mindspore.Tensor. |
ValueError
|
If the shape of the hidden_states parameter is not (batch_size, feature_size). |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseGatedActDense
¶
Bases: Module
This class represents a custom neural network module called Pop2PianoDenseGatedActDense that implements a dense gated activation function using Pop2PianoConfig parameters. The module consists of dense layers with gated activation functions for neural network computations. It inherits from the nn.Module class and provides methods for initializing and forwarding the neural network layers. The class contains methods for initializing network parameters and performing forward computations through the network layers.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseGatedActDense.__init__(config)
¶
Initializes a Pop2PianoDenseGatedActDense instance with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoDenseGatedActDense class. |
config |
An instance of Pop2PianoConfig containing configuration parameters.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the configuration parameters are invalid or missing. |
TypeError
|
If the data types of the configuration parameters are incorrect. |
KeyError
|
If the activation function specified in the configuration is not supported. |
Source code in mindnlp/transformers/models/pop2piano/modeling_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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoDenseGatedActDense.forward(hidden_states)
¶
This method 'forward' in the class 'Pop2PianoDenseGatedActDense' forwards hidden states based on the provided input hidden states.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the class Pop2PianoDenseGatedActDense. It is used to access the class attributes and methods.
|
hidden_states |
A tensor representing the input hidden states. It is used as the initial input to forward the final hidden states. Type: Tensor.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value but updates the hidden_states variable within the method. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input parameters are not of the expected types. |
ValueError
|
If there are issues with the shapes or values of the tensors being manipulated. |
RuntimeError
|
If there are runtime issues during the execution of the method. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration
¶
Bases: Pop2PianoPreTrainedModel
The Pop2PianoForConditionalGeneration
class is a subclass of Pop2PianoPreTrainedModel
that represents a
Pop2Piano model for conditional generation. It is specifically designed for generating MIDI token ids based on
given input features.
Initialization
The class forwardor __init__
takes a Pop2PianoConfig
object as an argument and initializes the model.
It sets up the necessary components like the shared embedding layer, encoder, decoder, and LM head.
Model Components
shared
: An embedding layer that maps token ids to their corresponding embeddings.encoder
: The Pop2PianoStack module responsible for encoding the input features.decoder
: The Pop2PianoStack module responsible for decoding and generating the output sequence.lm_head
: A linear layer that maps the decoder output to the vocabulary space.
Getter and Setter Methods
get_input_embeddings
: Returns the shared embedding layer.set_input_embeddings
: Sets the shared embedding layer to the providednew_embeddings
.set_output_embeddings
: Sets the LM head to the providednew_embeddings
.get_output_embeddings
: Returns the LM head.get_encoder
: Returns the encoder module.get_decoder
: Returns the decoder module.
Generation Methods
get_mel_conditioner_outputs()
: Concatenates mel conditioner tokens to the front of the input features for controlling the type of MIDI token generated by the model. It takes the input features, composer name, generation config, and attention mask as inputs.forward()
: Constructs the model for conditional generation. It takes various inputs like input ids, attention mask, decoder input ids, etc., and returns the generated MIDI token ids.generate()
: Generates token ids for MIDI outputs. It takes input features, attention mask, composer name, generation config, and additional kwargs as inputs. It returns the generated MIDI token ids.prepare_inputs_for_generation()
: Prepares the inputs for generation. It takes input ids, past key values, attention mask, and various masks as inputs and returns a dictionary of prepared inputs.prepare_decoder_input_ids_from_labels()
: Prepares the decoder input ids from labels. It takes labels as input and returns the shifted right labels._reorder_cache()
: Reorders the past key values according to the beam index.
Please refer to the documentation of the parent class Pop2PianoPreTrainedModel
for more details on other
inherited methods and attributes.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 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 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.__init__(config)
¶
Initializes an instance of the Pop2PianoForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance.
|
config |
The configuration object used for initializing the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 |
|
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)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor], Seq2SeqLMOutput]
|
Union[Tuple[mindspore.Tensor], Seq2SeqLMOutput] |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
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. If
TYPE:
|
kwargs |
Ad hoc parametrization of
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
[ Since Pop2Piano is an encoder-decoder model (
|
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.get_decoder()
¶
Returns the decoder model used for conditional generation in the Pop2PianoForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoForConditionalGeneration class. This parameter is required to access the decoder model. |
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.get_encoder()
¶
Returns the encoder used for Pop2PianoForConditionalGeneration.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the Pop2PianoForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.get_input_embeddings()
¶
This method, 'get_input_embeddings', is defined within the class 'Pop2PianoForConditionalGeneration' and is used to retrieve the input embeddings.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 |
|
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
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.get_output_embeddings()
¶
Method to retrieve the output embeddings from the Pop2PianoForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
Pop2PianoForConditionalGeneration object. Represents the instance of the class.
|
RETURNS | DESCRIPTION |
---|---|
lm_head
|
The method returns the output embeddings from the 'lm_head' attribute of the instance. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.prepare_decoder_input_ids_from_labels(labels)
¶
Prepare decoder input IDs from labels for conditional generation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoForConditionalGeneration class. |
labels |
The labels tensor representing the target sequence. It serves as the input to forward the decoder input IDs by shifting the labels to the right.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return a value explicitly. It prepares the decoder input IDs for the model. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, head_mask=None, decoder_head_mask=None, cross_attn_head_mask=None, use_cache=None, encoder_outputs=None, **kwargs)
¶
This method prepares inputs for generation in the Pop2PianoForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
input_ids |
The input tensor containing the token ids for the input sequence.
TYPE:
|
past_key_values |
A tuple of tensors containing the past key and value states for fast decoding. Defaults to None.
TYPE:
|
attention_mask |
An optional tensor of the same size as input_ids, used to mask the input tokens. Defaults to None.
TYPE:
|
head_mask |
An optional tensor with shape (num_heads,) that is used to mask the attention heads. Defaults to None.
TYPE:
|
decoder_head_mask |
An optional tensor with shape (num_heads,) that is used to mask the decoder attention heads. Defaults to None.
TYPE:
|
cross_attn_head_mask |
An optional tensor with shape (num_heads,) that is used to mask the cross-attention heads. Defaults to None.
TYPE:
|
use_cache |
A flag indicating whether to use the cache for fast decoding. Defaults to None.
TYPE:
|
encoder_outputs |
A tuple of tensors containing the encoder outputs, used in the cross-attention mechanism.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.set_input_embeddings(new_embeddings)
¶
Set the input embeddings for the Pop2PianoForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoForConditionalGeneration class. |
new_embeddings |
The new input embeddings to be set for the model. Should be compatible with the model's encoder and decoder.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Sets the output embeddings of the Pop2PianoForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoForConditionalGeneration class. |
new_embeddings |
The new embeddings to be set as the output embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerCrossAttention
¶
Bases: Module
The Pop2PianoLayerCrossAttention class represents a layer that performs cross-attention within the Pop2Piano model architecture. This class inherits from nn.Module and contains methods for initializing the layer and forwarding the cross-attention mechanism.
ATTRIBUTE | DESCRIPTION |
---|---|
EncDecAttention |
Instance of Pop2PianoAttention for performing cross-attention.
|
layer_norm |
Instance of Pop2PianoLayerNorm for layer normalization.
|
dropout |
Dropout layer for regularization.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the Pop2PianoLayerCrossAttention with the given configuration. |
forward |
Constructs the cross-attention mechanism by applying layer normalization, attention computation, and dropout. |
RETURNS | DESCRIPTION |
---|---|
outputs
|
Tuple containing the layer output and additional attention outputs. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerCrossAttention.__init__(config)
¶
Initialize a Pop2PianoLayerCrossAttention object.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoLayerCrossAttention class. |
config |
Configuration object containing necessary parameters for initialization.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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.modeling_pop2piano.Pop2PianoLayerCrossAttention.forward(hidden_states, key_value_states, attention_mask=None, position_bias=None, layer_head_mask=None, past_key_value=None, use_cache=False, query_length=None, output_attentions=False)
¶
Method 'forward' in the class 'Pop2PianoLayerCrossAttention'.
This method forwards the output of the Pop2PianoLayerCrossAttention layer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
hidden_states |
The input hidden states to the layer.
TYPE:
|
key_value_states |
The key-value states used in attention computation.
TYPE:
|
attention_mask |
Mask to avoid attending to certain positions.
TYPE:
|
position_bias |
Bias applied to positions for relative attention.
TYPE:
|
layer_head_mask |
Mask applied to the heads in the layer.
TYPE:
|
past_key_value |
Tuple containing past key and value tensors.
TYPE:
|
use_cache |
If True, cache the computed key-value states.
TYPE:
|
query_length |
Length of the query sequence.
TYPE:
|
output_attentions |
If True, return attention weights.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing the layer output tensor and additional outputs from attention computation. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerFF
¶
Bases: Module
This class represents a feed-forward layer used in the Pop2Piano model. It is inherited from the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
DenseReluDense |
A dense layer with gated activation function, if config.is_gated_act is True, otherwise a dense layer with regular activation function. |
layer_norm |
A layer normalization module.
TYPE:
|
dropout |
A dropout module.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the Pop2PianoLayerFF instance with the provided configuration. |
forward |
Constructs the feed-forward layer by applying layer normalization, dense layer, dropout, and residual connection. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerFF.__init__(config)
¶
Initializes the Pop2PianoLayerFF class instance with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoLayerFF class.
TYPE:
|
config |
An instance of the Pop2PianoConfig class containing configuration parameters. This parameter is required for configuring the behavior of the Pop2PianoLayerFF instance. It should be of type Pop2PianoConfig and must not be None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerFF.forward(hidden_states)
¶
Constructs the forward pass of the Pop2PianoLayerFF model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the Pop2PianoLayerFF class.
TYPE:
|
hidden_states |
The input hidden states. A tensor of shape (batch_size, hidden_size).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
torch.Tensor: The updated hidden states. A tensor of shape (batch_size, hidden_size). |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerNorm
¶
Bases: Module
Pop2PianoLayerNorm class represents a layer normalization module in the Pop2Piano style, designed without bias and mean subtraction. This class inherits from nn.Module and provides functionality for performing layer normalization on hidden states in a neural network. The class includes methods for initialization and forwardion, applying the Pop2Piano style normalization to the input hidden states. The 'Pop2PianoLayerNorm' class is suitable for use in deep learning models requiring efficient and effective normalization techniques.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
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
62 63 64 65 66 67 68 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerNorm.forward(hidden_states)
¶
Method 'forward' in the class 'Pop2PianoLayerNorm'.
PARAMETER | DESCRIPTION |
---|---|
self |
Represents the instance of the class Pop2PianoLayerNorm. It is used to access attributes and methods of the class.
|
hidden_states |
Represents the hidden states input to the method.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return a value but updates the hidden_states in-place after normalizing them. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerSelfAttention
¶
Bases: Module
This class represents a self-attention mechanism used in the Pop2PianoLayer model.
The Pop2PianoLayerSelfAttention class is a subclass of the nn.Module class in the PyTorch library. It is responsible for performing self-attention on the input hidden states.
ATTRIBUTE | DESCRIPTION |
---|---|
SelfAttention |
An instance of the Pop2PianoAttention class used for self-attention computation.
TYPE:
|
layer_norm |
An instance of the Pop2PianoLayerNorm class used for layer normalization.
TYPE:
|
dropout |
An instance of the Dropout class used for dropout regularization.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Constructs a new Pop2PianoLayerSelfAttention object. |
forward |
Performs self-attention on the input hidden states. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerSelfAttention.__init__(config, has_relative_attention_bias=False)
¶
Initializes an instance of the Pop2PianoLayerSelfAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing configuration parameters for the attention layer.
TYPE:
|
has_relative_attention_bias |
Specifies whether the attention layer has relative attention bias. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoLayerSelfAttention.forward(hidden_states, attention_mask=None, position_bias=None, layer_head_mask=None, past_key_value=None, use_cache=False, output_attentions=False)
¶
Constructs the Pop2PianoLayerSelfAttention.
This method is responsible for forwarding the Pop2PianoLayerSelfAttention in the given class. It takes in several parameters to perform the forwardion and returns None.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the Pop2PianoLayerSelfAttention class. |
hidden_states |
The input hidden states.
TYPE:
|
attention_mask |
An optional mask tensor. Default is None.
TYPE:
|
position_bias |
An optional tensor for position bias. Default is None.
TYPE:
|
layer_head_mask |
An optional tensor for layer head mask. Default is None.
TYPE:
|
past_key_value |
An optional tuple of past key and value tensors. Default is None.
TYPE:
|
use_cache |
A flag indicating whether to use cache. Default is False.
TYPE:
|
output_attentions |
A flag indicating whether to output attentions. Default is False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
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
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoStack
¶
Bases: Pop2PianoPreTrainedModel
This class represents a stack of Pop2Piano blocks that can be used for modeling and processing tasks in a Pop2Piano-based architecture. The class inherits from Pop2PianoPreTrainedModel and includes methods for initializing the model, setting input embeddings, and forwarding the model with various input and output options.
The class includes methods for initializing the model with token embeddings, processing input data, and generating model outputs. It also supports features such as caching, attention masks, and output options for hidden states and attentions.
The Pop2PianoStack class is designed to handle multiple layers of Pop2Piano blocks and provides flexibility for customizing model behavior and output based on the input configurations.
For more detailed information on the methods and their parameters, refer to the method docstrings within the class implementation.
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoStack.__init__(config, embed_tokens=None)
¶
Initializes a Pop2PianoStack instance.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoStack class.
|
config |
A configuration object containing parameters for the model.
|
embed_tokens |
Tokens used for embedding.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
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 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoStack.forward(input_ids=None, attention_mask=None, encoder_hidden_states=None, encoder_attention_mask=None, inputs_embeds=None, head_mask=None, cross_attn_head_mask=None, past_key_values=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
This method forwards the Pop2PianoStack model with the specified input parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoStack class.
|
input_ids |
Tensor of shape (batch_size, sequence_length) representing input token IDs.
TYPE:
|
attention_mask |
Tensor of shape (batch_size, sequence_length) representing attention mask.
TYPE:
|
encoder_hidden_states |
Tensor representing hidden states from the encoder.
TYPE:
|
encoder_attention_mask |
Tensor representing the attention mask for encoder_hidden_states.
TYPE:
|
inputs_embeds |
Tensor representing the input embeddings.
TYPE:
|
head_mask |
Tensor representing the head mask for self-attention.
TYPE:
|
cross_attn_head_mask |
Tensor representing the head mask for cross-attention.
TYPE:
|
past_key_values |
List of past key values for caching.
TYPE:
|
use_cache |
Boolean indicating whether to use caching.
TYPE:
|
output_attentions |
Boolean indicating whether to output attentions.
TYPE:
|
output_hidden_states |
Boolean indicating whether to output hidden states.
TYPE:
|
return_dict |
Boolean indicating whether to return a dictionary.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both input_ids and inputs_embeds are specified simultaneously. |
ValueError
|
If neither input_ids nor inputs_embeds are specified. |
ValueError
|
If model is not initialized with valid token embeddings. |
ValueError
|
If |
Warning
|
If |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoStack.get_input_embeddings()
¶
This method retrieves the input embeddings from the Pop2PianoStack class.
PARAMETER | DESCRIPTION |
---|---|
self |
Pop2PianoStack instance. The self parameter is the instance of the Pop2PianoStack class.
|
RETURNS | DESCRIPTION |
---|---|
embed_tokens
|
This method returns the embed_tokens attribute of the Pop2PianoStack instance, which represents the input embeddings. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
|
mindnlp.transformers.models.pop2piano.modeling_pop2piano.Pop2PianoStack.set_input_embeddings(new_embeddings)
¶
Set the input embeddings for the Pop2PianoStack model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the Pop2PianoStack class.
TYPE:
|
new_embeddings |
The new embeddings to be set for input.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method updates the embed_tokens attribute of the Pop2PianoStack instance. |
Source code in mindnlp/transformers/models/pop2piano/modeling_pop2piano.py
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 |
|
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 |