언어 작업 평가 지표: Perplexity와 BLEU

Python으로 배우는 LLM 입문

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

LLM 작업과 지표

 

언어 작업용 평가 지표

Python으로 배우는 LLM 입문

Perplexity

  • 다음 단어를 정확하고 확신 있게 예측하는 능력
  • Perplexity↓ = 자신감↑
input_text = "Latest research findings in Antarctica show"

generated_text = "Latest research findings in Antarctica show that the ice sheet 
is melting faster than previously thought."


# Encode the prompt, generate text and decode it input_text_ids = tokenizer.encode(input_text, return_tensors="pt") output = model.generate(input_text_ids, max_length=20) generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
Python으로 배우는 LLM 입문

Perplexity 결과

perplexity = evaluate.load("perplexity", module_type="metric")
results = perplexity.compute(predictions=generated_text, model_id="gpt2")

print(results)
{'perplexities': [245.63299560546875, 520.3106079101562, ....], 
 'mean_perplexity': 2867.7229790460497}
print(results["mean_perplexity"])
2867.7229790460497
  • 기준선과 비교
Python으로 배우는 LLM 입문

BLEU

  • 인간 참조 대비 번역 품질 측정

  • Predictions: LLM 출력

  • References: 인간 참조
bleu = evaluate.load("bleu")


input_text = "Latest research findings in Antarctica show" references = [["Latest research findings in Antarctica show significant ice loss due to climate change.", "Latest research findings in Antarctica show that the ice sheet is melting faster than previously thought."]] generated_text = "Latest research findings in Antarctica show that the ice sheet is melting faster than previously thought."
Python으로 배우는 LLM 입문

BLEU 결과

results = bleu.compute(predictions=[generated_text], references=references)
print(results)
{'bleu': 1.0, 
 'precisions': [1.0, 1.0, 1.0, 1.0], 
 'brevity_penalty': 1.0, 
 'length_ratio': 1.2142857142857142, 
 'translation_length': 17, 
 'reference_length': 14}
  • 0~1 점수: 1에 가까울수록 유사도 높음
Python으로 배우는 LLM 입문

연습해 봅시다!

Python으로 배우는 LLM 입문

Preparing Video For Download...