Skip to Content
Technical Articles

Leverage SAP Leonardo Machine Learning Functional Services with SAP Data Hub

One of the advantages of SAP Data Intelligence over SAP Data Hub, besides being a Software as a Service offering and innovation platform, is that it includes the SAP Leonardo Machine Learning Foundation.

However, since depending on where most of your big data resides, in my opinion, an on-premise SAP Data Hub could be the right choice, in this blog, I will show how to leverage SAP Leonardo Machine Learning Functional Services nearly as seamlessly.

The key to this is the MLF Functional Services Interface Operator in conjunction with the OpenAPI Client Operator (the Graph can be found in the appendix) accessing the SAP API Business Hub:

In this example, I am leveraging the Inference Service for Machine Translation that is one of the SAP Leonardo Machine Learning Foundation – Functional Services:

From there I copy the Example Value into my Constant Generator Operator:

{
  "sourceLanguage": "en",
  "targetLanguages": [
    "de",
    "fr"
  ],
  "units": [
    {
      "value": "The shopping cart contains ten items.",
      "key": "CART_CONTENTS"
    }
  ]
}

As well as the host, schemes, basePath, method and apiKey into my OpenAPI Client:

With this I can run my Graph and get the expected outcome from the Wiretap Operator:

{
  "units": [
    {
      "value": "The shopping cart contains ten items.",
      "key": "CART_CONTENTS",
      "translations": [
        {
          "language": "de",
          "value": "Der Einkaufswagen enthält zehn Positionen."
        },
        {
          "language": "fr",
          "value": "Le panier contient dix postes."
        }
      ]
    }
  ]
}

Alternatively, I could try to figure out what this coffee machine at the airport after SAP TechEd Barcelona is telling me:

For this, I load my photo into the SAP Data Hub Repository and run it through the Inference Service for Optical Character Recognition (OCR) (please be aware that you have to prefix the path by /vrep/vflow):

As a result I got my characters recognised:

{
  "id": "a3976d0b-eba1-4ada-9967-1ef1665bf419",
  "predictions": [
    " \n \n\nCAPPUCCINO\n\nv\nDisfrute de su bebida -\n\nre\n\f"
  ],
  "processedTime": "2019-10-18T14:27:55.418300+00:00",
  "status": "DONE"
}

Which I can then feed into the Inference Service for Machine Translation again:

{
  "units": [
    {
      "value": "Disfrute de su bebida.",
      "key": "CART_CONTENTS",
      "translations": [
        {
          "language": "en",
          "value": "Enjoy your drink."
        }
      ]
    }
  ]
}

Similarly, I could leverage any of the available Functional Services:

Appendix

{
  "properties": {},
  "description": "",
  "processes": {
    "openapiclient1": {
      "component": "com.sap.openapi.client",
      "metadata": {
        "label": "OpenAPI Client",
        "x": 355,
        "y": 12,
        "height": 80,
        "width": 120,
        "ui": "dynpath",
        "config": {
          "host": "sandbox.api.sap.com",
          "schemes": "https",
          "basePath": "/mlfs/api/v2/text/translation",
          "method": "POST",
          "authScheme": "apiKey",
          "apiKeyName": "APIKey",
          "apiKeyType": "header",
          "apiKeyValue": "XXX",
          "tlsSkipVerify": true
        }
      }
    },
    "mlffunctionalservicesinference1": {
      "component": "com.sap.ml.leonardo.MLFFunctionalServices",
      "metadata": {
        "label": "Functional Services",
        "x": 186,
        "y": 12,
        "height": 80,
        "width": 120,
        "extensible": true,
        "config": {
          "functionalServices": "Translation"
        }
      }
    },
    "constantgenerator1": {
      "component": "com.sap.util.constantGenerator",
      "metadata": {
        "label": "Constant Generator",
        "x": 17,
        "y": 12,
        "height": 80,
        "width": 120,
        "extensible": true,
        "config": {
          "content": "{   \"sourceLanguage\": \"en\",   \"targetLanguages\": [     \"de\",     \"fr\"   ],   \"units\": [     {       \"value\": \"The shopping cart contains ten items.\",       \"key\": \"CART_CONTENTS\"     }   ] }",
          "counter": 0
        }
      }
    },
    "wiretap1": {
      "component": "com.sap.util.wiretap",
      "metadata": {
        "label": "Wiretap",
        "x": 524,
        "y": 12,
        "height": 80,
        "width": 120,
        "ui": "dynpath",
        "config": {}
      }
    }
  },
  "groups": [],
  "connections": [
    {
      "metadata": {
        "points": "310,52 350,52"
      },
      "src": {
        "port": "output",
        "process": "mlffunctionalservicesinference1"
      },
      "tgt": {
        "port": "in",
        "process": "openapiclient1"
      }
    },
    {
      "metadata": {
        "points": "141,52 181,52"
      },
      "src": {
        "port": "out",
        "process": "constantgenerator1"
      },
      "tgt": {
        "port": "input",
        "process": "mlffunctionalservicesinference1"
      }
    },
    {
      "metadata": {
        "points": "479,52 519,52"
      },
      "src": {
        "port": "out",
        "process": "openapiclient1"
      },
      "tgt": {
        "port": "in",
        "process": "wiretap1"
      }
    }
  ],
  "inports": {},
  "outports": {}
}
1 Comment
You must be Logged on to comment or reply to a post.