class_docstr: Base class for attacking a model with word substiutitions using a
  genetic algorithm.
  
  Args:
      pop_size (int): The population size. Defaults to 20.
      max_iters (int): The maximum number of iterations to use. Defaults to 50.
      temp (float): Temperature for softmax function used to normalize probability dist when sampling parents.
          Higher temperature increases the sensitivity to lower probability candidates.
      give_up_if_no_improvement (bool): If True, stop the search early if no candidate that improves the score is found.
      post_crossover_check (bool): If True, check if child produced from crossover step passes the constraints.
      max_crossover_retries (int): Maximum number of crossover retries if resulting child fails to pass the constraints.
          Applied only when `post_crossover_check` is set to `True`.
          Setting it to 0 means we immediately take one of the parents at random as the child upon failure.
class_docstr_tok: ["Base","class","for","attacking","a","model","with","word","substiutitions","using","a","genetic","algorithm",".","Args",":","pop_size","(","int",")",":","The","population","size",".","Defaults","to","20.","max_iters","(","int",")",":","The","maximum","number","of","iterations","to","use",".","Defaults","to","50.","temp","(","float",")",":","Temperature","for","softmax","function","used","to","normalize","probability","dist","when","sampling","parents",".","Higher","temperature","increases","the","sensitivity","to","lower","probability","candidates",".","give_up_if_no_improvement","(","bool",")",":","If","True",",","stop","the","search","early","if","no","candidate","that","improves","the","score","is","found",".","post_crossover_check","(","bool",")",":","If","True",",","check","if","child","produced","from","crossover","step","passes","the","constraints",".","max_crossover_retries","(","int",")",":","Maximum","number","of","crossover","retries","if","resulting","child","fails","to","pass","the","constraints",".","Applied","only","when","`","post_crossover_check","`","is","set","to","`","True","`",".","Setting","it","to","0","means","we","immediately","take","one","of","the","parents","at","random","as","the","child","upon","failure","."]
docstr: Generates a crossover between pop_member1 and pop_member2.
  
  If the child fails to satisfy the constraints, we re-try crossover for a fix number of times,
  before taking one of the parents at random as the resulting child.
  Args:
      pop_member1 (PopulationMember): The first population member.
      pop_member2 (PopulationMember): The second population member.
      original_text (AttackedText): Original text
  Returns:
      A population member containing the crossover.
docstr_tok: ["Generates","a","crossover","between","pop_member1","and","pop_member2",".","If","the","child","fails","to","satisfy","the","constraints",",","we","re-try","crossover","for","a","fix","number","of","times",",","before","taking","one","of","the","parents","at","random","as","the","resulting","child",".","Args",":","pop_member1","(","PopulationMember",")",":","The","first","population","member",".","pop_member2","(","PopulationMember",")",":","The","second","population","member",".","original_text","(","AttackedText",")",":","Original","text","Returns",":","A","population","member","containing","the","crossover","."]
code: def _crossover(self, pop_member1, pop_member2, original_text):
      """Generates a crossover between pop_member1 and pop_member2.
  
      If the child fails to satisfy the constraints, we re-try crossover for a fix number of times,
      before taking one of the parents at random as the resulting child.
      Args:
          pop_member1 (PopulationMember): The first population member.
          pop_member2 (PopulationMember): The second population member.
          original_text (AttackedText): Original text
      Returns:
          A population member containing the crossover.
      """
      x1_text = pop_member1.attacked_text
      x2_text = pop_member2.attacked_text
  
      num_tries = 0
      passed_constraints = False
      while num_tries < self.max_crossover_retries + 1:
          new_text, attributes = self._crossover_operation(
              pop_member1, pop_member2
          )
  
          replaced_indices = new_text.attack_attrs[
              "newly_modified_indices"
          ]
          new_text.attack_attrs["modified_indices"] = (
              x1_text.attack_attrs["modified_indices"]
              - replaced_indices
          ) | (
              x2_text.attack_attrs["modified_indices"]
              & replaced_indices
          )
  
          if "last_transformation" in x1_text.attack_attrs:
              new_text.attack_attrs[
                  "last_transformation"
              ] = x1_text.attack_attrs["last_transformation"]
          elif "last_transformation" in x2_text.attack_attrs:
              new_text.attack_attrs[
                  "last_transformation"
              ] = x2_text.attack_attrs["last_transformation"]
  
          if self.post_crossover_check:
              passed_constraints = self._post_crossover_check(
                  new_text, x1_text, x2_text, original_text
              )
  
          if not self.post_crossover_check or passed_constraints:
              break
  
          num_tries += 1
  
      if self.post_crossover_check and not passed_constraints:
          # If we cannot find a child that passes the constraints,
          # we just randomly pick one of the parents to be the child for the next iteration.
          pop_mem = (
              pop_member1 if np.random.uniform() < 0.5 else pop_member2
          )
          return pop_mem
      else:
          new_results, self._search_over = self.get_goal_results(
              [new_text]
          )
          return PopulationMember(
              new_text, result=new_results[0], attributes=attributes
          )
  
imports: from abc import ABC, abstractmethod
  import numpy
  import torch
  from textattack.goal_function_results import GoalFunctionResultStatus
  from textattack.search_methods import PopulationBasedSearch, PopulationMember
  from textattack.shared.validators import transformation_consists_of_word_swaps
label_desc: Use image node_id 7 for calling the GeneticAlgorithm obj's underlying member method code with example usage: obj._crossover(pop_member1, pop_member2, original_text) and returns: pop_mem, PopulationMember