BLOCKS Reference

Watson

Create and train a classifier

Overview

This BLOCK is currently in beta and will become unavailable post official release. Please use the official version once it is released.

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

Your IBM Cloud account must be configured to allow use of the Natural Language Classifier service in order to use this BLOCK. You must also have Natural Language Classifier service credentials.

This BLOCK allows you to use Create classifier from the IBM Watson Natural Language Classifier API from BLOCKS.

You can create and train a natural language classifier by executing this BLOCK. The following image shows the placement for using this BLOCK:

Create and train a classifier BLOCK placement example
  1. Create and train a classifier BLOCK

    The classifier learns (does its training) from text format data.

  2. Classify text BLOCK

    The trained classifier takes new text data (untrained data) and interprets it to determine its class. It classifies the data as the most appropriate class from among the ones set during the training.

You can prepare your training data as one of the following three formats:

The following sections will briefly explain each training data format and how to use them with a BLOCKS Big Data Board.

Natural Language Classifier-specific text format (CSV)

Refer to the IBM Cloud documentationopen_in_new for details about text data formatting for the Natural Language Classifier.

This section will explain how to use the Natural Language Classifier API’s specific text data format from a Big Data Board.

On your Big Data Board, you will place a Load to variable from GCS BLOCK to read a file stored in Google Cloud Storage (GCS), then simply connect a Create and train a classifier BLOCK.

First, upload your data to GCS. For this example, assume we’ve uploaded a file called weather_data_train.csv to a GCS bucket named my-blocks-bucket (GCS URL: gs://my-blocks-bucket/weather_data_train.csv.

info_outline You can use the GCS Explorer BLOCKS service to easily upload files from your PC to GCS.

Then, create a Flow like the following to create and train your classifier.

Sample Flow with each BLOCK’s properties

You must set the file format property for both the Load to variable from GCS and Create and train a classifier BLOCKS to none.

Google Spreadsheet (BLOCKS-specific function)

You can use Google Spreadsheet data as your training data by using BLOCKS. Your data must be formatted as follows:

Natural Language Classifier with Google Spreadsheet training data sample

Once you have prepared your spreadsheet, you can create and train your classifier using a Flow like the one shown below:

Sample Flow with each BLOCK’s properties

You must share the Google Spreadsheet with the email for your GCP service account. Also, be sure to set the file format property of the Create and train a classifier BLOCK to JSON.

Array format (BLOCKS-specific function)

You can also use an object whose members are each arrays as the training data (BLOCKS-specific function).

The following example shows how to create training data using the Construct object BLOCK. The contents of the data are the same as in the previous Google Spreadsheet example.

Example using the construct object BLOCK

(Click image to enlarge)

  • Create one Object. The object in this example has the key name data.
  • Inside the object, create Array type members.
  • Enter the classes as the Key for each array. In this example, the classes are temperature and conditions.
  • Enter the elements of the array as the text to classify (string format).

Once you have finished preparing the Construct object BLOCK, you can create and train your classifier with a Flow like the one shown below:

Sample Flow with each BLOCK’s properties

Make sure to set the file format property of the Create and train a classifier BLOCK to None.

Properties

Property Explanation
BLOCK name

Configure the name displayed on this BLOCK

Username

The value of "username" from your Natural Language Classifier service credentials (as shown below).

Service credentials username example

(Click image to enlarge)

Password

The value of "password" from your Natural Language Classifier service credentials (as shown below).

Service credentials password example

(Click image to enlarge)

Variable containing training data

Designate the variable that contains the training data.

File format

Designate the format of the training data.

  • None: Select this when using the Natural Language Classifier-specific text format (CSV) or array format (BLOCKS-specific function).
  • JSON: Select this when using Google Spreadsheet (BLOCKS-specific function).
Classifier name

Designate a unique name to identify this classifier.

BLOCK memos

Make notes about this BLOCK.

Language

Designate the language of the training data.