다음과 같은 코드를 정말 많이 사용하게 된다.
from transformers import (
AutoConfig,
AutoModelForQuestionAnswering,
AutoTokenizer)
model_name = "원하는 모델"
config = AutoConfig.from_pretrained(
model_name
)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
use_fast=True
)
model = AutoModelForQuestionAnswering.from_pretrained(
model_name,
config=config
)
그래...
그런데 다 좋은데 그래서 config 이거 왜 넣는데?
AutoModelForQuestionAnswering에서 불러오면서 다 된거 아니야? 라고 생각할 수 있다.
config를 명시적으로 집어넣어주면 사실 이하와 같은 코드로 커스터마이징된 config를 집어넣을 수도 있다는 점에서 다르다 !
from transformers import AutoConfig
# 기본 설정을 불러옴
config = AutoConfig.from_pretrained(model_name)
# 커스터마이징: 히든 레이어 크기와 드롭아웃 비율을 변경
config.hidden_size = 768
config.num_attention_heads = 12
config.hidden_dropout_prob = 0.2
# 모델을 로드할 때 커스터마이징된 config를 사용
model = AutoModelForQuestionAnswering.from_pretrained(
model_name,
config=config
)
print(config)
마냥 똑같은 모델을 불러오는 것이 아니라
config를 조금 수정해서 불러올 수도 있다는 사실 !
매우 간편히 모델구조를 건들 수 있다!