Skip to content

romanoneg/WordGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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: $$\text{GameScore} = \frac{1 - \mu_{\text{sim}}}{\text{normalization factor}}$$ where $\mu$ is the average of all the pairwise cosine-similarities between vectors calculated as: $$\mu_{\text{sim}} = {n \choose 2}^{-1} \sum_{i=0}^{n} \sum_{j=i+1}^{n} \text{cosine-similarity} (v_{i}, v_{j})$$ Where $v_{i}$ denotes the i-th word embedding vector and the $\text{normalization factor} = 0.8$ and is hand-chosen to make the scores roughly go from $0$ to $100$.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published