-
Notifications
You must be signed in to change notification settings - Fork 12
/
train.ts
39 lines (32 loc) · 915 Bytes
/
train.ts
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
35
36
37
38
39
// @ts-ignore can't exclude this from build config
const { writeFileSync } = require('fs');
const { join } = require('path');
const { containerBootstrap } = require('@nlpjs/core');
const { Nlp } = require('@nlpjs/nlp');
const { LangEn } = require('@nlpjs/lang-en');
const { LangId } = require('@nlpjs/lang-id');
const corpora = [
require('./corpus-en.json'),
require('./corpus-id.json'),
require('./corpus-ja.json')
];
interface corpus {
locale: string;
data: Array<data>;
};
interface data {
intent: string;
utterances: Array<string>;
answers: Array<string>;
}
(async () => {
const container = await containerBootstrap();
container.use(Nlp);
container.use(LangEn);
container.use(LangId);
const nlp = container.get('nlp');
nlp.settings.autoSave = false;
await nlp.addCorpora(corpora);
await nlp.train();
writeFileSync(join(__dirname, 'model.json'), nlp.export(true));
})();