[Paper Review] CodeIE: Large Code Generation Models are Better Few-Shot Information Extractors
CodeIE reformulates NER and RE as code generation tasks and uses Code-LLMs with code-style prompts to achieve superior few-shot IE performance over UIE and NL-LLMs; Codex with code prompts yields the best results among tested configurations.
Large language models (LLMs) pre-trained on massive corpora have demonstrated impressive few-shot learning ability on many NLP tasks. A common practice is to recast the task into a text-to-text format such that generative LLMs of natural language (NL-LLMs) like GPT-3 can be prompted to solve it. However, it is nontrivial to perform information extraction (IE) tasks with NL-LLMs since the output of the IE task is usually structured and therefore is hard to be converted into plain text. In this paper, we propose to recast the structured output in the form of code instead of natural language and utilize generative LLMs of code (Code-LLMs) such as Codex to perform IE tasks, in particular, named entity recognition and relation extraction. In contrast to NL-LLMs, we show that Code-LLMs can be well-aligned with these IE tasks by designing code-style prompts and formulating these IE tasks as code generation tasks. Experiment results on seven benchmarks show that our method consistently outperforms fine-tuning moderate-size pre-trained models specially designed for IE tasks (e.g., UIE) and prompting NL-LLMs under few-shot settings. We further conduct a series of in-depth analyses to demonstrate the merits of leveraging Code-LLMs for IE tasks.
Motivation & Objective
- Motivate few-shot information extraction (IE) with large models by leveraging code-based outputs and Code-LLMs.
- Propose a code-generation formulation for NER and RE that aligns with Code-LLMs pre-training.
- Demonstrate that code-style prompts with Code-LLMs outperform fine-tuned IE models and NL-LLMs in few-shot settings.
- Provide analysis on format consistency and model fidelity to explain performance gains.
Proposed method
- Formulate NER outputs as Python dictionaries with keys 'text' and 'type' inside a Python list.
- Formulate RE outputs as Python dictionaries with keys 'rel_type','ent1_type','ent1_text','ent2_type','ent2_text' inside a Python list.
- Wrap input x into a Python function with docstring and use an empty list to collect outputs; prompt Code-LLMs to append dictionaries to the list.
- Use in-context demonstrations by concatenating several (x^c, y^c) pairs as demonstrations prior to the test prompt.
- Prompts are tested in few-shot settings using Code-LLMs (Codex) and NL-LLMs (GPT-3) with both code-style and natural-language prompts.
- Analyze structure fidelity, format consistency, and semantic fidelity to understand performance gains.
Experimental results
Research questions
- RQ1Can Code-LLMs with code-style prompts effectively perform NER and RE in few-shot settings?
- RQ2Does coding-formatted output improve alignment with Code-LLMs pre-training and reduce structural errors compared to text-formatted outputs?
- RQ3Are Code-LLMs superior to NL-LLMs and fine-tuned IE models for few-shot IE tasks?
- RQ4What factors (format consistency, fidelity) contribute most to CodeIE's performance gains?
Key findings
- Code-LLMs with code prompts outperform UIE (fine-tuned IE models) and NL-LLMs under few-shot settings on seven IE benchmarks.
- For the same LLM, code prompts yield better performance than text prompts, indicating format (code-style) drives gains beyond prompt content.
- Codex (Code-LLM) generally surpasses GPT-3 (NL-LLM) in both NER and RE tasks under similar prompting.
- Code prompts exhibit higher output structure fidelity, with near-zero structural errors, compared to text prompts.
- CodeIE with Codex and code prompts achieves the best average results across benchmarks, outperforming strong baselines in few-shot settings.
- Code pre-training alignment and higher fidelity contribute to improved few-shot IE performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.