Code for "Semantic Role Labeling as Dependency Parsing: Exploring Latent Tree Structures Inside Arguments".

Overview

crfsrl

image

Yu Zhang, Qingrong Xia, Shilin Zhou, Yong Jiang, Zhenghua Li, Guohong Fu, Min Zhang. Semantic Role Labeling as Dependency Parsing: Exploring Latent Tree Structures Inside Arguments. 2021. [arxiv]

Setup

The following packages should be installed:

Run the following scripts to obtain the training data. Please make sure PTB and OntoNotes are available:

bash scripts/conll05.sh PTB=<path-to-ptb>             SRL=data
bash scripts/conll12.sh ONTONOTES=<path-to-ontonotes> SRL=data

Run

Try the following commands to train first-order CRF and second-order CRF2o models:

# LSTM
# CRF
python -u crf.py   train -b -c configs/conll05.crf.srl.lstm.char-lemma.ini   -d 0 -f char lemma -p exp/conll05.crf.srl.lstm.char-lemma/model
# CRF2o
python -u crf2o.py train -b -c configs/conll05.crf2o.srl.lstm.char-lemma.ini -d 0 -f char lemma -p exp/conll05.crf2o.srl.lstm.char-lemma/model
# BERT finetuning
# CRF
python -u crf.py   train -b -c configs/conll05.crf.srl.bert.ini   -d 0 -p exp/conll05.crf.srl.bert/model   --batch-size=1000 --encoder bert --bert bert-large-cased 
# CRF2o
python -u crf2o.py train -b -c configs/conll05.crf2o.srl.bert.ini -d 0 -p exp/conll05.crf2o.srl.bert/model --batch-size=1000 --encoder bert --bert bert-large-cased

To do evaluation:

# end-to-end
python -u crf.py   evaluate -c configs/conll05.crf.srl.bert.ini  -d 0 -p exp/conll05.crf.srl.bert/model    --data data/conll05/test.conllu
# w/ gold predicates
python -u crf.py   evaluate -c configs/conll05.crf.srl.bert.ini  -d 0 -p exp/conll05.crf.srl.bert/model    --data data/conll05/test.conllu --prd

To make predictions:

python -u crf.py   predict  -c configs/conll05.crf.srl.bert.ini   -d 0 -p exp/conll05.crf.srl.bert/model   --data data/conll05/test.conllu --pred pred.conllu
bash scripts/eval.sh pred=pred.conllu gold=data/conll05/test.conllu

Contact

If you have any questions, feel free to contact me via emails.

Comments
  • RuntimeError while using the train script

    RuntimeError while using the train script

    Hi,

    I have preprocessed the Conll05 data and am trying to train the SRL model using your train scripts but I am bumping into a RuntimeError. Here's the stack trace:

      self._train(train.loader)
      File "/home/sanchit/crfsrl/crfsrl/parser.py", line 133, in _train
        s_edge, s_role = self.model(words, feats)
      File "/home/sanchit/crfsrl/.venv/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
        return forward_call(*input, **kwargs)
      File "/home/sanchit/crfsrl/crfsrl/model.py", line 162, in forward
        s_role = self.role_attn(role_d, role_h).permute(0, 2, 3, 1)
    RuntimeError: number of dims don't match in permute
    

    So I printed the s_role's shape ([1, 26, 26]) before permuting it and it's a 3d tensor, unlike the operation that is being performed above. Can you have a look at this? Thanks a lot!

    opened by sanchit-ahuja 4
  • Error while generating ConLL dataset objects for training the model

    Error while generating ConLL dataset objects for training the model

    Hi,

    I have been getting an assertion error when trying to generate data for the ConLL training.

    Converting data/conll05/train.prop to conllu format
      0%|                                                                          | 49/989860 [00:01<9:20:53, 29.41it/s]
    Traceback (most recent call last):
      File "scripts/prop2conllu.py", line 76, in <module>
        process(args.prop, args.file)
      File "scripts/prop2conllu.py", line 61, in process
        sentences.append(prop2conllu(lines[start:i]))
      File "scripts/prop2conllu.py", line 41, in prop2conllu
        assert len(prds) == len(args)
    AssertionError
    

    Can you please have a look at this? The command that I used to run the script: bash scripts/conll05.sh PTB=ptb SRL=data

    opened by sanchit-ahuja 4
  • Error when training with conll12

    Error when training with conll12

    When I run the following command,

    python -u crf.py train -b -c configs/conll12.crf.srl.bert.ini -d 0 -p exp/conll12.crf.srl.bert/model --batch-size=1000 --encoder bert --bert bert-large-cased --cache --binarize

    I suffer from the error below:

    tdteach@tdteach-u2004:~/workspace/crfsrl$ python -u crf.py train -b -c configs/conll12.crf.srl.bert.ini -d 0 -p exp/conll12.crf.srl.bert/model --batch-size=1000 --encoder bert --bert bert-large-cased --cache --binarize 2022-07-16 17:21:18 INFO ---------------------+------------------------------- Param | Value
    ---------------------+------------------------------- bert | bert-large-cased
    n_bert_layers | 4
    mix_dropout | 0.0
    bert_pooling | mean
    encoder_dropout | 0.1
    n_edge_mlp | 500
    n_role_mlp | 100
    mlp_dropout | 0.1
    lr | 5e-05
    lr_rate | 20
    mu | 0.9
    nu | 0.9
    eps | 1e-12
    weight_decay | 0
    clip | 5.0
    min_freq | 2
    fix_len | 20
    epochs | 10
    warmup | 0.1
    update_steps | 1
    batch_size | 1000
    prd | False
    mode | train
    path | exp/conll12.crf.srl.bert/model device | 0
    seed | 1
    threads | 16
    workers | 0
    cache | True
    binarize | True
    amp | False
    feat | None
    build | True
    checkpoint | False
    finetune | False
    encoder | bert
    max_len | None
    buckets | 32
    train | /home/tdteach/.cache/supar/data/srl/conll12/train.conllu dev | /home/tdteach/.cache/supar/data/srl/conll12/dev.conllu test | /home/tdteach/.cache/supar/data/srl/conll12/test.conllu embed | glove-6b-100
    ---------------------+-------------------------------

    2022-07-16 17:21:18 INFO Building the fields Using bos_token, but it is not set yet. 2022-07-16 17:21:19 INFO CoNLL(
    (words): SubwordField(vocab_size=28996, pad=[PAD], unk=[UNK], bos=[CLS]) (edges): ChartField(use_vocab=False) (roles): ChartField(vocab_size=1, unk=O) (spans): RawField() ) 2022-07-16 17:21:19 INFO Building the model 2022-07-16 17:21:25 INFO CRFSemanticRoleLabelingModel( (encoder): TransformerEmbedding(bert-large-cased, n_layers=4, n_out=1024, stride=256, pooling=mean, pad_index=0, finetune=True) (encoder_dropout): Dropout(p=0.1, inplace=False) (edge_mlp_d): MLP(n_in=1024, n_out=500, dropout=0.1) (edge_mlp_h): MLP(n_in=1024, n_out=500, dropout=0.1) (role_mlp_d): MLP(n_in=1024, n_out=100, dropout=0.1) (role_mlp_h): MLP(n_in=1024, n_out=100, dropout=0.1) (edge_attn): Biaffine(n_in=500, bias_x=True) (role_attn): Biaffine(n_in=100, bias_x=True, bias_y=True) )

    2022-07-16 17:21:27 INFO Loading the data 2022-07-16 17:21:27 INFO Seeking to cache the data to /home/tdteach/.cache/supar/data/srl/conll12/train.conllu.pt first Traceback (most recent call last):
    File "crf.py", line 43, in main() File "crf.py", line 39, in main init(parser) File "/media/tdteach/LinuxWork/workspace/crfsrl/supar/cmds/cmd.py", line 34, in init parse(0 if torch.cuda.is_available() else -1, args) File "/media/tdteach/LinuxWork/workspace/crfsrl/supar/cmds/cmd.py", line 54, in parse parser.train(**args) File "/media/tdteach/LinuxWork/workspace/crfsrl/crfsrl/parser.py", line 72, in train train = Dataset(self.transform, args.train, **args).build(batch_size, buckets, True, dist.is_initialized(), workers) File "/media/tdteach/LinuxWork/workspace/crfsrl/supar/utils/data.py", line 160, in build with cache(self.transform.load(self.data, **self.kwargs)) as chunks, mp.Pool(32) as pool: File "/home/tdteach/anaconda3/envs/allennlp/lib/python3.8/contextlib.py", line 113, in enter return next(self.gen) File "/media/tdteach/LinuxWork/workspace/crfsrl/supar/utils/data.py", line 145, in cache sentences = binarize({'sentences': progress_bar(sentences)}, fs)[1]['sentences'] KeyError: 'sentences'

    opened by TDteach 3
  • Predict mode with --prob option throws RuntimeError

    Predict mode with --prob option throws RuntimeError

    Hello, @yzhangcs. Thank you for sharing your great work!! After training a model, I'm trying to get probabilities of each answers on "predict" mode. But, I got an error shown below from File "/crfsrl/crfsrl/parser.py", line 272, in _predict. I tried to cast the lens tensor into another type but it doesn't work. Would it be possible to get any advices to fix this ??

    preds['probs'].extend([prob[1:i, :i].cpu() for i, prob in zip(lens.softmax(-1).unbind())])
    RuntimeError: "host_softmax" not implemented for 'Long' 
    
    opened by RyosukeMitani 2
  • Trained model

    Trained model

    Hi! I was wondering if you plan to release a trained model any time soon? I do not have direct access to Ontonotes so training the model would be impossible for me :(

    opened by kanishkamisra 1
  • Comparison with predpatt?

    Comparison with predpatt?

    Hi, I truly believe dependency parsing has a huge potential for semantic role labeling/information extraction. Predpatt is some intersting prior work and I wonder how they compare on precision/recall, please benchmark! https://www.cs.jhu.edu/~s.zhang/assets/pdf/iwcs17.pdf

    Moreover, regarding a way to further increase accuracy, I wonder if you could leverage Enhanced dependencies which predpatt unfortunately do not make use of.. despite their impressive expressive power. @yzhangcs

    opened by LifeIsStrange 1
  • Syntax errors while running script to extract data

    Syntax errors while running script to extract data

    Hi, I get the following error while running the first script to extract the data:

    [dnagaraj@tir crfsrl]$ bash scripts/conll05.sh PTB=/projects/tir1/corpora/treebank_3 SRL=data PTB: /projects/tir1/corpora/treebank_3 SRL: data Extracting evaluation files Converting data/conll05/train.prop to conllu format File "scripts/prop2conllu.py", line 30 rels[start-1] = '|'.join((rels[start-1], f'{prd}:B-{label}')) ^ SyntaxError: invalid syntax Converting data/conll05/dev.prop to conllu format File "scripts/prop2conllu.py", line 30 rels[start-1] = '|'.join((rels[start-1], f'{prd}:B-{label}')) ^ SyntaxError: invalid syntax Converting data/conll05/test.prop to conllu format File "scripts/prop2conllu.py", line 30 rels[start-1] = '|'.join((rels[start-1], f'{prd}:B-{label}')) ^

    Please could you let me know why this is the case and what should I do to resolve this error. Thanks in advance :)

    opened by divija96 4
Owner
Yu Zhang
PhD student @SUDA-LA; NLP/CL/ML.
Yu Zhang
A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code or write code yourself

Scriptfab - What is it? A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code

DevNugget 3 Jul 28, 2021
Code for the Python code smells video on the ArjanCodes channel.

7 Python code smells This repository contains the code for the Python code smells video on the ArjanCodes channel (watch the video here). The example

null 55 Dec 29, 2022
Code for CodeT5: a new code-aware pre-trained encoder-decoder model.

CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation This is the official PyTorch implementation

Salesforce 564 Jan 8, 2023
Galois is an auto code completer for code editors (or any text editor) based on OpenAI GPT-2.

Galois is an auto code completer for code editors (or any text editor) based on OpenAI GPT-2. It is trained (finetuned) on a curated list of approximately 45K Python (~470MB) files gathered from the Github. Currently, it just works properly on Python but not bad at other languages (thanks to GPT-2's power).

Galois Autocompleter 91 Sep 23, 2022
Code-autocomplete, a code completion plugin for Python

Code AutoComplete code-autocomplete, a code completion plugin for Python.

xuming 13 Jan 7, 2023
Code of paper: A Recurrent Vision-and-Language BERT for Navigation

Recurrent VLN-BERT Code of the Recurrent-VLN-BERT paper: A Recurrent Vision-and-Language BERT for Navigation Yicong Hong, Qi Wu, Yuankai Qi, Cristian

YicongHong 109 Dec 21, 2022
Easy, fast, effective, and automatic g-code compression!

Getting to the meat of g-code. Easy, fast, effective, and automatic g-code compression! MeatPack nearly doubles the effective data rate of a standard

Scott Mudge 97 Nov 21, 2022
Easily train your own text-generating neural network of any size and complexity on any text dataset with a few lines of code.

textgenrnn Easily train your own text-generating neural network of any size and complexity on any text dataset with a few lines of code, or quickly tr

Max Woolf 4.8k Dec 30, 2022
Code for the paper "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer"

T5: Text-To-Text Transfer Transformer The t5 library serves primarily as code for reproducing the experiments in Exploring the Limits of Transfer Lear

Google Research 4.6k Jan 1, 2023
Easily train your own text-generating neural network of any size and complexity on any text dataset with a few lines of code.

textgenrnn Easily train your own text-generating neural network of any size and complexity on any text dataset with a few lines of code, or quickly tr

Max Woolf 4.3k Feb 18, 2021
Code for the paper "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer"

T5: Text-To-Text Transfer Transformer The t5 library serves primarily as code for reproducing the experiments in Exploring the Limits of Transfer Lear

Google Research 3.2k Feb 17, 2021
Official PyTorch code for ClipBERT, an efficient framework for end-to-end learning on image-text and video-text tasks

Official PyTorch code for ClipBERT, an efficient framework for end-to-end learning on image-text and video-text tasks. It takes raw videos/images + text as inputs, and outputs task predictions. ClipBERT is designed based on 2D CNNs and transformers, and uses a sparse sampling strategy to enable efficient end-to-end video-and-language learning.

Jie Lei 雷杰 612 Jan 4, 2023
Collection of scripts to pinpoint obfuscated code

Obfuscation Detection (v1.0) Author: Tim Blazytko Automatically detect control-flow flattening and other state machines Description: Scripts and binar

Tim Blazytko 230 Nov 26, 2022
Code associated with the "Data Augmentation using Pre-trained Transformer Models" paper

Data Augmentation using Pre-trained Transformer Models Code associated with the Data Augmentation using Pre-trained Transformer Models paper Code cont

null 44 Dec 31, 2022
Official code for "Parser-Free Virtual Try-on via Distilling Appearance Flows", CVPR 2021

Parser-Free Virtual Try-on via Distilling Appearance Flows, CVPR 2021 Official code for CVPR 2021 paper 'Parser-Free Virtual Try-on via Distilling App

null 395 Jan 3, 2023
This is the source code of RPG (Reward-Randomized Policy Gradient)

RPG (Reward-Randomized Policy Gradient) Zhenggang Tang*, Chao Yu*, Boyuan Chen, Huazhe Xu, Xiaolong Wang, Fei Fang, Simon Shaolei Du, Yu Wang, Yi Wu (

null 40 Nov 25, 2022
Official code of our work, Unified Pre-training for Program Understanding and Generation [NAACL 2021].

PLBART Code pre-release of our work, Unified Pre-training for Program Understanding and Generation accepted at NAACL 2021. Note. A detailed documentat

Wasi Ahmad 138 Dec 30, 2022
code for "AttentiveNAS Improving Neural Architecture Search via Attentive Sampling"

AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling This repository contains PyTorch evaluation code, training code and pretrain

Facebook Research 94 Oct 26, 2022