Skip to content

Commit fc09372

Browse files
authored
docs: moved quickstart (#54)
1 parent 7df8cbc commit fc09372

File tree

5 files changed

+52
-31
lines changed

5 files changed

+52
-31
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ format: ## Running code formatter: black and isort
88
@echo "(isort) Ordering imports..."
99
@isort .
1010
@echo "(black) Formatting codebase..."
11-
@black --config pyproject.toml src tests examples experiments
11+
@black --config pyproject.toml src tests docs experiments
1212
@echo "(black) Formatting stubs..."
1313
@find src -name "*.pyi" ! -name "*_pb2*" -exec black --pyi --config pyproject.toml {} \;
1414
@echo "(ruff) Running fix only..."
15-
@ruff check src examples tests --fix-only
15+
@ruff check src docs tests --fix-only
1616
lint: ## Running lint checker: ruff
1717
@echo "(ruff) Linting development project..."
18-
@ruff check src examples tests
18+
@ruff check src docs tests
1919
type: ## Running type checker: pyright
2020
@echo "(pyright) Typechecking codebase..."
2121
@pyright src

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<a href="https://github.com/explodinggradients/ragas/blob/master/LICENSE">
1717
<img alt="License" src="https://img.shields.io/github/license/explodinggradients/ragas.svg?color=green">
1818
</a>
19-
<a href="https://colab.research.google.com/github/explodinggradients/ragas/blob/main/examples/quickstart.ipynb">
19+
<a href="https://colab.research.google.com/github/explodinggradients/ragas/blob/main/docs/quickstart.ipynb">
2020
<img alt="Open In Colab" src="https://colab.research.google.com/assets/colab-badge.svg">
2121
</a>
2222
<a href="https://discord.gg/5djav8GGNZ">
@@ -77,7 +77,7 @@ results = evaluate(dataset)
7777
# {'ragas_score': 0.860, 'context_relavency': 0.817,
7878
# 'faithfulness': 0.892, 'answer_relevancy': 0.874}
7979
```
80-
If you want a more in-depth explanation of core components, check out our [quick-start notebook](./examples/quickstart.ipynb)
80+
If you want a more in-depth explanation of core components, check out our [quick-start notebook](./docs/quickstart.ipynb)
8181
## :luggage: Metrics
8282

8383
Ragas measures your pipeline's performance against two dimensions
File renamed without changes.

examples/quickstart.ipynb renamed to docs/quickstart.ipynb

+16
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
"id": "2e63f667",
66
"metadata": {},
77
"source": [
8+
"<a href=\"https://colab.research.google.com/github/explodinggradients/ragas/blob/main/docs/quickstart.ipynb\">\n",
9+
" <img alt=\"Open In Colab\" \n",
10+
" align=\"left\"\n",
11+
" src=\"https://colab.research.google.com/assets/colab-badge.svg\">\n",
12+
"</a>\n",
813
"# Quickstart\n",
914
"\n",
1015
"welcome to the ragas quickstart. We're going to get you up and running with ragas as qickly as you can so that you can go back to improving your Retrieval Augmented Generation pipelines while this library makes sure your changes are improving your entire pipeline.\n",
1116
"\n",
1217
"to kick things of lets start with the data"
1318
]
1419
},
20+
{
21+
"cell_type": "code",
22+
"execution_count": 1,
23+
"id": "18274e1f",
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"# if using colab uncomment this\n",
28+
"#!pip install ragas"
29+
]
30+
},
1531
{
1632
"cell_type": "code",
1733
"execution_count": 1,

experiments/assesments/metrics_assesments.ipynb

+31-26
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@
177177
"outputs": [],
178178
"source": [
179179
"def get_corr(targets, predictions):\n",
180-
" scores = [kendalltau(x, y).correlation for x, y in zip(targets, predictions)]\n",
181-
" return [score if not np.isnan(score) else 0 for score in scores ]"
180+
" scores = [kendalltau(x, y).correlation for x, y in zip(targets, predictions)]\n",
181+
" return [score if not np.isnan(score) else 0 for score in scores]"
182182
]
183183
},
184184
{
@@ -355,18 +355,25 @@
355355
"metadata": {},
356356
"outputs": [],
357357
"source": [
358-
"def gpt_faithfulness(question:list, context:list, answer:list):\n",
359-
" prompt = [faithfulness.format(c,q, a) for c,q,a in zip(question,context,answer)]\n",
360-
" output = [output for output in llm(prompt)['choices']]\n",
361-
" scores = [(out[\"text\"].strip()) for out in output ]\n",
362-
" scores = [int(score) if score in ['1','2','3','4','5'] else 1 for score in scores]\n",
358+
"def gpt_faithfulness(question: list, context: list, answer: list):\n",
359+
" prompt = [\n",
360+
" faithfulness.format(c, q, a) for c, q, a in zip(question, context, answer)\n",
361+
" ]\n",
362+
" output = [output for output in llm(prompt)[\"choices\"]]\n",
363+
" scores = [(out[\"text\"].strip()) for out in output]\n",
364+
" scores = [\n",
365+
" int(score) if score in [\"1\", \"2\", \"3\", \"4\", \"5\"] else 1 for score in scores\n",
366+
" ]\n",
363367
" return scores\n",
364368
"\n",
365-
"def gpt_relevance(question:list, answer:list):\n",
366-
" prompt = [relevence.format(q,a) for q,a in zip(question,answer)]\n",
367-
" output = [output for output in llm(prompt)['choices']]\n",
368-
" scores = [(out[\"text\"].strip()) for out in output ]\n",
369-
" scores = [int(score) if score in ['1','2','3','4','5'] else 1 for score in scores]\n",
369+
"\n",
370+
"def gpt_relevance(question: list, answer: list):\n",
371+
" prompt = [relevence.format(q, a) for q, a in zip(question, answer)]\n",
372+
" output = [output for output in llm(prompt)[\"choices\"]]\n",
373+
" scores = [(out[\"text\"].strip()) for out in output]\n",
374+
" scores = [\n",
375+
" int(score) if score in [\"1\", \"2\", \"3\", \"4\", \"5\"] else 1 for score in scores\n",
376+
" ]\n",
370377
" return scores"
371378
]
372379
},
@@ -425,7 +432,11 @@
425432
"metadata": {},
426433
"outputs": [],
427434
"source": [
428-
"q,a,c = wikiqa_ragas['train'][0]['question'],wikiqa_ragas['train'][0]['generated_without_rag'],wikiqa_ragas['train'][0]['context']"
435+
"q, a, c = (\n",
436+
" wikiqa_ragas[\"train\"][0][\"question\"],\n",
437+
" wikiqa_ragas[\"train\"][0][\"generated_without_rag\"],\n",
438+
" wikiqa_ragas[\"train\"][0][\"context\"],\n",
439+
")"
429440
]
430441
},
431442
{
@@ -446,7 +457,7 @@
446457
}
447458
],
448459
"source": [
449-
"gpt_faithfulness([q],[c], [a])"
460+
"gpt_faithfulness([q], [c], [a])"
450461
]
451462
},
452463
{
@@ -517,12 +528,12 @@
517528
"def predict_(examples):\n",
518529
" scores = {}\n",
519530
" questions = examples[\"question\"]\n",
520-
" context = examples['context']\n",
531+
" context = examples[\"context\"]\n",
521532
" for col in COLUMNS:\n",
522533
" passage = examples[col]\n",
523534
" inputs = list(zip(questions, passage))\n",
524-
" #scores[f\"{col}_relevance\"] = t5_qgen.predict(inputs, show_progress=False)\n",
525-
" scores[f\"{col}_relevance\"] = gpt_faithfulness(questions,context,passage)\n",
535+
" # scores[f\"{col}_relevance\"] = t5_qgen.predict(inputs, show_progress=False)\n",
536+
" scores[f\"{col}_relevance\"] = gpt_faithfulness(questions, context, passage)\n",
526537
" return scores"
527538
]
528539
},
@@ -553,10 +564,7 @@
553564
},
554565
"outputs": [],
555566
"source": [
556-
"output = (\n",
557-
" wikiqa_ragas[\"train\"]\n",
558-
" .map(predict_relevance, batched=True, batch_size=10)\n",
559-
")"
567+
"output = wikiqa_ragas[\"train\"].map(predict_relevance, batched=True, batch_size=10)"
560568
]
561569
},
562570
{
@@ -622,10 +630,7 @@
622630
}
623631
],
624632
"source": [
625-
"output = (\n",
626-
" wikiqa_ragas[\"train\"]\n",
627-
" .map(predict_relevance, batched=True, batch_size=10)\n",
628-
")"
633+
"output = wikiqa_ragas[\"train\"].map(predict_relevance, batched=True, batch_size=10)"
629634
]
630635
},
631636
{
@@ -877,7 +882,7 @@
877882
"metadata": {},
878883
"outputs": [],
879884
"source": [
880-
"def predict_faithfulness(examples,scoring_fun=NLI.score):\n",
885+
"def predict_faithfulness(examples, scoring_fun=NLI.score):\n",
881886
" scores = {}\n",
882887
" questions = examples[\"question\"]\n",
883888
" contexts = examples[\"answer_context\"]\n",

0 commit comments

Comments
 (0)