.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_validation/plot_05_compare_evaluators.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_05_compare_evaluators.py: A judge-substitution study ========================== Before an AI judge replaces people in a session, the same queries should be answered by both, and four questions answered: How often do they agree? How often is each right (where a ground truth exists)? Does the AI's reported uncertainty predict its errors — the property hybrid escalation relies on? What does each answer cost? :func:`~easyiec.validation.compare_evaluators` runs such a study. .. GENERATED FROM PYTHON SOURCE LINES 14-19 Segmentation quality with a ground truth ---------------------------------------- :class:`~easyiec.problems.ImageSegmentation` knows the true cell mask, so the Dice coefficient is an objective oracle. The panel asks a careful and a hurried simulated person, two mock AI judges and a three-persona panel. .. GENERATED FROM PYTHON SOURCE LINES 19-39 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.evaluators import LLMJudge, MockJudgeClient, Panel from easyiec.problems import ImageSegmentation from easyiec.validation import compare_evaluators problem = ImageSegmentation() dice = problem.utility evaluators = { "careful person": ei.SimulatedUser(problem, target="default", noise=0.03, seed=1), "hurried person": ei.SimulatedUser(problem, target="default", noise=0.12, lapse=0.1, seed=2), "good AI": LLMJudge(MockJudgeClient(dice, score_on="genome", noise=0.05, seed=3), problem, image_size=48), "weak AI": LLMJudge(MockJudgeClient(dice, score_on="genome", noise=0.2, seed=4), problem, image_size=48), "AI panel (3)": Panel([LLMJudge(MockJudgeClient(dice, score_on="genome", noise=0.2, seed=10 + k), problem, image_size=48) for k in range(3)]), } study = compare_evaluators(problem, evaluators, n_queries=40, kind="pairs", n_items=4, reference="careful person", oracle=dice, seed=0) print(study.table().round(3).to_string(index=False)) .. rst-class:: sphx-glr-script-out .. code-block:: none evaluator oracle_accuracy cost_seconds agreement_with_careful person uncertainty_auroc cost_tokens_in cost_tokens_out cost_usd cost_calls careful person 0.862 1.110 NaN NaN NaN NaN NaN NaN hurried person 0.775 1.107 0.762 NaN NaN NaN NaN NaN good AI 0.788 4.128 0.738 0.950 184400.0 2720.0 0.0 80.0 weak AI 0.631 2.761 0.694 0.864 184400.0 2720.0 0.0 80.0 AI panel (3) 0.762 8.261 0.712 0.722 553200.0 8160.0 0.0 240.0 .. GENERATED FROM PYTHON SOURCE LINES 40-42 Agreement between evaluators ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python ei.viz.plot_agreement(study.agreement, title="share of duels decided alike") .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_05_compare_evaluators_001.png :alt: share of duels decided alike :srcset: /auto_examples/04_validation/images/sphx_glr_plot_05_compare_evaluators_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 45-50 Accuracy and the value of uncertainty ------------------------------------- AUROC of 0.5 means the reported uncertainty says nothing about errors; the debiased AI judges flag their own uncertain duels, which is what makes escalation to a person efficient. .. GENERATED FROM PYTHON SOURCE LINES 50-63 .. code-block:: Python tab = study.table().set_index("evaluator") fig, axes = plt.subplots(1, 2, figsize=(10, 3)) axes[0].barh(tab.index, tab["oracle_accuracy"], color="#285780") axes[0].set_xlim(0.5, 1) axes[0].set_title("agreement with the Dice oracle", fontsize=9) if "uncertainty_auroc" in tab: au = tab["uncertainty_auroc"].dropna() axes[1].barh(au.index, au, color="#D55E00") axes[1].axvline(0.5, color="0.5", ls="--", lw=0.8) axes[1].set_xlim(0, 1) axes[1].set_title("AUROC of uncertainty for predicting errors", fontsize=9) fig.tight_layout() plt.show() .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_05_compare_evaluators_002.png :alt: agreement with the Dice oracle, AUROC of uncertainty for predicting errors :srcset: /auto_examples/04_validation/images/sphx_glr_plot_05_compare_evaluators_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 18.695 seconds) .. _sphx_glr_download_auto_examples_04_validation_plot_05_compare_evaluators.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_05_compare_evaluators.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_compare_evaluators.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_compare_evaluators.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_compare_evaluators.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_