Package: rst-parser
Neural-based RST Parsing And Analysis In Persuasive DiscourseThis is the official PyTorchrepoforRST-NN-Parser, a deep neural network model for RST parsing.Neural-based RST Parsing And Analysis In Persuasive Discourse
Jinfen Li, Lu Xiao
W-NUT 2021If Multi-EmoBERT is helpful for your research, please consider citing our paper:@inproceedings{li2021neural,
  title={Neural-based rst parsing and analysis in persuasive discourse},
  author={Li, Jinfen and Xiao, Lu},
  booktitle={Proceedings of the Seventh Workshop on Noisy User-generated Text (W-NUT 2021)},
  pages={274--283},
  year={2021}
}Usage via Pip Packageinstall pip packagepip install rst-parseruse pip packagefrom rst_parser import rst_parser
tree_results, dis_results = rst_parser.parse(["The scientific community is making significant progress in understanding climate change. Researchers have collected vast amounts of data on temperature fluctuations, greenhouse gas emissions, and sea-level rise. This data shows a clear pattern of increasing global temperatures over the past century. However, there are still debates about the causes and consequences of climate change."])tree_results explanationeach tree in the tree_results is the binary tree with the following node attributes
    text # text of an EDU
    own_rel # own relation
    edu_span # edu span
    own_nuc # own nuclearity
    lnode # left child nodes
    rnode # right child nodes
    pnode # parent node
    nuc_label # nuc_label: NN, NS, SN
    rel_label # one of the 18 relationsdis_results explanation( Root (span 1 4)
  ( Nucleus (span 1 2) (rel2par span)
    ( Nucleus (leaf 1) (rel2par span) (text _!The scientific community is making significant progress!_) )
    ( Satellite (leaf 2) (rel2par Elaboration) (text _!in understanding climate change .!_) )
  )
  ( Satellite (span 3 4) (rel2par Elaboration)
    ( Nucleus (leaf 3) (rel2par span) (text _!Researchers have collected vast amounts of data on temperature fluctuations , greenhouse gas emissions , and sea-level rise .!_) )
    ( Satellite (leaf 4) (rel2par Contrast) (text _!This data shows a clear pattern of increasing global temperatures over the past century . However , there are still debates about the causes and consequences of climate change .!_) )
  )
)Usage viaSource CodeEnvironmentcreate a virtual environmentconda create -n emo_env python=3.9.16install packages via conda first and then via pippip install -r requirements.txt
conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit
conda install pytorch torchvision pytorch-cuda=11.8 -c pytorch -c nvidiarename .env.example as .env and change the variable values in the fileNeptuneBefore running the code, you need to complete the following steps:Create aNeptuneaccount and project.Edit the [NEPTUNE_API_TOKEN] and [NEPTUNE_NAME] fields in the .env file.MultirunDo grid search over different configs.python main.py -m \
    dataset=rst_dt \
    seed=0,1,2,3,4,5 \Evaluate checkpointThis command evaluates a checkpoint on the train, dev, and test sets.python main.py \
    training=evaluate \
    training.ckpt_path=/path/to/ckpt \
    training.eval_splits=train,dev,test \Finetune checkpointpython main.py \
    training=evaluate \
    training.ckpt_path=/path/to/ckpt \Offline ModeIn offline mode, results are not logged to Neptune.python main.py logger.offline=TrueDebug ModeIn debug mode, results are not logged to Neptune, and we only train/evaluate for limited number of batches and/or epochs.python main.py debug=TrueHydra Working DirectoryHydra will change the working directory to the path specified inconfigs/hydra/default.yaml. Therefore, if you save a file to the path'./file.txt', it will actually save the file to somewhere likelogs/runs/xxxx/file.txt. This is helpful when you want to version control your saved files, but not if you want to save to a global directory. There are two methods to get the "actual" working directory:Usehydra.utils.get_original_cwdfunction callUsecfg.work_dir. To use this in the config, can do something like"${data_dir}/${.dataset}/${model.arch}/"Config Keywork_dircurrent working directory (wheresrc/is)data_dirwhere data folder islog_dirwhere log folder is (runs & multirun)root_dirwhere the saved ckpt & hydra config areExample CommandsHere, we assume the following:Thedata_dirisdata, which meansdata_dir=${work_dir}/../data.The dataset isRST Discourse Treebank.1. Build datasetThe commands below are used to build pre-processed datasets, saved as pickle files. The model architecture is specified so that we can use the correct tokenizer for pre-processing.
Remember to put a xxx.yaml file in the configs/dataset folder for the dataset you want to build.python scripts/build_dataset.py --data_dir data \
    --dataset rst_dt --arch bert-base-uncased --max_length 32 --split train

python scripts/build_dataset.py --data_dir data \
    --dataset rst_dt --arch bert-base-uncased --split dev

python scripts/build_dataset.py --data_dir data \
    --dataset rst_dt --arch bert-base-uncased --split testIf the dataset is very large, you have the option to subsample part of the dataset for smaller-scale experiements. For example, in the command below, we build a train set with only 1000 train examples (sampled with seed 0).python scripts/build_dataset.py --data_dir data \
    --dataset rst_dt --arch bert-base-uncased --split train \
    --num_samples 10 --seed 02. Train RST ParserThe command below is the most basic way to runmain.pyNoted: train_batch_size, eval_batch_size are the number of documents in a batch, mini_batch_size is the number of EDUs in a documentpython main.py -m \
    data=rst_dt \
    model.optimizer.lr=2e-5 \
    setup.train_batch_size=1 \
    setup.accumulate_grad_batches=1 \
    setup.eff_train_batch_size=1 \
    setup.eval_batch_size=1 \
    setup.mini_batch_size=10 \
    setup.num_workers=3 \
    seed=0,1,23. Train Model with Different ConfigsChange blstm_hidden_sizepython main.py -m \
    data=rst_dt \
    model.blstm_hidden_size=300 \
    model.optimizer.lr=2e-5 \
    setup.train_batch_size=1 \
    setup.accumulate_grad_batches=1 \
    setup.eff_train_batch_size=1 \
    setup.eval_batch_size=1 \
    setup.mini_batch_size=10 \
    setup.num_workers=3 \
    seed=0,1,24. Evaluate Modelexp_id is the folder name under your save_dir (e.g., "rst_dt_xxx"), ckpt_path is the checkpoint under the checkpoints folder in the exp_id folder.
The results will be saved in the model_outputs folder in the exp_id folder.python main.py -m \
    data=rst_dt \
    training=evaluate \
    ckpt_path = xxx \
    exp_id = xxx \
    setup.eval_batch_size=1 \
    setup.mini_batch_size=10 \
    setup.num_workers=3 \
    seed=0,1,2