GPT-RE: In-context Learning for Relation Extraction using Large Language Models

November 28, 2025 ยท View on GitHub

This is the official repository for the paper "GPT-RE: In-context Learning for Relation Extraction using Large Language Models" (EMNLP 2023).

Updates

[New] The GPT-RE with Fine-Tuned representations (GPT-RE_FT) method is now available! The code has been reproduced and organized in our follow-up work. Please visit:

GPT-RE-FT Repository

This repository contains the complete implementation including fine-tuned representation methods that were not included in the original release.

Supported Features

This repository supports the following methods from the paper:

  • GPT-Random: Random demonstration selection
  • GPT-SimCSE: SimCSE-based similar demonstration retrieval
  • Reasoning Logic: Task-aware reasoning in demonstrations
  • Entity-aware Similarity: Entity information enhanced retrieval

Usage

bash run_relation_ace.sh

Configuration Options

In the example script file run_relation_ace.sh, the following options are available:

Basic Settings

OptionDescriptionExample
--taskName of the tasksemeval, ace05, scierc
--modelGPT model nametext-davinci-003
--seedRandom seed42

Data Settings

OptionDescription
--num_testNumber of test examples (should be smaller than test dataset size)
--example_datasetFile path for demonstration examples
--test_datasetPath to test data (use test.json for full test set)

Demonstration Settings

OptionDescription
--fixed_example1: Fixed demonstrations; 0: Re-retrieve for each test (use 0 for kNN)
--fixed_test1: Fixed test dataset (can be ignored, use --test_dataset instead)
--num_per_relExamples per relation type for demonstrations (use 0 for kNN)
--num_naNA examples for demonstrations (use 0 for w/o NA and kNN setups)
--num_runKeep 1

Method Settings

OptionDescription
--random_label1: Use random labels in demonstrations
--reasoning1: Add reasoning to demonstrations
--use_knn1: Use kNN for demonstration retrieval
--kTop-k for kNN retrieval
--reverse1: Reverse demonstration order (default 0: more similar at top)
--entity_infoEntity-aware sentence similarity (from our paper)

Advanced Options (can be ignored)

OptionDescription
--varKeep 0
--verbalizeKeep 0
--structureStructured prompt trial, keep default
--use_ftFine-tuned representation - see GPT-RE-FT for full support
--self_errorKeep 0
--use_dev, --store_error_reason, --discriminatorKeep 0

Datasets

The repository includes preprocessed data for:

  • SemEval 2010 Task 8
  • ACE05
  • SciERC

Citation

If you find this work helpful, please cite our paper:

@inproceedings{wan2023gpt,
  title={GPT-RE: In-context Learning for Relation Extraction using Large Language Models},
  author={Wan, Zhen and Cheng, Fei and Mao, Zhuoyuan and Liu, Qianying and Song, Haiyue and Li, Jiwei and Kurohashi, Sadao},
  booktitle={Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing},
  year={2023}
}

License

Please refer to the LICENSE file for details.