Dataset Viewer
Duplicate
The dataset viewer is not available for this split.
Cannot load the dataset split (in streaming mode) to extract the first rows.
Error code:   StreamingRowsError
Exception:    CastError
Message:      Couldn't cast
id: string
choices: list<item: struct<finish_reason: string, index: int64, logprobs: null, message: struct<content: stri (... 104 chars omitted)
  child 0, item: struct<finish_reason: string, index: int64, logprobs: null, message: struct<content: string, role: s (... 92 chars omitted)
      child 0, finish_reason: string
      child 1, index: int64
      child 2, logprobs: null
      child 3, message: struct<content: string, role: string, function_call: null, tool_calls: null, refusal: null, annotati (... 22 chars omitted)
          child 0, content: string
          child 1, role: string
          child 2, function_call: null
          child 3, tool_calls: null
          child 4, refusal: null
          child 5, annotations: list<item: null>
              child 0, item: null
created: int64
model: string
object: string
service_tier: string
system_fingerprint: string
usage: struct<completion_tokens: int64, prompt_tokens: int64, total_tokens: int64, prompt_tokens_details: s (... 200 chars omitted)
  child 0, completion_tokens: int64
  child 1, prompt_tokens: int64
  child 2, total_tokens: int64
  child 3, prompt_tokens_details: struct<cached_tokens: int64, audio_tokens: int64>
      child 0, cached_tokens: int64
      child 1, audio_tokens: int64
  child 4, completion_tokens_details: struct<reasoning_tokens: int64, audio_tokens: int64, accepted_prediction_tokens: int64, rejected_pre (... 22 chars omitted)
      child 0, reasoning_tokens: int64
      child 1, audio_tokens: int64
      child 2, accepted_prediction_tokens: int64
      child 3, rejected_prediction_tokens: int64
request: struct<model: string, temperature: double, max_tokens: int64, top_p: int64, frequency_penalty: int64 (... 110 chars omitted)
  child 0, model: string
  child 1, temperature: double
  child 2, max_tokens: int64
  child 3, top_p: int64
  child 4, frequency_penalty: int64
  child 5, presence_penalty: int64
  child 6, n: int64
  child 7, seed: int64
  child 8, messages: list<item: struct<role: string, content: string>>
      child 0, item: struct<role: string, content: string>
          child 0, role: string
          child 1, content: string
task_id: int64
relative_id: string
prompt_input: struct<task_id: int64, messages: list<item: struct<role: string, content: string>>>
  child 0, task_id: int64
  child 1, messages: list<item: struct<role: string, content: string>>
      child 0, item: struct<role: string, content: string>
          child 0, role: string
          child 1, content: string
relation: string
to
{'id': Value('string'), 'choices': List({'finish_reason': Value('string'), 'index': Value('int64'), 'logprobs': Value('null'), 'message': {'content': Value('string'), 'role': Value('string'), 'function_call': Value('null'), 'tool_calls': Value('null'), 'refusal': Value('null'), 'annotations': List(Value('null'))}}), 'created': Value('int64'), 'model': Value('string'), 'object': Value('string'), 'service_tier': Value('string'), 'system_fingerprint': Value('string'), 'usage': {'completion_tokens': Value('int64'), 'prompt_tokens': Value('int64'), 'total_tokens': Value('int64'), 'prompt_tokens_details': {'cached_tokens': Value('int64'), 'audio_tokens': Value('int64')}, 'completion_tokens_details': {'reasoning_tokens': Value('int64'), 'audio_tokens': Value('int64'), 'accepted_prediction_tokens': Value('int64'), 'rejected_prediction_tokens': Value('int64')}}, 'prompt_input': {'task_id': Value('int64'), 'messages': List({'role': Value('string'), 'content': Value('string')})}, 'relation': Value('string'), 'relative_id': Value('string')}
because column names don't match
Traceback:    Traceback (most recent call last):
                File "/src/services/worker/src/worker/utils.py", line 149, in get_rows_or_raise
                  return get_rows(
                      dataset=dataset,
                  ...<4 lines>...
                      column_names=column_names,
                  )
                File "/src/libs/libcommon/src/libcommon/utils.py", line 272, in decorator
                  return func(*args, **kwargs)
                File "/src/services/worker/src/worker/utils.py", line 129, in get_rows
                  rows_plus_one = list(itertools.islice(safe_iter(ds, dataset=dataset), rows_max_number + 1))
                File "/src/services/worker/src/worker/utils.py", line 544, in safe_iter
                  yield from ds.decode(False) if ds.features else ds
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 3052, in __iter__
                  for key, example in ex_iterable:
                                      ^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 2559, in __iter__
                  for key, pa_table in self._iter_arrow():
                                       ~~~~~~~~~~~~~~~~^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 2584, in _iter_arrow
                  for key, pa_table in self.ex_iterable._iter_arrow():
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 558, in _iter_arrow
                  for key, pa_table in iterator:
                                       ^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 440, in _iter_arrow
                  for key, pa_table in self.generate_tables_fn(**gen_kwags):
                                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 361, in _generate_tables
                  self._cast_table(pa_table, json_field_paths=json_field_paths),
                  ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 132, in _cast_table
                  pa_table = table_cast(pa_table, self.info.features.arrow_schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2381, in table_cast
                  return cast_table_to_schema(table, schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2309, in cast_table_to_schema
                  raise CastError(
                  ...<3 lines>...
                  )
              datasets.table.CastError: Couldn't cast
              id: string
              choices: list<item: struct<finish_reason: string, index: int64, logprobs: null, message: struct<content: stri (... 104 chars omitted)
                child 0, item: struct<finish_reason: string, index: int64, logprobs: null, message: struct<content: string, role: s (... 92 chars omitted)
                    child 0, finish_reason: string
                    child 1, index: int64
                    child 2, logprobs: null
                    child 3, message: struct<content: string, role: string, function_call: null, tool_calls: null, refusal: null, annotati (... 22 chars omitted)
                        child 0, content: string
                        child 1, role: string
                        child 2, function_call: null
                        child 3, tool_calls: null
                        child 4, refusal: null
                        child 5, annotations: list<item: null>
                            child 0, item: null
              created: int64
              model: string
              object: string
              service_tier: string
              system_fingerprint: string
              usage: struct<completion_tokens: int64, prompt_tokens: int64, total_tokens: int64, prompt_tokens_details: s (... 200 chars omitted)
                child 0, completion_tokens: int64
                child 1, prompt_tokens: int64
                child 2, total_tokens: int64
                child 3, prompt_tokens_details: struct<cached_tokens: int64, audio_tokens: int64>
                    child 0, cached_tokens: int64
                    child 1, audio_tokens: int64
                child 4, completion_tokens_details: struct<reasoning_tokens: int64, audio_tokens: int64, accepted_prediction_tokens: int64, rejected_pre (... 22 chars omitted)
                    child 0, reasoning_tokens: int64
                    child 1, audio_tokens: int64
                    child 2, accepted_prediction_tokens: int64
                    child 3, rejected_prediction_tokens: int64
              request: struct<model: string, temperature: double, max_tokens: int64, top_p: int64, frequency_penalty: int64 (... 110 chars omitted)
                child 0, model: string
                child 1, temperature: double
                child 2, max_tokens: int64
                child 3, top_p: int64
                child 4, frequency_penalty: int64
                child 5, presence_penalty: int64
                child 6, n: int64
                child 7, seed: int64
                child 8, messages: list<item: struct<role: string, content: string>>
                    child 0, item: struct<role: string, content: string>
                        child 0, role: string
                        child 1, content: string
              task_id: int64
              relative_id: string
              prompt_input: struct<task_id: int64, messages: list<item: struct<role: string, content: string>>>
                child 0, task_id: int64
                child 1, messages: list<item: struct<role: string, content: string>>
                    child 0, item: struct<role: string, content: string>
                        child 0, role: string
                        child 1, content: string
              relation: string
              to
              {'id': Value('string'), 'choices': List({'finish_reason': Value('string'), 'index': Value('int64'), 'logprobs': Value('null'), 'message': {'content': Value('string'), 'role': Value('string'), 'function_call': Value('null'), 'tool_calls': Value('null'), 'refusal': Value('null'), 'annotations': List(Value('null'))}}), 'created': Value('int64'), 'model': Value('string'), 'object': Value('string'), 'service_tier': Value('string'), 'system_fingerprint': Value('string'), 'usage': {'completion_tokens': Value('int64'), 'prompt_tokens': Value('int64'), 'total_tokens': Value('int64'), 'prompt_tokens_details': {'cached_tokens': Value('int64'), 'audio_tokens': Value('int64')}, 'completion_tokens_details': {'reasoning_tokens': Value('int64'), 'audio_tokens': Value('int64'), 'accepted_prediction_tokens': Value('int64'), 'rejected_prediction_tokens': Value('int64')}}, 'prompt_input': {'task_id': Value('int64'), 'messages': List({'role': Value('string'), 'content': Value('string')})}, 'relation': Value('string'), 'relative_id': Value('string')}
              because column names don't match

Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

REPaL

This repository maintains the code and data for Grasping the Essentials: Tailoring Large Language Models for Zero-Shot Relation Extraction.

Links

Overview

REPaL is a framework to obtain a small language model based relation extractor for any target relation by distilling from a large language model. For any target relation (aka positive relation), we only assume the definition/description for that relation and an unlabeled relation instance corpus is given. REPaL works by (see the framework in the figure below): (1) synthesizing initial positive instances with the large language model and randomly sample from the unlabeled corpus as initial negative relation instances; (2) fine-tune a small pre-trained language model with initial instances and conduct inference over the unlabeled corpus; (3) sample instances from the unlabeled corpus as feedback and use previous synthesis history as feedback for follow-up positive instance and negative instance synthesis (first synthesize negative relation definitions and then synthesize follow-up negative instances). Note that the more subsequent iterations can be conducted following the above procedure. Also note that we also synthesize the dev set data with the same size as train data for automatically picking the checkpoint for the fine-tuned relation extractor.

For our defined Definition Only Zero-Shot Relation Extraction Setting, you will obtain a relation extractor for each relation with given definition. To convert it into the mutli-way relation classification setting, you can leverage the synthesized positive instances for a set of positive relations to train a multi-way relation classifier or decompose the multi-way classification task into multiple binary classification tasks (In this paper, we train the KnowPrompt with our synthesized data).

Requirements

The codes are written in Python 3.8 (verified working on Python 3.11 as well). Please first install the required packages by the following command:

pip install -r requirements.txt

Environment note

requirements.txt keeps numpy<2 because spaCy 3.7 / thinc 8.2 need numpy 1.x. Python 3.11 is the recommended version for a new environment. The reported experiments were run on Python 3.12 (run.log paths). Do not pin torch: the GPU decides the build (see CLAUDE.md).

Quick run

pip install -r requirements.txt
python run_experiments.py --list --data-root reproduce_main_data/data     # show planned runs
python run_experiments.py --datasets fewrel_defon --splits 1 --stages initial --data-root reproduce_main_data/data
python run_experiments.py --aggregate-only                                # rebuild results/aggregate.csv

Recommended GPU specification

The roberta-large-mnli backbone is fine-tuned in fp32 by default (no mixed precision), which uses roughly 5.6GB of fixed VRAM per relation (model weights + Adam optimizer states + gradients) before any activation memory. The original scripts/run_init.sh / scripts/run.sh batch sizes (--eval_batch_size 3600, --unlabel_infer_batch_size 4200) assume 4 large (>=24GB) GPUs.

GPU VRAM Works? Recommended settings
CPU only Not practical Full 14/15-relation evaluation split can take many hours per pass; fine only for a quick single-relation smoke test with small batch sizes (--eval_batch_size 16 --unlabel_infer_batch_size 16).
~8GB (e.g. RTX 4000, RTX 3070) Yes, with adjustments --train_batch_size 8 --accum_steps 2 (keeps the paper's effective batch size of 16), --eval_batch_size 128 --unlabel_infer_batch_size 128, and --use_amp to enable mixed precision (roughly halves activation memory, also faster).
>=16GB (e.g. RTX 4080/4090, A4000 Ada, V100) Yes Paper's --train_batch_size 16 works as-is; --eval_batch_size/--unlabel_infer_batch_size can go up to a few hundred without --use_amp, or match the paper's 3600/4200 on a single >=24GB GPU.
Multi-GPU (paper setup) Yes Original batch sizes as released; the code wraps the model in torch.nn.DataParallel automatically when torch.cuda.device_count() > 1.

--use_amp (mixed-precision training via torch.cuda.amp) is opt-in and CUDA-only; it is a no-op on CPU.

If you use run_experiments.py instead of the shell scripts, pass --device-profile {cpu,small_gpu,gpu} (auto-detected from torch.cuda.get_device_properties when omitted) and it will apply the batch sizes and --use_amp above automatically.

Renting a larger GPU (e.g. on vast.ai) rather than running on a small local card avoids small_gpu/AMP entirely. On a fresh instance, bash vastai_setup.sh installs dependencies, fetches the datasets, and starts the full sweep in one go β€” see docs/VASTAI.md for the full walkthrough and GPU sizing notes.

Datasets

Download data from datasets. Extract the data.tar.gz file (DefOn-FewRel and DefOn-WikiZSL) by

tar -xf data.tar.gz

and place the corresponding data folder under the current coda base ./.

Extract the reproduce_main_data.tar.gz file (DefOn-FewRel and DefOn-WikiZSL for reproducing the main experiments) by

tar -xf reproduce_main_data.tar.gz

and place the extracted reproduce_main_data/ folder in the repository root, so that the splits are at reproduce_main_data/data/<dataset>_<split>/.

You can adjust the --dataset_dir for running experiments over data in your specified folder.

Definition-Based Seed Construction and First-Round of Pattern Learning w/ SLM

The original scripts/run_init.sh was replaced by run_experiments.py, which drives src/run.py directly and writes structured results under results/. Run just the initial stage:

python run_experiments.py --stages initial --data-root reproduce_main_data/data

Feedback-Driven Instance Improvement & Bias Rectification

Likewise, scripts/run.sh was replaced by the followup stage:

python run_experiments.py --stages followup --data-root reproduce_main_data/data

Or run both stages for every split/dataset in one sweep (see python run_experiments.py --help for all options, and docs/VASTAI.md / vastai_setup.sh for a one-shot cloud setup):

python run_experiments.py --data-root reproduce_main_data/data --skip-existing --continue-on-error

TODO

  • Complete the contents under reproduce folder
  • Further organize the current implementation for more modularized organization

Citations

Please cite the following paper if you find the code helpful!

@inproceedings{zhou-etal-2024-grasping,
    title = "Grasping the Essentials: Tailoring Large Language Models for Zero-Shot Relation Extraction",
    author = "Zhou, Sizhe  and
      Meng, Yu  and
      Jin, Bowen  and
      Han, Jiawei",
    editor = "Al-Onaizan, Yaser  and
      Bansal, Mohit  and
      Chen, Yun-Nung",
    booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2024",
    address = "Miami, Florida, USA",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.emnlp-main.747",
    pages = "13462--13486",
    abstract = "Relation extraction (RE) aims to identify semantic relationships between entities within text. Despite considerable advancements, existing models predominantly require extensive annotated training data, which is both costly and labor-intensive to collect. Moreover, these models often struggle to adapt to new or unseen relations. Few-shot learning, aiming to lessen annotation demands, typically provides incomplete and biased supervision for target relations, leading to degraded and unstable performance. To accurately and explicitly describe relation semantics while minimizing annotation demands, we explore the definition only zero-shot RE setting where only relation definitions expressed in natural language are used to train a RE model. We introduce REPaL, comprising three stages: (1) We leverage large language models (LLMs) to generate initial seed instances from relation definitions and an unlabeled corpus. (2) We fine-tune a bidirectional Small Language Model (SLM) with initial seeds to learn relations for the target domain. (3) We expand pattern coverage and mitigate bias from initial seeds by integrating feedback from the SLM{'}s predictions on the unlabeled corpus and the synthesis history. To accomplish this, we leverage the multi-turn conversation ability of LLMs to generate new instances in follow-up dialogues, informed by both the feedback and synthesis history. Studies reveal that definition-oriented seed synthesis enhances pattern coverage whereas indiscriminately increasing seed quantity leads to performance saturation. Experiments on two datasets show REPaL significantly improved cost-effective zero-shot performance by large margins.",
}

Acknowledgements

  • Thanks to BERTNet regarding the implementation of relation definition bootstraping
  • Thanks to OpenAI regarding the implementation of calling api asynchronously

Code Base Structure

$CODE_DIR
β”œβ”€β”€ CLAUDE.md            # context for Claude Code, if you use it on this repo
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ fewrel_defon_1
β”‚   β”œβ”€β”€ fewrel_defon_2
β”‚   β”œβ”€β”€ fewrel_defon_3
β”‚   β”œβ”€β”€ fewrel_defon_4
β”‚   β”œβ”€β”€ fewrel_defon_5
β”‚   β”œβ”€β”€ wikizsl_defon_1
β”‚   β”œβ”€β”€ wikizsl_defon_2
β”‚   └── wikizsl_defon_3
β”œβ”€β”€ docs
β”‚   └── VASTAI.md        # cloud GPU setup walkthrough
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ figures
β”œβ”€β”€ README.md
β”œβ”€β”€ reproduce
β”‚   └── README.md
β”œβ”€β”€ reproduce_main_data   # authors' cached GPT-4o bundle (git-ignored)
β”‚   └── data
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ results               # run_experiments.py output: summary.csv, aggregate.csv, per-run logs
β”œβ”€β”€ run_experiments.py    # experiment driver (replaces the old scripts/run_init.sh, run.sh)
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ dataloader.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ llm_gen.py
β”‚   β”œβ”€β”€ model.py
β”‚   β”œβ”€β”€ pattern_learning.py
β”‚   β”œβ”€β”€ run.py
β”‚   β”œβ”€β”€ trainer.py
β”‚   └── utils.py
└── vastai_setup.sh       # one-shot setup + run script for a fresh cloud instance
Downloads last month
207

Paper for Manu2711/REPaL