NLP -Cimat at S em E val-2025 Task 11: Prompt Optimization for LLM s via Genetic Algorithms and Systematic Mutation applied on Emotion Detection (2025)

Abstract: Large Language Models (LLMs) have shown remarkable performance across diverse natural language processing tasks in recent years. However, optimizing instructions to maximize model performance remains a challenge due to the vast search space and the nonlinear relationship between input structure and output quality. This work explores an alternative prompt optimization technique based on genetic algorithms with different structured mutation processes. Unlike traditional random mutations, our method introduces variability in each generation through a guided mutation, enhancing the likelihood of obtaining better prompts for each generation. We apply this approach to emotion detection in the context of SemEval 2025 Task 11, demonstrating the potential to improve prompt efficiency, and consequently task performance. Experimental results show that our method yields competitive results compared to standard optimization techniques while maintaining interpretability and scalability.

## introduction large language models (llms) have experienced significant growth in recent years. their remarkable performance stems from their ability to understand and model language more effectively than any previously developed tool @xcite . the essential interest in llms lies in their capacity to excel at numerous specific tasks without requiring extensive fine-tuning or contextual information @xcite . this is quite powerful in many ways. on the one hand, more traditional machine learning or deep learning models require a significant amount of data to achieve llm performance @xcite . on the other hand, by having an llm available, you have a model capable of performing almost any natural language-related task with a high level of competence. nevertheless, despite the outstanding performance demonstrated by llms, their ability to process and understand subjective aspects of text, such as human emotions, remains a complex challenge @xcite @xcite . one particularly challenging task is identifying the emotion experienced by the author when writing a text, rather than the emotion perceived by the reader @xcite . this distinction is crucial in tasks such as sentiment analysis, psychological research, and user experience evaluation. the semeval 2025 task 11a competition focuses precisely on this challenge @xcite , providing a dataset where sentences are labeled based on the author's emotional state at the time of writing, rather than how a reader interprets the text @xcite . this task is more complex than traditional emotion classification, especially for llms, which lack direct access to human emotional experiences. they infer emotions based purely from linguistic patterns present in their training data @xcite . therefore, determining the optimal way to prompt an llm to infer the author's emotions is non-trivial and requires careful design @xcite . however, the performance of llms is highly dependent on how prompts are constructed @xcite . developing more effective prompts is essential, particularly given that there is no single correct method for doing so @xcite . within this context, prompt engineering has reached a boom, and human-constructed prompts are the vast majority of the time used to perform tasks with an llm @xcite . despite this, determining how to best phrase a prompt to make an llm infer the emotional state of an author remains an open problem. in this paper, we explore an approach based on the use of genetic algorithms to optimize prompts for for llm-based emotion classification. we explore an alternative mutation designed to introduce structured variability at each generation, ensuring that mutations are aligned with patterns that have shown potential for enhancing prompt quality. by systematically evolving prompts without human intervention, this method offers a robust and scalable solution for tasks that require accurate emotional inference. while our approach is evaluated in the context of emotion classification, its potential applications include in contexts where optimized prompts without human intervention are needed, such as chatbots @xcite , code generation @xcite , and automation of complex tasks with llms @xcite . ## related work the traditional methods used for emotion classification were lexicon-based approaches @xcite , where a predefined list of words was used to classify sentences according to sentiment by num-algorithm 1 evoprompt classic vs evoprompt sm 1: input: initial population of prompts p0, number of generations g, population size n 2: output: optimized set of prompts pg 3: initialize population p0 with n prompts (human-crafted + llm-generated) 4: for @xmath0: selection: choose m parent prompts using tournament, wheel or random selection 6: crossover: generate offspring prompts via crossover operation 7: mutation: apply random mutation to offspring 9: selection: choose top n prompts based on fitness 10: selection 1: choose top candidates for mutation after crossover 12: mutation: apply structured mutation from predefined set 13: selection 2: choose top n prompts based on fitness after mutation 14: update population: pg+1 ← selected best prompts 16: end for 17: return final optimized prompt set pg ber of occurrences or any other linguistic criterion. these methods faced significant challenges related to context dependency and polysemy, which limited their accuracy in complex texts @xcite . the advent of deep learning marked a revolution, as word embeddings and transformer-based approaches could be used to do emotion classification. models such roberta and ts showed superior performance compared to more traditional approaches @xcite . more recently, llms have shown comparable performance while being more cost-effective in terms of data and training requirements. therefore, optimizing prompts for these tasks has become a more efficient approach @xcite . the process of optimizing prompts for a language model in an automated manner is known as automated prompt generation. different approaches aim to generate improved synthetic prompts @xcite . biologically inspired approaches to prompt optimization treat the problem as an evolutionary process @xcite . in evolution, prompts are viewed as organisms, which are managed through genetic operations such as mutation or crossover over epochs. the pioneering work in implementing an evolutionary process using an llm as an optimizer is evoprompt @xcite . in evoprompt a more traditional approach to an evolutionary algorithm is proposed, in which an evaluation function chooses the best prompts that maximize the score of the task at hand. other approaches, such as promptbreeder, introduce a self-referential method, where both task-prompts and mutation-prompts evolve through a genetic algorithm guided by llms @xcite . emotion classification using llms has been extensively explored in recent studies. various approaches have reshaped the way llms are employed for this task. specifically, we can divide these efforts into two main categories: those that fine-tune llms for emotion classification tasks @xcite and those that leverage llms' inherent ability to detect emotions, assessing their performance across different contexts solely through prompt optimization @xcite . in both contexts, an automated approach to find optimal prompts for emotion classification is a highly desirable need. therefore, this study explores an alternative framework that mitigates the stochastic nature of genetic algorithms by changing the way mutations are performed. ## methodology to tackle the problem, we propose a solution based on llms using a zero-shot/few-shot approach. as previously discussed, selecting the optimal prompt is challenging and directly impacts llm performance. we employed a genetic algorithm to optimize prompts through an evolutionary process customized to the requirements of the task. the overall structure follows a classical genetic algorithm approach, where prompts undergo iterative selection, crossover, and mutation to improve a fitness function. the distinction between random mutations (classical evoprompt) and systematic mutations (our approach) is visually depicted in figure 1 , highlighting the key differences between both strategies. the step-by-step process is outlined in algorithm 1. the process begins with an initial population of 2n prompts, comprising both human-crafted prompts, manually designed based on linguistic heuristics and task-specific considerations, and those generated by gpt-4o. all initial prompts are evaluated individually. the elements then enter the evolutionary cycle, following an approach similar to evoprompt, which utilizes a classical genetic algorithm. prompt selection is performed using three different methods: tournament selection, roulette wheel selection, and random selection. once a pair of parent prompts is selected, a crossover operation is applied resulting in a child prompt. after all crossover operations, the top n prompts are evaluated and selected for the next generation. this process is iterated for a predetermined number of epochs using the top n prompts. the prompts from the final epoch are expected to be superior to those from the initial population. the typical range in which we use our approach is 10 ≤ @xmath1. for this work we use @xmath2. the optimization process was run for 10 epochs due to computational limitations. the prompts are evaluated using the same llm as the fitness function. the main idea is to iteratively refine the prompts generated during evolution, as these prompts are directly used to perform the emotion detection task. each prompt is evaluated over the validation set of the dataset by calculating the f1 score for its predictions. the selection process is detailed in algorithm 1. the process is run for each sentiment independently. predictions are made through a discrete prompting setup: the llm is asked to make a binary decision using prespecified target words. initially, the words used are positive and negative, where the model predicts the presence or absence of a target emotion in a sentence. to further understand the sensitivity of the evaluation, we include an ablation study where the target words are replaced with present and absent, and analyze the resulting impact on prompt performance. ## results and discussion the model was executed using the random mutation configuration, following an approach similar to evoprompt. this was done to compare the results obtained with the proposed systematic mutation model. likewise, the systematic mutation model was executed, and its results are presented in one of the best-performing prompt was from the joy category ( this reasoning explains the overall structure of the best-performing prompts for fear and joy, as these findings underscore the potential of systematic mutations, which, relying solely on prompt engineering assumptions, produced targeted modifications. this approach generated prompts that effectively identified task-relevant patterns, surpassing the evoprompt method, where random mutations failed to yield superior results. this suggests that replacing stochastic mutations with structured linguistic modifications enhances both effectiveness and consistency in prompt generation, leading to improved overall performance. another possible explanation for the model's success in prediction could come from a class imbalance. from the dataset paper (muhammad et al., 2025a), we know that the most represented emotion is fear, while the least represented is anger, which aligns with the results obtained in ## conclusion this study introduced a novel approach for optimizing prompts via systematic mutations guided by genetic algorithm principles. by replacing stochastic mutations with structured linguistic modifications, the proposed method enhanced prompt effectiveness and consistency, leading to superior performance across all emotion categories. notably, the improvements in joy and fear suggest that aligning mutations with underlying linguistic patterns can significantly impact classification accuracy. these findings highlight the potential of systematic mutation strategies in prompt engineering, paving the way for more efficient and automated optimization techniques in llm-driven emotion classification. future work could explore refining mutation strategies further and extending this approach to other nlp tasks.