File size: 1,255 Bytes
b03fd59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!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 => {
                let text = "Bonjour à tous. Ceci est du français";
                console.log(text);
                printVector(model.predict(text, 5, 0.0));

                text = "Hello, world. This is english";
                console.log(text);
                printVector(model.predict(text, 5, 0.0));

                text = "Merhaba dünya. Bu da türkçe"
                console.log(text);
                printVector(model.predict(text, 5, 0.0));
            });
        });

    </script>
</body>

</html>