Orensomekh commited on
Commit
66fa4d8
·
verified ·
1 Parent(s): 3dd8550

Upload create-submission-result 1.ipynb

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