-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
43 lines (34 loc) · 1.3 KB
/
example.py
File metadata and controls
43 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from dotenv import load_dotenv
from tokenburn.tokenburn import TokenBurn
# Load environment variables from .env
load_dotenv()
api_key = os.getenv("HF_API_KEY")
tb = TokenBurn(
url="https://router.huggingface.co/v1/chat/completions",
model="openai/gpt-oss-120b:cerebras",
api_key=api_key
)
# Example prompt 1
logprobs = tb.get_logprobs(messages=[
{"role": "user", "content": "Who won the Nobel Prize in Physics in 2029"}
], max_tokens=50, top_logprobs=5)
print("Perplexity:", tb.perplexity(logprobs))
print("Hallucination Risk:", tb.hallucination_risk(logprobs))
print("Optimal CoT Length:", tb.find_optimal_cot_length(n=len(logprobs), epsilon=0.9))
# NEW: Info-theoretic trust score
score = tb.info_theoretic_score(logprobs)
print("Info-theoretic Score:", score)
# Example prompt 2
logprobs = tb.get_logprobs(messages=[
{"role": "user", "content": """
Respond in plain text, one word answers.
What is the capital of France?
"""}
], max_tokens=50, top_logprobs=5)
print("Perplexity:", tb.perplexity(logprobs))
print("Hallucination Risk:", tb.hallucination_risk(logprobs))
print("Optimal CoT Length:", tb.find_optimal_cot_length(n=len(logprobs), epsilon=0.9))
# NEW: Info-theoretic trust score
score = tb.info_theoretic_score(logprobs)
print("Info-theoretic Score:", score)