%22%22%22A%20marimo%20notebook%20that%20gets%20the%20local%20explanations%20of%20an%20EBM%20in%20several%20languages.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20os%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20polars%20as%20pl%0A%20%20%20%20from%20interpret.glassbox%20import%20ExplainableBoostingClassifier%0A%20%20%20%20from%20sklearn.datasets%20import%20fetch_openml%0A%0A%20%20%20%20from%20ebaml%20import%20(%0A%20%20%20%20%20%20%20%20DescribeEBMRequest%2C%0A%20%20%20%20%20%20%20%20ExplainInstanceRequest%2C%0A%20%20%20%20%20%20%20%20Layperson%2C%0A%20%20%20%20%20%20%20%20MissingAPIKeyError%2C%0A%20%20%20%20%20%20%20%20ModelOptions%2C%0A%20%20%20%20%20%20%20%20PromptOptions%2C%0A%20%20%20%20%20%20%20%20compute_local_facts%2C%0A%20%20%20%20%20%20%20%20describe_ebm%2C%0A%20%20%20%20%20%20%20%20explain_instance%2C%0A%20%20%20%20%20%20%20%20facts_to_texts%2C%0A%20%20%20%20)%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20DescribeEBMRequest%2C%0A%20%20%20%20%20%20%20%20ExplainInstanceRequest%2C%0A%20%20%20%20%20%20%20%20ExplainableBoostingClassifier%2C%0A%20%20%20%20%20%20%20%20Layperson%2C%0A%20%20%20%20%20%20%20%20MissingAPIKeyError%2C%0A%20%20%20%20%20%20%20%20ModelOptions%2C%0A%20%20%20%20%20%20%20%20PromptOptions%2C%0A%20%20%20%20%20%20%20%20compute_local_facts%2C%0A%20%20%20%20%20%20%20%20describe_ebm%2C%0A%20%20%20%20%20%20%20%20explain_instance%2C%0A%20%20%20%20%20%20%20%20facts_to_texts%2C%0A%20%20%20%20%20%20%20%20fetch_openml%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20os%2C%0A%20%20%20%20%20%20%20%20pl%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Explanations%20in%20your%20language%0A%0A%20%20%20%20A%20local%20explanation%20says%20*why%20the%20model%20predicted%20this%20for%20this%20person*.%20The%20reader%20of%20that%20text%20may%20not%20read%0A%20%20%20%20English.%20The%20argument%20%60language%3D%60%20of%20%60explain_instance%60%20asks%20the%20LLM%20to%20write%20the%20three%20explanations%20in%20the%20language%0A%20%20%20%20of%20the%20reader.%20It%20is%20one%20string%2C%20and%20it%20works%20with%20every%20audience.%0A%0A%20%20%20%20What%20you%20learn%20here%3A%0A%0A%20%20%20%201.%20The%20facts%20do%20not%20depend%20on%20the%20language.%20Python%20computes%20them%2C%20and%20the%20LLM%20only%20puts%20them%20in%20words.%0A%20%20%20%202.%20How%20to%20name%20a%20language%2C%20and%20how%20to%20use%20%60language%3D%60%20with%20the%20audiences%20of%20the%20package.%0A%20%20%20%203.%20The%20error%20that%20you%20meet%20when%20the%20key%20is%20missing.%0A%0A%20%20%20%20What%20you%20need%3A%20nothing%20up%20to%20the%20section%20%22Put%20it%20in%20words%22.%20After%20that%2C%20you%20need%20an%20LLM.%20The%20default%20model%20needs%0A%20%20%20%20%60OPENROUTER_API_KEY%60.%20Each%20call%20to%20the%20LLM%20sits%20behind%20a%20button%2C%20so%20you%20never%20pay%20by%20accident.%20To%20use%20another%20model%2C%0A%20%20%20%20pass%20%60model%3D%60%3A%20see%20the%20documentation%20page%20%22Choosing%20the%20model%22.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20os)%3A%0A%20%20%20%20key_from_env%20%3D%20bool(os.environ.get(%22OPENROUTER_API_KEY%22))%0A%20%20%20%20api_key_input%20%3D%20None%20if%20key_from_env%20else%20mo.ui.text(kind%3D%22password%22%2C%20label%3D%22OpenRouter%20API%20key%22%2C%20full_width%3DTrue)%0A%20%20%20%20key_status%20%3D%20(%0A%20%20%20%20%20%20%20%20mo.callout(%22Loaded%20%60OPENROUTER_API_KEY%60%20from%20the%20environment.%22%2C%20kind%3D%22success%22)%0A%20%20%20%20%20%20%20%20if%20key_from_env%0A%20%20%20%20%20%20%20%20else%20mo.vstack(%5Bmo.callout(%22%60OPENROUTER_API_KEY%60%20is%20not%20set%20in%20the%20environment.%22%2C%20kind%3D%22warn%22)%2C%20api_key_input%5D)%0A%20%20%20%20)%0A%20%20%20%20key_status%0A%20%20%20%20return%20(api_key_input%2C)%0A%0A%0A%40app.cell%0Adef%20_(api_key_input%2C%20os)%3A%0A%20%20%20%20%23%20a%20typed%20key%20only%20lives%20in%20this%20process%3B%20the%20BAML%20clients%20read%20the%20variable%20when%20they%20send%20a%20request%0A%20%20%20%20if%20api_key_input%20is%20not%20None%20and%20api_key_input.value%3A%0A%20%20%20%20%20%20%20%20os.environ%5B%22OPENROUTER_API_KEY%22%5D%20%3D%20api_key_input.value%0A%20%20%20%20has_api_key%20%3D%20bool(os.environ.get(%22OPENROUTER_API_KEY%22))%0A%20%20%20%20return%20(has_api_key%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20The%20model%20and%20the%20facts%0A%0A%20%20%20%20The%20same%20Titanic%20EBM%20as%20in%20the%20other%20notebooks%3A%20a%20binary%20classifier%20without%20interactions.%20Pick%20a%20passenger.%20The%0A%20%20%20%20facts%20below%20come%20from%20%60compute_local_facts%60%20and%20%60facts_to_texts%60.%20Neither%20function%20takes%20a%20language%2C%20because%20a%0A%20%20%20%20number%20is%20the%20same%20in%20every%20language.%20The%20language%20only%20changes%20the%20words%20around%20the%20facts.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ExplainableBoostingClassifier%2C%20fetch_openml%2C%20pl)%3A%0A%20%20%20%20%23%20The%20liac-arff%20parser%20reads%20the%20categories%20as%20text.%20The%20pandas%20parser%20of%20scikit-learn%201.9%20fails%20on%20pandas%203.1.%0A%20%20%20%20titanic%20%3D%20pl.from_pandas(fetch_openml(%22titanic%22%2C%20version%3D1%2C%20as_frame%3DTrue%2C%20parser%3D%22liac-arff%22).frame)%0A%20%20%20%20features%20%3D%20titanic.select(%22pclass%22%2C%20%22sex%22%2C%20%22age%22%2C%20%22sibsp%22%2C%20%22parch%22%2C%20%22fare%22%2C%20%22embarked%22).with_columns(%0A%20%20%20%20%20%20%20%20pl.col(%22sex%22%2C%20%22embarked%22).cast(pl.String)%2C%0A%20%20%20%20)%0A%20%20%20%20survived%20%3D%20titanic%5B%22survived%22%5D.cast(pl.String).cast(pl.Int8)%0A%20%20%20%20ebm%20%3D%20ExplainableBoostingClassifier(feature_names%3Dfeatures.columns%2C%20interactions%3D0%2C%20random_state%3D42)%0A%20%20%20%20ebm.fit(features%2C%20survived)%0A%20%20%20%20complete%20%3D%20features.drop_nulls()%0A%20%20%20%20return%20complete%2C%20ebm%0A%0A%0A%40app.cell%0Adef%20_(complete%2C%20mo)%3A%0A%20%20%20%20passenger%20%3D%20mo.ui.slider(0%2C%20len(complete)%20-%201%2C%20value%3D0%2C%20label%3D%22Passenger%22%2C%20show_value%3DTrue)%0A%20%20%20%20passenger%0A%20%20%20%20return%20(passenger%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20Layperson%2C%0A%20%20%20%20complete%2C%0A%20%20%20%20compute_local_facts%2C%0A%20%20%20%20ebm%2C%0A%20%20%20%20facts_to_texts%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20passenger%2C%0A)%3A%0A%20%20%20%20instance%20%3D%20complete.row(passenger.value%2C%20named%3DTrue)%0A%20%20%20%20facts%20%3D%20compute_local_facts(ebm%2C%20instance)%0A%20%20%20%20texts%20%3D%20facts_to_texts(facts%2C%20Layperson())%0A%20%20%20%20mo.md(f%22**The%20facts%20that%20the%20LLM%20reads**%20(for%20the%20layperson)%5Cn%5Cn%60%60%60json%5Cn%7Btexts.counterfactual%7D%5Cn%60%60%60%22)%0A%20%20%20%20return%20(instance%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20name%20a%20language%0A%0A%20%20%20%20Pass%20any%20name%20that%20the%20LLM%20knows.%20The%20package%20does%20not%20keep%20a%20list%20of%20languages%2C%20so%20a%20new%20language%20needs%20no%20new%0A%20%20%20%20release.%20The%20table%20shows%20names%20that%20work%20well%3A%0A%0A%20%20%20%20%7C%20%60language%3D%60%20%7C%20Result%20%7C%0A%20%20%20%20%7C%20---%20%7C%20---%20%7C%0A%20%20%20%20%7C%20%60%22English%22%60%20%7C%20The%20default.%20%7C%0A%20%20%20%20%7C%20%60%22French%22%60%2C%20%60%22German%22%60%2C%20%60%22Japanese%22%60%20%7C%20The%20name%20of%20the%20language%20in%20English.%20This%20is%20the%20clearest%20form.%20%7C%0A%20%20%20%20%7C%20%60%22Deutsch%22%60%2C%20%60%22%E6%97%A5%E6%9C%AC%E8%AA%9E%22%60%20%7C%20The%20name%20of%20the%20language%20in%20that%20language.%20%7C%0A%20%20%20%20%7C%20%60%22Brazilian%20Portuguese%22%60%2C%20%60%22Simplified%20Chinese%22%60%20%7C%20A%20variety%20of%20a%20language%2C%20where%20the%20variety%20matters.%20%7C%0A%20%20%20%20%7C%20%60%22formal%20German%22%60%20%7C%20A%20language%20with%20a%20register.%20%7C%0A%0A%20%20%20%20The%20package%20does%20not%20check%20the%20name.%20A%20misspelt%20name%20goes%20to%20the%20LLM%20as%20it%20is%2C%20and%20the%20LLM%20may%20guess%20the%20language%20or%0A%20%20%20%20answer%20in%20English.%20If%20the%20text%20comes%20back%20in%20the%20wrong%20language%2C%20check%20the%20spelling%20first.%0A%0A%20%20%20%20The%20facts%20and%20the%20numbers%20stay%20as%20they%20are.%20The%20instruction%20asks%20the%20LLM%20to%20keep%20every%20number%20and%20to%20translate%20the%0A%20%20%20%20names%20of%20the%20inputs%20only%20where%20the%20reader%20needs%20them.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Put%20it%20in%20words%0A%0A%20%20%20%20Now%20call%20the%20LLM.%20%60explain_instance%60%20needs%20the%20global%20explanation%20of%20the%20model%2C%20computed%20once%20with%20%60describe_ebm%60.%0A%20%20%20%20That%20is%20the%20slow%20step%3A%20one%20chain%20per%20feature%2C%20then%20a%20summary.%20The%20global%20explanation%20is%20written%20in%20English%20here%2C%20and%0A%20%20%20%20the%20local%20explanations%20are%20not%3A%20the%20argument%20%60language%3D%60%20sets%20the%20language%20of%20the%20local%20ones%20only.%20If%20you%20want%20the%0A%20%20%20%20global%20explanation%20in%20another%20language%20too%2C%20write%20it%20in%20that%20language%20and%20pass%20it%20as%20it%20is.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20describe_button%20%3D%20mo.ui.run_button(label%3D%22Describe%20the%20model%22)%0A%20%20%20%20describe_button%0A%20%20%20%20return%20(describe_button%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20DescribeEBMRequest%2C%0A%20%20%20%20PromptOptions%2C%0A%20%20%20%20describe_button%2C%0A%20%20%20%20describe_ebm%2C%0A%20%20%20%20ebm%2C%0A%20%20%20%20has_api_key%2C%0A%20%20%20%20mo%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20describe_button.value%2C%20mo.md(%22Press%20the%20button%20to%20describe%20the%20model%20first.%22))%0A%20%20%20%20mo.stop(not%20has_api_key%2C%20mo.callout(%22Enter%20your%20OpenRouter%20API%20key%20above%20first.%22%2C%20kind%3D%22warn%22))%0A%20%20%20%20dataset_description%20%3D%20(%0A%20%20%20%20%20%20%20%20%22The%20RMS%20Titanic%20sank%20in%20April%201912.%20Each%20row%20is%20a%20passenger%3B%20the%20outcome%20is%20whether%20they%20survived.%20%22%0A%20%20%20%20%20%20%20%20%22pclass%20is%20the%20ticket%20class%20(1%20first%2C%203%20third)%2C%20sibsp%20and%20parch%20count%20relatives%20aboard%2C%20%22%0A%20%20%20%20%20%20%20%20%22fare%20is%20in%201912%20pounds%2C%20embarked%20is%20the%20port%20(C%2C%20Q%20or%20S).%20%22%0A%20%20%20%20%20%20%20%20%22The%20graphs%20show%20contributions%20in%20log-odds%20towards%20survival.%22%0A%20%20%20%20)%0A%20%20%20%20with%20mo.status.spinner(%22Describing%20the%20model...%22)%3A%0A%20%20%20%20%20%20%20%20global_explanation%20%3D%20describe_ebm(%0A%20%20%20%20%20%20%20%20%20%20%20%20DescribeEBMRequest(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ebm%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20max_concurrency%3D2%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20prompt%3DPromptOptions(dataset_description%3Ddataset_description)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20).text%0A%20%20%20%20mo.md(global_explanation)%0A%20%20%20%20return%20dataset_description%2C%20global_explanation%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20One%20passenger%2C%20several%20languages%0A%0A%20%20%20%20Choose%20the%20languages%20and%20press%20the%20button.%20Each%20language%20is%20one%20call%20of%20%60explain_instance%60%2C%20which%20sends%20three%0A%20%20%20%20requests.%20Three%20languages%20send%20nine%20requests%2C%20so%20keep%20the%20list%20short.%20The%20tabs%20show%20the%20three%20explanations%20of%20each%0A%20%20%20%20language%2C%20side%20by%20side%20with%20the%20same%20facts.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20language_choice%20%3D%20mo.ui.multiselect(%0A%20%20%20%20%20%20%20%20options%3D%5B%22English%22%2C%20%22French%22%2C%20%22German%22%2C%20%22Spanish%22%2C%20%22Japanese%22%2C%20%22Brazilian%20Portuguese%22%2C%20%22Simplified%20Chinese%22%5D%2C%0A%20%20%20%20%20%20%20%20value%3D%5B%22French%22%2C%20%22German%22%2C%20%22Japanese%22%5D%2C%0A%20%20%20%20%20%20%20%20label%3D%22Languages%22%2C%0A%20%20%20%20)%0A%20%20%20%20languages_button%20%3D%20mo.ui.run_button(label%3D%22Explain%20in%20these%20languages%22)%0A%20%20%20%20mo.hstack(%5Blanguage_choice%2C%20languages_button%5D%2C%20justify%3D%22start%22)%0A%20%20%20%20return%20language_choice%2C%20languages_button%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExplainInstanceRequest%2C%0A%20%20%20%20PromptOptions%2C%0A%20%20%20%20dataset_description%2C%0A%20%20%20%20ebm%2C%0A%20%20%20%20explain_instance%2C%0A%20%20%20%20global_explanation%2C%0A%20%20%20%20instance%2C%0A%20%20%20%20language_choice%2C%0A%20%20%20%20languages_button%2C%0A%20%20%20%20mo%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20languages_button.value%2C%20mo.md(%22Press%20the%20button%20to%20explain%20the%20passenger%20above.%22))%0A%20%20%20%20mo.stop(not%20language_choice.value%2C%20mo.callout(%22Choose%20at%20least%20one%20language.%22%2C%20kind%3D%22warn%22))%0A%20%20%20%20explanations%20%3D%20%7B%7D%0A%20%20%20%20for%20chosen_language%20in%20language_choice.value%3A%0A%20%20%20%20%20%20%20%20with%20mo.status.spinner(f%22Asking%20the%20LLM%20in%20%7Bchosen_language%7D...%22)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20explanations%5Bchosen_language%5D%20%3D%20explain_instance(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ExplainInstanceRequest(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ebm%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20instance%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20global_explanation%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20language%3Dchosen_language%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20prompt%3DPromptOptions(dataset_description%3Ddataset_description)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20mo.ui.tabs(%7B%0A%20%20%20%20%20%20%20%20chosen_language%3A%20mo.md(f%22%22%22%0A%20%20%20%20%20%20%20%20**What%20would%20have%20to%20change**%0A%0A%20%20%20%20%20%20%20%20%7Bexplanation.counterfactual%7D%0A%0A%20%20%20%20%20%20%20%20**Which%20inputs%20settle%20it**%0A%0A%20%20%20%20%20%20%20%20%7Bexplanation.sufficient_reason%7D%0A%0A%20%20%20%20%20%20%20%20**How%20certain%20it%20gets%20as%20inputs%20become%20known**%0A%0A%20%20%20%20%20%20%20%20%7Bexplanation.completions%7D%0A%20%20%20%20%20%20%20%20%22%22%22)%0A%20%20%20%20%20%20%20%20for%20chosen_language%2C%20explanation%20in%20explanations.items()%0A%20%20%20%20%7D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20The%20same%20language%2C%20another%20audience%0A%0A%20%20%20%20The%20language%20and%20the%20audience%20are%20two%20settings%2C%20and%20each%20one%20has%20its%20own%20job.%20The%20audience%20decides%20which%20facts%20the%0A%20%20%20%20LLM%20gets%20and%20how%20it%20is%20told%20to%20write%20for%20the%20reader.%20The%20language%20decides%20the%20language%20of%20the%20words.%20So%20a%20data%0A%20%20%20%20scientist%20who%20reads%20Spanish%20gets%20the%20scores%20of%20the%20data%20scientist%2C%20in%20Spanish.%20Type%20any%20language%20name%20below.%20It%20does%0A%20%20%20%20not%20need%20to%20be%20in%20the%20list.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20audience_choice%20%3D%20mo.ui.dropdown(options%3D%5B%22layperson%22%2C%20%22data_scientist%22%5D%2C%20value%3D%22data_scientist%22%2C%20label%3D%22Audience%22)%0A%20%20%20%20language_text%20%3D%20mo.ui.text(value%3D%22Spanish%22%2C%20label%3D%22Language%22)%0A%20%20%20%20audience_button%20%3D%20mo.ui.run_button(label%3D%22Explain%20with%20this%20audience%20and%20language%22)%0A%20%20%20%20mo.hstack(%5Baudience_choice%2C%20language_text%2C%20audience_button%5D%2C%20justify%3D%22start%22)%0A%20%20%20%20return%20audience_button%2C%20audience_choice%2C%20language_text%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExplainInstanceRequest%2C%0A%20%20%20%20PromptOptions%2C%0A%20%20%20%20audience_button%2C%0A%20%20%20%20audience_choice%2C%0A%20%20%20%20dataset_description%2C%0A%20%20%20%20ebm%2C%0A%20%20%20%20explain_instance%2C%0A%20%20%20%20global_explanation%2C%0A%20%20%20%20instance%2C%0A%20%20%20%20language_text%2C%0A%20%20%20%20mo%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20audience_button.value%2C%20mo.md(%22Press%20the%20button%20to%20explain%20the%20passenger%20with%20this%20pair.%22))%0A%20%20%20%20mo.stop(not%20language_text.value.strip()%2C%20mo.callout(%22Type%20a%20language%20name.%22%2C%20kind%3D%22warn%22))%0A%20%20%20%20with%20mo.status.spinner(%22Asking%20the%20LLM...%22)%3A%0A%20%20%20%20%20%20%20%20audience_explanation%20%3D%20explain_instance(%0A%20%20%20%20%20%20%20%20%20%20%20%20ExplainInstanceRequest(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ebm%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20instance%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20global_explanation%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20audience%3Daudience_choice.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20language%3Dlanguage_text.value.strip()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20prompt%3DPromptOptions(dataset_description%3Ddataset_description)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20**What%20would%20have%20to%20change**%0A%0A%20%20%20%20%7Baudience_explanation.counterfactual%7D%0A%0A%20%20%20%20**Which%20inputs%20settle%20it**%0A%0A%20%20%20%20%7Baudience_explanation.sufficient_reason%7D%0A%0A%20%20%20%20**How%20certain%20it%20gets%20as%20inputs%20become%20known**%0A%0A%20%20%20%20%7Baudience_explanation.completions%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20When%20the%20setup%20is%20wrong%0A%0A%20%20%20%20EBaMl%20checks%20the%20provider%20before%20the%20first%20paid%20request%2C%20and%20it%20turns%20the%20failures%20that%20you%20can%20fix%20into%20errors%20with%0A%20%20%20%20fix%20steps.%20The%20cell%20below%20sends%20no%20request.%20It%20asks%20for%20an%20explanation%20in%20French%20from%20a%20model%20whose%20key%20is%20not%20in%0A%20%20%20%20the%20environment.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20ExplainInstanceRequest%2C%0A%20%20%20%20MissingAPIKeyError%2C%0A%20%20%20%20ModelOptions%2C%0A%20%20%20%20ebm%2C%0A%20%20%20%20explain_instance%2C%0A%20%20%20%20instance%2C%0A%20%20%20%20mo%2C%0A)%3A%0A%20%20%20%20%23%20the%20variable%20name%20is%20made%20up%2C%20so%20the%20environment%20cannot%20have%20it%0A%20%20%20%20unset%20%3D%20ModelOptions(provider%3D%22openai%22%2C%20model%3D%22gpt-4o-mini%22%2C%20api_key_env%3D%22EBAML_NOTEBOOK_UNSET_KEY%22)%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20explain_instance(%0A%20%20%20%20%20%20%20%20%20%20%20%20ExplainInstanceRequest(ebm%2C%20instance%2C%20%22The%20global%20explanation.%22%2C%20language%3D%22French%22%2C%20model%3Dunset)%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20except%20MissingAPIKeyError%20as%20error%3A%0A%20%20%20%20%20%20%20%20missing_key_view%20%3D%20mo.callout(mo.md(f%22%60MissingAPIKeyError%60%3A%20%7Berror%7D%22)%2C%20kind%3D%22danger%22)%0A%20%20%20%20missing_key_view%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Pass%20%60language%3D%60%20to%20%60explain_instance%60%20in%20your%20own%20code%20in%20the%20same%20way%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20explain_instance(ExplainInstanceRequest(ebm%2C%20instance%2C%20global_explanation%2C%20audience%3D%22layperson%22%2C%20language%3D%22French%22))%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20To%20change%20the%20role%20of%20the%20reader%20as%20well%20as%20the%20language%2C%20write%20an%20audience.%20The%20audiences%20notebook%20shows%20six.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
7d7b8af63277cf14131ed43d8ba2e38e