Spaces:
Running
Running
Update Operational_Instructions/create-submission-result.ipynb
Browse files
Operational_Instructions/create-submission-result.ipynb
CHANGED
|
@@ -1,68 +1,98 @@
|
|
| 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 |
-
"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}")
|