Step 2: Model Training and Serving

In this part of our blog series, you’ll start to train and serve the model using sample data.

In Step 1, we created a subaccount for Personalized Recommendation, obtained our service key, retrieved our bearer token, and learned how to access the Swagger API page. Here’s a short video that shows how to train and serve your model using sample data:

Video walk-through of Step 2

Swagger Documentation

Training, serving, and inference calls take place in the Swagger API page of Personalized Recommendation.

To access the Swagger API page, you need the url (not from the uaa section) and swagger values from the service key generated in Step 1. In the address bar of a new browser tab, paste the url value, followed by the swagger value and choose Enter.

Swagger API section of the service key

The Swagger API page of Personalized Recommendation is divided into four categories:

  1. Resource APIs allow you to view and manage subaccount and tenant resources, including the deletion of tenant/site data.

    Resource APIs in the Swagger API Page

  2. Training APIs allow you to upload and trigger model training jobs and get training job statuses.

    Training APIs in the Swagger API Page

  3. Inference APIs allow you to get real-time inference (recommendation) results.

    Inference APIs in the Swagger API Page

  4. Serving APIs allow you to manage real-time model serving instances and get the serving statuses of their models.

    Serving APIs in the Swagger API Page

For more information about the Personalized Recommendation Swagger API page, see the service’s API Reference documentation.

2. Authorization Using Bearer Token

Before using the APIs, you must authorize yourself using the Authorize button in the upper-right corner of the screen.

Authorize button in the Swagger API Page

When you click the button, a popup appears, asking you to input your Bearer Token. In the input box, make an entry with the format Bearer <your_token>. Here, your_token is the “access_token” value from the response received when you generated the bearer token earlier in Step 1. (See the following graphic).

Enter Bearer Token on the Authorize screen

Next, click Authorize to use the APIs.

3. Training Job Submission

To train the model, navigate to the Training section, expand the file-upload dropdown, and click Try it out. Bear in mind that users with the free tier model for SAP BTP are limited to only two training endpoint executions. When you call the third training API, you get a 403 response stating that you have exceeded your quota for the month.

File-upload Training API

To execute the training endpoint, do the following:

  1. Enter tenant name.
    You must enter a name for the tenants, so please input a name of your choice.
  2. Upload Data.
    For the sake of simplicity, use the sample data from this link. For more details of the training dataset, see this documentation.

    Upload data field in the API request

    After downloading the sample data, go back to the Swagger API page and upload the file.

  3. Enter site name.
    A site name is also required, but if you leave this field blank, it’s automatically filled with “default”.

    Site Field in the API request

  4. Set serve_model=True.
    Make this setting to automatically deploy the real-time model serving instance.

    Serve_model field in the API request

  5. Click the Execute Bear in mind that users with the free tier model for SAP BTP are limited to only two training endpoint executions.

After you trigger the training, there are three possible outcomes.

  1. Still ongoing, with the status “PENDING” and code 200

    Pending Status in the API response

  2. Conflict, where the trigger has clashed with the ongoing training from the previous trigger. The status is “Previously submitted job still in progress”, and the code is 409.

    Conflict Status in the API response

  3. Forbidden, where the user has exceeded their training quota for the month. The API returns a short message with code 403.

    Forbidden Error in the API response

To check the status of the ongoing job, navigate to the latest path, click Try it out, and enter the following information: tenant name and site name (must be exactly the same as in the preceding step).

Get Training Status API

After you click Execute, there are three possible outcomes:

  1. Job is still ongoing, with the status “SUBMITTED” and code 200. Please wait for around 5– 10 minutes before rechecking the progress.

    status SUBMITTED in the API response

  2. The job is completed, with the status “SUCCEEDED” and code 200. You can now proceed to the next step.

    status SUCCEEDED in the API response

  3. The job fails, with the status “FAILED” and code 200. Please retrigger the training and make sure that you’ve entered all information correctly.

    status FAILED in the API response

3. Model Serving

To get the deployment status for model serving, navigate to the Serving section and the servings path. Click Try it out and enter the site name and tenant name.

When you click Execute, there are two possible outcomes:

  1. Instance deployment is still ongoing. The status is “PENDING” with code 200.

    status PENDING in the API response

  2. Instance deployment is successful. The status is “SUCCEEDED” with code 200.

    status SUCCEEDED in the API response

Things to note:

  • stage” in the response indicates the progress of deployment.
  • For more information about real-time model serving and deployment, refer to this link.

Cheers

At this point, we have successfully trained the model. If you have encountered any issues, feel free to leave a comment below, I will definitely help you out. Alternatively, check out the Q&A areas in the community.

In the next step, we will be using the APIs to get recommendations from the model trained in this step. Feel free to follow my profile and stay tuned for the next steps. See you in the next blog!