Tensorflow Embeddings

by Cody Bennett

HTML

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder"></script>

JavaScript

const sentences = `Will it snow tomorrow?
Recently a lot of hurricanes have hit the US
Global warming is real

An apple a day, keeps the doctors away
Eating strawberries is healthy

what is your age?
How old are you?
How are you?

The dog bit Johnny
Johnny bit the dog

The cat ate the mouse
The mouse ate the cat
`;

use.load().then(model => {
  model.embed(sentences).then(embeddings => {
    // console.log('Tensor: ', embeddings.arraySync()[0]);
    embeddings.print(true);
  });
});