Views
No views yet
1Input Text: 야이 미친놈아 꺼져
2Generated Text: 이런, 제발 그만 좀 해줘.1training_args = TrainingArguments(
2)
3• GPU: NVIDIA RTX A5000
• 학습 시간: 약 3시간| Step | Training Loss | Validation Loss |
|---|---|---|
| 0 | 0. | 0.0 |
모델은 입력 문장의 앞에 반드시[순화]토큰을 붙여야 올바르게 작동합니다.
1import torch
2from transformers import BartForConditionalGeneration, PreTrainedTokenizerFast
3
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5
6model = BartForConditionalGeneration.from_pretrained("heloolkjdasklfjlasdf/slang-kobart").to(device)
7tokenizer = PreTrainedTokenizerFast.from_pretrained("heloolkjdasklfjlasdf/slang-kobart")
8
9model.eval()
10
11def refine_text(text):
12 input_text = "[순화] " + text
13 input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
14
15 with torch.no_grad():
16 output = model.generate(
17 input_ids=input_ids,
18 max_length=128,
19 num_beams=5,
20 early_stopping=True
21 )
22
23 return tokenizer.decode(output[0], skip_special_tokens=True)
24
25# ✅ 테스트 예시
26print("🧨 원문:", "야이 미친놈아 꺼져")
27print("✅ 순화:", refine_text("야이 미친놈아 꺼져"))
28