AutoTokenizer로 텍스트 전처리하기
농업 현장에서 발생하는 문제를 농부들이 직접 질문할 수 있는 정밀 농업 애플리케이션을 만들고 있습니다. 농부들이 현장에서 자주 겪는 문제에 대한 질문과 답변 데이터셋을 활용할 예정이며, 이 데이터셋의 필드 구성은 다음과 같습니다.
question: 일반적인 농업 관련 질문answers: 농업 관련 질문에 대한 답변
분산 학습의 첫 번째 단계로, 이 텍스트 데이터셋을 전처리하는 작업을 시작합니다.
다음 데이터가 미리 로드되어 있습니다.
dataset: 농업 관련 질문과 답변 샘플 데이터셋AutoTokenizer:transformers에서 임포트됨
이 연습은 강의의 일부입니다
PyTorch로 AI 모델 효율적으로 학습시키기
연습 안내
- 사전 학습된
tokenizer를 불러오세요. tokenizer를 사용하여example["question"]을 토큰화하세요.dataset에encode()함수를 적용하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Load a pre-trained tokenizer
tokenizer = ____.____("distilbert-base-uncased")
def encode(example):
# Tokenize the "question" field of the training example
return ____(____["____"], padding="max_length", truncation=True, return_tensors="pt")
# Map the function to the dataset
dataset = ____.____(____, batched=True)
dataset = dataset.map(lambda example: {"labels": example["answers"]}, batched=True)
print(dataset)