pytorch 3

Hugging Face / NLP Preprocess (전처리) 튜토리얼 (Pytorch)

Preprocess 모델에 데이터를 직접 사용하기 전 우리는 전처리가 필요합니다. 해당 데이터들은 numbers 혹은 tensor로 assembled된 형식 등 이어야 합니다. Tokenize pretrained tokenizer를 불러옵니다 from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("bert-base-cased") encoded_input = tokenizer("Do not meddle in the affairs of wizards, for they are subtle and quick to anger.") print(encoded_input) """output {'input_ids': [101, 2..

Hugging Face / AutoClass 로 pertained instance 불러오기 (Pytorch)

AutoClass AutoClass는 주어진 체크포인트(Check point)에서 올바른 아키텍처(Architecture)를 자동으로 추론하고 로드합니다. from_pretrained 메소드를 사용하면 모든 아키텍처에 대해 pretrained 모델을 신속하게 로드할 수 있으므로 처음부터 모델을 교육하는 데 시간과 리소스를 투자할 필요가 없습니다. * 아키텍처는 모델의 뼈대임을 의미하고, 체크포인트는 주어진 아키텍처에 해당하는 가중치입니다. AutoTokenizer from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") sequence = "In a hole in the groun..

Pytorch 모델 저장하기 & 불러오기

모델을 저장하고 불러올 때는 3가지의 핵심 함수가 있습니다. 1. torch.save() : 직렬화된 객체를 디스크에 저장합니다. 이 함수는 Python 의 pickle을 사용하여 직렬화하고 객체를 저장합니다. 2. torch.load() : 객체 파일을 역직렬화하여 메모리에 올립니다. 이 함수는 데이터를 장치에 불러올 때도 사용합니다. 3. torch.nn.Module.load_state_dict : 역직렬화된 state_dict를 사용하여 모델의 매개변수를 불러옵니다. state_dict 이름에서도 알 수 있듯이 해당 모델의 state(상태)를 dict(딕셔너리) 형태로 가지고 있는 객체입니다. 만약 예를 든다면 다음과 같이 나올 수 있습니다. Model's state_dict: conv1.weigh..