As a beginner with Tensorflow.js concepts, I recently attempted to tokenize a sentence using the Universal Sentence Encoder in Javascript. You can explore more about it on Github Reference
$ npm install @tensorflow/tfjs @tensorflow-models/universal-sentence-encoder
After running this command, a package-lock.json file was generated which I placed alongside my index.html file within the same directory structure shown below.
/*
Folder
|_index.html
|_package-lock.json
|_index.js
|_index.css
*/
Within index.html:
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>
<script src="index.js" defer></script>
</head>
Contents of index.js:
function tokenizePad(text){
text = use.loadTokenizer().then(tokenizer => {
tokenizer.encode(text);
});
return text;
}
text = "I enjoy my holiday very much."
var tokenized = tokenizePad(text); //error
The console displayed an error message as follows:
Uncaught TypeError: use.loadTokenizer is not a function
Is there a solution to this issue? Are there alternative methods to achieve the desired outcome of converting the string into an array of encoded values like [341, 4125, 8, 140, 31, 19, 54, ......] mentioned in the Github Reference link?