from cleanlab_studio import Studio
studio = Studio("<CLEANLAB_API_KEY>") # Get your API key from above
tlm = studio.TLM(options={"log": ["explanation"], "model": "gpt-4o"}) # GPT, Claude, etc
#set the prompt
out = tlm.prompt("How many vowels are there in the word 'Abracadabra'.?")
#the TLM response contains the actual output 'response', trustworthiness score and explanation
print(f"Model's response = {out['response']}")
print(f"Trustworthiness score = {out['trustworthiness_score']}")
print(f"Explanation = {out['log']['explanation']}")
를 기반으로 deepseek-r1-distill-70b 를 사용하고 DeepSeek의 더 큰 671 억 개의 매개 변수 혼합물에서 증류 할 것입니다 (MOE ) 모델. 지식 증류는 미리 훈련 된 대규모 모델의 학습을 "교사 모델"의 학습을 더 작은 "학생 모델"으로 이전하는 것을 목표로하는 기계 학습 기술입니다.
여기 deepseek-r1-distill-llama-70b
모델의 출력이 있습니다
Model's response = The word "Abracadabra" contains 6 vowels. The vowels are: A, a, a, a, a, and a.
Trustworthiness score = 0.6842228802750124
Explanation = This response is untrustworthy due to a lack of consistency in possible responses from the model. Here's one inconsistent alternate response that the model considered (which may not be accurate either):
5.
신뢰할 수있는 래그 개발
우리는 이제 헝겊에서 LLM 응답의 신뢰성을 측정 할 수있는 방법을 보여주기 위해 헝겊을 개발할 것입니다. 이 래그는 주어진 링크에서 데이터를 긁어 내고 Markdown 형식으로 구문 분석하고 벡터 스토어를 작성하여 개발됩니다.
다음 코드를 위해 다음 라이브러리를 설치해야합니다.
html을 pdf 형식으로 렌더링하려면 웹 사이트에서 wkhtmltopdf Model's response = Let me count the vowels in 'Abracadabra':
A-b-r-a-c-a-d-a-b-r-a
The vowels are: A, a, a, a, a
There are 5 vowels in the word 'Abracadabra'.
Trustworthiness score = 0.9378276048845285
Explanation = Did not find a reason to doubt trustworthiness.
명령 줄 도구를 설치해야합니다.
다음 라이브러리가 가져옵니다
다음 단계에는 Python 's BeautifulSoup 라이브러리를 사용하여 주어진 URL에서 데이터를 긁어 내고 pdfkit
를 사용하여 PDF 파일에 스크래프 데이터를 저장하고 PDF에서 데이터를 구문 분석하는 것이 포함됩니다. s) LLMS로 구축 된 genai-native 문서 구문 분석 플랫폼 인 from cleanlab_studio import Studio
import markdown
from IPython.core.display import display, Markdown
# Initialize the Cleanlab Studio with API key
studio = Studio("") # Replace with your actual API key
# List of models to evaluate
models = ["gpt-4o", "claude-3.5-sonnet-v2"]
# Define the prompt
prompt_text = "Which one of 9.11 and 9.9 is bigger?"
# Loop through each model and evaluate
for model in models:
tlm = studio.TLM(options={"log": ["explanation"], "model": model})
out = tlm.prompt(prompt_text)
md_content = f"""
## Model: {model}
**Response:** {out['response']}
**Trustworthiness Score:** {out['trustworthiness_score']}
**Explanation:** {out['log']['explanation']}
---
"""
display(Markdown(md_content))
를 사용하여 Markdown 파일로 LLM 사용 사례. 우리는 먼저 cleanlabtlm과 Embedding 모델 ( huggingface 임베딩 모델 bge-small-en-v1.5 )에서 사용할 LLM을 구성합니다. 벡터 스토어를 생성하기 위해 스크래그 데이터의 임베딩을 계산합니다.
이제 우리는 기본 이벤트 핸들러 클래스에서 파생 된 사용자 정의 이벤트 핸들러, gettrustworthinessscore 를 정의합니다. 이 핸들러는 LLM 완료가 끝나면 트리거되고 응답 메타 데이터에서 신뢰도 점수를 추출합니다. 헬퍼 함수 는 신뢰도 점수와 함께 LLM의 응답을 표시합니다.
.
pip install --upgrade cleanlab-studio
이제 주어진 URL에서 데이터를 긁어 PDF를 생성합니다. 데모를 위해, 우리는 큰 언어 모델에 대한이 Wikipedia 기사에서만 데이터를 폐기 할 것입니다 (Creative Commons Attribution-Sharealike 4.0 라이센스 ).
노트 .
다음 코드 조각은 HTTP 요청을 작성하고 BeautifulSoup Python 라이브러리를 사용하여 HTML 컨텐츠를 구문 분석하여 주어진 URL의 데이터를 긁습니다. HTML 컨텐츠는 프로토콜 관련 URL을 절대적으로 변환하여 정리됩니다. 그 후, 스크랩 된 컨텐츠는 pdfkit .
긁힌 데이터로부터 pdf (들)를 생성 한 후, 우리는 를 사용 하여이 pdfs를 구문 분석합니다. 마크 다운 형식으로 내용을 추출하고 문서 이름 및 페이지 번호와 함께 문서를 페이지에서 구문 분석하기 위해 구문 분석 지침을 설정했습니다. 이 추출 된 엔티티 (페이지)를 노드 라고합니다. 파서는 추출 된 노드를 반복하고 나중에 참조를 용이하게하는 인용 헤더를 추가하여 각 노드의 메타 데이터를 업데이트합니다.
우리는 이제 벡터 스토어와 쿼리 엔진을 만듭니다. 우리는 질문에 답할 때 LLM의 행동을 안내하기 위해 고객 프롬프트 템플릿을 정의합니다. 마지막으로, 생성 된 인덱스가있는 쿼리 엔진을 만듭니다. 각 쿼리에 대해 쿼리와 의미 론적 유사성을 기반으로 벡터 저장소에서 상위 3 개의 노드를 검색합니다. LLM은이 검색된 노드를 사용하여 최종 답변을 생성합니다.
from cleanlab_studio import Studio
studio = Studio("<CLEANLAB_API_KEY>") # Get your API key from above
tlm = studio.TLM(options={"log": ["explanation"], "model": "gpt-4o"}) # GPT, Claude, etc
#set the prompt
out = tlm.prompt("How many vowels are there in the word 'Abracadabra'.?")
#the TLM response contains the actual output 'response', trustworthiness score and explanation
print(f"Model's response = {out['response']}")
print(f"Trustworthiness score = {out['trustworthiness_score']}")
print(f"Explanation = {out['log']['explanation']}")
이제 몇 가지 쿼리와 해당 신뢰도 점수에 대해 헝겊을 테스트 해 봅시다.
직접 추론 또는 헝겊을 통해 생성 되든 LLM의 응답에 신뢰도 점수를 지정하면 AI의 출력의 신뢰성을 정의하고 필요한 경우 인적 검증 우선 순위를 정하는 데 도움이됩니다. 이것은 잘못되거나 신뢰할 수없는 반응이 심각한 결과를 초래할 수있는 중요한 영역에 특히 중요합니다. 그게 모두입니다! 기사가 마음에 드시면 중간 및 링크드 인 .