-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodeltester.ts
78 lines (70 loc) · 1.67 KB
/
modeltester.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const nlp = require("node-nlp");
import { colors } from "./Helpers";
const manager_ = new nlp.NlpManager({ languages: ["en"], forceNER: true });
//import model
manager_.load("./model.nlp");
const test = [
"who are you ?",
"what about age ?",
"what is your name ?",
"where do you live",
"who made you?",
"what language are you made in ?",
"what is your owner name?",
"can you give your source code?",
];
//using test arrays to test the model
test.forEach(async (item: string) => {
const response: RootObject = await manager_.process("en", item);
console.log(
`${
response.score * 100 < 75 || response?.intent === "None"
? colors.FgRed
: colors.FgGreen
}\nWord: ${item}\nClassification: ${
response?.intent
}\nConfidence : ${Math.round(response?.score * 100)}%\nAnswer: ${
response.answer
}\nSentiment : ${response?.sentiment?.vote} (${Math.round(
response?.sentiment?.score * 100
)}%)`
);
});
//just some interface
interface RootObject {
locale: string;
utterance: string;
settings: undefined;
languageGuessed: boolean;
localeIso2: string;
language: string;
nluAnswer: NluAnswer;
classifications: Classification[];
intent: string;
score: number;
domain: string;
sourceEntities: any[];
entities: any[];
answers: any[];
answer: undefined;
actions: any[];
sentiment: Sentiment;
}
interface Sentiment {
score: number;
numWords: number;
numHits: number;
average: number;
type: string;
locale: string;
vote: string;
}
interface Classification {
intent: string;
score: number;
}
interface NluAnswer {
classifications: Classification[];
entities: undefined;
explanation: undefined;
}