Last active
August 29, 2015 14:27
-
-
Save germanattanasio/2eba167fbc9fb6c8a5f6 to your computer and use it in GitHub Desktop.
How to create a classifier using the nodejs wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var watson = require('../nodejs-wrapper/lib/index'); | |
var fs = require('fs'); | |
var natural_language_classifier = watson.natural_language_classifier({ | |
url: 'https://gateway.watsonplatform.net/natural-language-classifier/api', | |
username: 'USERNAME', | |
password: 'PASSWORD', | |
version: 'v1' | |
}); | |
// Classifiers can be created using a string, csv stream or json object | |
// 1. string | |
var csv = fs.readFileSync('./training_data.csv'); | |
// 2. stream - util for large files | |
var stream = fs.createReadStream('./training_data.csv'); | |
// 3. json - converted to csv | |
var json = [ | |
{ text: 'text 1', classes: ['class1','class2'] }, | |
{ text: 'text 2', classes: ['class1'] }, | |
//... | |
]; | |
var params = { | |
language: 'en', | |
name: 'my-json-classifier', | |
training_data: json //replace with stream or csv | |
}; | |
natural_language_classifier.create(params, function(err, response) { | |
if (err) | |
console.log(err); | |
else | |
console.log(JSON.stringify(response, null, 2)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
training_data.csv
file can be found here.json
make sure you have more than 5 training elements.