Photo by Agnieszka Kowalczyk on Unsplash
Detecting Emotions in Star Wars using AI
Learn how to easily detect emotions in your favorite movie scene using code
The problem today is that emotional data isn't really used - whether it's Youtube videos, live stream boxing matches, or the news. We rarely consider all of this data - yet there are a ton of real-world use cases that can leverage emotional data.
Think about it - there are trillions of videos across the internet, but do we really understand how people feel?
We’re usually focused on the bare minimum: engagement metrics such as duration, length, and the number of likes. That doesn't tell us much.
So, what can we do to start using all of this data?
Let's look at this famous scene from A New Hope. What emotions have you recognized in this scene? Were they positive or negative? Happy or Sad?
Let's see if we can figure out how Princess Lea and Obi-Wan are feeling.
Alright, let’s detect some emotions
Go to this website and download the above Star Wars Youtube video as a WMV audio file. You can use different audio files if you'd like to apply this to a different video clip.
Let's head over to the One AI Studio. One AI is basically a free-to-use Language API that allows you to apply AI to text and video. The studio is an intuitive UI that's basically a playground for you to test out different scenarios on your input.
Drag the audio file to the left part of the screen where it says 'Upload File'. You can now see that One AI has suggested the 'Transcribe Audio' skill automatically.
- Since we want to detect emotion, let's add the skills 'Sentiments' and 'Emotions' by double clicking on them. Skills are basically different ways you can apply Language AI to the content.
Your screen should now look like this:
- Hit 'Run Pipeline' on the top right of the screen.
You can now see that One AI has marked different parts of the text with sentiments and emotions!
For example, "You're my only hope" is marked with a positive sentiment.
Time to get it in our code
- All you need to do now is copy the code snippet from the bottom left of the Studio window into your code editor and you're good to go:
import OneAI from "oneai";
const oneai = new OneAI(*Your Key*);
const conversation = [
{ "speaker": "Princess Lea", "utterance": "This is our most desperate hour. Help me Obi-Wan Kenobi. You're my only hope.", "timestamp": "00:00:00.590" }
];
const pipeline = new oneai.Pipeline(
oneai.skills.sentiments(),
oneai.skills.emotions(),
oneai.skills.summarize()
);
const output = await pipeline.run(conversation);
So what can we do with this?
Imagine creating an app that scans the (ex)President's posts. You could measure the emotions of the reactions compared to the emotions of the President and identify trends.
Another type of event you may want to monitor is if people feel happier after they've had lunch compared to before. You could also do that with emotion detection on a sample of social media users.
That's all folks - head over to the One AI Studio and start building your own app.