textual-similarity-universal-sentence-encoder
textual-similarity-universal-sentence-encoder copied to clipboard
Uncaught TypeError: use.loadTokenizer is not a function
index.html
<head>
<script src="index.js" defer>
import * as use from '@tensorflow-models/universal-sentence-encoder';
</script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>
</head>
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
Error message in the console as shown below
Uncaught TypeError: use.loadTokenizer is not a function
How do you manage to use Universal Sentence Encoder? I've no clue how to solve this error.
I'm not sure where you got your codes from, because the index.html and index.js in this repo does not contain the code snippet you presented. Does this demo works for you?
Based on the code you provided, maybe you need to install @tensorflow-models/universal-sentence-encoder first:
npm install @tensorflow/tfjs @tensorflow-models/universal-sentence-encoder
I refer to this repo tfjs-models because it consists of the guide for Tokenizer.
Yup. Your demo is working fine in my computer. Amazing work!
Yea I did. I ran npm install @tensorflow/tfjs @tensorflow-models/universal-sentence-encoder in my terminal and got package-lock.json. Then I moved it to the same directory as both index.html and index.js. The code doesn't seem to have any problem. It probably has something to do with the way of dealing with the package?