forked from watson-developer-cloud/social-customer-care
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain-classifier.js
35 lines (29 loc) · 1.03 KB
/
train-classifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env node
'use strict';
var debug = require('debug')('scc:train');
// This helps to run the application in local development environment
// by faking CloudFoundry's VCAP_SERVICES environment variable
process.env.VCAP_SERVICES = process.env.VCAP_SERVICES || fs.readFileSync('./credentials.json', 'utf-8');
var fs = require('fs');
var replace = require('replace');
var watson = require('watson-developer-cloud');
var naturalLanguageClassifier = new watson.natural_language_classifier({ version: 'v1' });
debug('Training Natural Language Classifier');
naturalLanguageClassifier.create({
language: 'en',
name: 'Twitter topics',
training_data: fs.createReadStream('./training/classifier-training-data.csv')
}, function(err, classifier) {
if (err) {
debug('Error training Natural Language Classifier');
debug(err);
} else {
replace({
regex: 'REPLACE WITH YOUR CLASSIFIER ID',
replacement: classifier.classifier_id,
paths: ['./credentials.json'],
recursive: true,
silent: true
});
}
});