Orensomekh commited on
Commit
a6ecfb9
·
verified ·
1 Parent(s): a9800e5

Update Operational_Instructions/create-submission-result.ipynb

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