BLOCKS Reference

Block Reference

Machine Learning

ML Board prediction (online)

Trainings made prior to 2017/4/12 will become unusable after 2017/6/1. Please use trainings made after 2017/4/12 for making predictions.

This BLOCK is currently in beta and will become unavailable post official release.
*Please make use of the official BLOCK once released.

As a beta release, there is the possibility that some functions may not execute properly. We appreciate feedback from users, through the BLOCKS Forum or direct contact, regarding bugs or ways to improve BLOCKS.

Overview

This BLOCK uses prediction input data with an ML Board’s training to make predictions.

It reads in the input data from a variable and outputs the prediction results as another variable.

ML Board Predict BLOCK overview

We recommend using the ML Board prediction (batch) BLOCK for predictions with a large amount of prediction input data.

  • There is a 1,000 row limit when making predictions from the results of a BigQuery query.
  • This BLOCK may not be able to make predictions if there is a very large amount of prediction input data.

You must first click “Apply” for a training on an ML Board to make predictions with this BLOCK.

Prediction input data formatting

Store prediction input data into a variable before executing this BLOCK.

The contents of this variable differ when using the regression and classification type ML Boards versus the image classification type ML Board.

This page uses the Construct Object BLOCK and a data notation format called JSON to explain what kind of data should be contained within the variable.

What is JSON?

First, we will briefly explain the basics of JSON. For a more detailed explanation, please refer to Introducing JSON and RFC 7159 .

  • JSON is a notation format for expressing data.
    {
      "name": "John Smith",
      "age": 35,
      "languages": ["English", "Japanese"]
    }
    
  • Data is referred to as values in JSON. Values can be of the following types:
    • String: These are strings of characters enclosed within double quotes ("), such as "abc" or "xyz".
    • Numerical values: Directly entered numbers such as 1 or 1.23. These are expressed in base 10. Scientific notation, such as 1.234e-5 can also be used.
    • Boolean values: Shows if the value is true or false. Expressed as true or false.
    • null: Shows that the value is empty. Expressed as null.
    • Arrays: Ordered series of values, such as [1, 2, 3] that are separated by commas (,). Arrays are enclosed by square brackets ([ and ]). Each value in an array is called an element.
    • Object: Sets of name and value pairs.
      • Objects are enclosed by curly brackets ({ and }).
      • Name/value pairs are separated by commas (,), as in {"a": 1, "b": 2, "c": 3}.
      • A name and it’s accompanying value are separated by a : (name: value.
      • Names are expressed as strings (enclosed in ").
      • Name/value pairs are called members.
  • Data expressed with JSON is called JSON text.
When using the regression/classification types

Store a set of the input data and a key into a variable.

  • Construct Object BLOCK example:

    Example with one set of input data

    As shown in the image above, select Object for the value type, and set its contents (click the + button next to Object) as a key and the input data. Follow these rules when entering the data:

    • You must set a key for the data calledkey. The value of this key acts as an identifier for this set of input data. The value type must be set to String.
    • For the input data, set each key as the item names from the ML Board’s training data. Set the values as the input data that will be used to make the prediction. Set the value types according to each type of data.

    Numbers that have been converted into strings can also be accepted for numerical values, month, and days. For example, numerical values that have been converted into strings, like “99” or “1.5”, are treated as 99 and 1.5. Similarly, string data like “0” and “6” signifying days of the week are treated as 0 and 6.

  • JSON text example:
    {
      "key": "1",
      "sepal_length": 5.9,
      "sepal_width": 3.0,
      "petal_length": 4.2,
      "petal.width": 1.5
    }
    
    • Specify an object ({...}).
    • You must set a member to act as a key for the object. This member must be named "key". Set its value as a string that will act as an identifier for this set of input data.
    • Set other members with names as found in the item names for the ML Board’s training data, and values in accordance with the data for each item.

Do the following for making predictions with multiple sets of input data:

  • Construct Object BLOCK example:

    Predictions with multiple sets of prediction input data

    As shown in the image above, select Array for the “Value type”. Add an object for each set of prediction input data to the array by clicking the + button next to Array. Enter the data to each object as explained earlier.

  • JSON text example:
    [
      {
        "key": "1",
        "sepal_length": 5.9,
        "sepal_width": 3.0,
        "petal_length": 4.2,
        "petal_width": 1.5
      },
      {
        "key": "2",
        "sepal_length": 6.9,
        "sepal_width": 3.1,
        "petal_length": 5.4,
        "petal_width": 2.1
      },
      {
        "key": "3",
        "sepal_length": 5.1,
        "sepal_width": 3.3,
        "petal_length": 1.7,
        "petal_width": 0.5
      }
    ]
    
    • Set as an array ([...]).
    • Set each element of the array as objects for the prediction input data. The format for each object is the same as explained previously.
When using the image classification type

The variable’s contents should point to the JPEG format, image files that will be used for the prediction. There are various ways to accomplish this.

  • Specify the image file’s GCS URL (gs://BUCKETNAME/FILENAME) as a string.

    • Example using the Construct Object BLOCK:

      Image classification: prediction input data as strings

      As shown in the image above, select String for the value type.

      Assuming that the above Construct Object BLOCK’s Results variable property is set to _, _.data would refer to the prediction input data.

    • Example using JSON text:

      "gs://my-bucket/sample01.jpg"

      Specify the image file’s GCS URL using a string value ("...").

  • Use an array to specify multiple image files.

    • Example using the Construct Object BLOCK:

      Image classification: prediction input data as an array of strings

      As shown in the image above, select Array as the value type. Click the + button to the left of Array to add elements to the array and set each element as a string for an image file’s GCS URL.

      Assuming that the above Construct Object BLOCK’s Results variable property is set to _, _.data would refer to the prediction input data.

    • Example using JSON text:

      ["gs://my-bucket/sample01.jpg", "gs://my-bucket/sample02.jpg"]

      • Set as an array ([...]).
      • Set each element of the array as a string for each image file’s GCS URL.
  • As with the regression and classification type models, you can also assign keys to image files. By using these keys, you can make it easier to manage prediction input images and prediction results for predictions involving multiple images.

    • Example using the Construct Object BLOCK:

      Image classification: prediction input data as an object

      As shown in the image above, select Object as the value type. For the contents of the Object, click the + button next to Object to enter a key, and again to enter a string for a GCS URL. Set the Key portion for each as key and image, respectively.

    • Example using JSON text:

      {"key": "sample01", "image": "gs://my-bucket/sample01.jpg"}

      • Set as an object ({...}).
      • You must set a member to act as a key for the object. This member must be named "key". Set its value as a string that will be the identifier for an image file.
      • Set another member with information for the image file. This member must be named "image". Set its value as a string for the image file’s GCS URL.

    Use an array to specify multiple image files.

    • Example using the Construct Object BLOCK:

      Image classification: prediction input data as multiple objects

      As shown in the image above, select Array for the type. Enter objects with information for each image file into the array by clicking the + button next to Array. Follow the same instructions as earlier for entering each file’s information into each object.

      Assuming that the above Construct Object BLOCK’s Results variable property is set to _, _.data would refer to the prediction input data.

    • Example as JSON text:
      [
        {
          "key": "sample01",
          "image": "gs://my-bucket/sample01.jpg"
        },
        {
          "key": "sample02",
          "image": "gs://my-bucket/sample02.jpg"
        }
      ]
      
      • Set an array ([...]).
      • Set each element of the array as an object containing an image file’s information. Format each object the same as explained previously.
  • When setting objects with keys, it is also possible to pass image files using the following formats (aside from using a GCS URL):

    • The contents of the image file as Base64 encoded data.
    • The contents of the image file directly as binary data.

Prediction results formatting

Results from a prediction are output as a variable. We will explain the formatting of the prediction results by using the “Output to log” BLOCK to see the contents (JSON format) of this variable.

When using the classification model

The following example shows results for a classification-type model:

        {
          "predictions": [
            {
              "score": [
                8.715780131751671e-05,
                0.9995228052139282,
                0.00039013021159917116
              ],
              "key": "1",
              "label": 1
            },
            {
              "score": [
                9.230815578575857e-08,
                0.007054927293211222,
                0.9929450154304504
              ],
              "key": "2",
              "label": 2
            },
            {
              "score": [
                0.9998869895935059,
                0.00011299729521851987,
                1.5803254260760013e-09
              ],
              "key": "3",
              "label": 0
            }
          ]
        }
        
  • The results are output as a single JSON object.
  • "predictions": An array containing the results of the prediction. The elements of this array are objects with the following members:
    • "score": The level of certainty for predicting each class.
      • Shows the certainty level for each class in order, i.e. certainty for class 0, certainty for class 1, certainty for class 2, and so on.
      • For example, results of [8.715780131751671e-05, 0.9995228052139282, 0.00039013021159917116] show a 0.00871578% certainty for class 0, a 99.952280521% certainty for class 1, and a 0.039013021% certainty for class 2.
      • The class with the highest certainty level is the predicted class.
    • "key": The value of the "key" used in the prediction input data.
    • "label": The predicted class. The class with the highest value from "score".
When using the regression model

The following is an example of results for a regression-type model:

        {
          "predictions": [
            {
              "output": 10261.9072265625,
              "key": "20170101"
            },
            {
              "output": 12506.2861328125,
              "key": "20170102"
            },
            {
              "output": 10304.1962890625,
              "key": "20170103"
            },
            {
              "output": 10350.099609375,
              "key": "20170104"
            }
          ]
        }
        
  • The results are output as a single JSON object.
  • "predictions": An array containing the results of the prediction. The elements of this array are objects with the following members:
    • "output": The predicted value.
    • "key": The value of the "key" used in the prediction input data.
When using the image classification model

The following example shows results from the image classification model:

        {
          "predictions": [
            {
              "score": [
                0.9999533891677856,
                4.6590834244852886e-05
              ],
              "key": "sample01",
              "label": "cat"
            },
            {
              "score": [
                0.0005344885867089033,
                0.9994655251502991
              ],
              "key": "sample02",
              "label": "dog"
            }
          ]
        }
        
  • Formatting is the same as the classification model.
  • This example if for a model that classifies images of cats and dogs. The first element in "score" is the certainty for "cat", and the second element is the certainty for "dog".
  • "key" will contain the value of the key used in the prediction input data, if one was used. If no key was used, “key” will contain the GCS URL for the image file.

Properties

Property Explanation
BLOCK name Configure the name displayed on this BLOCK.
GCP service account Select the GCP service account to use with this BLOCK.
ML Board Select the BLOCKS ML Board whose applied training will be used to make the predictions.
Input variable Designate the variable that contains the input data that will be used to make a prediction.
Output variable Designate the variable that will store the results of the predictions from the ML model.
BLOCK memos Make notes about this BLOCK.