# Code4Struct: Code Generation for Few-Shot Event Structure Prediction

Source: [Code4Struct: Code Generation for Few-Shot Event Structure Prediction](<https://www.sota2.com/research/paper/68fa6f7b1e209131cea45dc9>)

Collection index: [llms.txt](<https://www.sota2.com/research/llms.txt>)

Data updated: 2025-10-28T13:56:59.024Z

Authors: Xingyao Wang, Sha Li, Heng Ji

Published: 2022-10-23T18:18:51.000Z

## Abstract

Large Language Model (LLM) trained on a mixture of text and code has demonstrated impressive capability in translating natural language (NL) into structured code. We observe that semantic structures can be conveniently translated into code and propose Code4Struct to leverage such text-to-structure translation capability to tackle structured prediction tasks. As a case study, we formulate Event Argument Extraction (EAE) as converting text into event-argument structures that can be represented as a class object using code. This alignment between structures and code enables us to take advantage of Programming Language (PL) features such as inheritance and type annotation to introduce external knowledge or add constraints. We show that, with sufficient in-context examples, formulating EAE as a code generation problem is advantageous over using variants of text-based prompts. Despite only using 20 training event instances for each event type, Code4Struct is comparable to supervised models trained on 4,202 instances and outperforms current state-of-the-art (SOTA) trained on 20-shot data by 29.5% absolute F1. Code4Struct can use 10-shot training data from a sibling event type to predict arguments for zero-resource event types and outperforms the zero-shot baseline by 12% absolute F1.

## Recorded benchmark results

A research result applies to its stated dataset, split, metric and evaluation configuration. Compare like-for-like settings, preserve the metric's unit and direction, and distinguish paper-reported results from independent reproduction. The best result recorded here is not a claim of exhaustive, current global coverage.

- [Event Argument Extraction on ACE 2005 (test)](<https://www.sota2.com/research/sota/event-argument-extraction-on-ace-2005-test.md>): Event Argument Extraction; ACE 2005 (test); F1 Score: 57.

- [Event Detection on ACE 2005 (test)](<https://www.sota2.com/research/sota/event-detection-on-ace-2005-test.md>): Event Detection; ACE 2005 (test); F1 Score: 37.4.

## Original sources and implementation

[Original paper](<https://arxiv.org/abs/2210.12810>)

[PDF](<https://arxiv.org/pdf/2210.12810.pdf>)
