Skip to content

Instantly share code, notes, and snippets.

@tondrej
Last active April 16, 2018 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tondrej/14fb685f2dd1a730f3ede80bd0c1bc80 to your computer and use it in GitHub Desktop.
Save tondrej/14fb685f2dd1a730f3ede80bd0c1bc80 to your computer and use it in GitHub Desktop.
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