                                                 Neural Genetic Search in Discrete Spaces

any existing algorithm with sequential generative models.                probability ofPan object x ∈ X being generated is defined
Finally, compared to single-pass generation, the population-             as pθ (x) = s:g(s)=x pθ (s). Additionally, we assume the
based iterative generation in NGS allows the generation                  existence of a reward function rX : X → R which evaluates
process to adapt over time, improving the quality of gener-              the quality of a generated object x. For instance, in routing
ated outputs and even the robustness to distribution shifts.             problems, we can define rX (x) = −c(x) where c(x) is the
                                                                         length of the route x that we want to minimize. In molecular
We evaluated our algorithm in three distinct domains where
                                                                         optimization, c could represent a property such as binding
sequential generative models are widely applied: routing
                                                                         affinity or drug-likeness, which we aim to maximize. Since
problems, red-teaming language models, and de novo molec-
                                                                         this work focuses on sequence generation, we mainly use
ular design. Our extensive experiments validate that NGS
                                                                         the reward function over sequences, r = rX ◦ g.
can serve as an effective test-time search method, fulfill-
ing its main purpose. We also found that NGS can replace                 Our task is to maximize the reward function by generat-
the conventional decoding algorithms, offering improved                  ing a set of objects using the sequential generative model.
robustness. Additionally, NGS can be viewed as an auto-                  Depending on the task, we may also want to maintain the di-
mated genetic algorithm that leverages sequential generative             versity in the generated objects. We provide a more detailed
models to learn genetic operators, eliminating the need for              discussion for each problem we considered in Appendix A.
extensive labor for algorithm design. These results suggest
that NGS has significant potential as a versatile and efficient          2.2. Genetic Algorithm
search strategy, adaptable to a wide range of applications
with sequential generative models.                                       Genetic algorithms (GAs) are evolutionary-inspired meta-
                                                                         heuristics. By mimicking natural selection and genetic evo-
                                                                         lution, GAs iteratively refine a population of candidate solu-
2. Background                                                            tions. The main components of GA are as follows:
2.1. Sequential Generation in Discrete Space                             • Chromosome: A representation of a potential solution,
This paper focuses on the sequential generation of discrete                encoded in a suitable format (e.g., a sequence of numbers).
objects to optimize predefined criteria, i.e., maximize re-              • Population: A group of chromosomes that evolve over
ward functions. This setting includes many practical appli-                the iterative refinement by GA.
cations, including solution generation for vehicle routing               • Selection: Parent chromosomes are selected based on
problems, prompt optimization in language models, and                      their reward, with chromosomes having higher reward
atom or fragment-based generation for molecular optimiza-                  being more likely to be chosen.
tion.
                                                                         • Crossover: Parents exchange genetic material to create
Let s ∈ S represent a sequence that corresponds to a discrete              offspring, combining strengths from both.
object x ∈ X . Without loss of generality and to make the
                                                                         • Mutation: Random changes to the offspring’s genetic
explanation simpler, we assume that the sequence length is
                                                                           material to maintain diversity and explore new regions of
T , i.e., s = (s1 , s2 , . . . , sT ) where st ∈ V is a token from
                                                                           the solution space.
vocabulary V . We also denote the partial sequence with
length t − 1 as s<t .                                                    • Replacement: Offspring replace individuals with low
                                                                           rewards in the population.
We assume that we have a sequential generative policy pθ .
The probability of a sequence s being generated by the                   The challenge in developing GAs lies in designing each
policy pθ is:                                                            component, particularly crossover and mutation operators,
                              T
                                                                         that respect the unique problem-specific constraints while
                                                                         effectively searching the solution space. In various do-
                              Y
                   pθ (s) =         pθ (st |s<t ),             (1)
                              t=1
                                                                         mains, extensive effort has been devoted to developing
                                                                         highly specialized operators that can handle these complex-
where s<1 is defined as an empty sequence and pθ (st |s<t )              ities. While these specialized operators are essential for
denotes the conditional distribution over next token st given            handling problem-specific constraints, they make it chal-
the partial sequence s<t modeled by pθ . In our work, this               lenging to generalize across different problems or adapt to
conditional distribution is given by a pretrained neural net-            new variations without redesigning the operators.
work, which is often conditioned on some contexts or con-
                                                                         Despite these challenges, the evolving framework of GAs
strained with problem-specific constraints.
                                                                         remains highly powerful due to their inherent capacity to ex-
Note that the mapping from a sequence to a discrete object               plore large, complex solution spaces. The GA’s population-
g : S → X is not necessarily injective, i.e., there can be mul-          based approach, which maintains a diverse set of solutions,
tiple sequences that correspond to a single object. Thus, the            enables the algorithm to explore many potential solutions si-

                                                                     2
