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 58 59 60 61 62
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
<script type="module">
const printVector = function(predictions, limit) {
limit = limit || Infinity;
for (let i=0; i<predictions.size() && i<limit; i++){
let prediction = predictions.get(i);
console.log(predictions.get(i));
}
}
import {FastText, addOnPostRun} from "./fasttext.js";
addOnPostRun(() => {
let ft = new FastText();
const url = "lid.176.ftz";
ft.loadModel(url).then(model => {
/* isQuant */
console.log(model.isQuant());
/* getDimension */
console.log(model.getDimension());
/* getWordVector */
let v = model.getWordVector("Hello");
console.log(v);
/* getSentenceVector */
let v1 = model.getSentenceVector("Hello");
console.log(v1);
let v2 = model.getSentenceVector("Hello this is a sentence");
console.log(v2);
/* getNearestNeighbors */
printVector(model.getNearestNeighbors("Hello", 10));
/* getAnalogies */
printVector(model.getAnalogies("paris", "france", "london", 10));
/* getWordId */
console.log(model.getWordId("Hello"));
/* getSubwords */
let subWordInformation = model.getSubwords("désinstitutionnalisation");
printVector(subWordInformation[0]);
/* getInputVector */
console.log(model.getInputVector(832));
});
});
</script>
</body>
</html>
|