CoolFace
Apppublic

thameena/semantic-word-ladder

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
App README

Semantic Word Ladder πŸͺœ

A small hobby project to explore how words are connected in embedding space by treating semantic similarity as a search problem.

Given a start word and a target word, the system finds a semantic ladder - a sequence of intermediate words that gradually move from the start to the target based on cosine similarity.


Core Ideas

The project is built around a few key concepts.


1. Word Embeddings

Words are converted into dense vectors using a pretrained sentence-transformer model.

Semantic similarity between words is measured using cosine similarity, which captures how closely two words align in meaning.


2. Semantic Space as a Graph

  • β€”Each word is treated as a node
  • β€”Edges are implicit: the top-k most similar words form the local neighborhood
  • β€”The full graph is never built explicitly

This allows semantic navigation to be treated as a graph search problem rather than a static similarity lookup.


3. A* Search for Semantic Navigation

The ladder is found using A\* search, where:

  • β€”Each step moves to a nearby semantic neighbor
  • β€”The algorithm balances:
  • β€”local smoothness (don’t jump too far)
  • β€”progress toward the target

Project Structure

Setup & Usage

This project is designed to be run locally using Python + uv.

Prerequisites

  • β€”Python 3.10 or 3.11
  • β€”uv installed
bash
pip install uv

Install dependencies

uv pip install -r requirements.txt

Prepare dataset

Create or edit the vocabulary file:

data/words.txt

The dataset that is used for this project is from: https://github.com/first20hours/google-10000-english/blob/master/google-10000-english-no-swears.txt

Generate embeddings (one-time step)

Convert words into vectors and save them locally:

uv run python src/embed.py

This generates:

data/embeddings.npy
data/word_to_idx.json

Build / load FAISS index

The FAISS index is loaded automatically when the app runs.

To test it manually:

uv run python -m src.index

Run streamlit app

uv run streamlit run app.py