Home

Awesome

Empirical Study of Zero-Shot NER with ChatGPT

This is the github repository for the paper to be appeared at EMNLP 2023 main conference: Empirical Study of Zero-Shot NER with ChatGPT.

Introduction

This work focuses on exploring LLM performance on zero-shot information extraction, with a focus on the ChatGPT and named entity recognition (NER) task.

Inspired by the remarkable reasoning capability of LLM on symbolic and arithmetic reasoning, we adapt the prevalent reasoning methods to NER and propose reasoning strategies tailored for NER:

Please find more details of this work in our paper.

Usage

Requirements

We run our code on Windows. The following are the dependencies: python 3.8, openai 0.27.4, pytorch 2.0.1, pandas, hanlp

Datasets

We provide processed datasets used in our paper at the Google Drive, except ACE04, ACE05 and Ontonotes 4 for copyright reasons. Power plant datasets, PowerPlantFlat and PowerPlantNested, involve ongoing collaborative projects with our partners, and we will release them after the project is completed and the data is desensitized.

You can download the dataset files and put them in the data folder.

We provide five randomly sampled test samples of MSRA in msra_5_samples for quick start.

Run

We provide shell scripts in folder scripts for quick start on a few sampled examples msra_5_samples. Each script can be used to quickly run the pipeline of (1) generating prompts, (2) run LLM and (3) computing the evaluation results.

We use Pos tagging as the example syntactic information in all related scripts. The generated prompts will be saved to folder prompts. The response from the LLM and the evaluation results will be saved to folder result. The output files generated after running the following commands are provide in this repository for demonstration.

Run the following commands to use our methods. We recommend using the syntactic augmentation and SC methods under the proposed decomposed-QA paradigm, where these strategies exhibit more potential than in the vanilla paradigm.

Before you run on ChatGPT, please set your OpenAI API Keys in my_openai_api_keys in const.py.

# Vanilla paradigm
# Basic
sh scripts/msra_5_samples_zs_vanilla.sh
# Syntactic prompting
sh scripts/msra_5_samples_zs_vanilla_syn.sh
# Tool augmentation
sh scripts/msra_5_samples_zs_vanilla_tool.sh
# Tool augmentation with syntactic prompting
sh scripts/msra_5_samples_zs_vanilla_tool_syn.sh
# Combination of tool augmentation, syntactic prompting and SC
sh scripts/msra_5_samples_zs_vanilla_tool_syn_SC5.sh

# Decomposed-QA paradigm
# Basic
sh scripts/msra_5_samples_zs_qa.sh
# Syntactic prompting
sh scripts/msra_5_samples_zs_qa_syn.sh
# Tool augmentation
sh scripts/msra_5_samples_zs_qa_tool.sh
# Tool augmentation with syntactic prompting
sh scripts/msra_5_samples_zs_qa_tool_syn.sh
# Combination of tool augmentation, syntactic prompting and SC
sh scripts/msra_5_samples_zs_qa_tool_syn_SC5.sh

Arguments

Decomposed-QA

Syntactic prompting

Tool augmentation

Self-consistency (SC)

Generate syntactic information

Use the python script here to generate syntactic information with Hanlp.