Text Similarity Test (using TensorFlow.js)
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
https://codepen.io/hchiam/pen/oNjzQRa
open index.html
or yarn start
or npm start
You can run useModelToEmbedAllSentences
from CLI with node tfjs-stuff.js
<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
https://codepen.io/hchiam/pen/abJGGox
https://github.com/hchiam/text-similarity-test/blob/master/summary-test.html
(See the coglangtext
sub-folder.)
- https://github.com/tensorflow/tfjs-models/tree/master/universal-sentence-encoder
- https://towardsdatascience.com/how-to-build-a-textual-similarity-analysis-web-app-aa3139d4fb71
- https://github.com/jinglescode/demos/tree/master/src/app/components/nlp-sentence-encoder
- https://towardsdatascience.com/how-to-measure-distances-in-machine-learning-13a396aa34ce
- https://en.wikipedia.org/wiki/Cosine_similarity
https://github.com/hchiam/learning-tensorflow
https://github.com/hchiam/text-similarity-test-microservice
https://github.com/hchiam/learning-annoy
https://github.com/hchiam/learning-gpt4all
Text Sentiment Analysis Classification and Scoring (using @tensorflow/tfjs
): https://codepen.io/hchiam/full/bGQWdmV