# GenAI Biased Generalization [[CGenAI - Generative Artificial Intelligence|Generative AI]]'s tendency to produce inaccurate or obsolete outputs when its training data contains a lot of contents significantly outdated or no longer reflective of current state of the art knowledge. ## Specific contexts This outdated generalization can occur in specific contexts. For instance, if a prompt to a Generative AI uses terms that are language-agnostic or derived from other programming languages ; such as using `hashmap` instead of the Python-specific term `dict` ; it may guide the model toward a context that produces suboptimal or outdated outputs. These outputs might reflect content from tutorials aimed at absolute beginners in Python. ### Example of bad context In the following example, the prompt misled the model (specifically OpenAI GPT-4o, as of 21-01-2025) into a context that resulted in an overly simplistic solution, far from Python's professional recommendations. Prompt: > Count occurences from a list to a hashmap. > Example of list: [1, 2, 2, 2, 3, 3] Ouput: > To count the occurrences of elements in a list and store them in a hashmap (dictionary in Python), you can use the following code: > > ```python > # Example list > example_list = [1, 2, 2, 2, 3, 3] > > # Create an empty hashmap > occurrences = {} > > # Count occurrences > for item in example_list: > if item in occurrences: > occurrences[item] += 1 > else: > occurrences[item] = 1 > > # Print the hashmap > print(occurrences) > ``` > \[…] Here is a comparison of solutions that are better suited for this task, ranging from less professional to more professional: - Using `dict.get`: Replace the `if-else` block with `occurrences[item] = occurrences.get(item, 0) + 1`. - Using `collections.defaultdict`: Initialize `occurrences = collections.defaultdict(int)` instead of using a regular dictionary, then replace the `if-else` block with `occurrences[item] += 1`. - Using `collections.Counter`: Simplify the process by replacing the dictionary initialization and counting loop with `occurrences = collections.Counter(example_list)`. The most professional solution aligns closely with idiomatic and state-of-the-art Python practices, which are typically preferred when building robust, long-term software rather than quick prototypes or one-off scripts. ### Example of better context In this example, a more effective context was provided to the model. The modification is minimal but sufficient to elicit the most up-to-date and state-of-the-art output: > Count occurrences from a list to a dict. > Example of list: [1, 2, 2, 2, 3, 3] Output: > To count occurrences from a list and store them in a dictionary, you can use Python's `collections.Counter` or a simple loop. […] It is important to note that this example is simplistic, but it demonstrates how small changes can significantly reduce the quality of an output. --- Bibliography: - [Title - website.com](need bibliography)