-
-
Save vicpada/64227b8b991d598132058685689b4daf to your computer and use it in GitHub Desktop.
RAGAS evaluation with Noise Sensitivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ragas import evaluate | |
| from ragas.metrics import ( | |
| faithfulness, answer_relevancy, | |
| context_precision, context_recall | |
| ) | |
| from datasets import Dataset | |
| # Standard evaluation dataset | |
| data = { | |
| 'question': ['What is the capital of France?'], | |
| 'answer': ['Paris is the capital of France.'], | |
| 'contexts': [['France is a country in Western Europe.', | |
| 'Paris, the capital city of France, is...']], | |
| 'ground_truth': ['Paris'] | |
| } | |
| dataset = Dataset.from_dict(data) | |
| results = evaluate( | |
| dataset=dataset, | |
| metrics=[faithfulness, answer_relevancy, context_precision, context_recall], | |
| llm=your_llm, | |
| embeddings=your_embeddings | |
| ) | |
| # faithfulness: 0.85, answer_relevancy: 0.92, | |
| # context_precision: 0.78, context_recall: 0.91 | |
| # For Noise Sensitivity: add known-irrelevant documents to contexts | |
| # and re-run evaluation. Score degradation = noise sensitivity. | |
| # If answer_relevancy drops >0.15 with noise injection, | |
| # invest in RAFT/DRAG robustness training. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment