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

WordEmbeddings: Token Axis2D

Where does a word land on a 2D map?

By jtrue·Created about a year ago·Updated about a year ago· 1
WordEmbeddings: Token Axis2D
  • we_model
  • x
  • y
  • summary
  • x_cos_left
  • x_cos_right
  • y_cos_left
  • y_cos_right
tokenking
axis1man,boy,he,him,his,father,brother,husband|woman,girl,she,her,hers,mother,sister,wife
axis2royal,king,kingly,noble|common,commoner,peasant,ordinary
token_can_be_phrasetrue
lowercasetrue
neutral_eps0.08
equal_eps0.020
strong_proj0.35
strong_cos0.65
strong_gap0.30

Same trick as Token Axis, twice. You give it a token and two left|right axes, and it returns two projections - x for axis 1, y for axis 2 - so you can place a word on a two-dimensional semantic map. Gender on one axis, royalty on the other, and suddenly you can plot where a whole batch of words fall in that little grid. It's the node to reach for when one axis isn't enough to separate the words you care about.

The defaults show the idea immediately: axis 1 is gender (man...husband | woman...wife), axis 2 is royalty (royal,king,kingly,noble | common,commoner,peasant,ordinary). Run queen through it and you get a strongly female x, a strongly royal y, and a summary that says both. That's the whole pitch.

How it works

Each axis is processed exactly like the 1D node - pole means, axis direction, projection, per-pole cosines - and the two results are computed independently. The math doesn't know the other axis exists; the axes don't need to be orthogonal or anything fancy, which is worth remembering if you ever stack two axes that turn out to be measuring nearly the same thing.

The inputs are the 1D node's, doubled: we_model (required), token, axis1, axis2, plus the shared token_can_be_phrase, lowercase, neutral_eps, and equal_eps knobs.

The three new ones gate the summary and are the closest thing this node has to a tunable personality:

  • strong_proj (default 0.35) - minimum |x|/|y| before an axis counts as "strong."
  • strong_cos (default 0.65) - minimum pole cosine for strength.
  • strong_gap (default 0.30) - minimum gap between the two pole cosines.

An axis must clear those bars to appear in the summary sentence; weak axes get left out, and if neither qualifies you get shows no strong alignment on the provided axes. That's a feature - it keeps the summary honest instead of blurting out "mildly male-ish, maybe slightly warm."

Outputs: x, y, summary, and the four cosines x_cos_left, x_cos_right, y_cos_left, y_cos_right - plenty of floats to wire into comparisons, scatter-plot logic, or whatever numeric gadget your workflow has lying around.

Where it fits

The 2D version is where this pack starts becoming an actual analysis tool rather than a toy. Two axes let you classify tokens - is prince on the "royal" side of axis 2 while still solidly male on axis 1? Yes. Where does duchess land? Now you're doing real semantic cartography. If you're building a workflow that scores prompt terms before they reach the sampler, this node is a natural source for those scores.

Reality check, same as its siblings: the map is drawn in the word embedding's space, not your text encoder's, and the biases baked into the training corpus show up loud and clear on these grids. And since the axes aren't orthogonalized, pick poles that are actually distinct or the summary will tell you everything leans one way. Install is the pack standard - Manager search "ComfyUI-WordEmbeddings," or git clone https://github.com/jtrue/ComfyUI-WordEmbeddings into custom_nodes, pip install gensim numpy, restart.

CategoryWordEmbeddings

Inputs (11)

NameTypeDefaultDescription
we_modelWE_MODEL
tokenoptSTRINGking
axis1optSTRINGman,boy,he,him,his,father,brother,husband|woman,girl,she,her,hers,mother,sister,wife
axis2optSTRINGroyal,king,kingly,noble|common,commoner,peasant,ordinary
token_can_be_phraseoptBOOLEANtrue
lowercaseoptBOOLEANtrue
neutral_epsoptFLOAT0.080–0.5
equal_epsoptFLOAT0.0200–0.2
strong_projoptFLOAT0.350–1
strong_cosoptFLOAT0.650–1
strong_gapoptFLOAT0.300–1

Outputs (7)

NameTypeDescription
xFLOAT
yFLOAT
summarySTRING
x_cos_leftFLOAT
x_cos_rightFLOAT
y_cos_leftFLOAT
y_cos_rightFLOAT