misc.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. </head>
  7. <body>
  8. <script type="module">
  9. const printVector = function(predictions, limit) {
  10. limit = limit || Infinity;
  11. for (let i=0; i<predictions.size() && i<limit; i++){
  12. let prediction = predictions.get(i);
  13. console.log(predictions.get(i));
  14. }
  15. }
  16. import {FastText, addOnPostRun} from "./fasttext.js";
  17. addOnPostRun(() => {
  18. let ft = new FastText();
  19. const url = "lid.176.ftz";
  20. ft.loadModel(url).then(model => {
  21. /* isQuant */
  22. console.log(model.isQuant());
  23. /* getDimension */
  24. console.log(model.getDimension());
  25. /* getWordVector */
  26. let v = model.getWordVector("Hello");
  27. console.log(v);
  28. /* getSentenceVector */
  29. let v1 = model.getSentenceVector("Hello");
  30. console.log(v1);
  31. let v2 = model.getSentenceVector("Hello this is a sentence");
  32. console.log(v2);
  33. /* getNearestNeighbors */
  34. printVector(model.getNearestNeighbors("Hello", 10));
  35. /* getAnalogies */
  36. printVector(model.getAnalogies("paris", "france", "london", 10));
  37. /* getWordId */
  38. console.log(model.getWordId("Hello"));
  39. /* getSubwords */
  40. let subWordInformation = model.getSubwords("désinstitutionnalisation");
  41. printVector(subWordInformation[0]);
  42. /* getInputVector */
  43. console.log(model.getInputVector(832));
  44. });
  45. });
  46. </script>
  47. </body>
  48. </html>