Closed bittlingmayer closed 2 years ago
@bittlingmayer I will check this out, VSCode has a new functionality that let you convert Promise.then().catch() in the async await pattern.
@bittlingmayer I have just realized that Node10 has worker threads!!!! that is a huge improvements, and will speed up fastText execution a lot!!! Check this out!
https://github.com/a1xon/Node-Workers-Example/blob/master/worker.js
This code snippet show how to use async/await
let FastText = require('../lib/index');
let ft = new FastText({
predict: {
// k most likely labels for each line <= labels count
mostlikely: 2,
verbosity: 2,
// true to normalize input text before prediction
normalize: false
},
loadModel: MODELS_ROOT + '/lid.176.ftz' // must specifiy filename and ext
});
let text = "Bonjour à tous. Ceci est du français";
// use WASM api
try {
await ft.loadWASM();
var labels = await ft.predictWASM(text);
console.log("TEXT:", text, "\nPREDICT:", labels);
} catch (error) {
console.error("predict error", error);
}
This would be easy to do with
promisify
in newer versions of Node.Personally I far prefer
async
/await
to the callback syntax.