🛠Creating Custom Datasets
Build datasets from your own QA data.
Document Structure
from rankify.dataset.dataset import Document, Question, Answer, Context
# Create a document
doc = Document(
question=Question("What is Python?"),
answers=Answer(["A programming language", "A high-level language"]),
contexts=[
Context(
text="Python is a high-level programming language.",
id="1",
title="Python (programming)",
score=0.95
),
]
)
From JSON/JSONL
import json
# Load custom data
with open("my_data.jsonl") as f:
data = [json.loads(line) for line in f]
documents = []
for item in data:
doc = Document(
question=Question(item["question"]),
answers=Answer(item["answers"]),
contexts=[
Context(text=ctx["text"], id=ctx["id"])
for ctx in item.get("contexts", [])
]
)
documents.append(doc)