-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
49 lines (38 loc) · 1.1 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const readline = require('node:readline');
const { stdin: input, stdout: output } = require('node:process');
const { dirname } = require('path');
const __root = dirname(require.main.filename);
const { Language: LM } = require('../../models');
const TestDataset = require(`${__root}/training/datasets/Default`);
const rl = readline.createInterface({ input, output });
const MyLanguageModel = async (verbose = false) => {
const agent = await LM({
dataset: TestDataset
});
const print = input => {
if (
input.toLowerCase() === '/bye' ||
input.toLowerCase() === '/exit'
) {
console.log('Bye!');
rl.close();
process.exit();
}
const {
completion,
completions,
rankedTokenList
} = agent.getCompletions(input);
console.log(`${completion}`, '\n');
if (verbose) {
console.log('Top K (next words):', rankedTokenList);
console.log('Top K (next phrases):', completions);
}
prompt();
};
const prompt = () => {
rl.question('Type something... (press ENTER to suggest) ', print);
};
prompt();
};
MyLanguageModel();