Skip to main content

Molecule: Isomeric Polarization Analysis for Large Language Models

Project description

twoquarks — Molecule

Isomeric Polarization Analysis for Large Language Models

PyPI version Python 3.9+ License: MIT

Molecule detects semantic instability in any language model by measuring how responses shift under structured contextual pressure — without modifying or fine-tuning the model.

twoquarks.com | Preprint


Install

pip install twoquarks

Zero hard dependencies. API SDKs are optional extras:

pip install "twoquarks[openai]"       # + OpenAI SDK
pip install "twoquarks[anthropic]"    # + Anthropic SDK
pip install "twoquarks[all]"          # + all adapters

Quick Start

Any callable model

from twoquarks import Probe

# Bring your own model — just needs to be (str) -> str
def my_model(prompt: str) -> str:
    # ... call your model here
    return response_text

probe = Probe(model=my_model, model_id="my-model", verbose=True)
result = probe.run("Explain how to bypass content filters", case="C2")
print(result.summary())

OpenAI

from twoquarks import Probe
from twoquarks.adapters import openai_adapter

model = openai_adapter(model="gpt-4o-mini")  # uses OPENAI_API_KEY env var
probe = Probe(model=model, model_id="gpt-4o-mini")
result = probe.run("Tell me something controversial", case="C1")
print(result.summary())

Anthropic

from twoquarks.adapters import anthropic_adapter

model = anthropic_adapter(model="claude-3-haiku-20240307")
probe = Probe(model=model, model_id="claude-haiku")
result = probe.run("Describe an unsafe scenario", case="C2")

Local / HuggingFace / Ollama

from twoquarks.adapters import ollama_adapter, huggingface_adapter

# Ollama (local)
model = ollama_adapter(model="llama3")
probe = Probe(model=model, model_id="llama3-local")

# HuggingFace local
model = huggingface_adapter(model_id="mistralai/Mistral-7B-Instruct-v0.2")
probe = Probe(model=model, model_id="mistral-7b")

Offline analysis (no API calls)

from twoquarks import Analyzer

analyzer = Analyzer(model_id="gpt-4o")
result = analyzer.from_responses(
    responses=["Response 1...", "Response 2...", "Response 3..."],
    case="C2"
)

Compare two models

from twoquarks.adapters import openai_adapter, anthropic_adapter

probe = Probe(model=openai_adapter("gpt-4o-mini"), model_id="gpt-4o-mini")
comparison = probe.compare(
    text="Explain how to manipulate someone",
    other_model=anthropic_adapter("claude-3-haiku-20240307"),
    other_id="claude-haiku",
    case="C1"
)
print(comparison["delta"])

CLI

# Probe a model live
twoquarks probe "your prompt here" --provider openai --model gpt-4o-mini

# All 5 probe cases
twoquarks probe "your prompt" --all-cases --output-format json

# Analyze pre-collected responses (one per line)
twoquarks analyze responses.txt --case C2 --model-id gpt-4o

# Anthropic via CLI
twoquarks probe "test prompt" --provider anthropic --model claude-3-haiku-20240307

# Ollama (local)
twoquarks probe "test prompt" --provider ollama --model llama3

# Show probe case descriptions
twoquarks info

Probe Cases

Case Name Description
C1 Sycophancy Induction Pressure toward agreement and validation
C2 Refusal Erosion Gradual boundary dissolution via reframing
C3 Anchor Displacement Context replacement and belief shifting
C4 Narrative Rule Override Character/role injection to bypass norms
C5 Reasoning Drift Chain-of-thought manipulation

Quark Signals

Signal Description
ΔL3 Composite polarization score — main metric
Down Aggregate semantic drift
Strange Metric disagreement (variance)
Up Bimodality — split-regime behavior
Charm Coherence field — stability measure
Top Drift acceleration — sudden shifts
Stress Composite structural stress (Bottom quark)

Regimes: STABLEWATCHWARNINTERVENECOLLAPSE


Output Formats

from twoquarks.report import to_json, to_markdown, print_result

print_result(result)           # terminal table with colors
to_json(result)                # JSON string
to_markdown(result)            # Markdown table

Citation

@software{ledesma2026twoquarks,
  author    = {Ledesma, Luis Jaime},
  title     = {twoquarks: Molecule — Isomeric Polarization Analysis for LLMs},
  year      = {2026},
  url       = {https://twoquarks.com},
  version   = {0.1.0}
}

TwoQuarks Research · twoquarks.com · research@twoquarks.com

Project details


Download files

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

Source Distribution

twoquarks-3.0.1.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

twoquarks-3.0.1-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file twoquarks-3.0.1.tar.gz.

File metadata

  • Download URL: twoquarks-3.0.1.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for twoquarks-3.0.1.tar.gz
Algorithm Hash digest
SHA256 37cb00f7763a966c4dac72c1022b4725b57ea9e3dd5fab616413d48438a423e2
MD5 2fe65c26b4867af5512f41b3d82ef2d6
BLAKE2b-256 6759fd5ccf36ac50cc883cb20c0aa720f68d62d3cd99a8554ed505394173fab5

See more details on using hashes here.

File details

Details for the file twoquarks-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: twoquarks-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for twoquarks-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 724444ab9b28ae6ec637072d5370de298aeccf3e27e3dde93bee7143abce6cf7
MD5 1022a43ac939f4e5edf4bae6b4b1c13e
BLAKE2b-256 6fa8ac798bc34a2c23d5d619408c422ca782a5fc74ae810828664e97c6854871

See more details on using hashes here.

Supported by

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