Code4Struct: Code Generation for Few-Shot Event Structure Prediction
Xingyao Wang, Sha Li, Heng Ji · 2023
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-tostructure 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 1 and type annotation 2 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 stateof-the-art (SOTA) trained on 20-shot data by 29.5% absolute F1.By leveraging the inheritance feature of PL, 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. 3 Event Argument Extraction Programming Language (Python) Event / Entity Type Transport, VEH Class definition class Transport, class VEH Hierarchical Event Ontology Movement:Transport Inheritance Inheritance is a way to create a hierarchy of classes in PL.A child class can base upon another class, retaining similar implementation.class Transport(Movement) Event Arguments vehicle Function arguments def function(vehicle=...) Argument ConstraintEach argument can has a list of multiple entities; Argument vehicle should be entities of type VEH. Type Annotation & Argument Default ValueType annotations are used by developers to indicate the data types of variables and input/outputs of functions.If a function is called without the argument, the argument gets its default value (a list in this case). def function( vehicle: List[VEH] = [], … ) Weakly-supervised InformationTransport Event describes someone transporting something in a vehicle from one place to another place. Docstring or Commentsclass Transport(Movement):""" self.agenttransported self.artifact in self.vehiclevehicle from self.origin place to self.destination place."""