HyGenar: An LLM-Driven Hybrid Genetic Algorithm for Few-Shot Grammar Generation

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Tang, Weizhi, Li, Yixuan, Sypherd, Chris, Polgreen, Elizabeth, Belle, Vaishak
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909631482167296
author Tang, Weizhi
Li, Yixuan
Sypherd, Chris
Polgreen, Elizabeth
Belle, Vaishak
author_facet Tang, Weizhi
Li, Yixuan
Sypherd, Chris
Polgreen, Elizabeth
Belle, Vaishak
contents Grammar plays a critical role in natural language processing and text/code generation by enabling the definition of syntax, the creation of parsers, and guiding structured outputs. Although large language models (LLMs) demonstrate impressive capabilities across domains, their ability to infer and generate grammars has not yet been thoroughly explored. In this paper, we aim to study and improve the ability of LLMs for few-shot grammar generation, where grammars are inferred from sets of a small number of positive and negative examples and generated in Backus-Naur Form. To explore this, we introduced a novel dataset comprising 540 structured grammar generation challenges, devised 6 metrics, and evaluated 8 various LLMs against it. Our findings reveal that existing LLMs perform sub-optimally in grammar generation. To address this, we propose an LLM-driven hybrid genetic algorithm, namely HyGenar, to optimize grammar generation. HyGenar achieves substantial improvements in both the syntactic and semantic correctness of generated grammars across LLMs.
format Preprint
id arxiv_https___arxiv_org_abs_2505_16978
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle HyGenar: An LLM-Driven Hybrid Genetic Algorithm for Few-Shot Grammar Generation
Tang, Weizhi
Li, Yixuan
Sypherd, Chris
Polgreen, Elizabeth
Belle, Vaishak
Artificial Intelligence
Programming Languages
Grammar plays a critical role in natural language processing and text/code generation by enabling the definition of syntax, the creation of parsers, and guiding structured outputs. Although large language models (LLMs) demonstrate impressive capabilities across domains, their ability to infer and generate grammars has not yet been thoroughly explored. In this paper, we aim to study and improve the ability of LLMs for few-shot grammar generation, where grammars are inferred from sets of a small number of positive and negative examples and generated in Backus-Naur Form. To explore this, we introduced a novel dataset comprising 540 structured grammar generation challenges, devised 6 metrics, and evaluated 8 various LLMs against it. Our findings reveal that existing LLMs perform sub-optimally in grammar generation. To address this, we propose an LLM-driven hybrid genetic algorithm, namely HyGenar, to optimize grammar generation. HyGenar achieves substantial improvements in both the syntactic and semantic correctness of generated grammars across LLMs.
title HyGenar: An LLM-Driven Hybrid Genetic Algorithm for Few-Shot Grammar Generation
topic Artificial Intelligence
Programming Languages
url https://arxiv.org/abs/2505.16978