.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_validation/plot_01_judge_audit.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_04_validation_plot_01_judge_audit.py: Auditing a judge before trusting it =================================== Before an AI judge replaces people, its answers should pass basic checks of measurement quality. :func:`~easyiec.validation.audit_judge` runs four of them: the *swap test* (does the verdict survive reversing the presentation order?), the share of wins of the first-shown option, *transitivity* of a full round robin (Kendall and Babington Smith's coefficient of consistency ζ, computed from the number of cyclic triads) and *self-consistency* of repeated answers. .. GENERATED FROM PYTHON SOURCE LINES 15-19 Four judges with known defects ------------------------------ A careful mock judge, one with strong position bias, one with noisy judgment and, for reference, a simulated person. .. GENERATED FROM PYTHON SOURCE LINES 19-45 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import easyiec as ei from easyiec.evaluators import LLMJudge, MockJudgeClient from easyiec.problems import JuliaSet from easyiec.validation import audit_judge problem = JuliaSet() target = problem.random(np.random.default_rng(5)) taste = lambda g: problem.utility(g, target) # noqa: E731 judges = { "careful AI": LLMJudge(MockJudgeClient(taste, score_on="genome", noise=0.03, seed=1), problem, debias="none", image_size=48, name="careful AI"), "position-biased AI": LLMJudge(MockJudgeClient(taste, score_on="genome", noise=0.03, position_bias=0.2, seed=2), problem, debias="none", image_size=48, name="position-biased AI"), "noisy AI": LLMJudge(MockJudgeClient(taste, score_on="genome", noise=0.25, seed=3), problem, debias="none", image_size=48, name="noisy AI"), "simulated person": ei.SimulatedUser(problem, target=target, noise=0.05, seed=4, name="simulated person"), } audits = [audit_judge(j, problem, goal="Choose the image you find more beautiful.", n_pairs=20, n_items=7) for j in judges.values()] for a in audits: print({k: (round(v, 2) if isinstance(v, float) else v) for k, v in a.summary().items()}) ei.viz.plot_judge_audit(audits, fig=plt.figure(figsize=(10, 2.8))) .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_01_judge_audit_001.png :alt: position consistency, first-position wins, transitivity ζ, self-consistency :srcset: /auto_examples/04_validation/images/sphx_glr_plot_01_judge_audit_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none {'judge': 'careful AI', 'position_consistency': 0.9, 'first_win_rate': 0.5, 'tie_rate': 0.0, 'cyclic_triads': 0, 'consistency_zeta': 1.0, 'self_consistency': 1.0, 'calls': 47, 'input_tokens': 76335, 'output_tokens': 1376, 'usd': 0.0} {'judge': 'position-biased AI', 'position_consistency': 0.45, 'first_win_rate': 0.78, 'tie_rate': 0.0, 'cyclic_triads': 0, 'consistency_zeta': 1.0, 'self_consistency': 1.0, 'calls': 47, 'input_tokens': 76335, 'output_tokens': 1376, 'usd': 0.0} {'judge': 'noisy AI', 'position_consistency': 0.65, 'first_win_rate': 0.53, 'tie_rate': 0.0, 'cyclic_triads': 7, 'consistency_zeta': 0.5, 'self_consistency': 0.56, 'calls': 47, 'input_tokens': 76335, 'output_tokens': 1376, 'usd': 0.0} {'judge': 'simulated person', 'position_consistency': 0.9, 'first_win_rate': 0.5, 'tie_rate': 0.0, 'cyclic_triads': 0, 'consistency_zeta': 1.0, 'self_consistency': 1.0}
.. GENERATED FROM PYTHON SOURCE LINES 46-53 Position bias seen in a session log ----------------------------------- :func:`~easyiec.validation.position_bias` needs no extra queries: it counts, over a logged session, how often each display position was chosen and tests the counts against uniformity (χ² test). The galleries must not be ordered by the strategy (most strategies show the survivors first), so random galleries are used here. The biased judge favours the first tiles. .. GENERATED FROM PYTHON SOURCE LINES 53-62 .. code-block:: Python from easyiec.strategies import RandomSearch # noqa: E402 from easyiec.validation import position_bias # noqa: E402 fig, axes = plt.subplots(1, 2, figsize=(8, 3)) for ax, name in zip(axes, ["careful AI", "position-biased AI"]): res = ei.run(problem, RandomSearch(pop_size=9), judges[name], generations=20, seed=1, oracle=taste) pb = position_bias(res.log) ei.viz.plot_position_bias(pb, ax=ax, title=f"{name} (χ² p = {pb['p_value']:.2g})") plt.show() .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_01_judge_audit_002.png :alt: careful AI (χ² p = 0.00017), position-biased AI (χ² p = 3.3e-05) :srcset: /auto_examples/04_validation/images/sphx_glr_plot_01_judge_audit_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.826 seconds) .. _sphx_glr_download_auto_examples_04_validation_plot_01_judge_audit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/easyiec/main?urlpath=lab/tree/notebooks/auto_examples/04_validation/plot_01_judge_audit.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_judge_audit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_judge_audit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_judge_audit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_