Download example.py from CobuildX-AI/cbx-rag-context-relevance-68M: direct link, hf CLI and curl.
- Browser
- Download file 929 Bytes
-
https://huggingface.co/CobuildX-AI/cbx-rag-context-relevance-68M/resolve/main/example.py
- Command line
-
hf download hf://CobuildX-AI/cbx-rag-context-relevance-68M/example.py
-
curl -L -o example.py https://huggingface.co/CobuildX-AI/cbx-rag-context-relevance-68M/resolve/main/example.py
929 Bytes
| """Which context sentences are relevant to the question? Run from this folder: python example.py""" | |
| from cbx_rag_eval import ContextRelevance | |
| judge = ContextRelevance(".") | |
| question = "What was the company's operating income in 2023?" | |
| passages = [ | |
| "The company was founded in 1998 and is headquartered in Ohio. It operates three plants.", | |
| "Operating income was $412 million in 2023, compared with $380 million in 2022. " | |
| "The increase reflects higher volumes.", | |
| "The board declared a quarterly dividend of $0.25 per share.", | |
| ] | |
| out = judge(question, passages) # several passages: also returns context precision | |
| print("relevance:", out["relevance"], "| context precision:", out.get("context_precision"), | |
| "| relevant passages:", out.get("passage_relevant")) | |
| for s in out["sentences"]: | |
| print(f" passage {s['passage']} relevant={s['relevant']!s:5} score={s['score']:.3f} {s['text']}") | |