Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Vriddhi
Advisor
Advisor
SAP's TechEds are annual events where you can find out about the latest in SAP technology and innovation. The 2022 SAP TechEd was hosted Nov 15-16 and covered a lot of interesting topics, including a talk from SAP's Global Head of AI, Fei Yu, on "Realising your business potential with SAP AI Solutions". One of the latest features that was shared was how you can now manage SAP AI Business Service models from SAP AI Launchpad (in the session here between 15:49 to 20:07).

This blog provides a guided reference to how you can get what you see in the demo working with your SAP Business Technology Platform (or BTP) account. I demonstrate how you can custom train one of the SAP AI Business Services available called Business Entity Recognition from SAP AI Launchpad.

For some context, SAP AI Launchpad and SAP AI Core together provide the means to productionize AI models and confidently run ML operations at scale. Both are available on SAP BTP and also on free tier. SAP AI Launchpad gives you a place to transparently manage your models from a single location and continuously improve their performance using a user-friendly interface. SAP AI Launchpad also supports connections to multiple runtimes, like SAP AI Core, SAP AI Business Services, etc.

Business Entity Recognition helps you to detect and highlight any type of business entity in unstructured text. You can use the service, for example, to automatically extract the context from incoming emails with invoice inquiries, automating recurring tasks associated with answering queries about the status and payment of invoices.

In this blog, we will do the following in sequence:

  1. Set up a Business Entity Recognition instance in your sub account

  2. Connect to the Business Entity Recognition instance via SAP AI Launchpad

  3. Custom train a model based on a dataset

  4. Deploy the model for use in production

  5. Perform inference using the deployed model


 

01 Set up a Business Entity Recognition instance in your sub account


Let us first go into our sub account in SAP BTP and add an entitlement for Business Entity Recognition.

Click on Configure Entitlements > Add Service Plans.


Select Business Entity Recognition from the list that appears, select a plan of interest and add the service plan.


You can now go into your Instances and Subscriptions and create a new instance for Business Entity Recognition by clicking on Create.


You should see Business Entity Recognition in the drop down for Services you can create.

Select it and follow the guided steps to create the instance. You will now be able to access the service key with which you can access the service from SAP AI Launchpad.


 

02 Connect to the Business Entity Recognition instance via SAP AI Launchpad


Go to your SAP AI Launchpad application and click on Add to create the connection to Business Entity Recognition.


 

Enter the credentials from Business Entity Recognition as per guidance below.


Click on the tile for the newly created API connection and the Function Explorer will become visible. Clicking on All Scenarios will show you the scenario for Business Entity Recognition.

Note: If you enter service key credentials for SAP AI Core in the API Connection, the SAP AI Core Administration & ML Operations tabs become visible. The context for the tabs that get activated depends on the type of API connection.


Clicking on the scenario “BusinessEntityRecognition”, takes you to pre-configured templates that enable customisation of the Business Entity Recognition models. There are 2 run templates and 1 deployment template. The typical sequence of use would be to:

  1. Use the training executable to run the custom model training

  2. Use the deployment template to push the model to production

  3. Use the inference template to query the deployed model


Let us now dive deeper in to how each of the above steps can be set up.


 

03 Custom train a model based on a dataset


Note: remember to replace the content highlighted in red with information relevant to your Business Entity Recognition instance.

(i) Get access token for Business Entity Recognition


Follow the instructions here to your Business Entity Recognition access token.

(ii) Create a placeholder for the dataset (via Postman)


Let’s create a POST call in postman.

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/api/v1/datasets

Set authorisation to Bearer Token & provide the access token created in step (i).

Set Body to raw >> json and copy over the sample body from below:
{
"datasetType": "training",
"description": "SAP BER blog demo dataset"
}

Hit send & note down the dataset ID in the response.



(iii) Upload data to the placeholder (via Postman)


 

Sample Data: The dataset here provides a json file with a text string annotated with labels like title, first name, last name, email ID, mobile ,designation, address, city, country and zip. We will use this to train the Business Entity Recognition model to also recognise these entities in any text provided.

Right click on the link provided, then click Save link as to download the files locally

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/api/v1/datasets/<dataset ID from previous step>/documents

Set authorisation to Bearer Token & provide the access token created in step (i).

Body: Enter key as “document”. Change the type of the field to “file”. You can hover your cursor at the edge of the column and the type selection will appear to you. Upload the data file saved previously into the value field.

Hit Send.


Note: If you'd like to check what your document looks like, you can replace the URL with below link and hit send. You will see the size of the document just uploaded.

URL: https://business-entity-recognition.cfapps.jp10.hana.ondemand.com/api/v1/datasets/<replace with your dataset ID>/documents/<replace with your document ID>




(iv) Register the artifact to SAP AI Launchpad (via Postman)


To register the artifact created in Business Entity Recognition to SAP AI Launchpad you need the dataset ID from BERBusiness Entity Recognition and the scenario ID from SAP AI Launchpad.

You can find your scenario ID from SAP AI Launchpad as shown below.


Copy this over and create your postman call as follows:

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/v2/lm/artifacts

Body:
{

"labels": [],

"description": "BER blog demo dataset",

"kind": "dataset",

"name": "dataset",

"url": "minio://<your dataset ID from BER>",

"scenarioId": "<your scenario ID from SAP AI Launchpad>"

}

You should see a response as below:




(v) Train the model (via SAP AI Launchpad)


Go to SAP AI Launchpad. Click on the Business Entity Recognition scenario. Click on training executable.


Click on Available Configurations. Click on Create.


Provide a suitable configuration name and hit Next.


Provide a suitable model name (without spaces) and hit Next.


Look for the dataset you just registered in Postman in the list on the right and under Assignment select "dataset". This passes the registered dataset to this configuration parameter.


 

Click review. If all looks ok, click "Create".


Click on "Create Run".


After a bit, your run will be successfully completed. This means the trained model is ready.


Click on "Metric Resource" next to "Overview" to see model performance. In this case the accuracy is 98.3%, which is good so we would now like to deploy it.




04 Deploy the model for use in production


Before we deploy, let us note the ID of the model just created. Scroll down to bottom of Overview page and note the ID of the trained model.


Go back to All Scenarios & click on the Business Entity Recognition scenario. Select the deployment template.


Click on "Available Configurations" and hit "Create".


Provide a suitable name to the configuration and hit "Next".

There are no input parameters for this model, so hit next.



Select your model from the list on the right. Click Review.


Click on "Create Deployment".


And then Create Deployment.


Once the model is running, you will see the status as below.


The deployed model is now ready for inference.

05 Perform inference using the deployed model


(i) Run inference on a sample text via SAP AI Launchpad


1. Set up in SAP AI Launchpad

Click on the inference executable in the Business Entity Recognition scenario.


 

Click on Available Configurations and hit Create.


Provide a suitable name and hit Next.


Provide the text you want to use to get inference. The sample I provided is as below:

"Mr. Harry Potter, Email id: harry.potter@hogwarts.edu.com Contact No: 9000900090 Mailing Address: 4 Privet Drive, Little Whinging, Surrey"



Add the model you deployed earlier. Hit Review, then Create and lastly Create Run.


After a while, you will see your inference go to the status Completed.


Scroll down to the bottom of the page to see the inference result artifact and copy the artifact ID.


2. Check results in Postman

Create a GET call in Postman. Replace the {{artifact_id}} in URL below with your inference results ID, which for me is c2d1f7cc-dd77-48b8-90bc-fe653013aed4.

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/v2/lm/artifacts/{{artifact_id}}

Set authorisation to Bearer Token & provide the access token created in step (3i).

Your response will look like this.


Click on the url at the bottom of the response. And provide your Bearer Token in Authorisation as before. Hit Send. 


The full response is as below.
{
"data": {
"result": [
{
"title": [
{
"confidence": 0.89,
"value": "Mr"
}
],
"firstname": [
{
"confidence": 1.0,
"value": "Harry"
}
],
"lastname": [
{
"confidence": 0.85,
"value": "Potter"
}
],
"emailID": [
{
"confidence": 1.0,
"value": "harry.potter@hogwarts.edu.com"
}
],
"mobile": [
{
"confidence": 1.0,
"value": "9000900090"
}
],
"designation": [],
"address": [
{
"confidence": 0.7,
"value": "Privet Drive"
}
],
"city": [],
"country": [],
"zip": []
}
],
"id": "6bd0d600-f122-4845-9bb9-9f24d27a94ab",
"status": "SUCCESS",
"createdAt": "2022-12-08T07:52:50Z",
"modifiedAt": "2022-12-08T07:52:54Z"
}
}

This tells me my inference text had address unlike the ones the model was trained on, but the rest of the metrics seemed to have been pulled correctly.

(ii) Run inference on a sample text via SAP AI APIs in Postman


We do this in 4 postman calls.

1. Let us create a configuration for inference with a POST call.

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/v2/lm/configurations

Set authorisation to Bearer Token & provide the access token created in step (3i).

Body:
{

"executableId": "69a122dc-9f8f-496d-995c-0cbaa86a447a",

"name": "inference on new text",

"inputArtifactBindings": [{

"key": "model",

"artifactId": "746e68de-bfa1-4a4e-bc5d-81e84a9528e9"

}],

"parameterBindings": [{

"key": "text",

"value": "Mr. Harry Potter, Email id: harry.potter@hogwarts.edu.com Contact No: 9000900090 Mailing Address: 4 Privet Drive, Little Whinging, Surrey"

}],

"scenarioId": "8df9852e-0b80-4a3d-87c1-cdb0198fa159"

}

You can find your executable ID under Template ID of your Inference Executable. Scenario ID comes from your Business Entity Recognition Scenario ID. Model ID can be found from your training / deployment runs.


Click Send and copy over the configuration ID you see.


2. Let us execute the configuration with another POST call.

Replace {{configurationID}} in URL below with the id in response of previous call. In my case it is 747edffe-4240-48c0-a48b-54c15e0b7d71.

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/v2/lm/configurations/{{configurationID}}

Set authorisation to Bearer Token & provide the access token created in step (3i).

Hit Send. You will see the execution ID in the response.


3. Let us get the inference artifact with a GET call

Replace {{executionID}} in URL below with your execution ID from previous response. In my case it is e1aefe666138ff2a.

URL: https://business-entity-recognition.cfapps.<region>.hana.ondemand.com/v2/lm/executions/{{executionID}}

Set authorisation to Bearer Token & provide the access token created in step (3i).

Hit Send.


 

4. Get inference results inside the artifact with a GET call

As before, you can see the inference results by clicking on URL at bottom of response, adding your Bearer Token to the GET call and hitting Send. The response is the same as the previous section and includes the results of applying my deployed model on the inference text.



Conclusion


With this feature, SAP AI Launchpad provides an interface to manage & monitor your models SAP AI Business Services models. Thus providing a single point of entry to transparently manage all AI models interacting with your SAP systems.

For more information, join our communities of AI experts:

 
1 Comment