Public
Edited
Apr 24, 2022
3 stars
Insert cell
Insert cell
Insert cell
chosen = []
Insert cell
Insert cell
Insert cell
clues = {
let remaining = [];
for (let i = 0; i < nearest.length; i++)
if (!chosen.includes(i)) remaining = remaining.concat(nearest[i]);
const scored = new Map();
for (const { word, distance } of remaining) {
if (!scored.has(word))
scored.set(word, { distance, count: distance > 0 ? 1 : 0 });
else
scored.set(word, {
distance: scored.get(word).distance + distance,
count: scored.get(word).count + (distance > 0 ? 1 : 0)
});
}
return d3.sort(scored.entries(), (a, b) => b[1].distance - a[1].distance);
}
Insert cell
nearest = Promise.all(
// my phone can't seem to handle all 25
board.map(async ({ word, score }) => {
if (!hasMatch(word)) word = word.charAt(0).toUpperCase() + word.slice(1);
if (!hasMatch(word)) return [];
const neighbors = await gloVe.getNearestNeighbors(word, 300);
return neighbors.map(({ word, distance }) => ({
word,
distance: distance * score
}));
})
)
Insert cell
hasMatch = (word) => gloVe.getVector(word).reduce((sum, i) => sum + i) !== 0
Insert cell
board = shuffled.slice(0, 25).map((word, i) => ({
word: word.toLowerCase(),
score: score(i)
}))
Insert cell
score = d3
.scaleThreshold()
.domain([
9, // blue team (9)
9 + 7, // bystander (7)
9 + 7 + 8 // red team (8)
])
.range([
1, // blue team (9)
-1, // bystander (7)
-2, // red team (8)
-10 // assassin (1)
])
Insert cell
shuffled = shuffle(words.slice())
Insert cell
shuffle = d3.shuffler(d3.randomLcg(seed))
Insert cell
Insert cell
import { gloVe } from "@dhowe/understanding-word-vectors"
Insert cell
// (await fetch("https://mb-14.github.io/embeddings.js/assets/embeddings.js")).text()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more