|
| 1 | +""" |
| 2 | +Demo: Show an example for each dataset type using the Gradio inspectors. |
| 3 | +
|
| 4 | +Run with: |
| 5 | + python show_dataset_examples.py |
| 6 | +
|
| 7 | +Requires: gradio |
| 8 | +""" |
| 9 | +from datafast.inspectors import ( |
| 10 | + inspect_classification_dataset, |
| 11 | + inspect_mcq_dataset, |
| 12 | + inspect_preference_dataset, |
| 13 | + inspect_raw_dataset, |
| 14 | + inspect_ultrachat_dataset, |
| 15 | +) |
| 16 | +from datafast.schema.data_rows import ( |
| 17 | + TextClassificationRow, |
| 18 | + MCQRow, |
| 19 | + PreferenceRow, |
| 20 | + TextRow, |
| 21 | + ChatRow, |
| 22 | +) |
| 23 | +from datafast.datasets import ( |
| 24 | + ClassificationDataset, |
| 25 | + MCQDataset, |
| 26 | + PreferenceDataset, |
| 27 | + RawDataset, |
| 28 | + UltrachatDataset, |
| 29 | +) |
| 30 | +from datafast.schema.config import ( |
| 31 | + ClassificationDatasetConfig, |
| 32 | + MCQDatasetConfig, |
| 33 | + PreferenceDatasetConfig, |
| 34 | +) |
| 35 | + |
| 36 | +# --- Classification Example --- |
| 37 | +classification_row = TextClassificationRow( |
| 38 | + text="The trail is blocked by a fallen tree.", |
| 39 | + label="trail_obstruction", |
| 40 | + model_id="gpt-4.1-nano", |
| 41 | + metadata={"language": "en"}, |
| 42 | +) |
| 43 | +classification_dataset = ClassificationDataset( |
| 44 | + ClassificationDatasetConfig(classes=[{"name": "trail_obstruction", "description": "Obstruction on the trail."}]) |
| 45 | +) |
| 46 | +classification_row2 = TextClassificationRow( |
| 47 | + text="The trail is well maintained and easy to follow.", |
| 48 | + label="positive_conditions", |
| 49 | + model_id="claude-3-5-haiku-latest", |
| 50 | + metadata={"language": "en"}, |
| 51 | +) |
| 52 | +classification_dataset.data_rows = [classification_row, classification_row2] |
| 53 | + |
| 54 | +# --- MCQ Example --- |
| 55 | +mcq_row = MCQRow( |
| 56 | + source_document="The Eiffel Tower is in Paris.", |
| 57 | + question="Where is the Eiffel Tower located?", |
| 58 | + correct_answer="Paris", |
| 59 | + incorrect_answer_1="London", |
| 60 | + incorrect_answer_2="Berlin", |
| 61 | + incorrect_answer_3="Rome", |
| 62 | + model_id="gemini-2.0-flash", |
| 63 | + metadata={"language": "en"}, |
| 64 | +) |
| 65 | +mcq_config = MCQDatasetConfig( |
| 66 | + text_column="source_document", |
| 67 | + local_file_path="dummy.jsonl", # Required by config, not used in this demo |
| 68 | +) |
| 69 | +mcq_dataset = MCQDataset(mcq_config) |
| 70 | +mcq_row2 = MCQRow( |
| 71 | + source_document="The Amazon River is the second longest river in the world.", |
| 72 | + question="Which river is the second longest in the world?", |
| 73 | + correct_answer="Amazon River", |
| 74 | + incorrect_answer_1="Nile River", |
| 75 | + incorrect_answer_2="Yangtze River", |
| 76 | + incorrect_answer_3="Mississippi River", |
| 77 | + model_id="gpt-4.1-nano", |
| 78 | + metadata={"language": "en"}, |
| 79 | +) |
| 80 | +mcq_dataset.data_rows = [mcq_row, mcq_row2] |
| 81 | + |
| 82 | +# --- Preference Example --- |
| 83 | +preference_row = PreferenceRow( |
| 84 | + input_document="Describe a recent Mars mission.", |
| 85 | + question="What was the main goal of the Mars 2020 mission?", |
| 86 | + chosen_response="To search for signs of ancient life and collect samples.", |
| 87 | + rejected_response="To launch a satellite.", |
| 88 | + chosen_model_id="claude-3-5-haiku-latest", |
| 89 | + rejected_model_id="gpt-4.1-nano", |
| 90 | + chosen_response_score=9, |
| 91 | + rejected_response_score=3, |
| 92 | + chosen_response_assessment="Accurate and detailed.", |
| 93 | + rejected_response_assessment="Too generic.", |
| 94 | + metadata={"language": "en"}, |
| 95 | +) |
| 96 | +preference_dataset = PreferenceDataset(PreferenceDatasetConfig(input_documents=["Describe a recent Mars mission."])) |
| 97 | +preference_row2 = PreferenceRow( |
| 98 | + input_document="Describe the Voyager 1 mission.", |
| 99 | + question="What is Voyager 1 known for?", |
| 100 | + chosen_response="It is the farthest human-made object from Earth, exploring interstellar space.", |
| 101 | + rejected_response="It is a Mars rover.", |
| 102 | + chosen_model_id="gemini-2.0-flash", |
| 103 | + rejected_model_id="gpt-4.1-nano", |
| 104 | + chosen_response_score=10, |
| 105 | + rejected_response_score=2, |
| 106 | + chosen_response_assessment="Factually correct and detailed.", |
| 107 | + rejected_response_assessment="Incorrect mission.", |
| 108 | + metadata={"language": "en"}, |
| 109 | +) |
| 110 | +preference_dataset.data_rows = [preference_row, preference_row2] |
| 111 | + |
| 112 | +# --- RawDataset Example --- |
| 113 | +from datafast.schema.data_rows import TextRow |
| 114 | +from datafast.schema.config import RawDatasetConfig, UltrachatDatasetConfig |
| 115 | + |
| 116 | +raw_row1 = TextRow( |
| 117 | + text="SpaceX launched a new batch of Starlink satellites.", |
| 118 | + text_source="human", |
| 119 | + metadata={"date": "2025-06-30", "topic": "space"} |
| 120 | +) |
| 121 | +raw_row2 = TextRow( |
| 122 | + text="The James Webb Space Telescope captured new images of a distant galaxy.", |
| 123 | + text_source="synthetic", |
| 124 | + metadata={"date": "2025-06-29", "topic": "astronomy"} |
| 125 | +) |
| 126 | +raw_config = RawDatasetConfig(document_types=["news_article", "science_report"], topics=["space", "astronomy"]) |
| 127 | +raw_dataset = RawDataset(raw_config) |
| 128 | +raw_dataset.data_rows = [raw_row1, raw_row2] |
| 129 | + |
| 130 | +# --- UltrachatDataset Example --- |
| 131 | +from datafast.schema.data_rows import ChatRow |
| 132 | +ultrachat_row1 = ChatRow( |
| 133 | + opening_question="How can we reduce space debris?", |
| 134 | + persona="space policy expert", |
| 135 | + messages=[{"role": "user", "content": "What are current efforts to clean up space debris?"}, {"role": "assistant", "content": "There are several ongoing projects, such as RemoveDEBRIS and ClearSpace-1."}], |
| 136 | + model_id="gpt-4.1-nano", |
| 137 | + metadata={"language": "en"} |
| 138 | +) |
| 139 | +ultrachat_row2 = ChatRow( |
| 140 | + opening_question="What is the importance of the Moon missions?", |
| 141 | + persona="lunar geologist", |
| 142 | + messages=[{"role": "user", "content": "Why do we keep returning to the Moon?"}, {"role": "assistant", "content": "The Moon offers scientific insights and is a stepping stone for Mars exploration."}], |
| 143 | + model_id="gemini-2.0-flash", |
| 144 | + metadata={"language": "en"} |
| 145 | +) |
| 146 | +ultrachat_config = UltrachatDatasetConfig() |
| 147 | +ultrachat_dataset = UltrachatDataset(ultrachat_config) |
| 148 | +ultrachat_dataset.data_rows = [ultrachat_row1, ultrachat_row2] |
| 149 | + |
| 150 | +if __name__ == "__main__": |
| 151 | + # print("Showing ClassificationDataset example...") |
| 152 | + # inspect_classification_dataset(classification_dataset) |
| 153 | + # print("Showing MCQDataset example...") |
| 154 | + # inspect_mcq_dataset(mcq_dataset) |
| 155 | + # print("Showing PreferenceDataset example...") |
| 156 | + # inspect_preference_dataset(preference_dataset) |
| 157 | + # print("Showing RawDataset example...") |
| 158 | + # inspect_raw_dataset(raw_dataset) |
| 159 | + # print("Showing UltrachatDataset example...") |
| 160 | + # inspect_ultrachat_dataset(ultrachat_dataset) |
0 commit comments