A search engine may find a relevant document yet still struggle to answer the user’s question or recognize that two passages mean the same thing. Fine-tuning adapts a pretrained model to such a specific task by training it on fit-for-purpose data. The starting model already has general language capabilities, so this is a smaller training process than building the original model. section 1.3.4 section 13.4.2
The training data determines what the model learns to do. For semantic search, labeled pairs of similar and dissimilar passages can teach text similarity, improving the embeddings used for nearest-neighbor search. SBERT is an example of a model already tuned for that task. For extractive question answering, the target is different: given a question and a document passage, identify the passage’s likely answer span. section 13.4.2 section 14.0
A practical question-answering workflow is:
- Start with question-and-answer content suited to the domain. Generate a provisional, machine-labeled silver set, then correct it into a trustworthy golden set; label quality and breadth limit the resulting model. section 14.2
- Split the labeled data for training, testing, and validation. Fine-tune an existing question-answering model, such as deepset/roberta-base-squad2, rather than training a language model from scratch. section 14.2 section 14.3
- Load the saved model into a question-answering pipeline. Pass it question/context pairs, check answers against held-out labels, then pair this reader with a search retriever that supplies candidate passages. section 14.4
From search result to short answer
For an outdoors query about removing pine sap from teeth, a passage provides the answer “Take a small amount of margarine and rub on the sap.” A fine-tuned reader extracts that span from the supplied context. On a ten-example holdout set, the reader returned seven answers matching their labels; that check precedes connecting it to the retriever. section 14.4
Listing 14.13 Loading the fine-tuned outdoors question-answering model
device = get_processor_device()
model_name = "data/question-answering/roberta-base-squad2-fine-tuned"
nlp2 = pipeline("question-answering", model=model_name,
tokenizer=model_name, device=device)
The Python listing loads a saved fine-tuned model and tokenizer with the transformers question-answering pipeline, ready to receive retrieved contexts. section 14.4
Fine-tuning changes the model through training; prompting supplies context when the model is used. Depending on the approach, training may update all model weights or retain them and add layers. GPU access can make the training run substantially more practical than a CPU. Neither adaptation nor a successful holdout check makes answers automatically reliable: models can confuse facts, and search-provided context remains important for factual questions. section 15.1.2 section 14.3 section 1.1




































