Beyond images: melodies and slogans#

The evaluator of a melody listens; the evaluator of a slogan reads. Melody evolves 16-step melodies in a chosen scale (GenJam of Biles, 1994, evolved jazz solos interactively); a gallery shows them as piano rolls and wav_bytes() renders them as sound for a notebook player. TextDesign evolves slogans from templates or, with a language model connected, lets the model propose variations of the chosen ones — an LLM acting as the variation operator while the person (or another model) judges.

Melodies#

import matplotlib.pyplot as plt

import easyiec as ei
from easyiec.problems import Melody, TextDesign
from easyiec.strategies import InteractiveGA

problem = Melody()
user = ei.SimulatedUser(problem, target="random", noise=0.03, seed=3)
res = ei.run(problem, InteractiveGA(pop_size=6), user, generations=10, seed=3)
ei.viz.plot_history(res.log, problem, steps=[0, 9], max_items=6, size=1.3)
audio = problem.wav_bytes(res.best.genome)       # IPython.display.Audio(audio) plays it in a notebook
print(f"{len(audio)} bytes of WAV;", problem.describe(res.best.genome))
plot 06 music and text
236304 bytes of WAV; D# dorian, 93 bpm, 16 steps; notes with lengths in steps: D#5(1) C#5(1) A#4(1) F#5(1) F#4(1) F5(1) F#5(1) C#6(1) G#4(1) C#6(1) A#4(1) F4(1) G#5(1) F5(2)

Slogans from templates#

Without a language model the variation operator recombines template phrases; the simulated reader prefers short, positive slogans that use the keywords.

text = TextDesign(topic="the open day of a university of technology", keywords=("future", "together", "discover"))
reader = ei.SimulatedUser(text, target="default", noise=0.03, seed=1)
res_t = ei.run(text, InteractiveGA(pop_size=6), reader, generations=8, seed=1)
for r in (res_t.log.records[0], res_t.log.records[-1]):
    print([text.describe(it.genome) for it in r.query.items][:3])
ax = ei.viz.plot_anytime(res_t, label="slogans")
ax.set_title("slogan design with a simulated reader", fontsize=9)
plt.show()
slogan design with a simulated reader
['Knowledge. discovery. Pannonia.', 'Shape the careers for real', 'Where engineering meets Veszprém']
['Discover the minds today', 'Discover minds minds for together', 'Discover the minds boldly']

Total running time of the script: (0 minutes 0.650 seconds)

Gallery generated by Sphinx-Gallery