Skip to content

Get the similarity between sentences (using TensorFlow.js).

License

Notifications You must be signed in to change notification settings

hchiam/text-similarity-test

Repository files navigation

Text Similarity Test (using TensorFlow.js)

version

It outputs a percent similarity between two sentences.

This tool could possibly be used to check whether a free-form answer closely matches the expected answer in meaning. For best results, you probably should constrain responses to short sentences (i.e. short answer questions only).

Powered by a Universal Sentence Encoder TensorFlow.js model (U.S.E.).

If you find this project interesting, you might also like this project that goes beyond just U.S.E.: https://github.com/hchiam/comment-analysis

Try it in your browser

https://codepen.io/hchiam/pen/oNjzQRa

Try it from your own computer

open index.html or yarn start or npm start

You can run useModelToEmbedAllSentences from CLI with node tfjs-stuff.js

Import it into your own project

<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="https://cdn.jsdelivr.net/gh/hchiam/[email protected]/tfjs-stuff.js"></script>
var sentence1 = "Hello there!";
var sentence2 = "Hi, nice to see you!";
function callback(similarityScore) {
  alert(Math.round(similarityScore * 100 * 100) / 100 + "%");
}
useModel(sentence1, sentence2, callback); // useModel comes from tfjs-stuff.js

Another example

https://codepen.io/hchiam/pen/abJGGox

https://github.com/hchiam/text-similarity-test/blob/master/summary-test.html

More things I'm testing

(See the coglangtext sub-folder.)

Useful references used

Related repos

https://github.com/hchiam/learning-tensorflow

https://github.com/hchiam/text-similarity-test-microservice

https://github.com/hchiam/learning-annoy

Future/Experimental

https://github.com/hchiam/learning-gpt4all

Text Sentiment Analysis Classification and Scoring (using @tensorflow/tfjs): https://codepen.io/hchiam/full/bGQWdmV

Other repos you might find interesting

https://github.com/hchiam/comment-analysis

https://github.com/hchiam/learning-tfjs-umap