Machine Learning with Mani Rathnam

Raghunandh GS
DataComics
Published in
5 min readJul 15, 2017
Manimerizing

Manirathnam, the genius film maker is known for his unique style of making movies as well as writing dialogues. The dialogues in his movies are hard to crack and even harder to hear. When humans ourselves find it hard to bring out the perspective, tone and mood of his dialogues, let’s try and see how well a machine understands and mimics it.

Before meddling with any of the Mani Rathnam’s movies, let’s look at an example of how a machine learns and how well it learns.

This is a screenshot taken while I was what-sapping. You can see that as soon as I type the phrase ‘I want’, the keypad (the machine) gives me 3 suggestions. The machine has understood that more than me wanting someone or to do something I want food. It’s heartwarming to see how well a machine has understood me than most of the people in my life.

Let’s follow the same approach and use a multilayer RNN with LSTM and train a model over a set of dialogues from a movie over several epochs and see how well it generates texts.

You don’t follow me, right? Never mind, I was just trying to be Manirathnam. Let me break it down for you. RNN — Recurring Neural network is a deep learning algorithm and LSTM — Long Short Term memory is one of its types. I won’t go about trying to break it down and explain as there are several hundred blogs over the net giving deep insights into this. Now let’s use this model and train it over a set of dialogues of a Manirathnam movie and then check how well the model is able to mimic it. In other words, the model takes one text file as input and trains a Recurrent Neural Network that learns to predict the next character in a sequence. The RNN can then be used to generate the text, character by character that will look like the original training data.

The movie dialogue over which I decided to train the model was none other than the epic movie Nayagan. I had to download the subtitle file which was in English, clean it and present it to the machine for learning.

Before looking at the results let me explain you one more term, epoch. An epoch is one complete presentation of the data-set to be learned to a learning machine. In our case, it is one cycle of going through all the dialogues from the movie. One common belief is that the more you train the machine better the results you get. After training, we will use the same model to generate the dialogues for us to see how well it has learnt.

So here is the result after 20 epochs.

After 20 epochs

No Machine, you have to do better. This is not you how you write dialogues, that too for a Manirathnam movie.

Let’s now train it for 100 epochs and the make it generate texts for us.

After 100 epochs

The machine has now started understanding that each line in a Manirathnam movie is short and not very long. But still, it doesn’t make sense.

Let’s now train it for 1000 cycles and see whether it shows any improvement.

After 1000 epochs

Not bad, at least the machine has understood that there is a person called Naicker and the statement Look Naicker I am talking makes some sense out of the lot.

This model is independent of the language used. It doesn’t care whether the underlying text file contains words from English language or not. Unlike governments, it doesn’t impose any language on us. All it does is to take into account how likely it is for one character to appear after another character and trains a model that can predict that.

Let’s take the lyrics of all the songs from another Manirathnam movie to train the new model. The movie I choose for this has an album full of super hit songs.

This is what machine generated after 20 epochs.

After 20 epochs

No machine, this no where looks close to the actual lyrics. It looks like some encrypted file from a Tom cruise movie. I want you to concentrate and learn better. Look at Sharma ji’s son! If you learn like this how will you get a job and settle in US. Too bad ! I am disappointed.

Let’s train this idiot for 100 cycles and then make it generate something.

After 100 epochs

Better, but I expect more. I will give you one last chance and train you over 1000 epochs. Better produce good results, else you will be put in a boarding school.

After 1000 epochs

Much better. The machine started generating almost short sentenced lyrics without any gap. Nice to see that the Machine has also learnt that there is humming in between. Yama nama na na hoi hoi Na Nama Nama Hoi ! All these lyrics that machine generated might still not make it to a movie which is directed by Manirathnam with AR Rahman music but these lyrics definitely does stand a chance in a Shankar movie with Harris Jeyaraj music.

--

--