Spaces:
Runtime error
Runtime error
File size: 28,282 Bytes
1b5ee9b 8c0e97b f5831ec 1b5ee9b |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Let's create a golden test set with Synthetic Data Generation!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded 141 documents\n",
"\n",
"Example document:\n",
"Content: {\"id\": \"135\", \"url\": \"https://www.csszengarden.com/135\", \"css_url\": \"https://www.csszengarden.com/135/135.css\", \"description\": \"This design uses an elegant and traditional aesthetic, with a muted color palette featuring cream and terracotta tones. The use of a patterned background adds texture, while the vertical layout and serif typography provide a classic and sophisticated feel. The design balances text-heavy content with organized sections, making information easily accessible, and its ornate flourishes add a touch of refinement.\", \"categories\": [\"Traditional\", \"Elegant\", \"Text-Heavy\", \"Classic\"], \"visual_characteristics\": [\"Muted Color Palette\", \"Vertical Layout\", \"Serif Typography\", \"Textured Background\", \"Ornate Flourishes\"]}\n",
"Metadata: {'source': '/Users/owner/Desktop/Projects/ai-maker-space/code/ImagineUI/src/data/designs/135/metadata.json', 'seq_num': 1, 'title': '', 'tags': []}\n"
]
}
],
"source": [
"from langchain_community.document_loaders import DirectoryLoader\n",
"from langchain_community.document_loaders import JSONLoader\n",
"import json\n",
"\n",
"def metadata_func(record: dict, metadata: dict) -> dict:\n",
" metadata[\"title\"] = record.get(\"title\", \"\")\n",
" metadata[\"tags\"] = record.get(\"tags\", [])\n",
" return metadata\n",
"\n",
"loader = DirectoryLoader(\n",
" path=\"data/designs\",\n",
" glob=\"**/*.json\",\n",
" loader_cls=JSONLoader,\n",
" loader_kwargs={\n",
" \"jq_schema\": \".\", # This will select the entire JSON object\n",
" \"content_key\": None, # We're not selecting a specific content key\n",
" \"metadata_func\": metadata_func,\n",
" \"text_content\": False\n",
" }\n",
")\n",
"\n",
"documents = loader.load()\n",
"\n",
"print(f\"Loaded {len(documents)} documents\")\n",
"if documents:\n",
" print(\"\\nExample document:\")\n",
" print(f\"Content: {documents[0].page_content}\")\n",
" print(f\"Metadata: {documents[0].metadata}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let's create a knowledge graph based on our design metadata."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from ragas.llms import LangchainLLMWrapper\n",
"from ragas.embeddings import LangchainEmbeddingsWrapper\n",
"from langchain_openai import ChatOpenAI\n",
"from langchain_openai import OpenAIEmbeddings\n",
"\n",
"# using 4o-mini due to rate limits\n",
"generator_llm = LangchainLLMWrapper(ChatOpenAI(model=\"gpt-4o-mini\"))\n",
"generator_embeddings = LangchainEmbeddingsWrapper(OpenAIEmbeddings())"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"KnowledgeGraph(nodes: 141, relationships: 0)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ragas.testset.graph import KnowledgeGraph, Node, NodeType\n",
"\n",
"kg = KnowledgeGraph()\n",
"\n",
"for doc in documents:\n",
" kg.nodes.append(\n",
" Node(\n",
" type=NodeType.DOCUMENT,\n",
" properties={\"page_content\": doc.page_content, \"document_metadata\": doc.metadata}\n",
" )\n",
" )\n",
"\n",
"kg"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "27552c622ca64d2abe4190ce6fb12d1d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying SummaryExtractor: 0%| | 0/141 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7e73db5f494c4db581b14baa2c23d12a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying CustomNodeFilter: 0%| | 0/141 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5e525eaa7bda4c52a876ae87835606a9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying [EmbeddingExtractor, ThemesExtractor, NERExtractor]: 0%| | 0/423 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "74e2eae6725142e8922955012318f4d9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying OverlapScoreBuilder: 0%| | 0/1 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"KnowledgeGraph(nodes: 141, relationships: 795)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ragas.testset.transforms import default_transforms, apply_transforms\n",
"\n",
"# why use these new variables?\n",
"transformer_llm = generator_llm\n",
"embedding_model = generator_embeddings\n",
"\n",
"default_transforms = default_transforms(documents=documents, llm=transformer_llm, embedding_model=embedding_model)\n",
"apply_transforms(kg, default_transforms)\n",
"kg"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"kg.save(\"css_zen_garden_design_data\")\n",
"design_kg = KnowledgeGraph.load(\"css_zen_garden_design_data\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Okay! With out knowledge graph of relationships, we can now generate a test set."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"from ragas.testset import TestsetGenerator\n",
"\n",
"testset_generator = TestsetGenerator(\n",
" knowledge_graph=design_kg,\n",
" llm=generator_llm,\n",
" embedding_model=generator_embeddings\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "82e3c2beea444035a84257bf881f44bd",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating personas: 0%| | 0/3 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f2c3a53c3df34620a4b17baec2c74c5a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating Scenarios: 0%| | 0/2 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "18bd0fdb023045f78c6251dec02e9a54",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating Samples: 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user_input</th>\n",
" <th>reference_contexts</th>\n",
" <th>reference</th>\n",
" <th>synthesizer_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>How do ornate flourishes contribute to the ove...</td>\n",
" <td>[{\"id\": \"135\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>Ornate flourishes in web design add a touch of...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>How does the nature-inspired design in the pro...</td>\n",
" <td>[{\"id\": \"132\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The nature-inspired design features a minimali...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Can you describe the design principles and vis...</td>\n",
" <td>[{\"id\": \"104\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The CSS Zen Garden design emphasizes a harmoni...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>How does the use of burgundy in web design con...</td>\n",
" <td>[{\"id\": \"103\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The design features a dark burgundy background...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>How vintage aesthetic show in this design?</td>\n",
" <td>[{\"id\": \"168\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The design cleverly combines a vintage aesthet...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>How do the designs at CSS Zen Garden utilize a...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"151\", \"url\": \"https://www....</td>\n",
" <td>The designs at CSS Zen Garden utilize a light ...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>How do the typography-focused designs in the d...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"155\", \"url\": \"https://www....</td>\n",
" <td>The typography-focused design in the dark them...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>What are the illustrative elements used in the...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"218\", \"url\": \"https://www....</td>\n",
" <td>The illustrative elements used in the designs ...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>What are the key visual characteristics of the...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"208\", \"url\": \"https://www....</td>\n",
" <td>The design at https://www.csszengarden.com/208...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Wht are the key visual characteristics of the ...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"001\", \"url\": \"https://www....</td>\n",
" <td>The key visual characteristics of the Zen Gard...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user_input \\\n",
"0 How do ornate flourishes contribute to the ove... \n",
"1 How does the nature-inspired design in the pro... \n",
"2 Can you describe the design principles and vis... \n",
"3 How does the use of burgundy in web design con... \n",
"4 How vintage aesthetic show in this design? \n",
"5 How do the designs at CSS Zen Garden utilize a... \n",
"6 How do the typography-focused designs in the d... \n",
"7 What are the illustrative elements used in the... \n",
"8 What are the key visual characteristics of the... \n",
"9 Wht are the key visual characteristics of the ... \n",
"\n",
" reference_contexts \\\n",
"0 [{\"id\": \"135\", \"url\": \"https://www.csszengarde... \n",
"1 [{\"id\": \"132\", \"url\": \"https://www.csszengarde... \n",
"2 [{\"id\": \"104\", \"url\": \"https://www.csszengarde... \n",
"3 [{\"id\": \"103\", \"url\": \"https://www.csszengarde... \n",
"4 [{\"id\": \"168\", \"url\": \"https://www.csszengarde... \n",
"5 [<1-hop>\\n\\n{\"id\": \"151\", \"url\": \"https://www.... \n",
"6 [<1-hop>\\n\\n{\"id\": \"155\", \"url\": \"https://www.... \n",
"7 [<1-hop>\\n\\n{\"id\": \"218\", \"url\": \"https://www.... \n",
"8 [<1-hop>\\n\\n{\"id\": \"208\", \"url\": \"https://www.... \n",
"9 [<1-hop>\\n\\n{\"id\": \"001\", \"url\": \"https://www.... \n",
"\n",
" reference \\\n",
"0 Ornate flourishes in web design add a touch of... \n",
"1 The nature-inspired design features a minimali... \n",
"2 The CSS Zen Garden design emphasizes a harmoni... \n",
"3 The design features a dark burgundy background... \n",
"4 The design cleverly combines a vintage aesthet... \n",
"5 The designs at CSS Zen Garden utilize a light ... \n",
"6 The typography-focused design in the dark them... \n",
"7 The illustrative elements used in the designs ... \n",
"8 The design at https://www.csszengarden.com/208... \n",
"9 The key visual characteristics of the Zen Gard... \n",
"\n",
" synthesizer_name \n",
"0 single_hop_specifc_query_synthesizer \n",
"1 single_hop_specifc_query_synthesizer \n",
"2 single_hop_specifc_query_synthesizer \n",
"3 single_hop_specifc_query_synthesizer \n",
"4 single_hop_specifc_query_synthesizer \n",
"5 multi_hop_specific_query_synthesizer \n",
"6 multi_hop_specific_query_synthesizer \n",
"7 multi_hop_specific_query_synthesizer \n",
"8 multi_hop_specific_query_synthesizer \n",
"9 multi_hop_specific_query_synthesizer "
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ragas.testset.synthesizers import default_query_distribution, \n",
"\n",
"query_distribution = default_query_distribution(\n",
" kg=design_kg,\n",
" llm=generator_llm\n",
")\n",
"\n",
"testset = testset_generator.generate(testset_size=10, query_distribution=query_distribution)\n",
"testset.to_pandas()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Just for comparison, let's see what the simplified version with langchain docs looks like.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "70a315ea06e3444ca84fbac63e51b678",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying SummaryExtractor: 0%| | 0/141 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f1446a35386844e1b414feda2399b2df",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying CustomNodeFilter: 0%| | 0/141 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6247060a50a7484ba9895280782e2235",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying [EmbeddingExtractor, ThemesExtractor, NERExtractor]: 0%| | 0/423 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "32df2719024e4fa395957525ab57abaa",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Applying OverlapScoreBuilder: 0%| | 0/1 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6522481d960e4129aa6f0e0b0b5b2187",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating personas: 0%| | 0/3 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4cc4b04da15d44ef9c76cc7afceb9a00",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating Scenarios: 0%| | 0/2 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "25c28f8088004e398f56cf22495f6714",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Generating Samples: 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>user_input</th>\n",
" <th>reference_contexts</th>\n",
" <th>reference</th>\n",
" <th>synthesizer_name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Can you tell me more about what makes this des...</td>\n",
" <td>[{\"id\": \"135\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>This design is classic because it employs an e...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>What makes this design typography-focused?</td>\n",
" <td>[{\"id\": \"132\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>This design is typography-focused because it u...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>How does the web design concept illustrated in...</td>\n",
" <td>[{\"id\": \"104\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The web design concept illustrated in the CSS ...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>What make this design vintage?</td>\n",
" <td>[{\"id\": \"103\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>This design features a vintage theme through i...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>How does the vintage aesthetic influence the d...</td>\n",
" <td>[{\"id\": \"168\", \"url\": \"https://www.csszengarde...</td>\n",
" <td>The vintage aesthetic in the design is cleverl...</td>\n",
" <td>single_hop_specifc_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>What are the key visual characteristics that m...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"201\", \"url\": \"https://www....</td>\n",
" <td>The design at CSS Zen Garden employs a strong ...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>What are the visual characteristics of designs...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"008\", \"url\": \"https://www....</td>\n",
" <td>The designs that effectively utilize bold typo...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>What are the key visual characteristics of the...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"151\", \"url\": \"https://www....</td>\n",
" <td>The key visual characteristics of the minimali...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>How do the subtle background colors and subtle...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"164\", \"url\": \"https://www....</td>\n",
" <td>The design featuring a minimalist layout with ...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>In what ways do the designs from CSS Zen Garde...</td>\n",
" <td>[<1-hop>\\n\\n{\"id\": \"109\", \"url\": \"https://www....</td>\n",
" <td>The designs from CSS Zen Garden exemplify info...</td>\n",
" <td>multi_hop_specific_query_synthesizer</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" user_input \\\n",
"0 Can you tell me more about what makes this des... \n",
"1 What makes this design typography-focused? \n",
"2 How does the web design concept illustrated in... \n",
"3 What make this design vintage? \n",
"4 How does the vintage aesthetic influence the d... \n",
"5 What are the key visual characteristics that m... \n",
"6 What are the visual characteristics of designs... \n",
"7 What are the key visual characteristics of the... \n",
"8 How do the subtle background colors and subtle... \n",
"9 In what ways do the designs from CSS Zen Garde... \n",
"\n",
" reference_contexts \\\n",
"0 [{\"id\": \"135\", \"url\": \"https://www.csszengarde... \n",
"1 [{\"id\": \"132\", \"url\": \"https://www.csszengarde... \n",
"2 [{\"id\": \"104\", \"url\": \"https://www.csszengarde... \n",
"3 [{\"id\": \"103\", \"url\": \"https://www.csszengarde... \n",
"4 [{\"id\": \"168\", \"url\": \"https://www.csszengarde... \n",
"5 [<1-hop>\\n\\n{\"id\": \"201\", \"url\": \"https://www.... \n",
"6 [<1-hop>\\n\\n{\"id\": \"008\", \"url\": \"https://www.... \n",
"7 [<1-hop>\\n\\n{\"id\": \"151\", \"url\": \"https://www.... \n",
"8 [<1-hop>\\n\\n{\"id\": \"164\", \"url\": \"https://www.... \n",
"9 [<1-hop>\\n\\n{\"id\": \"109\", \"url\": \"https://www.... \n",
"\n",
" reference \\\n",
"0 This design is classic because it employs an e... \n",
"1 This design is typography-focused because it u... \n",
"2 The web design concept illustrated in the CSS ... \n",
"3 This design features a vintage theme through i... \n",
"4 The vintage aesthetic in the design is cleverl... \n",
"5 The design at CSS Zen Garden employs a strong ... \n",
"6 The designs that effectively utilize bold typo... \n",
"7 The key visual characteristics of the minimali... \n",
"8 The design featuring a minimalist layout with ... \n",
"9 The designs from CSS Zen Garden exemplify info... \n",
"\n",
" synthesizer_name \n",
"0 single_hop_specifc_query_synthesizer \n",
"1 single_hop_specifc_query_synthesizer \n",
"2 single_hop_specifc_query_synthesizer \n",
"3 single_hop_specifc_query_synthesizer \n",
"4 single_hop_specifc_query_synthesizer \n",
"5 multi_hop_specific_query_synthesizer \n",
"6 multi_hop_specific_query_synthesizer \n",
"7 multi_hop_specific_query_synthesizer \n",
"8 multi_hop_specific_query_synthesizer \n",
"9 multi_hop_specific_query_synthesizer "
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"generator = TestsetGenerator(\n",
" llm=generator_llm,\n",
" embedding_model=generator_embeddings\n",
")\n",
"\n",
"testset = generator.generate_with_langchain_docs(\n",
" documents=documents,\n",
" testset_size=10,\n",
" query_distribution=query_distribution\n",
")\n",
"\n",
"testset.to_pandas()\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This isn't ideal, since our RAG use case is to subjectively show examples of good design. Our users won't be asking questions or looking for specific answers.\n",
"\n",
"We may still be able to use evaluators to illustrate direction changes, but what we really need is a test data set showing retrievals of designs that fit the description. This likely needs to be manually curated to ensure the returned design fits and represents a good example."
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|