Nodes/ComfyUI-WordEmbeddings/WordEmbeddings: Token Neighbors
ComfyUI Node

WordEmbeddings: Token Neighbors

Neighbors, but with the scores on a separate wire

By jtrue·Created about a year ago·Updated about a year ago· 1
WordEmbeddings: Token Neighbors
  • we_model
  • words_csv
  • cosines_csv
wordking
k10

If you already looked at WordEmbeddings: Explorer, this is its sibling with one deliberate difference: the neighbor words and their similarity scores come out on two separate wires instead of one combined string. Explorer gives you words_csv and a debug_csv that mixes words and scores together (queen:0.769,...). Token Neighbors gives you a clean words_csv and a parallel cosines_csv of just the numbers, one per word, in the same order.

That split matters exactly when you want to do something with the scores instead of just eyeballing them. If your workflow needs to take the top neighbor, compare similarity values, or feed cosine scores into a numeric node, having cosines_csv as a pure, index-aligned list of floats saves you a parsing step - and a hand-rolled parser is where this kind of string data usually dies. Pair words_csv and cosines_csv with a splitter and you can zip words back to their scores programmatically.

The mechanics

Nothing new under the hood - same most_similar call as Explorer, same case-insensitive lookup, same cosine similarity metric that runs through the whole pack. Inputs are the same three fields: we_model (required, from a Loader), word (default king), and k (1–100, default 10 - Explorer tops out at 50, so this one can reach a bit deeper). Outputs are words_csv (STRING) and cosines_csv (STRING).

One behavioral quirk inherited from Explorer: if the word isn't in the model's vocabulary, both outputs come back empty strings - no Not in vocab message in the debug this time, because there's no debug output to put it in. Empty strings everywhere is your clue.

Should you use this or Explorer?

Honestly? If you're just reading the results to learn what a word means to the model, Explorer's combined debug_csv is more convenient - the scores are right there next to the words. Reach for Token Neighbors when the scores are inputs to something else: comparisons, sorting, thresholds, driving a numeric parameter in your graph. That's the whole reason it exists, and it's the right node for it.

Same shared caveats as the family: neighbors are only as good as the model you loaded (the 50-dim default is coarse; word2vec-google-news-300 gives richer results and a ~1.6 GB first download), and the similarity scores describe the word embedding's space, not your text encoder's. Install is the pack standard either way: ComfyUI Manager → search "ComfyUI-WordEmbeddings," or git clone https://github.com/jtrue/ComfyUI-WordEmbeddings into custom_nodes, pip install gensim numpy, then restart ComfyUI.

CategoryWordEmbeddings

Inputs (3)

NameTypeDefaultDescription
we_modelWE_MODEL
wordoptSTRINGking
koptINT101–100

Outputs (2)

NameTypeDescription
words_csvSTRING
cosines_csvSTRING