Nodes/ComfyUI_HF_Inference/HF Text Question Answering
ComfyUI Node

HF Text Question Answering

Ask your workflow a question, get the exact answer span back

By bitaffinity·Created 2 years ago·Updated 2 years ago· 5
HF Text Question Answering
    • STRING
    endpoint
    question
    context

    Extractive question answering is the "find the answer inside this block of text" task, and that's exactly what HF Text Question Answering does: you give it a passage and a question, it hands back the exact span from the passage that answers it. It's a node from the bitaffinity/ComfyUI_HF_Inference pack, which means the actual model runs remotely on Hugging Face's servers - you just supply the words.

    What it does

    Three inputs, all plain text:

    • endpoint (STRING) - the model ID, like deepset/roberta-base-squad2 (the README's pick), or a full URL.
    • question (STRING, multiline) - what you want to know.
    • context (STRING, multiline) - the passage to search.

    The node POSTs {"inputs": {"question": ..., "context": ...}} to https://api-inference.huggingface.co/models/{endpoint}, and the server returns the answer plus a confidence score. The node hands you the answer through its STRING socket, ready to wire into a text display node, a save node, or whatever downstream logic needs it.

    The key word is extractive. This model doesn't generate an answer - it picks the best matching span out of the context you gave it. Ask "what resolution was used?" and the answer is literally a substring of your context text. That means two practical consequences: the answer is always grounded in what you provided (no hallucinations of new facts), and if the answer genuinely isn't in the context, you'll get a confident-sounding but wrong span. Garbage in, a very polite garbage out.

    Where it fits

    The natural use is querying text that's already flowing through your workflow - a saved caption, a scene description, a metadata dump, a prompt you're testing. Instead of eyeballing a long block of text, ask the node a question and route the one-line answer where it needs to go. It's a small but real workflow nicety: QA on your own pipeline's output, without loading a single local model.

    The README's model choice, roberta-base-squad2, is a solid, long-standing SQuAD model - small, fast on HF's servers, and purpose-built for exactly this span-extraction job. If you want to try other extractive QA checkpoints, most any will slot into the same endpoint text box.

    Installing it

    Same routine as the rest of the pack, and about as light as ComfyUI custom nodes get - the only Python dependency is requests:

    git clone https://github.com/bitaffinity/ComfyUI_HF_Inference custom_nodes/ComfyUI_HF_Inference
    cd custom_nodes/ComfyUI_HF_Inference
    pip install -r requirements.txt
    

    Restart ComfyUI (or search "ComfyUI_HF_Inference" in ComfyUI Manager), then set a Hugging Face token in an environment variable - free tier is fine:

    HF_AUTH_TOKEN=hf_yourtokenhere python main.py
    

    The usual cloud caveats

    You're on Hugging Face's serverless tier, which the README warns supports models 10GB and under and "fails for random reasons on different models." Cold starts are the realistic annoyance: the first call to a model that's been unloaded can hang for a minute or two while HF boots a container. The pack reads the reported estimated_time, waits, and retries once, so it usually recovers without you touching anything. For a node this simple, that retry behavior is the difference between "annoying pause" and "broken workflow."

    CategoryHF_Inference/Text

    Inputs (3)

    NameTypeDefaultDescription
    endpointSTRING
    questionSTRING
    contextSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING