Monday, February 14, 2022

Natural language processing at your fingertips with OCI Language

Learn how to use cloud-based APIs to perform AI tasks, such as analyzing text for language.

One of several AI services released by Oracle for Oracle Cloud Infrastructure (OCI) is OCI Language, a cloud platform service that performs sophisticated text analysis at scale. It allows you to perform natural language processing on text, such as sentiment analysis, key-phrase extraction, text classification, named entity recognitions, and text classification.

OCI AI services offer prebuilt and easy-to-customize machine learning (ML) models. These AI services can help apply AI to applications and business operations. Developers don’t need to have any data science expertise to use them, and the prebuilt models don’t even require training data.

Oracle has announced several of these services (see Figure 1). Two—OCI Language and OCI Anomaly Detection—are generally available. OCI Speech, OCI Vision, and OCI Forecast are coming soon. (A list of all the announced services is at the end of this article.)

Oracle Java Exam Prep, Oracle Java Cert, Oracle Java Certification, Oracle Java Guides, Core Java
Figure 1. Five of the available OCI AI services

Running OCI Language from the console


Once you log in to OCI, you can find OCI Language by navigating to Analytics & AI > AI Services > Language. There you will be greeted by a getting-started page that describes many of the capabilities of OCI Language. If you click Analyze your text in the console, you will be able to try the capabilities, as shown in Figure 2.

Oracle Java Exam Prep, Oracle Java Cert, Oracle Java Certification, Oracle Java Guides, Core Java
Figure 2. Analyzing text with OCI Language

Click Analyze to see OCI Language in action, as shown in Figure 3.

Oracle Java Exam Prep, Oracle Java Cert, Oracle Java Certification, Oracle Java Guides, Core Java
Figure 3. Some of the capabilities of OCI Language

Calling OCI Language from a Java application


Calling OCI Language from a Java application is relatively simple, but you need to do some initial setup before calling the OCI Language API. This example will use OCI Language to detect the human language in some sample text.


I relied on Maven to get the libraries I needed, oci-java-sdk-ailanguage and oci-java-sdk-common. The following is what the dependencies section looked like in my pom.xml file:

<dependencies>
    <dependency>
        <groupId>com.oracle.oci.sdk</groupId>
        <artifactId>oci-java-sdk-ailanguage</artifactId>
        <version>2.12.0</version>
    </dependency>
    <dependency>
        <groupId>com.oracle.oci.sdk</groupId>
        <artifactId>oci-java-sdk-common</artifactId>
        <version>LATEST</version>
    </dependency>
</dependencies>

Authentication. For your local code to have the rights to use your subscribed-to OCI services, it needs to have the privileges to do so—either by having an instance principal or by acting on behalf of a user (by reading a configuration file with the user’s credentials).

For this example, I created a .oci/config file (as described in that article) to try the capability locally. See the code under Step 1 in Listing 1.

Listing 1. Calling the OCI Language API from Java

package com.company;
import com.oracle.bmc.ConfigFileReader;
import com.oracle.bmc.auth.AuthenticationDetailsProvider;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.ailanguage.AIServiceLanguageClient;
import com.oracle.bmc.ailanguage.model.*;
import com.oracle.bmc.ailanguage.requests.*;
import com.oracle.bmc.ailanguage.responses.*;

import java.io.IOException;

public class Main {

    public static void main(String[] args) {
        try {
            /* Step 1: Just reading a config file with my credentials so the application acts on my behalf */
            final ConfigFileReader.ConfigFile configFile =
                    ConfigFileReader.parse("C:\\Users\\lecabrer\\.oci\\config", "DEFAULT");
            final AuthenticationDetailsProvider provider =
                    new ConfigFileAuthenticationDetailsProvider(configFile);

            /* Step 2: Create a service client */
            AIServiceLanguageClient client = new AIServiceLanguageClient(provider);

            /* Step 3: Create a request and dependent object(s). */
            DetectDominantLanguageDetails detectdominantLanguageDetails =
                    DetectDominantLanguageDetails.builder()
                    .text("Este es un texto en el idioma de mi madre, la mejor mamá del mundo.").build();

            DetectDominantLanguageRequest detectDominantLanguageRequest =
                    DetectDominantLanguageRequest.builder()
                    .detectDominantLanguageDetails(detectdominantLanguageDetails)
                    .opcRequestId("Just-some-unique-id")
                    .build();

            /* Step 4: Send request to the Client */
            DetectDominantLanguageResponse response = client.
                    detectDominantLanguage(detectDominantLanguageRequest);

            System.out.println("Detected language: " +
                            response.getDetectDominantLanguageResult().getLanguages().get(0).getName());
        }
        catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Call the OCI Language API. You simply need to create a language client to issue the calls (Step 2 in Listing 1), prepare a request with its dependent object (Step 3 in Listing 1), and then send a request to the client (Step 4 in Listing 1).

And voila: The output is correct!

Detected language: Spanish

Conclusion


This article introduced you to OCI AI services and, more specifically, the capabilities of OCI Language. You saw the steps necessary to use the OCI Language SDK, with an end-to-end example.

This is a simple example, but there are many other prebuilt models in OCI Language that you can try. For instance, you may want to identify named entities, apply sentiment analysis to a set of records, or automatically classify text.

With AI services, you can leverage the power of AI without needing to have a background in data science or natural language processing.

Announced OCI AI services, as of February 2022


OCI Language. Performs text analysis at scale to understand unstructured text in documents, customer feedback interactions, support tickets, and social media. With built-in pretrained models, OCI Language eliminates the need for machine learning expertise and empowers developers to apply sentiment analysis, key-phrase extraction, text classification, named entity recognition, and more into their applications.

OCI Speech. Provides automatic speech recognition through prebuilt models trained on thousands of native and nonnative language speakers for real-time speech recognition. OCI Speech enables developers to easily convert file-based audio data containing human speech into highly accurate text transcriptions, and it can be used to provide in-workflow closed captions, index content, and enhance analytics on audio and video content.

OCI Vision. Provides pretrained computer vision models for image recognition and document analysis tasks. It also enables users to extend the models to other industry- and customer-specific use cases—such as scene monitoring, defect detection, and document processing—with their own data. OCI Vision can be used to detect visual anomalies in manufacturing, extract text from forms to automate business workflows, and tag items in images to count products or shipments.

OCI Anomaly Detection. Delivers business-specific anomaly detection models that flag critical irregularities early, which enables faster resolution and less operational disruption. OCI Anomaly Detection provides REST APIs and SDKs for several programming languages, which developers can use to easily integrate anomaly detection models into business applications. It is built on the patented MSET2 algorithm, which is used worldwide in highly sensitive situations such as nuclear reactor health monitoring, and it can be used for fraud detection, predicting equipment breakdown, and receiving data from multiple devices to predict failures.

OCI Forecasting. Delivers time-series forecasts through machine learning and statistical algorithms without the need for data science expertise. OCI Forecasting helps developers to quickly create accurate forecasts for their critical business metrics, including product demand, revenue, and resource requirements. These forecasts all have confidence intervals and explainability to help developers make the right business decisions.

OCI Data Labeling. Helps users build labeled datasets to train AI models. Users can assemble data, create, and browse data sets and also apply labels to data records through user interfaces and public APIs. The labeled data sets can be exported and used for model development across many of Oracle’s AI and data science services, including OCI Vision and OCI Data Science, for a consistent model-building experience.

Source: oracle.com

Related Posts

0 comments:

Post a Comment