Analyze Sentiments with the Natural Language AI!

Hola! Today we will practice sentiment analysis with our next deep dive, ‘Entity and Sentiment Analysis with the Natural Language API’. This is from the quest ‘Integrate with Machine Learning APIs’. Click the button below to get 3 credits off your learning journey.

The API

An API or Application Programming Interface is a set of instructions and protocols for building and integrating application software. A natural language API is an interface to an existing language processing model that can be used to process the text input. Google offers an NLP API to several models for different tasks like sentiment analysis and text classification.

Takeaway

  • Creating a Natural Language API request and calling the API with curl
  • Extracting entities and running sentiment analysis on text with the Natural Language API
  • Performing linguistic analysis on text with the Natural Language API
  • Creating a Natural Language API request in a different language

Set up

First of all, make sure you sign in to your Qwiklabs account using an incognito window. Then, it’s usually a good idea to read through the lab manual before starting your lab. When you are ready, click on the start lab button.

Ready for your first task? It’s time to create an API key.

Create an API Key

To create an API key, follow the lab instructions. You can also refer to the screenshots for more help. To copy the API key, click on the API key1 under credentials and copy the API key.

Click on check my progress button to verify the objective.

Connect to the Provisioned Instance

To perform the next steps, you will need to connect to the provisioned instance via SSH. It’s easy to confuse the SSH window with a cloud shell, so be cautious as you follow the lab instructions. Go to VM instances and click on SSH.

Make an Entity Analysis Request

The analyzeEntities’ method of the Natural language API can extract entities from text. Follow the lab instructions to proceed with this step.

Call the Natural Language API

To see the response for each entity follow the steps in lab instructions. Refer to the screenshots for further help.

Sentiment analysis with the Natural Language API

Apart from extracting entities, NLP API let’s you perform sentiment analysis. Write your code in the .json file and see the result. Refer to instructions for help. Here’s your chance to analyze your own sentiment — I used “I like qwiklabs” and got this (screenshot). What did you use?

Analyzing entity sentiment

With the ‘analyzeEntitySentiment’ you can get the sentiment for each sentence. Follow the instructions to see how it works.

Analyzing syntax and parts of speech

To get more linguistic details of the text, use analyzeSyntax method. Refer to the lab instructions. Check your score. Did you receive 100 points?

Overachiever

This part of multilingual processing is optional. Apart from english, the NLP API supports many other languages. Modify the code as per the instructions to see the result for some other language. Happy learning.

Done with the steps and still not getting a full score? Don’t worry. Click on the score and then on the run step. Thereafter click on the end lab button. Refer to the screenshot below.