Eseguire una pipeline di QA
Estrarre risposte da un passaggio
Eseguire una pipeline di QA è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
What a Pipeline Gives You
A Hugging Face pipeline wraps a model and tokenizer into one easy call. You hand it a question and context, it hands back an answer. 🚀
Import the Helper
Everything starts with one import. The pipeline function from the transformers library builds the whole QA stack for you.
from transformers import pipelineCreate a QA Pipeline
Pass the task name question-answering to pipeline. With no model named, it downloads a sensible default for you.
qa = pipeline("question-answering")Give It a Context
The pipeline needs a context: the passage that contains the answer. Think of it as the text the model is allowed to read.
context = "The Eiffel Tower is located in Paris and was completed in 1889."Ask Your Question
Now call the pipeline with both a question and the context. It scans the passage and returns the best matching span.
result = qa(question="Where is the Eiffel Tower?", context=context)Read the Result
The result is a dictionary. The answer text lives under the answer key, ready to print or store.
print(result["answer"]) # ParisThe Confidence Score
Each result also carries a score between 0 and 1. Higher means the model is more sure about its chosen span.
print(result["score"]) # e.g. 0.98Start and End Positions
The result includes start and end character indexes. They tell you exactly where in the context the answer was found.
print(result["start"], result["end"])Choosing a Model
You can pin a specific model by name. A popular small QA model is distilbert fine-tuned on the SQuAD dataset.
qa = pipeline("question-answering",
model="distilbert-base-cased-distilled-squad")Reuse the Same Context
One context can answer many questions. Build the pipeline once, then call it repeatedly with new questions on the same passage.
It Only Reads the Context
Remember: this extractive pipeline answers only from the context you give. Ask about something not in the text and you get a poor span.
Quick Check
Recall how the QA pipeline returns its result.
Recap
One pipeline call takes a question plus context and returns a dict with answer, score, start, and end. You ran extractive QA in three lines. ✅
Domande Frequenti
La lezione «Eseguire una pipeline di QA» è gratuita?
Sì — il testo completo di «Eseguire una pipeline di QA» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.
Cosa imparerò in «Eseguire una pipeline di QA»?
Estrarre risposte da un passaggio Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare NLP Academy?
Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.
Quanto tempo richiede la lezione «Eseguire una pipeline di QA»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione NLP Academy?
Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- QA estrattivo e generativo
- Eseguire una pipeline di QA
- Trovare gli span di risposta nel contesto
- Gestire risposte assenti e documenti lunghi