Language models, retrieval, prompting, and language adaptation · Long-context and retrieval-augmented language · LNG052 · Architecture
Fusion-in-Decoder (FiD)
Reads multiple retrieved passages separately with a shared encoder and fuses their representations in a decoder.
In CodeSplash
Documented in the Academy only. There's no Set up button.
- Availability
- Explained here
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's own run
- CodeSplash's run
- The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: The chapter's authors report running it; there is no record for this entry alone. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Reads multiple retrieved passages separately with a shared encoder and fuses their representations in a decoder. It separates per-passage encoding from answer generation so the decoder can combine evidence across many documents.
Question / objective
Can a decoder combine separately encoded evidence passages for one generated answer?
Architecture / computational structure
A shared encoder processes each query/passage pair; a decoder attends to their concatenated representations. Learned encoder/decoder weights are parameters; passage count and per-passage token budget are hyperparameters.
Assumptions
Decoder memory and cross-attention cost grow with total encoded tokens.
Formula / computational definition
For passages z_1:k, encode h_i=Enc([x;z_i]); concatenate h_1:k as decoder memory and optimize -log p_theta(y|h_1:k). Cross-passage interaction occurs through the decoder's attention to the combined encoded states.
Parameters and notation
Learned parameters: identified in the architecture subsection. Hyperparameters, design and inference choices: Passage count, per-passage length, encoder/decoder size, retriever quality, decoder evidence budget, and training batch size.
Fitting, fine-tuning, and adaptation
Fit question/answer pairs with retrieved passages and conditional cross-entropy. Freeze the retriever initially, optionally freeze encoder layers or use compatible adapters. Validate total evidence length, factual consistency, memory growth, and answer quality as passage count increases; retriever updates require reindexing.
How to use and calibrate
Plot answer accuracy against passage count, retrieval recall, memory, and latency; test multi-document questions and conflicting evidence. Use development data for settings and an independent test set for the final estimate. Report uncertainty across examples or seeds when the evaluation design supports it; model scores and self-assessments are not automatically calibrated probabilities of correctness.
Example application
Synthesize an answer whose supporting facts are spread across multiple documents.
Interpretation / pitfalls
Watch out
Separate encoding does not automatically resolve contradictions, ensure provenance, or prevent distractor evidence from dominating. The code below isolates one stated component; successful execution does not validate model quality or reproduce the cited experiment.
Python and R code examples
Full implementation route: Use the authors' FiD implementation or implement shared passage encoding with a compatible sequence-to-sequence decoder. R normally bridges Python through reticulate. The native example calculates concatenated memory dimensions, illustrating the scaling constraint rather than generating an answer.
Example scope: FiD decoder-memory length and dense cross-attention score count; excludes encoder/other memory.
Dependencies: Python 3 standard library; base R; shared setup above. No model downloads or external services.
Validation: Python component executed in the combined example script; R counterpart supplied but not runtime-tested here. All numbers are synthetic.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — FiD decoder-memory length and dense cross-attention score count; excludes encoder/other memory.
Shared setup for this chapter
import math
def softmax(xs):
m = max(xs)
es = [math.exp(x-m) for x in xs]
return [e/sum(es) for e in es]
def dot(a, b):
return sum(x*y for x, y in zip(a, b))
def matvec(matrix, vector):
return [dot(row, vector) for row in matrix]
def meanvec(rows):
return [sum(row[j] for row in rows)/len(rows) for j in range(len(rows[0]))]
def sigmoid(x):
return 1/(1+math.exp(-x))
def nll(probabilities):
return -sum(math.log(p) for p in probabilities)
passages, tokens_per_passage, output_tokens = 20, 128, 32
memory_tokens = passages*tokens_per_passage
print({"memory_tokens":memory_tokens,"scores_per_head":memory_tokens*output_tokens})
Component demo, not a trained model — FiD decoder-memory length and dense cross-attention score count; excludes encoder/other memory.
Shared setup for this chapter
softmax <- function(x) {
shifted <- exp(x-max(x))
shifted/sum(shifted)
}
passages <- 20L; tokens_per_passage <- 128L; output_tokens <- 32L
memory_tokens <- passages*tokens_per_passage
print(c(memory_tokens=memory_tokens,scores_per_head=memory_tokens*output_tokens))
Sources
- Source 1arxiv.org
From the CodeSplash reference, entry LNG052.