Spaces:
Sleeping
Sleeping
Upload create-submission-result 1.ipynb
Browse files
Operational_Instructions/create-submission-result 1.ipynb
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "a5e875f5",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [],
|
| 9 |
+
"source": [
|
| 10 |
+
"import pandas as pd\n",
|
| 11 |
+
"import jsonschema\n",
|
| 12 |
+
"from jsonschema import validate\n",
|
| 13 |
+
"import json\n",
|
| 14 |
+
"\n",
|
| 15 |
+
"# LiveRAG Answer JSON schema: \n",
|
| 16 |
+
"json_schema = \"\"\"\n",
|
| 17 |
+
"{ \n",
|
| 18 |
+
"\"$schema\": \"http://json-schema.org/draft-07/schema#\", \n",
|
| 19 |
+
"\n",
|
| 20 |
+
" \"title\": \"Answer file schema\", \n",
|
| 21 |
+
" \"type\": \"object\", \n",
|
| 22 |
+
" \"properties\": { \n",
|
| 23 |
+
" \"id\": { \n",
|
| 24 |
+
" \"type\": \"integer\", \n",
|
| 25 |
+
" \"description\": \"Question ID\" \n",
|
| 26 |
+
" }, \n",
|
| 27 |
+
" \"question\": { \n",
|
| 28 |
+
" \"type\": \"string\", \n",
|
| 29 |
+
" \"description\": \"The question\" \n",
|
| 30 |
+
" }, \n",
|
| 31 |
+
" \"passages\": { \n",
|
| 32 |
+
" \"type\": \"array\", \n",
|
| 33 |
+
" \"description\": \"Passages used and related FineWeb doc IDs, ordered by decreasing importance\", \n",
|
| 34 |
+
" \"items\": { \n",
|
| 35 |
+
" \"type\": \"object\", \n",
|
| 36 |
+
" \"properties\": {\n",
|
| 37 |
+
" \"passage\": { \n",
|
| 38 |
+
" \"type\": \"string\", \n",
|
| 39 |
+
" \"description\": \"Passage text\" \n",
|
| 40 |
+
" }, \n",
|
| 41 |
+
" \"doc_IDs\": {\n",
|
| 42 |
+
" \"type\": \"array\", \n",
|
| 43 |
+
" \"description\": \"Passage related FineWeb doc IDs, ordered by decreasing importance\", \n",
|
| 44 |
+
" \"items\": { \n",
|
| 45 |
+
" \"type\": \"string\", \n",
|
| 46 |
+
" \"description\": \"FineWeb doc ID, e.g., <urn:uuid:d69cbebc-133a-4ebe-9378-68235ec9f091>\"\n",
|
| 47 |
+
" } \n",
|
| 48 |
+
" } \n",
|
| 49 |
+
" },\n",
|
| 50 |
+
" \"required\": [\"passage\", \"doc_IDs\"]\n",
|
| 51 |
+
" }\n",
|
| 52 |
+
" }, \n",
|
| 53 |
+
" \"final_prompt\": {\n",
|
| 54 |
+
" \"type\": \"string\",\n",
|
| 55 |
+
" \"description\": \"Final prompt, as submitted to Falcon LLM\"\n",
|
| 56 |
+
" },\n",
|
| 57 |
+
" \"answer\": {\n",
|
| 58 |
+
" \"type\": \"string\",\n",
|
| 59 |
+
" \"description\": \"Your answer\"\n",
|
| 60 |
+
" }\n",
|
| 61 |
+
" },\n",
|
| 62 |
+
" \"required\": [\"id\", \"question\", \"passages\", \"final_prompt\", \"answer\"]\n",
|
| 63 |
+
"}\n",
|
| 64 |
+
"\"\"\"\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"# Code that generates the output\n",
|
| 67 |
+
"answers = pd.DataFrame({\n",
|
| 68 |
+
" \"id\": [1, 2],\n",
|
| 69 |
+
" \"question\": [\"What is the capital of France?\", \"What is the capital of Germany?\"],\n",
|
| 70 |
+
" \"passages\": [\n",
|
| 71 |
+
" [\n",
|
| 72 |
+
" {\"passage\": \"Paris is the capital and most populous city of France.\",\n",
|
| 73 |
+
" \"doc_IDs\": [\"<urn:uuid:1234abcd-5678-efgh-9101-ijklmnopqrst>\", \"<urn:uuid:1234abcd-5678-efgh-9202-ijklmnopqrst>\"]},\n",
|
| 74 |
+
" {\"passage\": \"France is located in Western Europe.\",\n",
|
| 75 |
+
" \"doc_IDs\": [\"<urn:uuid:1234abcd-5678-efgh-9101-ijklmnopqrst>\"]}\n",
|
| 76 |
+
" ],\n",
|
| 77 |
+
" [\n",
|
| 78 |
+
" {\"passage\": \"Berlin is the capital of Germany.\",\n",
|
| 79 |
+
" \"doc_IDs\": [\"<urn:uuid:1234abcd-5678-efgh-9101-ijklmnopqrst>\"]}\n",
|
| 80 |
+
" ]\n",
|
| 81 |
+
" ],\n",
|
| 82 |
+
" \"final_prompt\": [\n",
|
| 83 |
+
" \"Using the following - Paris is the capital and most populous city of France - and - France is located in Western Europe - answer the question: What is the capital of France?\",\n",
|
| 84 |
+
" \"Using the following - Berlin is the capital of Germany - answer the question: What is the capital of Germany?\"\n",
|
| 85 |
+
" ],\n",
|
| 86 |
+
" \"answer\": [\"Paris\", \"Berlin\"]\n",
|
| 87 |
+
"})\n",
|
| 88 |
+
"\n",
|
| 89 |
+
"# Convert to JSON format\n",
|
| 90 |
+
"answers_json = answers.to_json(orient='records', lines=True, force_ascii=False)\n",
|
| 91 |
+
"\n",
|
| 92 |
+
"# Or just save to a file\n",
|
| 93 |
+
"answers.to_json(\"answers.jsonl\", orient='records', lines=True, force_ascii=False)\n",
|
| 94 |
+
"\n",
|
| 95 |
+
"# Load the file to make sure it is ok\n",
|
| 96 |
+
"loaded_answers = pd.read_json(\"answers.jsonl\", lines=True)\n",
|
| 97 |
+
"\n",
|
| 98 |
+
"# Load the JSON schema\n",
|
| 99 |
+
"schema = json.loads(json_schema)\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"# Validate each Answer JSON object against the schema\n",
|
| 102 |
+
"for answer in loaded_answers.to_dict(orient='records'):\n",
|
| 103 |
+
" try:\n",
|
| 104 |
+
" validate(instance=answer, schema=schema)\n",
|
| 105 |
+
" print(f\"Answer {answer['id']} is valid.\")\n",
|
| 106 |
+
" except jsonschema.exceptions.ValidationError as e:\n",
|
| 107 |
+
" print(f\"Answer {answer['id']} is invalid: {e.message}\")"
|
| 108 |
+
]
|
| 109 |
+
}
|
| 110 |
+
],
|
| 111 |
+
"metadata": {
|
| 112 |
+
"kernelspec": {
|
| 113 |
+
"display_name": "Python 3",
|
| 114 |
+
"language": "python",
|
| 115 |
+
"name": "python3"
|
| 116 |
+
},
|
| 117 |
+
"language_info": {
|
| 118 |
+
"codemirror_mode": {
|
| 119 |
+
"name": "ipython",
|
| 120 |
+
"version": 3
|
| 121 |
+
},
|
| 122 |
+
"file_extension": ".py",
|
| 123 |
+
"mimetype": "text/x-python",
|
| 124 |
+
"name": "python",
|
| 125 |
+
"nbconvert_exporter": "python",
|
| 126 |
+
"pygments_lexer": "ipython3",
|
| 127 |
+
"version": "3.13.1"
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
"nbformat": 4,
|
| 131 |
+
"nbformat_minor": 5
|
| 132 |
+
}
|