dspy.Prediction

dspy.Prediction

dspy.Prediction은 DSPy 모듈의 출력을 담는 예측 객체입니다. Example을 상속받아 동작합니다.

출처: 문서

본문

dspy.Prediction(*args, **kwargs)
  • Bases: Example(base=None, **kwargs)

DSPy 모듈의 출력을 담는 예측 객체입니다. Prediction은 Example을 상속받습니다.

피드백으로 보강된 점수(feedback-augmented scores)를 허용하기 위해, Prediction은 score 필드를 가진 Prediction에 대해 비교 연산(<, >, <=, >=)을 지원합니다. 비교 연산은 'score' 값을 float로 비교합니다. 동등 비교의 경우 기본 데이터 저장소가 같으면(Example에서 상속) 두 Prediction은 같습니다.

score 필드를 가진 Prediction에 대해 산술 연산(+, / 등)도 지원되며, score 값을 대상으로 동작합니다.

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

    del self._demos
    del self._input_keys

    self._completions = None
    self._lm_usage = None

소스 코드는 dspy/primitives/prediction.py에 있습니다.

Methods

copy(**kwargs)

얕은 복사를 반환하며, 선택적으로 필드를 재정의합니다.

Name Type Description Default
**kwargs 복사본에 추가하거나 재정의할 필드. {}
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.")
>>> ex.copy(answer="No reason.")
Example({'question': 'Why?', 'answer': 'No reason.'}) (input_keys=None)

from_completions(list_or_dict, signature=None)

completions(어댑터가 만든 완성 결과)에서 Prediction을 생성합니다.

get_lm_usage() / set_lm_usage(value)

이 예측과 연관된 LM 사용량(토큰 수 등)을 조회/설정합니다.

그 외 Example에서 상속받은 메서드

get(key, default=None), inputs(), items(include_dspy=False), keys(include_dspy=False), labels(), toDict(), values(include_dspy=False), with_inputs(*keys), without(*keys) 등은 Example에서 상속받은 공통 메서드입니다.

더 알아보기 (Learn more)