Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Verbal steering: “much brighter, slightly less saturated”#
People comment while they choose. easyiec turns comments into search
directions: each problem names semantic axes (brighter, more
contrast, warmer …) and linguistic hedges scale the step in the manner
of Zadeh’s (1972) hedges as operators on fuzzy sets — very and much
concentrate (stronger move), slightly and a bit dilate, less and not
negate. With a language model connected, free comments outside the vocabulary
are mapped to parameter changes as well.
Parsing comments#
import matplotlib.pyplot as plt
import easyiec as ei
from easyiec.evaluators import VerbalSteering
from easyiec.evaluators.steering import parse_hedged_phrases
from easyiec.problems import ImageEnhancement
from easyiec.strategies import InteractiveGA
problem = ImageEnhancement()
print(sorted(problem.semantic_axes))
for c in ["much brighter, but slightly less contrast", "a bit warmer and not so saturated", "lift the shadows a lot"]:
print(f"{c!r:45s} -> {parse_hedged_phrases(c, problem.semantic_axes)}")
vs = VerbalSteering(problem, step=0.12)
d = vs.direction("much brighter, but slightly less contrast")
print({k: round(float(v), 3) for k, v in zip(problem.space.names, d) if v != 0})
['brighter', 'cooler', 'darker', 'flatter', 'lift the shadows', 'more contrast', 'more muted', 'more saturated', 'more vignette', 'more vivid', 'recover highlights', 'sharper', 'softer', 'warmer']
'much brighter, but slightly less contrast' -> [('brighter', 2.0), ('more contrast', -0.4)]
'a bit warmer and not so saturated' -> [('warmer', 0.5), ('more saturated', -1.0)]
'lift the shadows a lot' -> [('lift the shadows', 2.0)]
{'exposure': 0.24, 'contrast': -0.048}
A user who comments#
The simulated user compares the chosen image with its target and says what
should change (“much warmer”, “lift the shadows a lot”). The same sessions
with the comments ignored (steering=False) are the baseline. With small
galleries of four images, where each selection carries little information,
the comments speed up the search noticeably (eight seeds).
from easyiec.validation import curve_frame # noqa: E402
results, labels = [], []
for seed in range(8):
for name, steer in [("selections + comments", None), ("selections only", False)]:
user = ei.SimulatedUser(problem, target="random", noise=0.04, comments=1.0, seed=seed)
results.append(ei.run(problem, InteractiveGA(pop_size=4), user, generations=10, seed=seed, steering=steer))
labels.append(name)
print([r.feedback.comment for r in results[0].log.records if r.feedback.comment][:6])
ei.viz.plot_convergence(curve_frame(results, labels=labels), title="photo enhancement, galleries of four")

['much cooler', 'much cooler', 'lift the shadows a lot', 'much sharper', 'much sharper', 'much softer']
<Axes: title={'center': 'photo enhancement, galleries of four'}, xlabel='n items', ylabel='best ground-truth utility'>
What the commenting user saw#
ei.viz.plot_history(results[0].log, problem, steps=[0, 3, 6, 9], max_items=4, size=1.1)
plt.show()

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