Q&A 파이프라인 구축하기
이전 연습 문제에서는 PyPDF로 여러 페이지 문서에서 텍스트를 추출하고, 하나의 문자열로 정리했어요.
이제 Hugging Face를 사용해 문서에서 특정 답을 찾는 질의응답(question-answering) 파이프라인을 만들어 보겠습니다.
pipeline 모듈과 document_text는 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Hugging Face 활용하기
연습 안내
- 올바른 작업과 모델로 질의응답 파이프라인을 초기화하세요.
- 질문과
document_text를 파이프라인에 전달하세요. - 결과를 출력해 답을 확인하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Load the question-answering pipeline
qa_pipeline = pipeline(task="____", model="distilbert-base-cased-distilled-squad")
question = "What is the notice period for resignation?"
# Get the answer from the QA pipeline
result = qa_pipeline(question=____, context=____)
# Print the answer
print(f"Answer: {result['____']}")