-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_tokens.js
57 lines (42 loc) · 1.15 KB
/
build_tokens.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
50
51
52
53
54
55
56
57
let fs=require('fs')
let fsPath=require('fs-path')
let dataBase=fsPath.findSync('./data').files
let {encode,decode}=require('gpt-3-encoder')
const path = require('path');
const fastText = require('fasttext');
const { pipeline } = require('node:stream/promises');
async function processChunk(line,{signal}){
fs.appendFileSync('./models/base',encode(line).join(' ')+'\n')
}
async function digest(data) {
await pipeline(
fs.createReadStream(data),
async function* (source, { signal }) {
source.setEncoding('utf8');
for await (const line of source) {
yield await processChunk(line, { signal });
}
},
);
return true
}
async function digestData(params) {
for(let k=0;k<dataBase.length;k++){
await digest(dataBase[k])
console.log(k)
}
let data = path.resolve(path.join(__dirname, './models/base'));
let model = path.resolve(path.join(__dirname, './models/vec'));
let classifier = new fastText.Classifier();
let options = {
input: data,
output: model,
ws:5,
neg:1,
epoch:50,
dim:8,
bucket: 2000000
}
classifier.train('cbow', options)
}
digestData()