> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wandb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# W&B에서 NLP 메트릭과 텍스트 출력을 어떻게 기록하나요?

`wandb.log()`를 사용해 코퍼스 수준의 NLP 점수(BLEU, ROUGE, perplexity)를 기록하고, `wandb.Table`을 사용해 예시별 출력을 기록할 수 있습니다. 일반적인 로깅 패턴은 [객체 및 미디어 기록](/ko/models/track/log) 및 [테이블 기록](/ko/models/track/log/log-tables)을 참조하세요.

다음 예시는 loss를 기록할 때와 같은 방식으로 BLEU, ROUGE, perplexity 및 기타 스칼라 점수를 기록하는 방법을 보여줍니다.

```python lines theme={null}
import wandb
from sacrebleu.metrics import BLEU
from rouge_score import rouge_scorer

with wandb.init(project="nmt-project") as run:
    bleu = BLEU()
    scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeL"])

    for epoch in range(num_epochs):
        train(model)
        hypotheses, references = evaluate(model, val_set)

        bleu_score = bleu.corpus_score(hypotheses, [references])
        rouge_scores = [scorer.score(ref, hyp) for ref, hyp in zip(references, hypotheses)]

        run.log({
            "epoch": epoch,
            "val/bleu": bleu_score.score,
            "val/rouge1": sum(s["rouge1"].fmeasure for s in rouge_scores) / len(rouge_scores),
            "val/rougeL": sum(s["rougeL"].fmeasure for s in rouge_scores) / len(rouge_scores),
            "val/perplexity": compute_perplexity(model, val_loader),
        })
```

***

<Badge stroke shape="pill" color="orange" size="md">[Experiments](/ko/support/models/tags/experiments)</Badge><Badge stroke shape="pill" color="orange" size="md">[메트릭](/ko/support/models/tags/metrics)</Badge><Badge stroke shape="pill" color="orange" size="md">[Runs](/ko/support/models/tags/runs)</Badge>
