Skip to Content

Text Processing services with the API Business Hub console

test
0 %
Text Processing services with the API Business Hub console
Details
// Explore More Tutorials

Text Processing services with the API Business Hub console

12/06/2018

Discover how to test SAP Leonardo Machine Learning Foundation service on the SAP API Business Hub

You will learn

In this tutorial, you will learn where to find and test the SAP Leonardo Machine Learning Functional Services published on the SAP API Business Hub that consumes text content.

The Topic Detection API Machine Learning Functional Services will be used as an example to demonstrate how to consume text content, but you will be able to transpose this tutorial to other services which also consume content like :

The Topic Detection service allows you to extracts topics from documents and scores them according to the most relevant topics.


Step 1: Search the SAP API Business Hub

In order to consume the Topic Detection API SAP Leonardo Machine Learning Foundation service, you will first need to get the service URI, request and response parameters.

Go to https://api.sap.com/.

SAP API Business Hub

Then you will be able to search for the SAP Leonardo Machine Learning - Functional Services, then click on the package found.

SAP API Business Hub

Select Inference Service for Topic Detection.

SAP API Business Hub

You can also access the page directly from the following address:

Log on to answer question
Step 2: Analyze the service

As you can notice the API has only one resource (or service): /topic-detection.

Now click on the /topic-detection link to expand the section.

Note: the term inference refers to the application phase (scoring) an existing model (as opposed to the training or inception phase) and sync for synchronous.

As stated in the description, the service accepts either:

  • an archive file with a zip/tar extensions containing multiple text files
  • a single text file
  • a list of text files as input

The service returns a list of detected topic with the associated keywords and scores (confidence).

The supported text file formats is plain text only.

The input file, files or archive file will be sent as a FormData query parameter in the service request.

A series of options are also required for the following parameters:

  • numTopics: Total number of topics to be detected
  • numTopicsPerDoc: Number of most relevant topics to be listed per document
  • numKeywordsPerTopic: Number of keywords to be listed per topic
  • numFeatures: Maximum number of keywords to be extracted from documents in total
Log on to answer question
Step 3: Test the service

First, let’s build an archive with at least 3 text files (so that we can set numTopics equal to 3).

If you are missing some inspiration, use the following articles content to create your text files:

Create a zip out of these text files.

In the top right corner of the page, click on the Log On button.

You will be prompted for your SAP credentials (you can use your SAP Cloud Platform credentials for example).

Scroll down to the Parameters section and click on the Try out button, then you can use the Choose File button next to files parameter to select your zip file.

In the options field enter the following:

{"numTopics":3, "numTopicsPerDoc":3, "numKeywordsPerTopic":5}

Now, scroll down and click on Execute.

API Hub

In the Response Body, you will get for each file, the associated keywords, topics and score.

The output will be sorted by descending topic score.

For example here, for the cheesecake.txt document, the first list of keywords represent to top topic (with id 1) and it’s score is 1.0059799604699027.

{
  "_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "processed_time": "Mon, 31 Jul 2017 14:52:20 GMT",
    "request": {
      "files": [
        "Desktop.zip"
      ],
      "options": {
        "numKeywordsPerTopic": 5,
        "numTopics": 3,
        "numTopicsPerDoc": 3
      },
      "tenantName": "imgclassif-tech-user",
      "texts": []
    },
    "status": "DONE",
    "tenantName": "imgclassif-tech-user",
    "topicDetection": [
      {
        "docName": "cheesecake.txt",
        "keywords": [
          [ "cheesecake", "cheese", "cream", "bake", "make" ],
          [ "deep", "learn", "neural", "jump", "network" ],
          [ "learn", "machine", "data", "jump", "algorithm" ]
        ],
        "scores": [
          1.0059799604699027,
          0,
          0
        ],
        "topics": [
          1,
          2,
          0
        ]
      },
      {
        "docName": "deep_learning.txt",
        "keywords": [
          [ "deep", "learn", "neural", "jump", "network" ],
          [ "learn", "machine", "data", "jump", "algorithm" ],
          [ "cheesecake", "cheese", "cream", "bake", "make" ]
        ],
        "scores": [
          1.0683225059034496,
          0.0008786062197741417,
          0
        ],
        "topics": [
          2,
          0,
          1
        ]
      },
      {
        "docName": "machine_learning.txt",
        "keywords": [
		  [ "learn", "machine", "data", "jump", "algorithm" ],
		  [ "cheesecake", "cheese", "cream", "bake", "make" ],
          [ "deep", "learn", "neural", "jump", "network" ]
        ],
        "scores": [
          0.890515209507582,
          2.1184791916652968e-9,
          0
        ],
        "topics": [
          0,
          1,
          2
        ]
      }
    ]
  }
Log on to answer question
Step 4: Validation

Provide an answer to the question below then click on Validate.

Based on the test you just completed, if your archive file contains 15 files, what would be the maximum
value for the numTopics option?
×

Optional

Step 5: Investigate similar services

You can also try the following Machine Learning Functional Services consuming text content:

For more information, you can also check the online SAP Leonardo Machine Learning Foundation documentation

Log on to answer question

Next Steps

Back to top