
# 데이터셋 불러오기
from datasets import load_dataset
dataset = load_dataset("e9t/nsmc", trust_remote_code=True)
# 슬라이싱
train_dataset = dataset['train'][:1000]
test_dataset = dataset['test'][:100]
>-------이 부분에서 에러------<
target_BT_set = train_dataset.select(range(0,100))
>-------이 부분에서 에러------<
에러 메세지를 보니 이하와 같다...
----> 2 target_BT_set = train_dataset.select(range(0,100))
3
4 target_BT_id = target_BT_set['id']
5 target_BT_docs = target_BT_set['document']
AttributeError: 'dict' object has no attribute 'select'
아아... dict 오브젝트는 select가 없다고... 그렇지 dict는 없지.. 그런데 너는 내가 datasets로 받아왔는데... 어쩌다 dict이 됐니..?
바로 아래 코드가 문제이다
train_dataset = dataset['train'][:1000]
test_dataset = dataset['test'][:100]
위 코드를 보면 dataset 객체에 대하여 슬라이싱을 진행하는데
이렇게 하게 되면 dataset 객체가 Dataset 형식이 아니라 리스트로 저장되게 된다...
따라서 위 문제를 해결하려면 애당초 Dataset에서 잘 만들어 놓은 select 메서드를 활용하면 된다.
train_dataset = dataset['train'].select(range(1000))
이렇게 바꾸고
target_BT_set = train_dataset.select(range(0,100))
위와 같이 실행하니
정상작동 !