더보기
53일 차 회고.
어제 빅데이터분석기사 이틀 치 공부를 하려고 했는데 오답노트를 작성할 때 수식이 많아서 하루치밖에 하지 못했다. 오늘은 저녁에 약속이 있어서 최대한 학원에서 공부를 끝내려고 했다. LLM 프로젝트를 수업시간에 진행하고 있는데 나 혼자 코드를 짜보라고 하면 힘들 것 같아서 주말 동안 이에 대해 공부를 해봐야 할 것 같다.
1. Transformer
1-1. Trainer
Fine Tuning
- Load Dataset
from datasets import load_dataset
raw_datasets = load_dataset('glue', 'mrpc')
"""
DatasetDict({
train: Dataset({
features: ['sentence1', 'sentence2', 'label', 'idx'],
num_rows: 3668
})
validation: Dataset({
features: ['sentence1', 'sentence2', 'label', 'idx'],
num_rows: 408
})
test: Dataset({
features: ['sentence1', 'sentence2', 'label', 'idx'],
num_rows: 1725
})
})
"""
raw_train_dataset = raw_datasets['train']
raw_train_dataset[0]
"""
{'sentence1': 'Amrozi accused his brother , whom he called " the witness " , of deliberately distorting his evidence .',
'sentence2': 'Referring to him as only " the witness " , Amrozi accused his brother of deliberately distorting his evidence .',
'label': 1,
'idx': 0}
"""
raw_train_dataset.features
"""
{'sentence1': Value(dtype='string', id=None),
'sentence2': Value(dtype='string', id=None),
'label': ClassLabel(names=['not_equivalent', 'equivalent'], id=None),
'idx': Value(dtype='int32', id=None)}
"""
- Model
from transformers import AutoModelForSequenceClassification, AutoTokenizer
checkpoint = 'bert-base-uncased'
model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
- Dataset Preprocessing
# Tokenization
# 1st Method
tokenized_dataset = tokenizer(
text=raw_datasets['train']['sentence1'],
text_pair=raw_datasets['train']['sentence2'],
padding=True,
truncation=True
)
# 2nd Method
def tokenize_function(example):
return tokenizer(example['sentence1'], example['sentence2'], truncation=True)
tokenized_dataset = raw_datasets.map(tokenize_function, batched=True)
# Data Collator
from transformers import DataCollatorWithPadding
tokenizer.add_special_tokens({'pad_token':'[PAD]'})
model.config.pad_token_id = tokenizer.pad_token
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
- Training Arguments
from transformers import TrainingArguments
training_args = TrainingArguments('test-trainer')
- Trainer
from transformers import Trainer
trainer = Trainer(
model=model,
args=training_args,
data_collator=data_collator,
train_dataset=tokenized_datasets['train'],
eval_dataset=tokenized_datasets['validation'],
tokenizer=tokenizer
)
- Fine Tuning
- Weights & Biases(wandb)의 API key를 입력한다.
trainer.train()

- Evaluation
import numpy as np
import evaluate
predictions = trainer.predict(tokenized_datasets['validation'])
preds = np.argmax(predictions.predictions, axis=-1)
metric = evaluate.load('accuracy')
metric.compute(predictions=preds, references=predictions.label_ids)
2. LLM 프로젝트
2-1. 파일 구조
파일 구조를 바꿨기 때문에 가상환경(web/.venv)을 삭제하고 다시 생성하였다.
LLM_PROJECT
├─ etl
│ └─ README.md
├─ training
│ └─ README.md
├─ web
│ ├─ .venv
│ ├─ common
│ │ ├─ database
│ │ ├─ display
│ │ │ ├─ constant.py
│ │ │ ├─ history.py
│ │ │ ├─ input.py
│ │ │ ├─ output.py
│ │ │ └─ utils.py
│ │ └─ model
│ │ ├─ groq.py
│ │ ├─ ollama.py
│ │ ├─ openai.py
│ │ ├─ provider_class.py
│ │ └─ provider.py
│ ├─ .env
│ ├─ chatbot.py
│ ├─ requirements.txt
│ └─ test.ipynb
├─ .gitignore
└─ README.md
2-2. 개발 과정
객체지향 프로그래밍
- web/common/model/groq.py
- web/common/model/ollama.py
- web/common/model/openai.py
- web/common/model/provider.py
'SK네트웍스 Family AI캠프 10기 > Daily 회고' 카테고리의 다른 글
| 55일차. Fine Tuning - DeepSpeed & Accelerate & LLM 프로젝트 (0) | 2025.03.31 |
|---|---|
| 54일차. Hugging Face - SFT Trainer & LLM 프로젝트 (0) | 2025.03.28 |
| 52일차. Hugging Face - Transformer Model & Pipeline & LLM - LLM 프로젝트 (0) | 2025.03.26 |
| 51일차. LLM - LLaMA & Claude & SciSpace & LLM 프로젝트 (0) | 2025.03.25 |
| 50일차. LLM - LLM 프로젝트(Chatbot) (0) | 2025.03.24 |