Create a gist now

Instantly share code, notes, and snippets.

@tondrej /ft.js
Last active Apr 16, 2018

Embed
What would you like to do?
FastText library JavaScript usage
model = "C:\\Data\\fasttext\\wiki\\enwik9.bin";
console.log("Loading file \"%s\"...", model);
fasttext.loadModel(model);
console.log("done.");
console.log("Computing vectors...");
vectors = fasttext.precomputeVectors();
try {
console.log("done.");
while (true) {
positive = prompt('positive words:');
if (positive == undefined)
break;
negative = prompt("negative words:");
fasttext.nn2(vectors, positive, negative, 5, (word, score) => {
console.log("\"%s\": %s", word, score);
});
}
} finally {
fasttext.releaseVectors(vectors);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment