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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qa_generator-0.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qa_generator-0.1.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file qa_generator-0.1.0.tar.gz.

File metadata

  • Download URL: qa_generator-0.1.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for qa_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ce97170df66539723de30ad3d2348f0df3d710000833de22dedcf1b11b3fe53
MD5 604338869110c6df1c57d1d75c614a01
BLAKE2b-256 a3d919d12117220ee9675471d1f659974e10a63359da70da9574c0937f300e10

See more details on using hashes here.

File details

Details for the file qa_generator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qa_generator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for qa_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 097ddff0a083e1640d225e1c1da45f6ac0b8ccf33d01fa1638cbc9c5187bee1b
MD5 6de2454b3127a0e2a06346903157e6a0
BLAKE2b-256 45d2b2de7ba0b899b7145dcffb2595614b89cea686dbdce2da8b8b59da15678a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page