CN116863893A - Method and system for generating chord based on melody - Google Patents

Method and system for generating chord based on melody Download PDF

Info

Publication number
CN116863893A
CN116863893A CN202310876374.9A CN202310876374A CN116863893A CN 116863893 A CN116863893 A CN 116863893A CN 202310876374 A CN202310876374 A CN 202310876374A CN 116863893 A CN116863893 A CN 116863893A
Authority
CN
China
Prior art keywords
chord
note
sequence
sequence vector
vector
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310876374.9A
Other languages
Chinese (zh)
Inventor
尹学渊
汤刚
刘鑫忠
杨杰
江天宇
陈超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Potential Artificial Intelligence Technology Co ltd
Original Assignee
Chengdu Potential Artificial Intelligence Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Potential Artificial Intelligence Technology Co ltd filed Critical Chengdu Potential Artificial Intelligence Technology Co ltd
Priority to CN202310876374.9A priority Critical patent/CN116863893A/en
Publication of CN116863893A publication Critical patent/CN116863893A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G10MUSICAL INSTRUMENTS; ACOUSTICS
    • G10HELECTROPHONIC MUSICAL INSTRUMENTS; INSTRUMENTS IN WHICH THE TONES ARE GENERATED BY ELECTROMECHANICAL MEANS OR ELECTRONIC GENERATORS, OR IN WHICH THE TONES ARE SYNTHESISED FROM A DATA STORE
    • G10H1/00Details of electrophonic musical instruments
    • G10H1/0033Recording/reproducing or transmission of music for electrophonic musical instruments
    • G10H1/0041Recording/reproducing or transmission of music for electrophonic musical instruments in coded form
    • G10H1/0058Transmission between separate instruments or between individual components of a musical system
    • G10H1/0066Transmission between separate instruments or between individual components of a musical system using a MIDI interface
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • GPHYSICS
    • G10MUSICAL INSTRUMENTS; ACOUSTICS
    • G10HELECTROPHONIC MUSICAL INSTRUMENTS; INSTRUMENTS IN WHICH THE TONES ARE GENERATED BY ELECTROMECHANICAL MEANS OR ELECTRONIC GENERATORS, OR IN WHICH THE TONES ARE SYNTHESISED FROM A DATA STORE
    • G10H1/00Details of electrophonic musical instruments
    • G10H1/36Accompaniment arrangements
    • G10H1/38Chord

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • General Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Multimedia (AREA)
  • Evolutionary Computation (AREA)
  • Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Acoustics & Sound (AREA)
  • Electrophonic Musical Instruments (AREA)

Abstract

The invention provides a method and a system for generating a chord based on melody, comprising the following steps: preprocessing MIDI files to obtain a note sequence and a chord sequence; vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; vectorizing the chord sequence according to the bars to obtain chord sequence vectors of a plurality of bars; inputting the note sequence vector and the chord sequence vector into an initial chord generation model, and constructing a loss function based on the predicted chord sequence vector and the chord sequence vector output by the initial chord generation model to obtain a chord generation model; processing the melody to be processed to obtain note sequence vectors to be processed of a plurality of bars; inputting a plurality of note sequence vectors to be processed into a chord generation model, and generating a chord sequence of the melody to be processed by the chord generation model; generating a chord of the melody to be processed based on the chord sequence of the melody to be processed; so that the chord is more matched with the melody, and the front and rear transition of the chord is reasonable.

Description

Method and system for generating chord based on melody
Technical Field
The invention relates to the technical field of audio processing, in particular to a method and a system for generating a chord based on melody.
Background
With the rapid development of economy and science and technology, various media are rushed into the music market, so that small impact is brought to the music industry, and meanwhile, the market demands on staff engaged in music are also increasing. Music composition is fundamental to the music industry, however, the past music composition threshold is high, and a musician is required to have firm theoretical knowledge of music and rich actual composition experience. The creation of music mainly has three major parts: melody, chord and rhythm, wherein the chord is assembled most complex, most chord is assembled by manual operation at present, the cost is higher, and the quality is also uneven. The music industry has long been a technology driven industry, and related researchers have long been able to edit chords for melodies through computers, and through computer technology, the threshold for music composition can be reduced, i.e. music composition can be freely performed without enriching music theory knowledge. Currently, there are three main methods: the template matching method, the probability model method and the deep neural network method are increasingly enhanced along with the continuous development of artificial intelligence technology, and the deep neural network model can learn the relationship between melody and chord, so that chord configuration can be completed according to the melody. However, the chord obtained by the existing chord configuration method is relatively illegal to the melody, the condition that no corresponding chord corresponds to the chord is easy to occur in one bar, and the chord front-rear correlation between bars is poor.
In view of the above, the invention provides a method and a system for generating a chord based on a melody, so that the chord is more matched with the melody, and the front-back transition of the chord is reasonable.
Disclosure of Invention
The invention aims to provide a method for generating a chord based on melody, which comprises the following steps: loading MIDI files, and preprocessing the MIDI files to obtain note sequences and chord sequences; vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; the note sequence vector comprises a plurality of note vectors, and the feature dimension of each note vector is 12; vectorizing the chord sequence according to bars to obtain chord sequence vectors of a plurality of bars; the chord sequence vector comprises a plurality of chord vectors, and the feature dimension of each chord vector is 24; inputting the note sequence vector and the chord sequence vector into an initial chord generation model, constructing a loss function based on a predicted chord sequence vector output by the initial chord generation model and the chord sequence vector, and obtaining a chord generation model when the loss function is not lowered; processing the melody to be processed to obtain note sequence vectors to be processed of a plurality of bars; inputting the plurality of note sequence vectors to be processed into the chord generation model, wherein the chord generation model generates a chord sequence of the melody to be processed; and generating the chord of the melody to be processed based on the chord sequence of the melody to be processed.
Further, the preprocessing includes: reading parameters in the MIDI file to obtain the number of beats per minute and the number of beats per tick, and determining the number of beats per minute; determining notes in the MIDI file, acquiring position information of each note, and dividing the notes according to the number of each section of the notes and the position information of the notes; the position information of the notes comprises a starting position and an ending position of the notes; converting the pitch of the notes into corresponding tone names, and sequencing the notes to obtain a note sequence; determining chords in the MIDI file, acquiring position information of each chord, and dividing the chords according to the number of each section of the chord and the position information of the chord; the chord position information comprises a chord start position and a chord end position; and converting the tone pitches of the chords into corresponding tone names, and sequencing the chords to obtain a chord sequence.
Further, the initial chord generation model is a transducer model; the input of the note sequence vector and the chord sequence vector into an initial chord generation model is an encoder module and a decoder module respectively inputting the note sequence vector and the chord sequence vector into a transducer model; the loss function is a cross entropy loss function.
Further, the inputting the note sequence vector and the chord sequence vector into an initial chord generation model, and constructing a loss function based on the initial chord sequence vector and the chord sequence vector output by the initial chord generation model includes: acquiring the position information of notes in the note sequence vector according to the bars to obtain a note representation matrix; inputting the note representation matrix into an encoder module of a transducer model to obtain encoder output; inputting the encoder output and the note representation matrix into a decoder module of a transducer model to obtain a decoder output; processing the decoder output through a linear layer and a softmax function to obtain a predicted chord sequence vector; and calculating the losses of the predicted chord sequence vector and the chord sequence vector to obtain a loss function.
Further, the calculation formula for acquiring the position information of the notes according to the measures is as follows:
PE(pos,2i)=sin(pos/10000 2i/d )
PE(pos,2i+1)=cos(pos/10000 2i/d )
wherein PE represents the position information of the note; pos represents the position of each bar in the input note sequence; i represents a column index of the note feature vector; d represents the dimension of the input note vector;
the expression of the obtained encoder output is:
En=Encoder(X)
where En represents the encoder output; x represents a note representation matrix; the Encoder represents the Encoder module of the transducer;
the expression for the decoder output is:
Dn=Decoder(X,En)
wherein Dn represents the decoder output; the Decoder represents a Decoder module of the transducer;
the expression of the obtained predicted chord sequence vector is as follows:
chord o =softmax(liner(Dn))
wherein chord o Representing a predicted chord sequence vector; softmax represents the softmax function of the transducer; link represents the linear layer of the transducer;
the expression of the loss function is:
loss=cross_entropy(chord i ,chord o )
where loss represents the calculated loss, cross_entopy represents the cross entropy loss function, chord i Representing an input chord sequence vector, chord o Representing the predicted chord sequence vector.
A system for generating a chord based on a melody comprises a preprocessing module, a note sequence vector acquisition module, a chord generation model construction module, a note sequence vector acquisition module to be processed, a chord sequence generation module and a chord generation module; the preprocessing module is used for loading MIDI files and preprocessing the MIDI files to obtain note sequences and chord sequences; the note sequence vector acquisition module is used for vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; the note sequence vector comprises a plurality of note vectors, and the feature dimension of each note vector is 12; the chord sequence vector acquisition module is used for vectorizing the chord sequence according to the bars to obtain chord sequence vectors of a plurality of bars; the chord sequence vector comprises a plurality of chord vectors, and the feature dimension of each chord vector is 24; the chord generation model building module is used for inputting the note sequence vector and the chord sequence vector into an initial chord generation model, building a loss function based on the predicted chord sequence vector and the chord sequence vector output by the initial chord generation model, and obtaining a chord generation model when the loss function is not lowered; the note sequence vector obtaining module is used for processing the melody to be processed to obtain note sequence vectors to be processed of a plurality of bars; the chord sequence generation module is used for inputting the plurality of note sequence vectors to be processed into the chord generation model, and the chord generation model generates a chord sequence of the melody to be processed; the chord generating module is used for generating the chord of the melody to be processed based on the chord sequence of the melody to be processed.
Further, the preprocessing includes: reading parameters in the MIDI file to obtain the number of beats per minute and the number of beats per tick, and determining the number of beats per minute; determining notes in the MIDI file, acquiring position information of each note, and dividing the notes according to the number of each section of the notes and the position information of the notes; the position information of the notes comprises a starting position and an ending position of the notes; converting the pitch of the notes into corresponding tone names, and sequencing the notes to obtain a note sequence; determining chords in the MIDI file, acquiring position information of each chord, and dividing the chords according to the number of each section of the chord and the position information of the chord; the chord position information comprises a chord start position and a chord end position; and converting the tone pitches of the chords into corresponding tone names, and sequencing the chords to obtain a chord sequence.
Further, the initial chord generation model is a transducer model; the input of the note sequence vector and the chord sequence vector into an initial chord generation model is an encoder module and a decoder module respectively inputting the note sequence vector and the chord sequence vector into a transducer model; the loss function is a cross entropy loss function.
Further, the inputting the note sequence vector and the chord sequence vector into an initial chord generation model, and constructing a loss function based on the initial chord sequence vector and the chord sequence vector output by the initial chord generation model includes: acquiring the position information of notes in the note sequence vector according to the bars to obtain a note representation matrix; inputting the note representation matrix into an encoder module of a transducer model to obtain encoder output; inputting the encoder output and the note representation matrix into a decoder module of a transducer model to obtain a decoder output; processing the decoder output through a linear layer and a softmax function to obtain a predicted chord sequence vector; and calculating the losses of the predicted chord sequence vector and the chord sequence vector to obtain a loss function.
Further, the calculation formula for acquiring the position information of the notes according to the measures is as follows:
PE(pos,2i)=sin(pos/10000 2i/d )
PE(pos,2i+1)=cos(pos/10000 2i/d )
wherein PE represents the position information of the note; pos represents the position of each bar in the input note sequence; i represents a column index of the note feature vector; d represents the dimension of the input note vector;
the expression of the obtained encoder output is:
En=Encoder(X)
where En represents the encoder output; x represents a note representation matrix; the Encoder represents the Encoder module of the transducer;
the expression for the decoder output is:
Dn=Decoder(X,En)
wherein Dn represents the decoder output; the Decoder represents a Decoder module of the transducer;
the expression of the obtained predicted chord sequence vector is as follows:
chord o =softmax(liner(Dn))
wherein chord o Representing a predicted chord sequence vector; softmax represents the softmax function of the transducer; link represents the linear layer of the transducer;
the expression of the loss function is:
loss=cross_entropy(chord i ,chord o )
where loss represents the calculated loss, cross_entopy represents the cross entropy loss function, chord i Representing the sum of inputsChord sequence vector, chord o Representing the predicted chord sequence vector.
The technical scheme of the embodiment of the invention has at least the following advantages and beneficial effects:
the notes of the chord are divided according to the bars, so that the division mode is more in accordance with the rules of chord configuration in the music science, and the chords are divided according to the bars when the model is trained, so that the melody of each bar corresponds to the harmony, and the integrity of the predicted chord sequence is ensured.
The number of notes in each bar in the music is not fixed, and the sequence of notes is converted into a fixed low-dimensional feature vector by encoding the notes, so that the model can better process the sequence of notes, and the data amount required by training is reduced.
According to the characteristics of a transducer model, the invention can carry out parallel processing on the long note sequence, thereby accelerating the chord configuration speed; in addition, by carrying out self-correlation on the note sequence and the chord sequence, the information contained in the extracted note and chord are more abundant, so that the chord sequence predicted by the model is more accurate; finally, since the self-attribute module in the transducer model can capture the context correlation, the model can learn the correlation between chords so that the composed chord sequence can satisfy the characteristics of the chords in the music structure.
Drawings
FIG. 1 is an exemplary flow chart of a method for generating a chord based on melodies according to some embodiments of the invention;
FIG. 2 is an exemplary schematic diagram of note vectors provided by some embodiments of the present invention;
FIG. 3 is an exemplary schematic diagram of chord vectors provided by some embodiments of the present invention;
fig. 4 is an exemplary block diagram of a system for generating a chord based on melodies according to some embodiments of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. The components of the embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Fig. 1 is an exemplary flowchart of a method of generating a chord based on a melody according to some embodiments of the present invention. As shown in fig. 1, the flow of the method of generating a chord based on the melody includes the following:
step 110, loading MIDI files and preprocessing the MIDI files to obtain note sequences and chord sequences.
MIDI (Musical Instrument Digital Interface) file is a standard file format for music production and control.
In some embodiments, the preprocessing comprises: reading parameters in the MIDI file to obtain the number of beats per minute and the number of beats per section (beat), and determining the number of beats per section; determining notes in the MIDI file, acquiring position information of each note, and dividing the notes according to the number of each section of the notes and the position information of the notes; the position information of the notes comprises a starting position and an ending position of the notes; converting the pitch of the notes into corresponding tone names, and sequencing the notes to obtain a note sequence; determining chords in the MIDI file, acquiring position information of each chord, and dividing the chords according to the number of each section of the chord and the position information of the chord; the chord position information comprises a chord start position and a chord end position; and converting the tone pitches of the chords into corresponding tone names, and sequencing the chords to obtain a chord sequence.
In some embodiments, parameters in the MIDI file can be read through a mido library (MIDI Objects for Python), and the number n of beats per minute and the number t of beats per bar can be obtained after processing, and the calculation formula of the number of beats per bar is as follows:
ticks=n×t
in some embodiments, the time value information of notes in midi files is stored in units of time on a tick basis and is stored in seconds in the actually generated audio, such that the operation involves later audio storage; it can be determined which bar the note belongs to from the note position information, i.e., the start and end positions.
In other embodiments, notes may be divided by 4 notes, 8 notes, or 16 notes.
The tone name refers to a naming method of representing pitch by letters in western music. For example, when the notes are emitted by a piano, the pitch ranges are generally between 21 and 108, corresponding to A0 to C8, respectively.
In some embodiments, notes may be ordered in a time series.
In some embodiments of the invention, the notes are divided according to the measures to better conform to the rules of actual chord assignment, the generated results are easier to control, and the generated discordance hearing feeling can be reduced.
Step 120, vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; the note sequence vector includes a plurality of note vectors, each of which has a feature dimension of 12.
The note sequence vector may refer to a vector obtained by serializing notes for each bar. The note vectors may be ordered in time order to obtain a note sequence vector. As shown in FIG. 2, the dimension of the note vector is 12, and for note C, the corresponding note vector is (000000000001), i.e., when processing notes in a bar, the corresponding position is set to 1
Step 130, vectorizing the chord sequence according to bars to obtain chord sequence vectors of a plurality of bars; the chord sequence vector includes a plurality of chord vectors, each of which has a feature dimension of 24.
The chord sequence vector may refer to a vector obtained by serializing chords for each bar. The chord vectors may be ordered in time order to obtain chord sequence vectors. As shown in fig. 3, the chord vector has dimensions 24, i.e., two major and minor chords. Example(s)E.g. major chord C maj The feature vector is as shown in fig. 3, when the chord of each bar is processed, the position corresponding to the chord is set to be 1, and the sequence of the chords is as follows: { C maj ,C min ,C# maj ,C# min ,D maj ,D min ,D# maj ,D# min ,E maj ,E min ,F maj ,F min ,F# maj ,F# min ,G maj ,G min ,G# maj ,G# min ,A maj ,A min ,A# maj ,B maj ,B min }。
And 140, inputting the note sequence vector and the chord sequence vector into an initial chord generation model, constructing a loss function based on the predicted chord sequence vector and the chord sequence vector output by the initial chord generation model, and obtaining the chord generation model when the loss function is not reduced.
In some embodiments, the initial chord generation model is a Transformer model; the input of the note sequence vector and the chord sequence vector into an initial chord generation model is an encoder module and a decoder module respectively inputting the note sequence vector and the chord sequence vector into a transducer model; the loss function is a cross entropy loss function.
In some embodiments, said inputting the note sequence vector and the chord sequence vector into an initial chord generation model, and constructing a loss function based on the initial chord sequence vector and the chord sequence vector output by the initial chord generation model comprises:
and acquiring the position information of the notes in the note sequence vector according to the bars to obtain a note representation matrix. In some embodiments, the calculation formula for obtaining the position information of the notes in the measure is:
PE(pos,2i)=sin(pos/10000 2i/d )
PE(pos,2i+1)=cos(pos/10000 2i/d )
wherein PE represents the position information of the note; pos represents the position of each bar in the input note sequence; i represents a column index of the note feature vector; d represents the dimension of the input note vector. For even-numbered position bars, position information is calculated using a first formula, i.e., a sine function; for odd-numbered position bars, calculating position information by using a second formula, namely a cosine function; and finally, adding the note feature vector and the bar position information to obtain a corresponding note representation.
And inputting the note representation matrix into an encoder module of a transducer model to obtain an encoder output.
In some embodiments, the expression that results in the encoder output is:
En=Encoder(X)
where En represents the encoder output; x represents a note representation matrix; the Encoder represents the Encoder module of the transducer.
And inputting the encoder output and the note representation matrix into a decoder module of a transducer model to obtain a decoder output.
In some embodiments, the expression that results in the decoder output is:
Dn=Decoder(X,En)
wherein Dn represents the decoder output; the Decoder represents the Decoder module of the transducer.
And processing the decoder output through a linear layer and a softmax function to obtain a predicted chord sequence vector.
In some embodiments, the expression for the resulting predicted chord sequence vector is:
chord o =softmax(liner(Dn))
wherein chord o Representing a predicted chord sequence vector; softmax represents the softmax function of the transducer; link represents the linear layer of the transducer.
And calculating the losses of the predicted chord sequence vector and the chord sequence vector to obtain a loss function.
In some embodiments, the loss function is expressed as:
loss=cross_entropy(chord i ,chord o )
wherein, loss tableShowing the calculated loss, cross_entcopy represents the cross entropy loss function, chord i Representing an input chord sequence vector, chord o Representing the predicted chord sequence vector.
And step 150, processing the melody to be processed to obtain the note sequence vectors to be processed of the bars.
The melody to be processed may refer to a melody in which a chord needs to be generated. The content of the to-be-processed melody to obtain the to-be-processed note sequence vector is specifically a MIDI file for loading the to-be-processed melody, the to-be-processed note sequence is generated, and then the to-be-processed note sequence is vectorized to obtain the to-be-processed note sequence vector. Wherein the content of generating the note sequence to be processed is similar to the content of generating the note sequence, the content of obtaining the note sequence vector to be processed is similar to the content of obtaining the note sequence vector, and for more content of obtaining the note sequence vector to be processed, see step 110 and step 120, and related descriptions thereof.
And step 160, inputting the plurality of note sequence vectors to be processed into the chord generation model, wherein the chord generation model generates a chord sequence of the melody to be processed.
Step 170, generating the chord of the melody to be processed based on the chord sequence of the melody to be processed.
Fig. 4 is an exemplary block diagram of a system for generating a chord based on melodies according to some embodiments of the present invention. As shown in fig. 4, the melody-based chord generating system may include a preprocessing module 410, a note sequence vector acquisition module 420, a chord sequence vector acquisition module 430, a chord generation model construction module 440, a note sequence vector to be processed acquisition module 450, a chord sequence generation module 460, and a chord generation module 470.
The preprocessing module 410 is configured to load MIDI files and perform preprocessing on the MIDI files to obtain note sequences and chord sequences. For more details on the preprocessing module 410, see FIG. 1 and its associated description.
The note sequence vector obtaining module 420 is configured to vectorize the note sequence according to bars, so as to obtain note sequence vectors of multiple bars; the note sequence vector includes a plurality of note vectors, each of which has a feature dimension of 12. For more details on the note sequence vector acquisition module 420, see FIG. 1 and its associated description.
The chord sequence vector obtaining module 430 is configured to vectorize the chord sequence according to bars to obtain chord sequence vectors of multiple bars; the chord sequence vector includes a plurality of chord vectors, each of which has a feature dimension of 24. For more details on the chord sequence vector acquisition module 430, see FIG. 1 and its associated description.
The chord generating model building module 440 is configured to input the note sequence vector and the chord sequence vector into an initial chord generating model, and build a loss function based on the predicted chord sequence vector and the chord sequence vector output by the initial chord generating model, and obtain the chord generating model when the loss function is not reduced any more. For more details on the chord generation model construction module 440, see FIG. 1 and its associated description.
The to-be-processed note sequence vector obtaining module 450 is configured to process the to-be-processed melody to obtain to-be-processed note sequence vectors of the plurality of bars. For more details of the pending note sequence vector acquisition module 450, see FIG. 1 and its associated description.
The chord sequence generation module 460 is configured to input the plurality of note sequence vectors to be processed into the chord generation model, where the chord generation model generates a chord sequence of the melody to be processed. For more details on the chord sequence generation module 460, see FIG. 1 and its associated description.
The chord generating module 470 is configured to generate a chord of the to-be-processed melody based on the chord sequence of the to-be-processed melody. For more on the chord generation module 470, see FIG. 1 and its associated description.
The above is only a preferred embodiment of the present invention, and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of generating a chord based on a melody, comprising:
loading MIDI files, and preprocessing the MIDI files to obtain note sequences and chord sequences;
vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; the note sequence vector comprises a plurality of note vectors, and the feature dimension of each note vector is 12;
vectorizing the chord sequence according to bars to obtain chord sequence vectors of a plurality of bars; the chord sequence vector comprises a plurality of chord vectors, and the feature dimension of each chord vector is 24;
inputting the note sequence vector and the chord sequence vector into an initial chord generation model, constructing a loss function based on a predicted chord sequence vector output by the initial chord generation model and the chord sequence vector, and obtaining a chord generation model when the loss function is not lowered;
processing the melody to be processed to obtain note sequence vectors to be processed of a plurality of bars;
inputting the plurality of note sequence vectors to be processed into the chord generation model, wherein the chord generation model generates a chord sequence of the melody to be processed;
and generating the chord of the melody to be processed based on the chord sequence of the melody to be processed.
2. The melody-based chord generation method according to claim 1, wherein the preprocessing includes:
reading parameters in the MIDI file to obtain the number of beats per minute and the number of beats per tick, and determining the number of beats per minute;
determining notes in the MIDI file, acquiring position information of each note, and dividing the notes according to the number of each section of the notes and the position information of the notes; the position information of the notes comprises a starting position and an ending position of the notes;
converting the pitch of the notes into corresponding tone names, and sequencing the notes to obtain a note sequence;
determining chords in the MIDI file, acquiring position information of each chord, and dividing the chords according to the number of each section of the chord and the position information of the chord; the chord position information comprises a chord start position and a chord end position;
and converting the tone pitches of the chords into corresponding tone names, and sequencing the chords to obtain a chord sequence.
3. The melody-based chord generation method according to claim 1, wherein the initial chord generation model is a transducer model;
the input of the note sequence vector and the chord sequence vector into an initial chord generation model is an encoder module and a decoder module respectively inputting the note sequence vector and the chord sequence vector into a transducer model;
the loss function is a cross entropy loss function.
4. The melody-based chord generation method according to claim 3, wherein the inputting the note sequence vector and the chord sequence vector into an initial chord generation model and constructing a loss function based on the initial chord sequence vector and the chord sequence vector output by the initial chord generation model includes:
acquiring the position information of notes in the note sequence vector according to the bars to obtain a note representation matrix;
inputting the note representation matrix into an encoder module of a transducer model to obtain encoder output;
inputting the encoder output and the note representation matrix into a decoder module of a transducer model to obtain a decoder output;
processing the decoder output through a linear layer and a softmax function to obtain a predicted chord sequence vector;
and calculating the losses of the predicted chord sequence vector and the chord sequence vector to obtain a loss function.
5. The method for generating a chord based on the melody of claim 4, wherein the calculation formula for obtaining the position information of the notes in bars is:
PE(pos,2i)=sin(pos/10000 2i/ )
PE(pos,2i+1)=cos(pos/10000 2i/ )
wherein PE represents the position information of the note; pos represents the position of each bar in the input note sequence; i represents a column index of the note feature vector; d represents the dimension of the input note vector;
the expression of the obtained encoder output is:
En=Encoder(X)
where En represents the encoder output; x represents a note representation matrix; the Encoder represents the Encoder module of the transducer;
the expression for the decoder output is:
Dn=Decoder(X,En)
wherein Dn represents the decoder output; the Decoder represents a Decoder module of the transducer;
the expression of the obtained predicted chord sequence vector is as follows:
chord o =softmax(liner(Dn))
wherein chord o Representing a predicted chord sequence vector; softmax represents the softmax function of the transducer; link represents the linear layer of the transducer;
the expression of the loss function is:
loss=cross_entropy(chord i ,chord o )
where loss represents the calculated loss, cross_entropy represents the cross entropy loss function,
chord i representing an input chord sequence vector, chord o Representing the predicted chord sequence vector.
6. The system for generating the chord based on the melody is characterized by comprising a preprocessing module, a note sequence vector acquisition module, a chord generation model construction module, a note sequence vector acquisition module to be processed, a chord sequence generation module and a chord generation module;
the preprocessing module is used for loading MIDI files and preprocessing the MIDI files to obtain note sequences and chord sequences;
the note sequence vector acquisition module is used for vectorizing the note sequence according to the bars to obtain note sequence vectors of a plurality of bars; the note sequence vector comprises a plurality of note vectors, and the feature dimension of each note vector is 12;
the chord sequence vector acquisition module is used for vectorizing the chord sequence according to the bars to obtain chord sequence vectors of a plurality of bars; the chord sequence vector comprises a plurality of chord vectors, and the feature dimension of each chord vector is 24;
the chord generation model building module is used for inputting the note sequence vector and the chord sequence vector into an initial chord generation model, building a loss function based on the predicted chord sequence vector and the chord sequence vector output by the initial chord generation model, and obtaining a chord generation model when the loss function is not lowered;
the note sequence vector obtaining module is used for processing the melody to be processed to obtain note sequence vectors to be processed of a plurality of bars;
the chord sequence generation module is used for inputting the plurality of note sequence vectors to be processed into the chord generation model, and the chord generation model generates a chord sequence of the melody to be processed;
the chord generating module is used for generating the chord of the melody to be processed based on the chord sequence of the melody to be processed.
7. The melody-based chord generation system according to claim 6, wherein the preprocessing includes:
reading parameters in the MIDI file to obtain the number of beats per minute and the number of beats per tick, and determining the number of beats per minute;
determining notes in the MIDI file, acquiring position information of each note, and dividing the notes according to the number of each section of the notes and the position information of the notes; the position information of the notes comprises a starting position and an ending position of the notes;
converting the pitch of the notes into corresponding tone names, and sequencing the notes to obtain a note sequence;
determining chords in the MIDI file, acquiring position information of each chord, and dividing the chords according to the number of each section of the chord and the position information of the chord; the chord position information comprises a chord start position and a chord end position;
and converting the tone pitches of the chords into corresponding tone names, and sequencing the chords to obtain a chord sequence.
8. The melody-based chord generation system according to claim 6, wherein the initial chord generation model is a transducer model;
the input of the note sequence vector and the chord sequence vector into an initial chord generation model is an encoder module and a decoder module respectively inputting the note sequence vector and the chord sequence vector into a transducer model;
the loss function is a cross entropy loss function.
9. The melody-based chord system according to claim 8, wherein the inputting the note sequence vector and the chord sequence vector into an initial chord generation model and constructing a loss function based on the initial chord sequence vector and the chord sequence vector output by the initial chord generation model includes:
acquiring the position information of notes in the note sequence vector according to the bars to obtain a note representation matrix;
inputting the note representation matrix into an encoder module of a transducer model to obtain encoder output;
inputting the encoder output and the note representation matrix into a decoder module of a transducer model to obtain a decoder output;
processing the decoder output through a linear layer and a softmax function to obtain a predicted chord sequence vector;
and calculating the losses of the predicted chord sequence vector and the chord sequence vector to obtain a loss function.
10. The melody-based chord generation system according to claim 9, wherein the calculation formula for obtaining the position information of notes in bars is:
PE(pos,2i)=sin(pos/10000 2i/ )
PE(pos,2i+1)=cos(pos/10000 2i/ )
wherein PE represents the position information of the note; pos represents the position of each bar in the input note sequence; i represents a column index of the note feature vector; d represents the dimension of the input note vector;
the expression of the obtained encoder output is:
En=Encoder(X)
where En represents the encoder output; x represents a note representation matrix; the Encoder represents the Encoder module of the transducer;
the expression for the decoder output is:
Dn=Decoder(X,En)
wherein Dn represents the decoder output; the Decoder represents a Decoder module of the transducer;
the expression of the obtained predicted chord sequence vector is as follows:
chord o =softmax(liner(Dn))
wherein chord o Representing a predicted chord sequence vector; softmax represents the softmax function of the transducer; link represents the linear layer of the transducer;
the expression of the loss function is:
loss=cross_entropy(chord i ,chord o )
where loss represents the calculated loss, cross_entopy represents the cross entropy loss function, chord i Representing an input chord sequence vector, chord o Representing the predicted chord sequence vector.
CN202310876374.9A 2023-07-17 2023-07-17 Method and system for generating chord based on melody Pending CN116863893A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310876374.9A CN116863893A (en) 2023-07-17 2023-07-17 Method and system for generating chord based on melody

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310876374.9A CN116863893A (en) 2023-07-17 2023-07-17 Method and system for generating chord based on melody

Publications (1)

Publication Number Publication Date
CN116863893A true CN116863893A (en) 2023-10-10

Family

ID=88231973

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310876374.9A Pending CN116863893A (en) 2023-07-17 2023-07-17 Method and system for generating chord based on melody

Country Status (1)

Country Link
CN (1) CN116863893A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114970651A (en) * 2021-02-26 2022-08-30 北京达佳互联信息技术有限公司 Training method of chord generation model, chord generation method, device and equipment

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114970651A (en) * 2021-02-26 2022-08-30 北京达佳互联信息技术有限公司 Training method of chord generation model, chord generation method, device and equipment

Similar Documents

Publication Publication Date Title
Brunner et al. JamBot: Music theory aware chord based generation of polyphonic music with LSTMs
CN111583891B (en) Automatic musical note vector composing system and method based on context information
CN111554255B (en) MIDI playing style automatic conversion system based on recurrent neural network
Chen et al. Continuous melody generation via disentangled short-term representations and structural conditions
CN116863893A (en) Method and system for generating chord based on melody
Nakamura et al. Automatic piano reduction from ensemble scores based on merged-output hidden markov model
CN113707112B (en) Automatic generation method of recursion jump connection deep learning music based on layer standardization
Zhao et al. A review of intelligent music generation systems
CN113299255A (en) Emotional music generation method based on deep neural network and music element drive
Zhang et al. Artificial intelligence techniques for pop music creation: A real music production perspective
CN114842819B (en) Single-track MIDI music generation method based on deep reinforcement learning
US10431191B2 (en) Method and apparatus for analyzing characteristics of music information
Syarif et al. Gamelan Melody Generation Using LSTM Networks Controlled by Composition Meter Rules and Special Notes
CN111627410B (en) MIDI multi-track sequence representation method and application
JP7251684B2 (en) Arrangement generation method, arrangement generation device, and generation program
Oliwa Genetic algorithms and the abc music notation language for rock music composition
CN115331648A (en) Audio data processing method, device, equipment, storage medium and product
Wang et al. Motif transformer: Generating music with motifs
Liang et al. Research on generating xi'an drum music based on generative adversarial network
Choi et al. Pop2Piano: Pop audio-based piano cover generation
Suzuki The second phase development of case based performance rendering system kagurame
Chen et al. Continuous Melody Generation via Disentangled Short-Term Representations and Structural
Ma et al. AMI–creating musical compositions with a coherent long-term structure
Sarmento et al. Shredgp: guitarist style-conditioned tablature generation
Peng et al. Chinese Chorales Dataset: A High-Quality Music Dataset for Score Generation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination