heidloff.net - Building is my Passion
Post
Cancel

Classify Natural Language without a Background in Machine Learning

With the Natural Language Classifier Watson service in IBM Bluemix developers can classify natural language so that, for example, you can build a virtual agent application that answers common questions. Below is a simple sample how you can use this service.

Here is a description on the service: “The service enables developers without a background in machine learning or statistical algorithms to create natural language interfaces for their applications. The service interprets the intent behind text and returns a corresponding classification with associated confidence levels. The return value can then be used to trigger a corresponding action, such as redirecting the request or answering a question.”

In order to use the service you need to provide training data that defines the different classes and text samples that fall under certain classes. In the scenario below I have two classes – positive and negative.

1
2
3
4
5
6
7
8
9
10
11
12
13
positive,positive
good,positive
excellent,positive
brilliant,positive
really good,positive
best,positive
supportive,positive
reassuring,positive
encouraging,positive
negative,negative
bad,negative
ugly,negative
really bad,negative

Save this file as cvs file and send it to the Watson service.

1
curl -i -u "<username>":"<password>" -F training_data=@./data_train.csv -F training_metadata="{\"language\":\"en\",\"name\":\"PosNegClassifier\"}" "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers

After a couple of minutes the training is done and the Watson service returns a classifier_id that you need to ask the service under which classes specific text falls. Here is a request for the word “awesome” which was not in the initial training data.

1
curl -G -u "<username>":"<password>" "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/3AE103x13-nlc-1116/classify" --data-urlencode "text=awesome"

The Watson service returns not only one class but up to the top five classes with the highest confidence levels.

image

To learn more about the service check out the online demo, the engagement gallery sample application, the documentation and the API documentation.

In order to improve the quality of the classifier you need to evaluate the results and update the training data. To simplify the management of the training data and the classifiers there is a toolkit/web application available.

image

Featured Blog Posts
Disclaimer
The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
Trending Tags