Skip to main content
QUICK REVIEW

[Paper Review] Code4Struct: Code Generation for Few-Shot Event Structure Prediction

Xingyao Wang, Sha Li|arXiv (Cornell University)|Oct 23, 2022
Topic ModelingComputer Science14 citations
TL;DR

This paper proposes Code4Struct, a few-shot event structure prediction framework that formulates Event Argument Extraction (EAE) as code generation using Python class definitions. By leveraging programming language features like inheritance and type annotations, Code4Struct achieves state-of-the-art performance with only 20-shot examples—surpassing supervised models trained on 4,202 instances and outperforming SOTA by 29.5% absolute F1 on 20-shot data.

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.

Motivation & Objective

  • Address the challenge of low-resource event structure prediction in NLP by leveraging code generation capabilities of large language models (LLMs).
  • Overcome limitations of text-based prompting in structured prediction tasks by mapping semantic structures to executable code.
  • Utilize programming language features such as inheritance and type annotations to encode structural constraints and hierarchical relationships in event ontologies.
  • Enable zero-shot prediction for low-resource event types by transferring knowledge from high-resource sibling event types using inheritance.
  • Demonstrate that code-based prompting outperforms text-based prompting in few-shot settings when sufficient in-context examples are available.

Proposed method

  • Represent event and entity types from an ontology as Python class definitions, with argument roles as class attributes and type annotations to specify data types.
  • Use inheritance to model hierarchical relationships between event types (e.g., Transport inherits from Movement), enabling knowledge transfer between related event types.
  • Construct a prompt with three components: (1) ontology code, (2) k-shot in-context examples, and (3) a partial class instantiation prompt for the LLM to complete.
  • Condition the LLM (e.g., code-davinci-002) on the full prompt to generate a complete code instantiation of the target event class.
  • Parse the generated code to extract predicted event arguments by instantiating the class with detected entities from the input sentence.
  • Leverage default values in arguments (e.g., empty list) to naturally support zero or multiple fillers for the same role, improving structural flexibility.

Experimental results

Research questions

  • RQ1Can code generation with structured programming language features improve few-shot event structure prediction compared to text-based prompting?
  • RQ2To what extent can inheritance in programming languages enable knowledge transfer from high-resource to zero-resource event types?
  • RQ3How does the performance of code-based prompting compare to text-based prompting in terms of F1 score under few-shot settings?
  • RQ4Can a code-based approach rival fully supervised models when only a small number of training examples (e.g., 20) are available?
  • RQ5Does the use of type annotations and default values in code improve the modeling of complex argument structures in EAE?

Key findings

  • With only 20-shot training data per event type, Code4Struct achieves an absolute F1 improvement of 29.5% over the current state-of-the-art model.
  • Code4Struct outperforms a fully supervised model trained on 4,202 instances when both are evaluated on the same 20-shot data.
  • By leveraging inheritance, Code4Struct achieves a 12% absolute F1 gain for zero-resource event types when using 10-shot examples from sibling event types.
  • The code-based prompting approach consistently outperforms two variants of text-based prompting across multiple LLMs when sufficient in-context examples are provided.
  • The method enables natural modeling of complex argument structures, such as multiple or zero fillers, through type annotations and default values in code.
  • The approach demonstrates strong generalization, with 0-shot performance exceeding that of the SOTA model on both 20-shot and 50-shot settings.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.