Skip to main content

QA Generator

Generate question-answer pairs from text using rule-based and LLM approaches.

Installation

pip install qa-generator

Quick Start

Rule-based Generation

from qa_generator import QAGenerator

qa_gen = QAGenerator()
text = "Python is a programming language created by Guido van Rossum in 1991."
qa_pairs = qa_gen.generate(text)

for question, answer in qa_pairs:
    print(f"Q: {question}")
    print(f"A: {answer}")

LLM-based Generation

from qa_generator import LLMQAGenerator

qa_gen = LLMQAGenerator(
    api_key="your-api-key",
    model="gpt-3.5-turbo"
)
qa_pairs = qa_gen.generate(text, max_pairs=5, difficulty="medium")

Easy Provider Setup

from qa_generator import create_qa_generator_from_provider

qa_gen = create_qa_generator_from_provider("openai")   # OpenAI
qa_gen = create_qa_generator_from_provider("ollama")   # Local Ollama
qa_gen = create_qa_generator_from_provider("together") # Together AI

Dataset Generation

from qa_generator import DatasetGenerator

dataset_gen = DatasetGenerator()
dataset_splits = dataset_gen.generate_comprehensive_dataset(
    total_samples=1000,
    use_llm=True
)

# Export for Hugging Face
file_paths = dataset_gen.export_to_huggingface_format(
    dataset_splits, 
    dataset_name="my_qa_dataset"
)

Features

  • Rule-based: Template questions with entity recognition
  • LLM-based: High-quality questions via language models
  • Multi-provider: OpenAI, Ollama, Together, Groq, local endpoints
  • Dataset creation: Hugging Face compatible exports
  • Difficulty levels: Easy, medium, hard
  • Question types: Factual, conceptual, analytical

Requirements

Python 3.8+, NLTK, requests

Metadata

Release files for qa-generator 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qa-generator 0.1.0
File Size Uploaded
qa_generator-0.1.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qa-generator 0.1.0
File Interpreter ABI Platform
qa_generator-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / qa_generator-0.1.0.tar.gz

Download URL qa_generator-0.1.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6ce97170df66539723de30ad3d2348f0df3d710000833de22dedcf1b11b3fe53
BLAKE2b-256 checksum
How to use checksums
a3d919d12117220ee9675471d1f659974e10a63359da70da9574c0937f300e10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / qa_generator-0.1.0-py3-none-any.whl

Download URL qa_generator-0.1.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
097ddff0a083e1640d225e1c1da45f6ac0b8ccf33d01fa1638cbc9c5187bee1b
BLAKE2b-256 checksum
How to use checksums
45d2b2de7ba0b899b7145dcffb2595614b89cea686dbdce2da8b8b59da15678a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page