Giter VIP home page Giter VIP logo

control_simp's Introduction

Controllable Simplification via Operation Classification

This repo contains code and data used to run experiments presented in the NAACL 2022 paper, Controllable Sentence Simplification via Operation Classification.

IRSD data

The IRSD dataset is available in data/. The publicly available version does not include any examples from Newsela-auto. To access the Newsela-auto examples, please obtain a licence from Newsela before contacting the authors directly.

Pretrained models

Pretrained PyTorch models for the 4-class operation classifier and controllable simplification model are available on HuggingFace.

To use the classifier:

from transformers import RobertaForSequenceClassification, AutoTokenizer

model = RobertaForSequenceClassification.from_pretrained("liamcripwell/ctrl44-clf")
tokenizer = AutoTokenizer.from_pretrained("liamcripwell/ctrl44-clf")

text = "Barack Hussein Obama II is an American politician who served as the 44th president of the United States from 2009 to 2017."
inputs = tokenizer(text, return_tensors="pt")

with torch.no_grad():
  logits = model(**inputs).logits
predicted_class_id = logits.argmax().item()
predicted_class_name = model.config.id2label[predicted_class_id]

To use the controllable simplification model:

from transformers import BartForConditionalGeneration, AutoTokenizer

model = BartForConditionalGeneration.from_pretrained("liamcripwell/ctrl44-simp")
tokenizer = AutoTokenizer.from_pretrained("liamcripwell/ctrl44-simp")

text = "<para> Barack Hussein Obama II is an American politician who served as the 44th president of the United States from 2009 to 2017."
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs, num_beams=10, max_length=128)

Training models

The following is an example of how to train a RoBERTa-based operation classifier:

doc_simp/models/train.py --data_file=<train_file.csv> --val_file=<val_file.csv> --learning_rate=3e-5 --x_col=complex --y_col=label --batch_size=32 --arch=classifier --model_type=roberta

Generative models can be trained as follows:

python control_simp/models/train.py --arch=bart --data_file=<train_file.csv> --val_file=<val_file.csv> --learning_rate=3e-5 --batch_size=16 --max_source_length=128 --max_target_length=128 --eval_beams=4 --x_col=complex --y_col=simple 

See the source code for additional arguments.

Evaluating models

Operation classifiers can be run from the terminal as follows (test_file should be a .csv):

python control_simp/models/eval.py clf <model_ckpt> <test_file> <out_file> --input_col=<sentence_col>

Generative models can be used for inference/evaluation in a similar fashion. For pipeline models, operation control tokens are dictated from a column in the input data specified via the --ctrl_toks flag. Disabling SAMSA with --samsa=False dramatically reduces runtime.

# End-to-End Model
python control_simp/models/eval.py bart <model_ckpt> <test_file> <output_dir> <run_name> --samsa=False

# CTRL Model
python control_simp/models/eval.py bart <model_ckpt> <test_file> <output_dir> <run_name> --ctrl_toks=<label_col> --samsa=False

Citation

If you find this repository useful, please cite our publication Controllable Sentence Simplification via Operation Classification.

@inproceedings{cripwell-etal-2022-controllable,
    title = "Controllable Sentence Simplification via Operation Classification",
    author = {Cripwell, Liam  and
      Legrand, Jo{\"e}l  and
      Gardent, Claire},
    booktitle = "Findings of the Association for Computational Linguistics: NAACL 2022",
    month = jul,
    year = "2022",
    address = "Seattle, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.findings-naacl.161",
    pages = "2091--2103",
}

control_simp's People

Contributors

liamcripwell avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

lliiillllill

control_simp's Issues

Dataset can not be able to download

Hello Cripwell,
when I try to download irsd_data.zip, there is an error,
This repository is over its data quota. Account responsible for LFS bandwidth should purchase more data packs to restore access.
It sames like you exceed the bandwidth and the storage. Could you offer a new way to download this dataset? Or just send it to my email.
Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.