본문 바로가기

명사 美 비격식 (무리 중에서) 아주 뛰어난[눈에 띄는] 사람[것]

이론

파인튜닝(Fine-Tuning): 전이학습시 사전학습된 모델에 새로운 데이터를 추가해 목적에 맞게 다시 학습시키는 과정

 

 

파인튜닝(Fine-Tuning)

전이학습시  사전학습된 모델에 새로운 데이터를 추가해 목적에 맞게 다시 학습시키는 과정. 

일반적인 언어 지식을 의료 법률 금융 등 특정 산업의 전문지식으로 확장할 수 있다. 

https://standout.tistory.com/1813

 

모델이 학습이 덜됬거나 과하게 됬거나: Underfitting (언더피팅), Overfitting (오버피팅)과 해결방법 -

Underfitting (언더피팅)모델이 충분히 학습되지않은 상태,아직 덜 배운상태.모델이 너무 단순하거나 학습이 부족하거나 특징이 부족할 수있다. 학습이 부족해서 발생한 언더피팅 → 더 학습하면

standout.tistory.com

 

 

대규모로 학습시킨 BERT 모델을 영화감정분석 모델로 활용할 수 있다 .

https://standout.tistory.com/1865

 

BERT란? 구글이 2018년에 공개한 33억 단어에 대해 약 4일간 학습시킨 사전 훈련된 언어 모델

BERT 구글이 2018년에 공개한 사전 훈련된 언어 모델33억 단어에 대해 약 4일간 학습시킨 언어 모델위키피디아의 25억개 단어와 북코퍼스의 8억개 레이블이 없는 데이터를 이용하여 사전 훈련됨레

standout.tistory.com

 

 

 

 

1. 이미 학습된 BERT 가져오기

2. 내 데이터(영화 리뷰) 넣기

3. 감정분석 작업에 맞게 추가 학습

4. "긍정/부정 판단 모델"로 변형

 

 

imdb파일에 라벨이 들어가있다고 보자. 

"this movie is great" 1 (긍정)
"this movie is terrible" 0 (부정)

 

 

num_labels=2

모델은 결과를 2개 중 하나로 분류한다

from transformers import BertTokenizer, BertForSequenceClassification
from transformers import Trainer, TrainingArguments
from datasets import load_dataset

# 1. 데이터 로드 (IMDb 영화 리뷰)
dataset = load_dataset("imdb")

# 2. 토크나이저
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")

def preprocess(example):
    return tokenizer(example["text"], truncation=True, padding="max_length")

encoded_dataset = dataset.map(preprocess, batched=True)

# 3. 사전학습된 모델 불러오기
model = BertForSequenceClassification.from_pretrained(
    "bert-base-uncased",
    num_labels=2
)

# 4. 학습 설정
training_args = TrainingArguments(
    output_dir="./results",
    evaluation_strategy="epoch",
    learning_rate=2e-5,
    per_device_train_batch_size=8,
    num_train_epochs=1,
)

# 5. Trainer 설정
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=encoded_dataset["train"],
    eval_dataset=encoded_dataset["test"],
)

# 6. 파인튜닝 실행
trainer.train()