|
25 | 25 | "nest_asyncio.apply()" |
26 | 26 | ] |
27 | 27 | }, |
28 | | - { |
29 | | - "cell_type": "code", |
30 | | - "execution_count": 2, |
31 | | - "id": "8333f65e", |
32 | | - "metadata": {}, |
33 | | - "outputs": [], |
34 | | - "source": [ |
35 | | - "%load_ext autoreload\n", |
36 | | - "%autoreload 2" |
37 | | - ] |
38 | | - }, |
39 | 28 | { |
40 | 29 | "cell_type": "markdown", |
41 | 30 | "id": "842e32dc", |
|
62 | 51 | "\n", |
63 | 52 | "llm = ChatOpenAI()\n", |
64 | 53 | "qa_chain = RetrievalQA.from_chain_type(\n", |
65 | | - " llm, retriever=index.vectorstore.as_retriever(), return_source_documents=True,\n", |
| 54 | + " llm,\n", |
| 55 | + " retriever=index.vectorstore.as_retriever(),\n", |
| 56 | + " return_source_documents=True,\n", |
66 | 57 | ")" |
67 | 58 | ] |
68 | 59 | }, |
|
115 | 106 | "]\n", |
116 | 107 | "\n", |
117 | 108 | "eval_answers = [\n", |
118 | | - " \"8,804,000\", # incorrect answer\n", |
119 | | - " \"Queens\", # incorrect answer\n", |
| 109 | + " \"8,804,000\", # incorrect answer\n", |
| 110 | + " \"Queens\", # incorrect answer\n", |
120 | 111 | " \"New York City's economic significance is vast, as it serves as the global financial capital, housing Wall Street and major financial institutions. Its diverse economy spans technology, media, healthcare, education, and more, making it resilient to economic fluctuations. NYC is a hub for international business, attracting global companies, and boasts a large, skilled labor force. Its real estate market, tourism, cultural industries, and educational institutions further fuel its economic prowess. The city's transportation network and global influence amplify its impact on the world stage, solidifying its status as a vital economic player and cultural epicenter.\",\n", |
121 | 112 | " \"New York City got its name when it came under British control in 1664. King Charles II of England granted the lands to his brother, the Duke of York, who named the city New York in his own honor.\",\n", |
122 | | - " 'The Statue of Liberty in New York City holds great significance as a symbol of the United States and its ideals of liberty and peace. It greeted millions of immigrants who arrived in the U.S. by ship in the late 19th and early 20th centuries, representing hope and freedom for those seeking a better life. It has since become an iconic landmark and a global symbol of cultural diversity and freedom.',\n", |
| 113 | + " \"The Statue of Liberty in New York City holds great significance as a symbol of the United States and its ideals of liberty and peace. It greeted millions of immigrants who arrived in the U.S. by ship in the late 19th and early 20th centuries, representing hope and freedom for those seeking a better life. It has since become an iconic landmark and a global symbol of cultural diversity and freedom.\",\n", |
123 | 114 | "]\n", |
124 | 115 | "\n", |
125 | | - "examples = [{\"query\": q, \"ground_truths\": [eval_answers[i]]} \n", |
126 | | - " for i, q in enumerate(eval_questions)]" |
| 116 | + "examples = [\n", |
| 117 | + " {\"query\": q, \"ground_truths\": [eval_answers[i]]}\n", |
| 118 | + " for i, q in enumerate(eval_questions)\n", |
| 119 | + "]" |
127 | 120 | ] |
128 | 121 | }, |
129 | 122 | { |
|
196 | 189 | "outputs": [], |
197 | 190 | "source": [ |
198 | 191 | "from ragas.langchain.evalchain import RagasEvaluatorChain\n", |
199 | | - "from ragas.metrics import faithfulness, answer_relevancy, context_relevancy, context_recall\n", |
| 192 | + "from ragas.metrics import (\n", |
| 193 | + " faithfulness,\n", |
| 194 | + " answer_relevancy,\n", |
| 195 | + " context_relevancy,\n", |
| 196 | + " context_recall,\n", |
| 197 | + ")\n", |
200 | 198 | "\n", |
201 | 199 | "# create evaluation chains\n", |
202 | 200 | "faithfulness_chain = RagasEvaluatorChain(metric=faithfulness)\n", |
|
469 | 467 | "from langchain.smith import RunEvalConfig, run_on_dataset\n", |
470 | 468 | "\n", |
471 | 469 | "evaluation_config = RunEvalConfig(\n", |
472 | | - " custom_evaluators=[faithfulness_chain, answer_rel_chain, context_rel_chain, context_recall_chain],\n", |
| 470 | + " custom_evaluators=[\n", |
| 471 | + " faithfulness_chain,\n", |
| 472 | + " answer_rel_chain,\n", |
| 473 | + " context_rel_chain,\n", |
| 474 | + " context_recall_chain,\n", |
| 475 | + " ],\n", |
473 | 476 | " prediction_key=\"result\",\n", |
474 | 477 | ")\n", |
475 | | - " \n", |
| 478 | + "\n", |
476 | 479 | "result = run_on_dataset(\n", |
477 | 480 | " client,\n", |
478 | 481 | " dataset_name,\n", |
|
0 commit comments