This is the code for ACL2021 paper A Unified Generative Framework for Aspect-Based Sentiment Analysis

Overview

This is the code for ACL2021 paper A Unified Generative Framework for Aspect-Based Sentiment Analysis

Install the package in the requirements.txt, then use the following commands to install two other packages

pip install git+https://github.com/fastnlp/fastNLP@dev
pip install git+https://github.com/fastnlp/fitlog

The structure of this code is as follows

 -  data
    - fan  # D_19 in paper
    - penga  # D_20a in paper
    - pengb  # D_20b in paper
    - wang  # D_17 in paper
- fan/
    train_fan.py  # training file for fan data
- peng/
    train.py  # training file for penga and pengb
- wang/
    train_wang.py  # training file for wang

Please do remember to cite these dataset paper if you use them.

After enter the folder, you can run the code by directly using

python train.py --dataset pengb/14lap

The following output should be achieved

Save cache to caches/data_facebook/bart-base_pengb/14lap_False.pt.                                                                   
The number of tokens in tokenizer  50265
50268 50273
The number of parameters is 140607744
input fields after batch(if batch size is 2):
        tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22]) 
        src_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 41]) 
        src_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 
        tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 
target fields after batch(if batch size is 2):
        tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22]) 
        target_span: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,) 
        tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 

training epochs started 2021-02-03-02-24-46-454466
Evaluate data in 6.19 seconds!                                                                                                       
Evaluate data in 12.32 seconds!                                                                                                      
EvaluateCallback evaluation on data-test:                                                                                            
Seq2SeqSpanMetric: triple_f=23.86, triple_rec=16.45, triple_pre=43.41, oe_ae_f=27.35, oe_ae_rec=18.85, oe_ae_pre=49.76, ae_sc_f=33.28
, ae_sc_rec=23.97, ae_sc_pre=54.410000000000004, em=0.1494, invalid=0.436
Evaluation on dev at Epoch 1/50. Step:57/2850:                                                                                       
Seq2SeqSpanMetric: triple_f=21.47, triple_rec=14.78, triple_pre=39.23, oe_ae_f=24.42, oe_ae_rec=16.81, oe_ae_pre=44.62, ae_sc_f=33.80
0000000000004, ae_sc_rec=24.32, ae_sc_pre=55.379999999999995, em=0.1507, invalid=0.4384

....

In Epoch:50/Step:2850, got best dev performance:
Seq2SeqSpanMetric: triple_f=58.03, triple_rec=57.099999999999994, triple_pre=58.98, oe_ae_f=63.92, oe_ae_rec=62.9, oe_ae_pre=64.97, ae_sc_f=73.91, ae_sc_rec=74.66000000000001, ae_sc_pre=73.18, em=0.4155, invalid=0.0502
Comments
  • 请问为什么换了一个新数据集(英文)无法跑通

    请问为什么换了一个新数据集(英文)无法跑通

    作者您好,我想要将ATE任务的数据集换成一个新的数据集(ASTE-Data-V2),在我将数据转换为ATE任务要求的格式后(与wang的数据格式一致),代码跑不通了。

    bug存在于BartDecoder中,具体如下:

    屏幕截图 2022-11-16 215038.png

    我输出了一下,这里input_ids并不是具体的tensor值,变成了数据的地址信息(比如 <torch.Tensor object at 0x7ff5ce4b2280>),positions也变成了类似情况。

    请问你们在数据预处理阶段有对数据做什么特殊处理吗?或者ATE任务对数据有什么特殊要求吗?

    opened by FanY1999 1
  • About reproduction

    About reproduction

    Hi, I am reproducing you work, but I found that after running with the default settings on the pengb/14lab, I got the triplet metrics as follows: triple_f=57.73, triple_rec=56.81, triple_pre=58.68, while in the paper, the results should be: triple_f=58.69, triple_rec=56.19, triple_pre=61.41. Is there any suggestion?

    opened by Life-0-1 1
  • error

    error

    您好,在我按照readme和issue#1安装好相关库后。 我在训练时遇到一个错误,不知道怎么回事。

    Traceback (most recent call last):
      File "train.py", line 24, in <module>
        fitlog.set_log_dir('logs')
      File "miniconda3/envs/bart-absa/lib/python3.7/site-packages/fitlog/__init__.py", line 122, in set_log_dir
        _logger.set_log_dir(log_dir, new_log)
      File "miniconda3/envs/bart-absa/lib/python3.7/site-packages/fitlog/fastlog/logger.py", line 32, in wrapper
        return func(*args, **kwargs)
      File "miniconda3/envs/bart-absa/lib/python3.7/site-packages/fitlog/fastlog/logger.py", line 174, in set_log_dir
        raise NotADirectoryError("`{}` is not exist.".format(log_dir))
    NotADirectoryError: `logs` is not exist.
    
    opened by Wangpeiyi9979 1
  • 显示的batch size问题

    显示的batch size问题

    无论设置的batch size是多少(4/8/32等都试过),都会显示一次如下信息。 input fields after batch(if batch size is 2): tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22]) src_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 41]) src_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) target fields after batch(if batch size is 2): tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22]) target_span: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,) tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2]) 这一块输出没有看懂。请求作者帮忙解释一下,谢谢。

    opened by suncong132 0
  • 中文数据集使用及模型加载问题

    中文数据集使用及模型加载问题

    你好: 我参考你们的文章A Unified Generative Framework for Aspect-Based Sentiment,想用这个模型作中文的ABSA,于是我将原文的facebook/bart-base替换成fnlp/bart-base-chinese,但是我这里有以下几个问题:

    1. 1:transformers在4.4.1版本加载模型时会报错:RuntimeError: Error(s) in loading state_dict for BartModel:

    size mismatch for encoder.embed_positions.weight: copying a param with shape torch.Size([514, 768]) from checkpoint, the shape in current model is torch.Size([512, 768]). size mismatch for encoder.embed_positions.weight: copying a param with shape torch.Size([514, 768]) from checkpoint, the shape in current model is torch.Size([512, 768]). 这主要是在这里:model = BartSeq2SeqModel.build_model(bart_name, tokenizer, label_ids=label_ids, decoder_type=decoder_type,copy_gate=False, use_encoder_mlp=use_encoder_mlp, use_recur_pos=False)

    1. 2:facebook提供的batr-base中有一些文件是merges.txt和json形式的vocab,这与您在huggingface上提供的不一致。我将您在

    huggingface上提供的有关bart-base-chinese提供的文件用tokenizer.from_pretrained("bart-base-chinese")使用时,pytorch报错: OSError: Can't load tokenizer for 'bart-base-chinese'. Make sure that: 'bart-base-chinese' is a correct model identifier listed on 'https://huggingface.co/models' or 'bart-base-chinese' is the correct path to a directory containing relevant tokenizer files 请问这个该怎么解决?

    opened by yedongyu1996 0
  • OSError

    OSError

    python train.py --dataset pengb/14lap 你好,我尝试运行你的代码然后遇到了这个问题,但是本地能正常运行,在服务器上就有这个问题,我以为是python版本太低,换了python3.8还是出现了这个问题。 OSError: libstdc++.so.6: cannot open shared object file: No such file or directory

    opened by xdcui-nlp 2
  • RuntimeError freeze_support()

    RuntimeError freeze_support()

    I'm following your readme, while using train.py in the dataset pengb I had this error:

    ` python train.py --dataset pengb/14lap
    Read cache from caches/data_facebook/bart-base_pengb/14lap_False.pt.
    The number of tokens in tokenizer  50265
    50268 50273
    input fields after batch(if batch size is 2):
            tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22])
            src_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 41])
            src_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
            tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
    target fields after batch(if batch size is 2):
            tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22])
            target_span: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,)
            tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
    
    training epochs started 2021-12-10-15-44-42-060416
    Epoch 1/50:   0%|                                                          | 0/2850 [00:00<?, ?it/s, loss:{0:<6.5f}]Read cache from caches/data_facebook/bart-base_pengb/14lap_False.pt.
    The number of tokens in tokenizer  50265
    50268 50273
    input fields after batch(if batch size is 2):
            tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22])
            src_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 41])
            src_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
            tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
    target fields after batch(if batch size is 2):
            tgt_tokens: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2, 22])
            target_span: (1)type:numpy.ndarray (2)dtype:object, (3)shape:(2,)
            tgt_seq_len: (1)type:torch.Tensor (2)dtype:torch.int64, (3)shape:torch.Size([2])
    
    training epochs started 2021-12-10-15-44-52-779581
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
        exitcode = _main(fd, parent_sentinel)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 125, in _main
        prepare(preparation_data)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 236, in prepare
        _fixup_main_from_path(data['init_main_from_path'])
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
        main_content = runpy.run_path(main_path,
      File "C:\ProgramData\Anaconda3\lib\runpy.py", line 265, in run_path
        return _run_module_code(code, init_globals, run_name,
      File "C:\ProgramData\Anaconda3\lib\runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\sp\.conda\envs\BARTABSA\project\BARTABSA-main\peng\train.py", line 155, in <module>
        trainer.train(load_best_model=False)
      File "C:\ProgramData\Anaconda3\lib\site-packages\fastNLP\core\trainer.py", line 667, in train
        raise e
      File "C:\ProgramData\Anaconda3\lib\site-packages\fastNLP\core\trainer.py", line 658, in train
        self._train()
      File "C:\ProgramData\Anaconda3\lib\site-packages\fastNLP\core\trainer.py", line 712, in _train
        for batch_x, batch_y in self.data_iterator:
      File "C:\ProgramData\Anaconda3\lib\site-packages\fastNLP\core\batch.py", line 266, in __iter__
        for indices, batch_x, batch_y in self.dataiter:
      File "C:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 359, in __iter__
        return self._get_iterator()
      File "C:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 305, in _get_iterator
        return _MultiProcessingDataLoaderIter(self)
      File "C:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 918, in __init__
        w.start()
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 121, in start
        self._popen = self._Popen(self)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 224, in _Popen
        return _default_context.get_context().Process._Popen(process_obj)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 327, in _Popen
        return Popen(process_obj)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
        prep_data = spawn.get_preparation_data(process_obj._name)
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
        _check_not_importing_main()
      File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
        raise RuntimeError('''
    RuntimeError:
            An attempt has been made to start a new process before the
            current process has finished its bootstrapping phase.
    
            This probably means that you are not using fork to start your
            child processes and you have forgotten to use the proper idiom
            in the main module:
    
                if __name__ == '__main__':
                    freeze_support()
                    ...`
    

    Reading around it seems that : multiprocessing usually doesn't work in a console in Windows. When using a spawning system instead of fork, python must import modules and create state in the child process to get things to work. The outer script must be protected with a if name=="main": clause. I don't know where to change the code however. Any hints?

    opened by Jurys22 1
Owner
I am currently a PhD candidate in Fudan University.
null
Source code for "UniRE: A Unified Label Space for Entity Relation Extraction.", ACL2021.

UniRE Source code for "UniRE: A Unified Label Space for Entity Relation Extraction.", ACL2021. Requirements python: 3.7.6 pytorch: 1.8.1 transformers:

Wang Yijun 109 Nov 29, 2022
Code and dataset for ACL2018 paper "Exploiting Document Knowledge for Aspect-level Sentiment Classification"

Aspect-level Sentiment Classification Code and dataset for ACL2018 [paper] ‘‘Exploiting Document Knowledge for Aspect-level Sentiment Classification’’

Ruidan He 146 Nov 29, 2022
Code for our paper Aspect Sentiment Quad Prediction as Paraphrase Generation in EMNLP 2021.

Aspect Sentiment Quad Prediction (ASQP) This repo contains the annotated data and code for our paper Aspect Sentiment Quad Prediction as Paraphrase Ge

Isaac 39 Dec 11, 2022
codes for paper Combining Dynamic Local Context Focus and Dependency Cluster Attention for Aspect-level sentiment classification

DLCF-DCA codes for paper Combining Dynamic Local Context Focus and Dependency Cluster Attention for Aspect-level sentiment classification. submitted t

null 15 Aug 30, 2022
A sample pytorch Implementation of ACL 2021 research paper "Learning Span-Level Interactions for Aspect Sentiment Triplet Extraction".

Span-ASTE-Pytorch This repository is a pytorch version that implements Ali's ACL 2021 research paper Learning Span-Level Interactions for Aspect Senti

来自丹麦的天籁 10 Dec 6, 2022
Code and data for ACL2021 paper Cross-Lingual Abstractive Summarization with Limited Parallel Resources.

Multi-Task Framework for Cross-Lingual Abstractive Summarization (MCLAS) The code for ACL2021 paper Cross-Lingual Abstractive Summarization with Limit

Yu Bai 43 Nov 7, 2022
Code for the ACL2021 paper "Lexicon Enhanced Chinese Sequence Labelling Using BERT Adapter"

Lexicon Enhanced Chinese Sequence Labeling Using BERT Adapter Code and checkpoints for the ACL2021 paper "Lexicon Enhanced Chinese Sequence Labelling

null 274 Dec 6, 2022
Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive Learning".

ERICA Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive L

THUNLP 75 Nov 2, 2022
Code for our paper "Sematic Representation for Dialogue Modeling" in ACL2021

AMR-Dialogue An implementation for paper "Semantic Representation for Dialogue Modeling". You may find our paper here. Requirements python 3.6 pytorch

xfbai 45 Dec 26, 2022
Code for ACL2021 paper Consistency Regularization for Cross-Lingual Fine-Tuning.

xTune Code for ACL2021 paper Consistency Regularization for Cross-Lingual Fine-Tuning. Environment DockerFile: dancingsoul/pytorch:xTune Install the f

Bo Zheng 42 Dec 9, 2022
Source code for the paper "PLOME: Pre-training with Misspelled Knowledge for Chinese Spelling Correction" in ACL2021

PLOME:Pre-training with Misspelled Knowledge for Chinese Spelling Correction (ACL2021) This repository provides the code and data of the work in ACL20

null 197 Nov 26, 2022
Code and data for ACL2021 paper Cross-Lingual Abstractive Summarization with Limited Parallel Resources.

Multi-Task Framework for Cross-Lingual Abstractive Summarization (MCLAS) The code for ACL2021 paper Cross-Lingual Abstractive Summarization with Limit

Yu Bai 43 Nov 7, 2022
A Unified Generative Framework for Various NER Subtasks.

This is the code for ACL-ICJNLP2021 paper A Unified Generative Framework for Various NER Subtasks. Install the package in the requirements.txt, then u

null 177 Jan 5, 2023
This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Information Maximization for Multimodal Sentiment Analysis, accepted at EMNLP 2021.

MultiModal-InfoMax This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Informa

Deep Cognition and Language Research (DeCLaRe) Lab 89 Dec 26, 2022
Code for the paper "MASTER: Multi-Aspect Non-local Network for Scene Text Recognition" (Pattern Recognition 2021)

MASTER-PyTorch PyTorch reimplementation of "MASTER: Multi-Aspect Non-local Network for Scene Text Recognition" (Pattern Recognition 2021). This projec

Wenwen Yu 255 Dec 29, 2022
Source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated Recurrent Memory Network

KaGRMN-DSG_ABSA This repository contains the PyTorch source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated

XingBowen 4 May 20, 2022
Inference code for "StylePeople: A Generative Model of Fullbody Human Avatars" paper. This code is for the part of the paper describing video-based avatars.

NeuralTextures This is repository with inference code for paper "StylePeople: A Generative Model of Fullbody Human Avatars" (CVPR21). This code is for

Visual Understanding Lab @ Samsung AI Center Moscow 18 Oct 6, 2022
A Multi-modal Model Chinese Spell Checker Released on ACL2021.

ReaLiSe ReaLiSe is a multi-modal Chinese spell checking model. This the office code for the paper Read, Listen, and See: Leveraging Multimodal Informa

DaDa 106 Dec 29, 2022
Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021

Contrastive Learning for Many-to-many Multilingual Neural Machine Translation(mCOLT/mRASP2), ACL2021 The code for training mCOLT/mRASP2, a multilingua

null 104 Jan 1, 2023