[PYTHON] I tried to predict the genre of music from the song title on the Recurrent Neural Network

Predict genre from song title

I want to study RNN, but I don't know what to make, so I consulted with my seniors.

Wai "Senior, I want to study RNN using TensorFlow. Is there any good subject?" Senior "Noisy. I'm busy so I'll leave you later." Wai "..."

Let's predict the genre of music from the song title. .. .. (´ ・ ω ・ `)

Input dataset

There is an item called genre in the song title list of itunes. Maybe there is a Rock-like song title or Pop-like song title pattern.

Extract data from itunes and save to csv file

train_data.csv


Ho!,2
Deuces Are Wild,2
575,4
movies,4
KICKS!,2
Raise it all,4
Nothing(movie ver.),4
Moratorium Girl,4
You've Got To Hide Your Love Away,0
Ordinary,5
What,4
Sword hunting suddenly,4
Borderline,4
Timber,4
M.I.Y.A.,2
Summer day 1993,4
broken bone,4

A dataset like this. Teacher data 2259, test data 565. The numbers in the right column correspond to the genre.

categories.csv


Classical,0
R&B,1
Alternative,2
Pop,3
Rock,4
Rap,5
Punk,6
Dance & House,7

Like this.

I tried to implement

This is the actual code

Since it seems that the song title can not be morphologically analyzed, we adopted Character RNN this time. Input time series data for each character into RNN and learn the pattern of song titles

input_data.py


 def data2id(self, data):
    self.__create_dict()
    data = [train.lower().replace(' ', '') for train in data]
    return [[[self.char_dict[train[i]]] if len(train) > i else [0] for i in range(self.max_length)] for train in data]
  

  def __create_dict(self, data_dir ='../data/'):
    data = self.__create_batchs(data_dir)
    data += self.__create_batchs(data_dir, test=True)
    sings = [d[0] for d in data]
    word = ''.join(sings).lower().replace(' ','')
    word_uniq = list(set(word))
    self.char_dict = {k:i for i,k in enumerate(word_uniq)}

In this part, the song title is converted into a form that can be fed to the network by assigning an ID for each character.

main.py


def cell():
    return tf.contrib.rnn.BasicRNNCell(num_units=NODE_NUM, activation=tf.nn.tanh) #Middle layer cell
cells = tf.contrib.rnn.MultiRNNCell([cell() for _ in range(NUM_LAYER)])
outputs, states = tf.nn.dynamic_rnn(cell=cells, inputs=x, dtype=tf.float32, time_major=False)

Since the song title is variable length, use dynamic_rnn. The middle layer has 128 units and two layers are stacked (super suitable), and the Cell is BasicRNN.

result

That's right. .. Yup. .. I can't even see it. The songs in my itunes are mostly Rock. Moreover, it is quite difficult for humans to guess the genre from the song title. So you can expect the result, right?

[TRAIN] loss : 1.349962, accuracy : 0.656250
[TEST loss : 1.369359, accuracy : 0.571681
{'Classical': 0.0, 'R&B': 0.0, 'Alternative': 0.0, 'Pop': 0.0, 'Rock': 1.0, 'Rap': 0.0, 'Punk': 0.0, 'Dance & House': 0.0}

I tried to learn to some extent. Lines 1 and 2 are Train, Test loss and correct answer rate, The third line is the ratio of the actual network prediction results to the test data. Yes, I insist that it's all Rock. Since there is almost no correlation between the song title and the genre, insisting that they are all Rock will result in minimal loss. (Because the data is biased towards Rock ...) I wish I had a better dataset. ..

Impressions

It became a practice of how to use RNN related API! !! I feel that the implementation is wrong, so I would be grateful if you could teach me various things! !! !!

Recommended Posts

I tried to predict the genre of music from the song title on the Recurrent Neural Network
I tried to classify music major / minor on Neural Network
I tried to predict the price of ETF
I tried how to improve the accuracy of my own Neural Network
Get the song name from the title of the video you tried to sing
I tried to implement a basic Recurrent Neural Network model
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried the common story of using Deep Learning to predict the Nikkei 225
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to touch the API of ebay
I tried to correct the keystone of the image
I ran the neural network on the actual FPGA
I tried to vectorize the lyrics of Hinatazaka46!
I tried to predict the deterioration of the lithium ion battery using the Qore SDK
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
I tried to predict the presence or absence of snow by machine learning.
I tried to rescue the data of the laptop by booting it on Ubuntu
I tried to display the infection condition of coronavirus on the heat map of seaborn
I tried to predict the number of people infected with coronavirus in consideration of the effect of refraining from going out
Introduction to AI creation with Python! Part 2 I tried to predict the house price in Boston with a neural network
python beginners tried to predict the number of criminals
I tried to detect the iris from the camera image
I tried to summarize the basic form of GPLVM
I tried to predict the J-League match (data analysis)
The story of making a music generation neural network
I tried to summarize four neural network optimization methods
I tried to visualize the spacha information of VTuber
I tried to notify the honeypot report on LINE
I tried to classify the voices of voice actors
I tried to summarize the string operations of Python
I tried to predict the victory or defeat of the Premier League using the Qore SDK
I tried to make it easy to change the setting of authenticated Proxy on Jupyter
I tried to find the entropy of the image with python
I want to change the symbolic link destination of / lib64 from / usr / lib64 to / my-lib64 on CentOS
I tried to get the location information of Odakyu Bus
I tried to find the average of the sequence with TensorFlow
Sentiment analysis with natural language processing! I tried to predict the evaluation from the review text
[Python] I tried to visualize the follow relationship of Twitter
[Machine learning] I tried to summarize the theory of Adaboost
I tried to predict the infection of new pneumonia using the SIR model: ☓ Wuhan edition ○ Hubei edition
I tried to summarize the languages that beginners should learn from now on by purpose
I tried to fight the Local Minimum of Goldstein-Price Function
How to easily draw the structure of a neural network on Google Colaboratory using "convnet-drawer"
I tried to sort out the objects from the image of the steak set meal-① Object detection
I tried to launch ipython cluster to the minimum on AWS
I tried a convolutional neural network (CNN) with a tutorial on TensorFlow on Cloud9-Classification of handwritten images-
I tried to get various information from the codeforces API
Implementation of recommendation system ~ I tried to find the similarity from the outline of the movie using TF-IDF ~
I tried to find the trend of the number of ships in Tokyo Bay from satellite images.
I tried to predict the sales of game software with VARISTA by referring to the article of Codexa
I made my own 3-layer forward propagation neural network and tried to understand the calculation deeply.
I tried to predict the number of domestically infected people of the new corona with a mathematical model
I tried to sort out the objects from the image of the steak set meal-② Overlap number sorting
I want to extract the tag information (title and artist) of a music file (flac, wav).
I tried to predict the up and down of the closing price of Gurunavi's stock price using TensorFlow (progress)
I tried to create an environment of MkDocs on Amazon Linux
[Linux] I tried to summarize the command of resource confirmation system
I tried to get the index of the list using the enumerate function
I tried to automate the watering of the planter with Raspberry Pi
I tried to digitize the stamp stamped on paper using OpenCV
I tried to register a station on the IoT platform "Rimotte"