Skip to main content

Algorithmic generation of rich, plot-like style descriptions for AI music systems

Project description

Metaphor Machine

Python 3.10+ License: MIT Code style: ruff

Algorithmic generation of rich, plot-like style descriptions for AI music systems.

The Metaphor Machine produces structured 5-slot "metaphors" that guide AI music generators (Suno, Producer.ai, Udio) toward specific textures, dynamics, and emotional arcs—transforming simple genre labels into cinematic sound narratives.

What is a "Metaphor"?

A metaphor is a short, evocative description that behaves like a mini-plot for a musical track:

cinematic pop-ballad, whispered bedside confessions, slow-bloom piano harmonies,
bedroom-lamp reverb haze, fragile-hope heartbeat

Each metaphor consists of 5 slots:

Slot Purpose Example
Genre Anchor Base genre/era/style darkwave electro
Intimate Gesture Vocal/lead behavior whispered confessions
Dynamic Tension Motion through time slow-bloom harmonies
Sensory Bridge Environment/space/lens neon-alley reverb haze
Emotional Anchor Inner feeling heartbreak crescendo

Why Use It?

When tested with Suno v5.0 and Producer.ai FUZZ-2.0-Pro:

  • 100% success rate producing rich vocal textures and "songs in unknown language" effects
  • Dramatically more varied outputs than bare genre labels
  • Reproducible results via seed-based generation
  • Systematic exploration of the vast combinatorial space

Installation

# From PyPI (when published)
pip install metaphor-machine

# From source
git clone https://github.com/metaphor-machine/metaphor-machine.git
cd module
pip install -e ".[dev]"

Quick Start

Python API

from metaphor_machine import MetaphorGenerator, StyleComponents

# Load component pools
components = StyleComponents.from_yaml("style_components.yaml")

# Create generator with seed for reproducibility
generator = MetaphorGenerator(components, seed=42)

# Generate a single metaphor
metaphor = generator.generate_single()
print(metaphor)
# → darkwave electro, whispered mantras, spiraling synths, neon-alley reverb, dread crescendo

# Generate a 3-act chain (Intro → Mid → Outro)
chain = generator.generate_chain()
print(chain.to_suno_style())
# → Intro: cinematic orchestral, ... → Mid: voice soars... → Outro: melody dissolves...

# Generate a diverse batch
batch = generator.generate_batch(10, enforce_diversity=True)

Command Line

# Single metaphor
metaphor generate --seed 42

# 3-act chain
metaphor chain --seed 42 --format suno

# Diverse batch
metaphor batch --count 10 --min-distance 3 --format json

# Explore seeds around a known good value
metaphor explore --seed 42 --range 10

# Show pool statistics
metaphor info

Configuration

style_components.yaml

The style_components.yaml file defines all component pools:

genre:
  eras:
    - lo-fi
    - darkwave
    - cinematic
    # ...
  subgenres:
    lo-fi:
      - boom-bap
      - chill-hop
    # ...

intimate_gesture:
  intensity_adjectives:
    energy:
      - whispered
      - hushed
      - breathy
    # ...
  delivery_nouns:
    spoken:
      - confessions
      - murmurs
    # ...

# ... (dynamic_tension, sensory_bridge, emotional_anchor)

Generator Configuration

from metaphor_machine import GeneratorConfig, DiversityConfig

config = GeneratorConfig(
    seed=42,                           # Random seed for reproducibility
    genre_hint="darkwave",             # Bias toward specific genre
    diversity=DiversityConfig(
        min_hamming_distance=3,        # Min slots different between batch items
        max_retries=100,               # Attempts before giving up
        allow_partial=True,            # Return partial batch on failure
    ),
)

generator = MetaphorGenerator(components, config=config)

Key Features

Seed-Based Reproducibility

Same seed + same components = same outputs:

gen1 = MetaphorGenerator(components, seed=42)
gen2 = MetaphorGenerator(components, seed=42)

assert str(gen1.generate_single()) == str(gen2.generate_single())

Diversity Constraints

Ensure batch variety via Hamming distance (count of differing slots):

batch = generator.generate_batch(10, enforce_diversity=True)
# All pairs differ in at least 3 of 5 slots

3-Act Chains

Generate complete track arcs:

chain = generator.generate_chain()
# Intro: how it begins
# Mid: the peak/chorus
# Outro: the resolution

print(chain.to_suno_style(separator=" → "))

Platform Formatting

from metaphor_machine.utils.formatting import format_for_suno, format_for_producer_ai

# Suno (120 char limit)
suno_style = format_for_suno(metaphor)

# Producer.ai (longer prompts allowed)
producer_prompt = format_for_producer_ai(chain)

Development

Setup

git clone https://github.com/metaphor-machine/metaphor-machine.git
cd metaphor-machine
pip install -e ".[dev]"
pre-commit install

Testing

# Run all tests
pytest

# With coverage
pytest --cov=metaphor_machine --cov-report=html

# Type checking
mypy src/metaphor_machine

Code Quality

# Lint and format
ruff check src tests
ruff format src tests

Architecture

src/metaphor_machine/
├── __init__.py           # Package exports
├── core/
│   ├── metaphor.py       # Data structures (Metaphor, MetaphorChain, etc.)
│   └── generator.py      # MetaphorGenerator class
├── schemas/
│   ├── components.py     # Pydantic models for style_components.yaml
│   └── config.py         # GeneratorConfig and related
├── cli/
│   └── main.py           # Click CLI implementation
└── utils/
    ├── formatting.py     # Platform-specific formatters
    └── validation.py     # YAML validation utilities

Roadmap

  • Phase 1 ✅ Core package structure, CLI, tests
  • Phase 2 🔜 Optimization layer (genetic algorithms, Bayesian optimization)
  • Phase 3 🔜 Learning layer (Markov chains on successful prompts, embeddings)
  • Phase 4 🔜 Platform integrations, analytics dashboard

Contributing

Contributions welcome! Please read our contributing guidelines and submit PRs.

License

MIT License - see LICENSE for details.

Acknowledgments

  • Inspired by community discoveries on r/SunoAI and AI music Discord servers
  • Built on research into transformer-based music generation
  • Component pools refined through 400+ generation tests

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

metaphor_machine-0.1.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

metaphor_machine-0.1.0-py3-none-any.whl (27.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: metaphor_machine-0.1.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for metaphor_machine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f07519c030094d35f91bb9f56d4183c864f377c476b36ab86f1764e6db7d9822
MD5 71e5afe6abcc5fcc641f489bef52207f
BLAKE2b-256 c4594c0aeaadd4e57be98a712aa41d29a57e95c659d4e9d32e7a7861d9b7a8ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for metaphor_machine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5092d6607d333921951c8ea516ca63d93e366a64af3465815d7b5ece71fec06e
MD5 40d509dda4f3320d66a5c753e61bc4b2
BLAKE2b-256 c1cc76f0205d43afda1be01e1c0d691ab6d40ebb184e9393a2ad5c3edd6fb1d3

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