Lab introduction
1. Lab introduction
SPEAKER: Now it's time for some hands-on practice. In the following lab, you'll use the Natural Language API to analyze text. Specifically, you'll identify entities and analyze sentiment with code. Before you begin, let's briefly review the main features of the Natural Language API you learned in the previous lesson. You can identify entities, which are subjects in the inputted text, such as Google as a company name and Mountain View as a location. You can identify the sentiment, which indicates emotion at both the overall document and individual subject level. You can analyze syntax and extract linguistic information, such as the relationship between words. And you can also classify the text to categories based on topics or keywords, similar to assigning a tag to a piece of text. You perform all of this analysis through a UI, which is a quick and efficient way to demonstrate and test these features. However, if you want to incorporate these features in production, you must embed the APIs into code. Using APIs in your code is similar to ordering a sandwich at a deli. You order from the menu and get your food without worrying about how it was made in the kitchen. The same concept applies to using APIs. You only need to know three things, the features, the menu, the input, the order, and the output, the sandwich. Like a menu, features are the types of requests that you can make to the Natural Language API. Like a food order, the input is how you construct the request. Then the sandwich you receive after you place the order is the response or output. With this, you can determine next steps. So, what are different types of requests that you can make? The Natural Language API provides several methods for performing analysis and annotation on your text. You'll practice with most of them in the lab. For entity analysis, you can use the analyze entities method. The sentiment analysis is performed through the analyze sentiment method at the entire text level and analyze entity sentiment at the individual, entity, and subject level. The syntax analysis is performed with the analyze syntax method. And the content classification is performed by using the classify text method. Now, how do you construct those requests? The Natural Language API is a REST API and consists of JSON requests and responses. A simple JSON request for entity analysis looks like the code shown here, where you define the type of the document, for example, plain text, the language, like EN, which stands for English, the content, which can be the text itself, or the file location in Cloud Storage, and finally, the encoding type, like UTF 8. After you construct the request, you need to call the API, just like, after you decide what you want at a deli, you need to place the order with the counter person. Here's an example to call the API with curl. Curl stands for Client URL and is a command line tool to transfer data between client and server. You can also use other programming languages, such as Python and Java SDKs, to call the APIs. Typically, the vendors of the product and services you're using define the APIs and provide the SDKs in different languages for you to choose. In this example, you call the Natural Language API feature analyze entities, pass the request.json file that you just constructed, and save the response to result.json file. Finally, how should you handle the responses? You can review the result by using a command like cat result.json, or parse it for further usage. Equipped with the technical details, in this lab, you'll use the Natural Language API to extract entities, analyze sentiment, and analyze syntax. By completing the lab, you'll get practice creating a Natural Language API request and calling the API with curl, extracting entities and running sentiment analysis on text, performing linguistic analysis on text, and creating a Natural Language API request in a different language. Let's start.2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.