code: def generate_rules(
      attribute_groups: Dict[str, List[str]],
      subject: str,
      subject_category: str,
      max_rules: int = 5,
      specific_category: bool = False,
  ) -> List[LanguageRule]:
      """Generates a random set of rules about a subject as dictionaries,
      given a list of potential attributes and the category (e.g. person) of the subject (e.g. Alice)
  
      These rules are guaranteed to not contradict one another, and attributes implied by a single rule will
      not imply any attributes in any other rules (i.e. there is only a single step of reasoning).
      """
      attributes_shuffled = list(attribute_groups.keys()).copy()
      random.shuffle(attributes_shuffled)
      rules: List[LanguageRule] = []
  
      while len(attributes_shuffled) > 2 and len(rules) < max_rules:
          rule_subject = (
              subject
              if specific_category
              else random.choice([subject_category, subject])
          )
          n_rule_attributes = random.randint(2, 3)
          rule_attributes, attributes_shuffled = (
              attributes_shuffled[:n_rule_attributes],
              attributes_shuffled[n_rule_attributes:],
          )
          rules.append(
              LanguageRule(
                  subject=rule_subject,
                  subject_category=subject_category,
                  specifier_type="a",
                  condition=rule_attributes[:-1],
                  condition_conjunction=random.choice(["and", "or"]),
                  consequent=rule_attributes[-1],
              )
          )
      return rules
  
imports: import random
  import dataclasses
  from copy import copy
  from typing import List, Dict, Literal, Tuple
  from dataclasses import dataclass
  from .scenario import Scenario, Instance, Reference, TRAIN_SPLIT, VALID_SPLIT, TEST_SPLIT, CORRECT_TAG, Input, Output
label_desc: Use image node_id 2 for calling a global function with example usage: generate_rules(attribute_groups, subject, subject_category, max_rules, specific_category) and returns: rules