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
0 comments:
Post a Comment