Download explainers/explainer_probability.py from j-js/GameAI: direct link, hf CLI and curl.
- Browser
- Download file 2.71 kB
-
https://huggingface.co/spaces/j-js/GameAI/resolve/508bc5133870fe40274885bfaf7405c77458bf2e/explainers/explainer_probability.py
- Command line
-
hf download hf://spaces/j-js/GameAI@508bc5133870fe40274885bfaf7405c77458bf2e/explainers/explainer_probability.py
-
curl -L -o explainer_probability.py https://huggingface.co/spaces/j-js/GameAI/resolve/508bc5133870fe40274885bfaf7405c77458bf2e/explainers/explainer_probability.py
2.71 kB
| import re | |
| from .explainer_types import ExplainerResult, ExplainerScaffold | |
| def explain_probability_question(text: str) -> ExplainerResult | None: | |
| t = text.lower() | |
| # ✅ STRONG detection | |
| probability_signals = [ | |
| "probability", | |
| "chance", | |
| "odds", | |
| "random", | |
| "chosen at random", | |
| "selected at random", | |
| "picked at random", | |
| "drawn", | |
| "without replacement", | |
| "with replacement", | |
| ] | |
| has_probability = any(p in t for p in probability_signals) | |
| if not has_probability: | |
| return None | |
| givens = [] | |
| relationships = [] | |
| constraints = [] | |
| trap_notes = [] | |
| numbers = re.findall(r"\b\d+\b", t) | |
| if numbers: | |
| givens.append(f"Numbers mentioned: {', '.join(numbers[:5])}") | |
| else: | |
| givens.append("A situation involving possible outcomes is described") | |
| if "without replacement" in t: | |
| relationships.append("The probabilities change after each selection") | |
| constraints.append("The total number of items decreases after each draw") | |
| if "with replacement" in t: | |
| relationships.append("The probabilities stay the same for each selection") | |
| if "at least" in t: | |
| relationships.append("This may require using the complement (1 - probability of the opposite event)") | |
| if "both" in t or "and" in t: | |
| relationships.append("You may need to combine probabilities of multiple events occurring together") | |
| if "or" in t: | |
| relationships.append("You may need to consider multiple possible favorable cases") | |
| # default structure | |
| relationships.append("Probability = favorable outcomes ÷ total possible outcomes") | |
| asks_for = "the probability of a specific event occurring" | |
| trap_notes.extend([ | |
| "Make sure you correctly identify the total number of possible outcomes", | |
| "Check whether events are independent or dependent", | |
| "Watch for 'at least' — often easier to use the complement", | |
| "Be careful not to double count outcomes", | |
| ]) | |
| return ExplainerResult( | |
| understood=True, | |
| topic="probability", | |
| asks_for=asks_for, | |
| givens=givens, | |
| constraints=constraints, | |
| relationships=relationships, | |
| needed_concepts=[ | |
| "favorable vs total outcomes", | |
| "independent vs dependent events", | |
| "complement rule", | |
| ], | |
| trap_notes=trap_notes, | |
| strategy_hint="Start by identifying all possible outcomes, then count how many satisfy the condition.", | |
| plain_english="The question is asking you to work out how likely an event is by comparing favorable outcomes to all possible outcomes.", | |
| ) |