Skip to main content
duktr logo

deduct + induct via LLMs

duktr is an LLM-powered Python package for dynamic concept mining and mixed-membership (multi-label) assignment/clustering over text. It maintains an evolving catalog of concepts and, for each input text, returns the set of concepts that describe it, reusing existing concepts where possible and introducing new concepts when needed.

This is useful when the concept set cannot be pre-defined and will evolve over time (e.g., news topics, issues in tickets, patients’ symptoms, canonical product identities). You define what a “concept” means for your use case, and duktr provides the flexibility to extract the concepts you have in mind to cluster textual information based on the specified concept.

Demo


Features

  • Mixed-membership labeling: each text can map to zero, one, or many concepts.
  • Dynamic concept discovery: concepts are discovered from data and the catalog grows over time.
  • Catalog-aware prompting: prompts reuse of existing concepts to avoid drift/duplication and to support clustering.
  • Scales to large catalogs: progressive partitioning keeps LLM inputs bounded as the catalog grows.
  • Pluggable LLM backends: OpenAI, Gemini, or a custom Python function (including your LLM of choice, e.g., Hugging Face).
  • Advantage over traditional clustering: Leverages LLM reasoning to capture semantic similarity beyond surface-level text features and density-based methods (e.g., DBSCAN), enabling finer-grained and more subtle concepts and better performance in low-density settings.

Installation

pip install duktr

Quick Start

from duktr import ConceptMiner, GeminiProvider

# Initialize a miner that extracts "symptom" as the target concept from text records.
miner = ConceptMiner(
    llm=GeminiProvider(api_key="YOUR_API_KEY"),
    task="Extract the symptom(s) of the patient from their record.",
    concept="symptom",
    rules="""
    - Use short noun phrases (2–6 words)
    - Symptom(s) must be independent; no duplicates
    - Output in English
    """,
)

# Example inputs (note: the third record paraphrases the first).
texts = [
     "Patient reports frequent headaches and occasional dizziness.",
     "The individual is experiencing shortness of breath during exertion.",
     "The patient describes recurrent head pain along with vertigo." # paraphrased version of first text
]

# Mine concepts per text.
per_text_concepts = miner.mine(texts)

print(per_text_concepts)  # concepts found in each record
print(miner.catalog)      # global catalog across all records  

Expected output:

[{"Headache", "Dizziness"}, {"Shortness of breath"}, {"Headache", "Dizziness"}]
{"Headache", "Dizziness", "Shortness of breath"}

Notes:

  • There are multiple ways to configure the prompt used by the ConceptMiner. See the documentation for more details.
  • Runtime is mainly determined by the computational speed of the underlying LLM.
  • Test different prompt templates and rules with a small sample of your data to see what works best for your use case before running on the full dataset.

Documentation

For more detailed information, see the full documentation.


License and contributing

  • License: MIT License. See the LICENSE file for full terms.
  • Contributing: Issues and pull requests are welcome.

Release files for duktr 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 duktr 0.1.0
File Size Uploaded
duktr-0.1.0.tar.gz 15.2 kB Details

Built distribution (wheel)

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

Total release size: 27.3 kB

Release files / duktr-0.1.0.tar.gz

Download URL duktr-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ab6fc4b3be0cc18d666413c6c41cb7d2477bb2ece9355ef0051fa905924fc662
BLAKE2b-256 checksum
How to use checksums
34d8cea506e6cd3b941150c66359604dc4f1ddb876a12d2f0afd658981977716
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

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

Download URL duktr-0.1.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15c236534a56e7d16656dbb16d2c10fccbc9813a35031db1055599295c68899d
BLAKE2b-256 checksum
How to use checksums
295529a2f4bcf899a319559bf6232a751d8f0a4559e58b7b79621474c49b4301
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

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