Skip to content

Files

Latest commit

f92eaff · Mar 14, 2024

History

History
45 lines (31 loc) · 1.71 KB

README.md

File metadata and controls

45 lines (31 loc) · 1.71 KB

The Dissimilarity WordGame

Fun project that checks if you can come up with words that are as dissimilar as possible. (Implementation details at the bottom.)

Play it at https://romanoneg.github.io/WordGame/

image

Implementation:

Code:

Uses tensorflow.js to load tensorflow's Universal-Sentence-Encoder in order to create vector representations of each word (or multiple words) entered in the text boxes.

The library is imported with the following in index.html:

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

The model is then loaded in script.js:

use.load().then(loadedModel => {
  model = loadedModel;
};

And inference is done with:

// sentences is a vector of strings to be embedded
model.embed(sentences).then(embeddings => {
  // calculating scores with embeddings
};

Score Calculation

These n vectors are then used calculate the final score: GameScore = 1 μ sim normalization factor where μ is the average of all the pairwise cosine-similarities between vectors calculated as: μ sim = ( n 2 ) 1 i = 0 n j = i + 1 n cosine-similarity ( v i , v j ) Where v i denotes the i-th word embedding vector and the normalization factor = 0.8 and is hand-chosen to make the scores roughly go from 0 to 100 .