Friday, March 9, 2018

Analyse emotion in OSCAR movies 2018 with Google Apps Script and Google Natural Language API

And OSCAR goes to...

There are a lot of indicators, who predict the winner's movie. One of them, no doubt, is emotions. When the screenplay is written in a way to change emotion from positive to negative and vice versa, it is creating a big impact on peoples mind.

Nowadays you can you Natural Language Processing without deep knowledge of all things like syntax analysis, grammar, external libraries. Especially big companies like Google, Amazon or Microsoft invest a huge amount of money to improve their algorithm and provide as service/API.

I am always interested in easily and fast proof-of-concept, so today I will show you how I put these things together.




I have chosen a category for Best picture (90th Academy Awards) and these movies

  • Call Me by Your Name – Peter Spears, Luca Guadagnino, Emilie Georges, and Marco Morabito
  • Darkest Hour – Tim Bevan, Eric Fellner, Lisa Bruce, Anthony McCarten, and Douglas Urbanski
  • Dunkirk – Emma Thomas and Christopher Nolan
  • Get Out – Sean McKittrick, Jason Blum, Edward H. Hamm Jr., and Jordan Peele
  • Lady Bird – Scott Rudin, Eli Bush, and Evelyn O'Neill
  • Phantom Thread – JoAnne Sellar, Paul Thomas Anderson, Megan Ellison and Daniel Lupi
  • The Post – Amy Pascal, Steven Spielberg, and Kristie Macosko Krieger
  • The Shape of Water – Guillermo del Toro and J. Miles Dale
  • Three Billboards Outside Ebbing, Missouri – Graham Broadbent, Pete Czernin, and Martin McDonagh

1. I downloaded subtitles from server Opensubtitles and saved these files (.srt) to my Google Drive.

2. I created a new project in Google Apps Script and setup Google Natural Language API endpoint in menu Resources -> Cloud Platform -> left menu API & Services -> Library -> Cloud Natural Language API.
Note: Google Apps Script creates a new Google Cloud project for you, so you don't have to create it yourself.



In Google Cloud platform dashboard I also got API key, which identifies applications.

API & Services -> Credentials > Create credentials -> API key
(You should setup Application restrictions for HTTP referrer as a minimum)




2. First I did preprocess. I borrow a term from machine learning - bucketing. I aggregated multiple lines of subtitles into time-framed text "window" of length 2 minutes. Here is a code:





3. The rest is simple - iteration over all "buckets" and send each grouped text to Google Natural Language. This API response with two numbers - sentiment and magnitude. In my case, I used sentiment number in the range <-1;1>. Everything is saved in Google Spreadsheet and charts are rendered directly from there.
4. I put together two functions from above:
You can see how sentiment changes during the movie (time is on the x-axis) for the best OSCAR movie of the year 2018:

Rest nominated movies:










Are you interested in this topic? Follow me on Twitter, Google+ or subscribe RSS

22 comments:


  1. Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
    Webdesining course in chennai

    ReplyDelete
  2. ¡Las mejores marcas de lujo del mundo ven los baratos mujer relojes de la más alta calidad! Si desea colocar estos relojes en su muñeca, deténgalos porque son caros. Así que detente y este es tu lugar más correcto.

    ReplyDelete
  3. There are many online movie download sites that allows you to download free movie online www.movieglide.com

    ReplyDelete
  4. Is there an elective method for purchasing motion pictures without looking through everywhere throughout the Internet or breaking into the piggy bank to get your next film DVD? The uplifting news is, indeed, there is a method for finding those motion pictures that you gotta have and films that you didn't know of but rather would not like to go over your month to month spending plan to chance purchasing a failure of a motion picture. NetflixInsider.com

    ReplyDelete
  5. ctivities before the movie starts will keep the crowd engaged, especially young children, who are likely to grow restless while waiting.Scott Mannion

    ReplyDelete
  6. Study that many burgeoning African American film makers seem all too willing to ignore in their movie making process, as these elements are often sorely lacking in the plots and storylines of the majority of Black cinema.solarmovies

    ReplyDelete
  7. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work. horror films

    ReplyDelete
  8. Cool stuff you have got and you keep update all of us. wallmart blockchain jobs

    ReplyDelete
  9. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks Oscars 2019

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Whether you watch several a week or haven't been to the theater in years, solarmovies.co are a part of your life. A leadership and learning expert shares three ways you can learn from movies.

    ReplyDelete
  12. one thing that i online movies hollywood like about the blog could be that the information is very helpful and keeps one informed on issues related to politics. 

    ReplyDelete
  13. This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. Putlockers

    ReplyDelete
  14. Yet, while it is unexpected I need to state I concur with Matthew Vaughn and figure the ongoing fame for Super Hero motion pictures could arrive at a smashing end inside a year or two. Why, well how about we take a gander at the actualities.
    Movie Decals for Model Cars

    ReplyDelete
  15. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. 123 movies

    ReplyDelete
  16. On the off chance that the faultfinders gave indistinguishable impression from you do in the wake of watching the film then that would be extraordinary. In any case, if not, there will dependably be different faultfinders and other movie surveys that you can peruse.all movies free online

    ReplyDelete
  17. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. marathi movies now

    ReplyDelete
  18. Turner Classic Movies Schedule is planned with much thought in mind. That's obvious from the movies run on many cable TV stations. During the recent Halloween scheduling, as an example, some of the finest horror movies set the mood with movies that moved from time-honored films that starred Vincent Price, Bela Lugosi and Lon Cheney to more recent classic productions. free working netflix accounts

    ReplyDelete
  19. In your search for a movie project to invest in, you can simply search the internet using the key words "how to invest in a movie" and you will get a good start in your search. blueray

    ReplyDelete
  20. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. fmovies

    ReplyDelete
  21. Any reason is good enough to have a party these days. It seems logical that people want more occasions to celebrate and let their hair down given their stressful lifestyles. But throwing a party is not only about gathering guests and having fun. Hosting a well-attended, fun party that people remember for years to come is an art and needs a whole lot of planning. And you need Party Supplies to put your plans into action and keep your guests entertained. stag night

    ReplyDelete