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

# 평가 소개

> W&B Weave에서 평가를 시작하는 방법을 알아보세요

<Note>
  이 문서는 대화형 노트북입니다. 로컬에서 실행하거나 다음 링크를 사용할 수 있습니다.

  * [Google Colab에서 열기](https://colab.research.google.com/github/wandb/docs/blob/main/weave/cookbooks/source/Intro_to_Weave_Hello_Eval.ipynb)
  * [GitHub에서 소스 보기](https://github.com/wandb/docs/blob/main/weave/cookbooks/source/Intro_to_Weave_Hello_Eval.ipynb)
</Note>

이 노트북은 최소한의 엔드투엔드 예시를 통해 W\&B Weave 평가를 소개합니다. Weave `Model`을 정의하고 작은 데이터셋으로 실행한 다음, 맞춤형 점수화 함수로 출력을 채점하고 Weave에서 결과를 검토합니다. Weave를 처음 사용하는 개발자가 고급 평가 워크플로를 살펴보기 전에 빠르게 직접 실습해 볼 수 있는 출발점입니다.

<h2 id="prerequisites">
  사전 요구 사항
</h2>

Weave 평가를 실행하려면 먼저 다음 사전 요구 사항을 완료하세요.

1. W\&B Weave SDK를 설치하고 [API 키](https://forge.coreweave.com/settings#apikeys)로 로그인하세요.
2. OpenAI SDK를 설치하고 [API 키](https://platform.openai.com/api-keys)로 로그인하세요.
3. Weights & Biases 프로젝트를 초기화하세요.

```python lines theme={"system"}
# 의존성 설치 및 임포트
!pip install wandb weave openai -q

import os
from getpass import getpass

from openai import OpenAI
from pydantic import BaseModel

import weave

# 🔑 API 키 설정
# 이 셀을 실행하면 `getpass`로 API 키를 입력하라는 메시지가 표시되며 터미널에 표시되지 않습니다.
#####
print("---")
print(
    "Create a W&B API key at: https://forge.coreweave.com/settings#apikeys"
)
os.environ["WANDB_API_KEY"] = getpass("Enter your W&B API key: ")
print("---")
print("You can generate your OpenAI API key here: https://platform.openai.com/api-keys")
os.environ["OPENAI_API_KEY"] = getpass("Enter your OpenAI API key: ")
print("---")
#####

# 🏠 W&B 프로젝트 이름 입력
weave_client = weave.init("MY_PROJECT_NAME")  # 🐝 W&B 프로젝트 이름
```

<h2 id="run-your-first-evaluation">
  첫 평가 실행하기
</h2>

환경을 설정한 후, 평가를 정의하고 실행할 준비가 되었습니다.

다음 코드 샘플은 Weave의 `Model` 및 `Evaluation` API를 사용하여 LLM을 평가하는 방법을 보여줍니다. 먼저 `weave.Model`을 서브클래싱하여 Weave 모델을 정의하고, 모델 이름과 프롬프트 형식을 지정한 다음 `@weave.op`로 `predict` 메서드를 추적합니다. `predict` 메서드는 OpenAI에 프롬프트를 보내고 Pydantic 스키마(`FruitExtract`)를 사용하여 응답을 구조화된 출력으로 파싱합니다. 그런 다음 입력 문장과 예상 대상으로 구성된 작은 평가 데이터셋을 만듭니다. 다음으로 모델의 출력을 대상 레이블과 비교하는 맞춤형 점수화 함수(마찬가지로 `@weave.op`를 사용하여 추적됨)를 정의합니다. 마지막으로 데이터셋과 Scorer를 지정하여 `weave.Evaluation`으로 모든 것을 래핑하고 `evaluate()`를 호출하여 평가 파이프라인을 비동기적으로 실행합니다.

```python lines theme={"system"}
# 1. Weave 모델 구성
class FruitExtract(BaseModel):
    fruit: str
    color: str
    flavor: str

class ExtractFruitsModel(weave.Model):
    model_name: str
    prompt_template: str

    @weave.op()
    def predict(self, sentence: str) -> dict:
        client = OpenAI()

        response = client.beta.chat.completions.parse(
            model=self.model_name,
            messages=[
                {
                    "role": "user",
                    "content": self.prompt_template.format(sentence=sentence),
                }
            ],
            response_format=FruitExtract,
        )
        result = response.choices[0].message.parsed
        return result

model = ExtractFruitsModel(
    name="gpt4o",
    model_name="gpt-4o",
    prompt_template='Extract fields ("fruit": <str>, "color": <str>, "flavor": <str>) as json, from the following text : {sentence}',
)

# 2. 샘플 수집
sentences = [
    "There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy.",
    "Pounits are a bright green color and are more savory than sweet.",
    "Finally, there are fruits called glowls, which have a very sour and bitter taste which is acidic and caustic, and a pale orange tinge to them.",
]
labels = [
    {"fruit": "neoskizzles", "color": "purple", "flavor": "candy"},
    {"fruit": "pounits", "color": "green", "flavor": "savory"},
    {"fruit": "glowls", "color": "orange", "flavor": "sour, bitter"},
]
examples = [
    {"id": "0", "sentence": sentences[0], "target": labels[0]},
    {"id": "1", "sentence": sentences[1], "target": labels[1]},
    {"id": "2", "sentence": sentences[2], "target": labels[2]},
]

# 3. 평가를 위한 점수화 함수 정의
@weave.op()
def fruit_name_score(target: dict, output: FruitExtract) -> dict:
    target_flavors = [f.strip().lower() for f in target["flavor"].split(",")]
    output_flavors = [f.strip().lower() for f in output.flavor.split(",")]
    # target flavor가 output flavors에 있는지 확인
    matches = any(tf in of for tf in target_flavors for of in output_flavors)
    return {"correct": matches}

# 4. 평가 실행
evaluation = weave.Evaluation(
    name="fruit_eval",
    dataset=examples,
    scorers=[fruit_name_score],
)
await evaluation.evaluate(model)
```

평가가 종료되면 Weave는 모델, 데이터셋, 예제별 점수를 프로젝트에 로깅하므로 Weights & Biases UI에서 결과를 확인할 수 있습니다.

<h2 id="looking-for-more-examples">
  더 많은 예시 찾기
</h2>

기본 평가를 실행한 후, 다음 튜토리얼에서 더 고급 워크플로를 살펴볼 수 있습니다:

* [엔드투엔드 평가 파이프라인을 구축하는 방법](/ko/products/wandb/weave/tutorial-eval)을 알아보세요.
* [RAG application을 평가하는 방법](/ko/products/wandb/weave/tutorial-rag)을 알아보세요.
