ComfyUI Node

πŸ“œ LDM BERT Text Encode

Your prompt goes through BERT here, not CLIP β€” write sentences, not tag soup

By WinlenskyΒ·Created 22 days agoΒ·Updated 16 days agoΒ· 1
πŸ“œ LDM BERT Text Encode
  • bert
  • CONDITIONING
β—„textβ–Ί

The first thing that will throw you off when you migrate from Stable Diffusion workflows: the text encoder in this pack is not CLIP. It's a BERT - a real, 64-layer transformer with 1280-dim hidden states and 8 attention heads, the exact text encoder the original CompVis LDM F8 Large shipped with in 2021. Stable Diffusion later swapped this out for CLIP, and the whole prompting culture you learned - tags, BREAK, weight syntax - was built for that replacement. Here, you're back on the original, and it wants plain sentences.

This node is the equivalent of CLIP Text Encode in a normal workflow: it takes your words and produces a CONDITIONING tensor the sampler can cross-attend over. You'll find it hanging right off the 🏰 Load LDM Checkpoint node, using the BERT output.

How it works

Your text is tokenized with HuggingFace's bert-base-uncased tokenizer, padded or truncated to 77 tokens, then run through the 64-layer BERT stack. The final hidden state is what gets fed to the UNet's cross-attention layers. Two practical consequences:

  1. The tokenizer is uncased, so lowercase is fine - don't bother with capitalization.
  2. The tokenizer downloads from HuggingFace on first use. It's only the tokenizer (a vocab file, not the 400 MB model), so the download is tiny - but it does need internet once. On an offline box, run a warm-up encode while you still have a connection, or the node looks like it's hanging forever.

The inputs and output

Two required inputs, both obvious: bert (the BERT output from Load LDM Checkpoint) and text - a multiline box holding your prompt. One output, CONDITIONING, which goes into the sampler's positive socket. That's the whole node.

How to prompt it

The model was trained without classifier-free guidance, so there's no negative prompt anywhere in this pack - the positive input on the sampler is your only conditioning. Within that constraint, the author's guidance is genuinely good advice for a BERT encoder:

  • Keep it short and concrete. "a red car" or "mountain landscape" - single-subject descriptions beat lists.
  • Say it in a sentence. BERT has limited compositional understanding, so "a red car in front of a mountain" works better than a comma-separated tag dump.
  • Skip complex syntax, negations, and long narratives. BERT does poorly with "no", "not", and multi-clause sentences - it tends to take negation literally or ignore it.
  • 77 tokens max. Anything past that gets truncated. It's a lot of room if you write economically, and not enough if you pad with adjectives.

What not to do

Don't reuse your SD habits. (masterpiece:1.2), ((best quality)), BREAK - none of that means anything to this encoder; BERT tokenizes the parentheses and colons as literal characters, so weight syntax becomes noise in your prompt. Don't try to wire this into a stock KSampler either - the LDM_CONDITIONING type is custom to this pack, and it only connects to this pack's own sampler.

Installing and common issues

Same install as the rest of the pack - ComfyUI Manager (search comfyui_compvis_ldm) or:

cd ComfyUI/custom_nodes
git clone https://github.com/Winlensky/comfyui_compvis_ldm

then restart ComfyUI. You also need a checkpoint loaded into ComfyUI/models/ldm (see the loader node's page) - this node does nothing without a BERT to run through.

The classic "issue" is disappointment: you write a glorious, detailed paragraph and get a vague image. That's not a bug. This is the 2021 state of the art - loose prompt-image alignment is what classifier-free guidance was invented to fix, and it isn't here. Concrete, short, single-subject prompts are the workaround, and they genuinely help.

CategoryLDM

Inputs (2)

NameTypeDefaultDescription
bertLDM_BERTBERT output from the Load LDM Checkpoint node.
textSTRINGText prompt. BERT tokenizer, 77 tokens max. Use for positive or negative conditioning.

Outputs (1)

NameTypeDescription
CONDITIONINGLDM_CONDITIONINGβ€”