GithubHelp home page GithubHelp logo

abrazinskas / fewsum Goto Github PK

View Code? Open in Web Editor NEW
35.0 4.0 6.0 18.44 MB

Few-shot learning framework for opinion summarization published at EMNLP 2020.

License: MIT License

Python 90.30% Jupyter Notebook 9.70%
machine-learning natural-language-processing summarization deep-learning opinion-summarization

fewsum's Introduction

Few-Shot Learning for Opinion Summarization

This repository contains the codebase along with accompanying artifacts of the corresponding work published at EMNLP 2020, Dominican Republic.

Installation

The easiest way to proceed is to create a separate conda environment.

conda create -n fewsum python=3.7.5
conda activate fewsum

Install required modules.

pip install -r requirements.txt

Add the root directory to the path if you want to execute scripts from the command line.

export PYTHONPATH=root_path:$PYTHONPATH

Data

Training data

Data pre-processing pipeline along with instructions is available from the previous project. Further, reviews needs to be enriched with ROUGE scores (coverage property) in the leave-one-out fashion using fewsum/scripts/postprocess_data.py. This is done to avoid online ROUGE computations that are time consuming.

We also provide the final pre-processed dataset versions, both for Amazon and Yelp. Unzip them to artifacts/[yelp or amazon]/. These datasets can be directly used to train the model.

Annotated summaries

For the purpose of fine-tuning and evaluation, we produced Yelp and Amazon annotated datasets. More information found in the corresponding readme file.

Running the model

In order to arrive to the final model, a number of steps need to be executed as described below. For each step, we provided checkpoints that can be used to generate summaries and also used as starting points for downstream steps.

In general, model hyper-parameters can modified by altering corresponding classes in fewsum/config/model_hp. In the same vein, one can modify the run configuration of each model in fewsum/config/run/ classes.

The fewsum/workflow.py is the main file for training and inference that has logic for assembling data pipelines, tokenizers, and other relevant components. Unless a custom setup is required, no modifications of this file is needed.

Preparation

We provide checkpoints for each step for Amazon, which can be downloaded by following links in each section below. Checkpoints need to be placed to artifacts/amazon/checkpoints/. If you use a different path, specify it in a run configuration file, e.g., fewsum/config/model_hp/unsup_run.py.

We also provide the word vocabulary, BPE vocabularies, and a true caser in artifacts/amazon/misc. These can be produced for custom datasets using scripts available in fewsum/scripts.

Unsupervised pre-training

Here, we use the leave-one-out objective in order to pre-train the model on unannotated reviews using the command below; checkpoint.

python fewsum/workflow.py --regime=unsupervised

Novelty reduction

At this stage, we reduce the novelty by penalizing output probability assignments to words that do not appear in the input reviews; checkpoint.

python fewsum/workflow.py --regime=novelty_reduction

Plug-in network initialization

Here, the plug-in network is added that is trained to predict property values for reviews (derived by the oracle) based on the leave-one-out setting; checkpoint.

python fewsum/workflow.py --regime=plugin_init

Plug-in network tuning

In this phase, we utilize human-written abstractive summaries and tune the plug-in network to predict their property values that are derived by the oracle; checkpoint.

python fewsum/workflow.py --regime=plugin_tuning

Joint-tuning

This is the final phase, where we fine-tune both the plug-in network and the attention mechanism over the encoder states; checkpoint.

python fewsum/workflow.py --regime=joint_tuning

Summary generation

In order to generate summaries at any stage, please replace the REGIME token in the command below.

python fewsum/workflow.py --regime=REGIME --inference

Already generated summaries by the final model are also available.

Citation

@inproceedings{brazinskas2020few,
  title={Few-Shot Learning for Opinion Summarization},
  author={Bra{\v{z}}inskas, Arthur and Lapata, Mirella and Titov, Ivan},
 booktitle={Proceedings of the conference on empirical methods in natural language processing (EMNLP)},
  year={2020}
}

License

MIT

fewsum's People

Contributors

abrazinskas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fewsum's Issues

Golden summaries for Amazon

Hi,
Nice paper! I was wondering whether the Amazon split's golden summaries correspond to reviews other than those under artifacts/amazon/reviews/. For instance, under artifacts/amazon/gold_summs/val.csv one product ID is "B006UF64CW". However, this ID does not show up in in either of artifacts/amazon/reviews/val/ and artifacts/amazon/reviews/train/ (the former has B006UAR138 and B006ULVKZ2 as the alphabetically closest ids, while the latter has B006UFMH3W as the closest one).
Are the IDs used in the Amazon Golden summaries mutually distinct from those with reviews?

training with multiple smmaries

Hello,
I just want to make sure that I understood your code correctly
During training, do you flatten the 3 reference summaries to become one summary ?
Thank you

Any pointers to how to use this model for inference ( user provided text rather than the validation review text in csv)

Hello,

I want to use this model in the inference regime, but I want to provide my text instead of looking at the validation text. However, the code has many moving parts, and I need some help.
This is the flow in which I would expect a typical inference to work. (text (set of reviews) -> pre-processing -> model -> output_summary)
Any tips for translating the above flow in your code?

Thanks.

unsupervised training error

when i follow the command on readme to train unsupervised model
I got the following error message

2022-04-17 22:32:50,496 [INFO]: Chunk # 4900 ppl: 26.1486, nll: 128.3368
2022-04-17 22:33:01,088 [INFO]: Chunk # 5000 ppl: 27.0186, nll: 128.0882
2022-04-17 22:33:01,200 [INFO]: Total data-chunks: 5000 and data-units: 270000.
2022-04-17 22:33:01,200 [INFO]: Epoch training time elapsed: 528.27 (s).
2022-04-17 22:33:01,200 [INFO]: Data-unit/sec: 511.101.
2022-04-17 22:33:01,281 [INFO]: Evaluation data source: {'data_path': 'artifacts/amazon/reviews/val/', 'early_term': 500}.
2022-04-17 22:33:57,546 [INFO]: Total data-chunks: 500 and data-units: 90000.
2022-04-17 22:33:57,547 [INFO]: Evaluation time elapsed: 55.24 (s).
2022-04-17 22:33:57,547 [INFO]: Data-unit/sec: 1629.164.
2022-04-17 22:33:57,547 [INFO]: Validation ppl: 27.2019, nll: 128.7210
2022-04-17 22:33:57,891 [INFO]: Saved the model's and optimizer's state to: '/home/nlplab/harry/review_rec/FewSum/runs/amazon/unsup/5/ep1_checkpoint.tar'.
2022-04-17 22:33:57,901 [INFO]: Performing summary evaluation on {'data_path': 'artifacts/amazon/gold_summs/val.csv'}.
/home/nlplab/harry/review_rec/FewSum/fewsum/utils/tools/beam_search.py:226: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  prev_k = best_scores_id // num_words
2022-04-17 22:33:58,801 [ERROR]: The shape of the 2D attn_mask is torch.Size([1, 1]), but should be (1, 2).
Traceback (most recent call last):
  File "fewsum/workflow.py", line 263, in <module>
    raise e
  File "fewsum/workflow.py", line 260, in <module>
    after_epoch_func=after_ep_func)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/interfaces/i_dev_summ.py", line 90, in standard_workflow
    after_epoch_func(epoch)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/interfaces/i_dev_summ.py", line 214, in after_ep_func
    **summ_eval_kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/interfaces/i_dev_summ.py", line 110, in summ_eval
    eval_proc.eval(data_source, out_file_path=out_file_path)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/eval/procedures/summ_eval_proc.py", line 73, in eval
    gen_summ, pred_props = self.summs_gen_func(batch)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/interfaces/i_dev_summ.py", line 222, in summ_gen_wrapper
    gen_summ, pred_props = self.imodel.generate(batch=batch, **kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/interfaces/i_summ.py", line 71, in generate
    minimum=1, **prop_vals)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/generators/beamer.py", line 109, in __call__
    out = self.decoding_func(prev_word_ids, **new_kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/models/basesum.py", line 149, in decode
    pos_offset=pos_offset, **kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/models/basesum.py", line 124, in _decode
    decode=True)
  File "/home/nlplab/harry/anaconda3/envs/fewsum/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/modules/transformer_stack.py", line 90, in forward
    mem_key_padding_mask=mem_key_padding_mask)
  File "/home/nlplab/harry/anaconda3/envs/fewsum/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/nlplab/harry/review_rec/FewSum/fewsum/modelling/modules/transformer_decoder_layer.py", line 86, in forward
    key_padding_mask=tgt_key_padding_mask)
  File "/home/nlplab/harry/anaconda3/envs/fewsum/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/nlplab/harry/anaconda3/envs/fewsum/lib/python3.7/site-packages/torch/nn/modules/activation.py", line 1045, in forward
    attn_mask=attn_mask, average_attn_weights=average_attn_weights)
  File "/home/nlplab/harry/anaconda3/envs/fewsum/lib/python3.7/site-packages/torch/nn/functional.py", line 5268, in multi_head_attention_forward
    raise RuntimeError(f"The shape of the 2D attn_mask is {attn_mask.shape}, but should be {correct_2d_size}.")
RuntimeError: The shape of the 2D attn_mask is torch.Size([1, 1]), but should be (1, 2).

I already trace the code in BaseSum class but I have no idea to fix the bug.
I did not change the code.

unsupervised training dataset

Hi, thank you for your great work first, I love your works!

I have some questions about unsupervised training steps
The paper said that
image

And the final pre-processed dataset provided by you be like
Example :
image

And here is my questions

  1. What is the "group" means, and how did you arrange the group? (In my opinion the group is not mean the category of the product!?)
  2. And in the example (the picture above), how do I know which review is ri during unsupervised training stage?

Thank you very much!

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.