Giter Site home page Giter Site logo

yangheng95 / pyabsa Goto Github PK

View Code? Open in Web Editor NEW
865.0 14.0 148.0 37.48 MB

Sentiment Analysis, Text Classification, Text Augmentation, Text Adversarial defense, etc.;

Home Page: https://pyabsa.readthedocs.io

License: MIT License

Python 27.12% Jupyter Notebook 72.88%
aspect-based-sentiment-analysis aspect-term-extraction lcf-bert pytorch pyabsa adversarial regression aspect-sentiment-triplet-extraction

pyabsa's Introduction

PyABSA - Open Framework for Aspect-based Sentiment Analysis (paper)

PyPI - Python Version PyPI Downloads Downloads License Documentation Status

total views total views per week total clones total clones per week

PWC

Hi, there! Please star this repo if it helps you! Each Star helps PyABSA go further, many thanks. PyABSA is a free and open-source tool for everyone, but please do not forget to attach the (informal or formal) author information and project address in your works, products and publications, etc.

Try our demos on Huggingface Space

Apart from the paper, there are two new features in PyABSA: Aspect sentiment triplet extraction and Aspect quadruple extraction. We have deployed the demos on Huggingface Space, you can try them online.

Usage Examples

We have prepared many examples for different tasks. Please refer to Examples for more usage examples.

Installation

install via pip

To use PyABSA, install the latest version from pip or source code:

pip install -U pyabsa

install via source

git clone https://github.com/yangheng95/PyABSA --depth=1
cd PyABSA 
python setup.py install

Quick-Start

Extract aspect terms and classify sentiments

from pyabsa import AspectTermExtraction as ATEPC, available_checkpoints

# you can view all available checkpoints by calling available_checkpoints()
checkpoint_map = available_checkpoints()

aspect_extractor = ATEPC.AspectExtractor('multilingual',
                                         auto_device=True,  # False means load model on CPU
                                         cal_perplexity=True,
                                         )

# instance inference
aspect_extractor.predict(['I love this movie, it is so great!'],
                         save_result=True,
                         print_result=True,  # print the result
                         ignore_error=True,  # ignore the error when the model cannot predict the input
                         )

inference_source = ATEPC.ATEPCDatasetList.Restaurant16
atepc_result = aspect_extractor.batch_predict(target_file=inference_source,  #
                                              save_result=True,
                                              print_result=True,  # print the result
                                              pred_sentiment=True,  # Predict the sentiment of extracted aspect terms
                                              )

print(atepc_result)

Aspect-based sentiment analysis

from pyabsa import AspectPolarityClassification as APC, available_checkpoints

# you can view all available checkpoints by calling available_checkpoints()
checkpoint_map = available_checkpoints(show_ckpts=True)

classifier = APC.SentimentClassifier('multilingual',
                                     auto_device=True,  # False means load model on CPU
                                     cal_perplexity=True,
                                     )

# instance inference
classifier.predict(['I love this movie, it is so great!'],
                   save_result=True,
                   print_result=True,  # print the result
                   ignore_error=True,  # ignore the error when the model cannot predict the input
                   )

inference_source = APC.APCDatasetList.Laptop14
apc_result = classifier.batch_predict(target_file=inference_source,  #
                                      save_result=True,
                                      print_result=True,  # print the result
                                      pred_sentiment=True,  # Predict the sentiment of extracted aspect terms
                                      )

print(apc_result)

Dataset Annotation and Model Training

please refer to the documentation: PyABSA Documentation. If you have any questions about the docs, please feel free to raise an issue. Also, you can join to improve the docs.

Notice

This repository is based on our papers for ABSA research. Here are the papers that you can cite or refer to for your implementations:

Aspect sentiment polarity classification models
  1. Back to Reality: Leveraging Pattern-driven Modeling to Enable Affordable Sentiment Dependency Learning ( e.g., Fast-LSA, 2020)
  2. Learning for target-dependent sentiment based on local context-aware embedding ( e.g., LCA-Net, 2020)
  3. LCF: A Local Context Focus Mechanism for Aspect-Based Sentiment Classification ( e.g., LCF-BERT, 2019)
Aspect sentiment polarity classification & Aspect term extraction models
  1. A multi-task learning model for Chinese-oriented aspect polarity classification and aspect term extraction] ( e.g., Fast-LCF-ATEPC, 2020)
  2. (Arxiv) A multi-task learning model for Chinese-oriented aspect polarity classification and aspect term extraction

If you are looking for the original proposal of local context focus, here are some introduction at here.

Citation

@inproceedings{YangZL23,
  author       = {Heng Yang and
                  Chen Zhang and
                  Ke Li},
  editor       = {Ingo Frommholz and
                  Frank Hopfgartner and
                  Mark Lee and
                  Michael Oakes and
                  Mounia Lalmas and
                  Min Zhang and
                  Rodrygo L. T. Santos},
  title        = {PyABSA: {A} Modularized Framework for Reproducible Aspect-based Sentiment
                  Analysis},
  booktitle    = {Proceedings of the 32nd {ACM} International Conference on Information
                  and Knowledge Management, {CIKM} 2023, Birmingham, United Kingdom,
                  October 21-25, 2023},
  pages        = {5117--5122},
  publisher    = {{ACM}},
  year         = {2023},
  url          = {https://doi.org/10.1145/3583780.3614752},
  doi          = {10.1145/3583780.3614752},
  timestamp    = {Thu, 23 Nov 2023 13:25:05 +0100},
  biburl       = {https://dblp.org/rec/conf/cikm/0008ZL23.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}

Contribution

This repository is developed and maintained by HENG YANG (yangheng95@GitHub), with great contribution from community researchers. We expect that you can help us improve this project, and your contributions are welcome. You can make a contribution in many ways, including:

  • Share your custom dataset in PyABSA and ABSADatasets
  • Integrates your models in PyABSA. (You can share your models whether it is or not based on PyABSA. if you are interested, we will help you)
  • Raise a bug report while you use PyABSA or review the code (PyABSA is a individual project driven by enthusiasm so your help is needed)
  • Give us some advice about feature design/refactor (You can advise to improve some feature)
  • Correct/Rewrite some error-messages or code comment (The comments are not written by native english speaker, you can help us improve documents)
  • Create an example script in a particular situation (Such as specify a SpaCy model, pretrained-bert type, some hyper-parameters)
  • Star this repository to keep it active

License

PyABSA is released under MIT licence, please cite this repo (or papers) or attach the author information in your work (repository, blog, product, etc.)

pyabsa's People

Contributors

allcontributors[bot] avatar brieucdandin avatar brightgems avatar francisdacian avatar jackie930 avatar lpfy avatar xumayi avatar yangheng95 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyabsa's Issues

I can't arrive the acc in your paper said

I can see in your paper,and your train.log file, the acc of laptop can achieve 82.29 in bert_cdm, but in my server I cant achieve your acc , my parameter is all like you ,but my pretrained_bert_name', default='bert-base-uncased' , i can only achieve 81.50470219435736,what thing I do wrong? can you help me?

Data leakage Train <=> Test?

Hi,

when loading the ATEPC model (ATEPCTrainedModelManager.get_checkpoint(checkpoint_name="English")) it prints that the model was trained on the following datasetsplit:

dataset_file: {
'train':
['datasets\\atepc_datasets\\SemEval\\laptop14\\Laptops_Train.xml.seg.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant14\\Restaurants_Train.xml.seg.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant15\\restaurant_train.raw.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant16\\restaurant_train.raw.atepc'],
'test':
['datasets\\atepc_datasets\\SemEval\\laptop14\\Laptops_Test_Gold.xml.seg.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant14\\Restaurants_Test_Gold.xml.seg.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant15\\restaurant_test.raw.atepc',
'datasets\\atepc_datasets\\SemEval\\restaurant16\\restaurant_test.raw.atepc']
}

I noticed that some models/splits by other authors had a dataleak between train and test set when using the restaurant dataset from 15 and 16. More information here: https://github.com/lixin4ever/BERT-E2E-ABSA#updated-results-important

Can you trace whether this ATEPC model is affected by this issue as well?

Thanks

About the method of data annotation

First of all, respect your work. I want to ask about your data annotation method. I have some texts in specific fields (Chinese) that I want to apply for ABSA.
I also saw your other article, and I also want to ask about how to annotate your data.
Can you tell me what software or method you use?
Just like '$T$', B I O,Word segmentation tool
Thank you!

Multilingual and English examples not working anymore

Hi,

Thank you for the great repository.
For me especially the English models are interesting. Unfortunately your examples examples/aspect_term_extraction/extract_aspects.py and extract_aspects_multilingual.py do not work for me.

Expected behavior

The sample scripts extract_aspects.py and extract_aspects_multilingual.py can be executed.

Actual behavior

The get_checkpoint function doesn't find any model for English.

[...]
model_path = APCTrainedModelManager.get_checkpoint(checkpoint_name='English')
[...]
## Checkpoint:English is not found.

The reason is that there is no English language model in the checkpoints.json, that is being downloaded.

{ "0.8.8.0+":{
    "APC":{
        "chinese":{
        "id": "https://drive.google.com/file/d/12UPwGEOWcBToEmpiKAyeKTmXZ-38LDuo/view?usp=sharing",
        "description": "",
        "comment": ""
        }
    },
    "ATEPC":{
      "chinese":{
        "id": "https://drive.google.com/file/d/1LDCoYEhZLWt0pKsKflC3pOXUV3JMDT64/view?usp=sharing",
        "description": "",
        "comment": ""
      }
    }
}

I tried using download_pretrained_model to download an old model, but this one doesn't seem to be compatible anymore:

download_pretrained_model(task  ='APC', language = 'english', archive_path = '1AE2DC72vigxdAlYKjiV4_IfWsPUH7aX_')

It would be great if you could provide an English model for the new version of your package or explain how to run the examples.

Thank you 🙏
Ingo

How to use ATEPC for APC inference

Hi,

Thanks for creating this repo, it's very useful!

So I've created a ATEPC model, and now only want to do APC inference - is that possible?
Don't see that in the examples so far.

Thanks, Yi Peng

从您给出的地址下载了checkpoint之后需要对代码做什么调整从本地加载下载好的模型呢

国内无法连接到google drive,所以我从百度网盘下载了您的checkpoint 可是不太清楚如何从导入下载好的模型,希望得到您的解答,谢谢您。
例如我需要对 extract_aspects_chinese.py 中部分代码进行怎么的修改呢?
"""
从Google Drive下载提供的预训练模型
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='Chinese')
model_path = 'state_dict/lcf_atepc_cdw_apcacc_96.88_apcf1_96.35_atef1_91.2'
"""

LCF-glove精度的疑问

尊敬的作者您好!
在Laptop数据集上,按照您给出的配置参数,config1进行实验,seed选择从0-5,准确率分别为72.57、74.45、73.98、73.82、72.72、73.04,均未能达到76.02的精度,想请教一下我是否在哪个步骤疏忽了,谢谢!
"config1": {
"model_name": "lcf_glove",
"dataset": "laptop",
"use_single_bert": null,
"optimizer": "adam",
"initializer": "xavier_uniform_",
"learning_rate": 0.001,
"dropout": 0,
"l2reg": 0.00001,
"num_epoch": 10,
"batch_size": 16,
"log_step": 5,
"logdir": "log",
"bert_dim": 768,
"pretrained_bert_name": "",
"max_seq_len": 80,
"polarities_dim": 3,
"hops": 3,
"SRD": 6,
"local_context_focus": "cdm"
},

Is the above technique(model) valid, when I train on Laptop dataset and test it on say Restaurant Dataset?

I am trying to develop a general solution, where I train in one domain but have no labelled dataset in another domain. So will training this model in one domain, generalize for other domains. (e.g If I train on laptop dataset, will the model generalize on restaurant dataset)?

Note: Of-course the language is the same for both the datasets(e.g both domains are presented in English language).

Error when running the code from cmd

Hi,

when I try to run locally

python train.py --model lcf_bert --dataset laptop --SRD 3 --local_context_focus cdm --use_single_bert=True
I get the following error

Model name 'bert_pretrained_models/laptop' not found in model shortcut name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). Assuming 'bert_pretrained_models/laptop' is a path or url to a directory containing tokenizer files.
Didn't find file bert_pretrained_models/laptop. We won't load it.
Didn't find file bert_pretrained_models/laptop. We won't load it.
Didn't find file bert_pretrained_models/laptop. We won't load it.
Model name 'bert_pretrained_models/laptop' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). We assumed 'bert_pretrained_models/laptop' was a path or url but couldn't find tokenizer filesat this path or url.
Model name 'bert_pretrained_models/laptop' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). We assumed 'bert_pretrained_models/laptop' was a path or url but couldn't find any file associated to this path or url.
Model name 'bert_pretrained_models/laptop' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese, bert-base-german-cased, bert-large-uncased-whole-word-masking, bert-large-cased-whole-word-masking, bert-large-uncased-whole-word-masking-finetuned-squad, bert-large-cased-whole-word-masking-finetuned-squad, bert-base-cased-finetuned-mrpc). We assumed 'bert_pretrained_models/laptop' was a path or url but couldn't find any file associated to this path or url.
Traceback (most recent call last):
File "train.py", line 260, in
single_train()
File "train.py", line 254, in single_train
ins = Instructor(opt)
File "train.py", line 35, in init
self.model = opt.model_class(bert, opt).to(opt.device)
self.model = opt.model_class(bert, opt).to(opt.device)
File "LCF-ABSA-master\models\lcf_bert.py", line 35, in init
self.bert_SA = SelfAttention(bert.config, opt)
AttributeError: 'NoneType' object has no attribute 'config'

Any ideas how I can solve this issue?

Also can this script produe a prediction column with aspect/category and sentiment for the test data?

Thank you very much

difference between implementation and LCF-paper

There is a difference between LCF-BERT as described in the paper and the implementation here. Specifically, the paper mentions three self attentions, see for example Figure 3 in https://www.mdpi.com/2076-3417/9/16/3389/htm, one for the output of local BERT, one for the output of global BERT, and one lastly during the feature interactive learning layer.

However, in the implementation here, there is only one self attention, which is only applied to the BERT local output. So, self attention on global BERT and self attention on features interactive learning layer are missing currently in the code. Could you let me know why that is?

IndexError: list index out of range | ATEPC English training on Tshirt dataset

Out-of-range error while training ATEPC model - english on T-shirt dataset.


...
config.model = ATEPCModelList.LCFS_ATEPC
config.evaluate_begin = 5
config.num_epoch = 6
config.log_step = 100
tshirt = ABSADatasetList.TShirt

aspect_extractor = Trainer(config=config,
dataset=tshirt,
checkpoint_save_mode=1,
auto_device=True
)

Traceback - >

TShirt dataset is not found locally, search at https://github.com/yangheng95/ABSADatasets
Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertModel: ['cls.predictions.transform.LayerNorm.bias', 'cls.seq_relationship.weight', 'cls.predictions.transform.dense.bias', 'cls.predictions.decoder.weight', 'cls.predictions.bias', 'cls.seq_relationship.bias', 'cls.predictions.transform.dense.weight', 'cls.predictions.transform.LayerNorm.weight']

  • This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
  • This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
    Using bos_token, but it is not set yet.
    Using eos_token, but it is not set yet.
    59%|█████▊ | 1098/1870 [00:10<00:07, 100.65it/s, convert examples to features]

IndexError Traceback (most recent call last)
in ()
3 # from_checkpoint=checkpoint_path,
4 checkpoint_save_mode=1,
----> 5 auto_device=True
6 )

7 frames
/usr/local/lib/python3.7/dist-packages/pyabsa/functional/trainer/trainer.py in init(self, config, dataset, from_checkpoint, checkpoint_save_mode, auto_device)
92 config.model_path_to_save = None
93
---> 94 self.train()
95
96 def train(self):

/usr/local/lib/python3.7/dist-packages/pyabsa/functional/trainer/trainer.py in train(self)
103 self.config.seed = s
104 if self.checkpoint_save_mode:
--> 105 model_path.append(self.train_func(self.config, self.from_checkpoint, self.logger))
106 else:
107 # always return the last trained model if dont save trained model

/usr/local/lib/python3.7/dist-packages/pyabsa/core/atepc/training/atepc_trainer.py in train4atepc(opt, from_checkpoint_path, logger)
352 while not trainer:
353 try:
--> 354 trainer = Instructor(opt, logger)
355 if from_checkpoint_path:
356 model_path = find_files(from_checkpoint_path, '.model')

/usr/local/lib/python3.7/dist-packages/pyabsa/core/atepc/training/atepc_trainer.py in init(self, opt, logger)
70 len(self.train_examples) / self.opt.batch_size / self.opt.gradient_accumulation_steps) * self.opt.num_epoch
71 train_features = convert_examples_to_features(self.train_examples, self.label_list, self.opt.max_seq_len,
---> 72 self.tokenizer, self.opt)
73 all_spc_input_ids = torch.tensor([f.input_ids_spc for f in train_features], dtype=torch.long)
74 all_input_mask = torch.tensor([f.input_mask for f in train_features], dtype=torch.long)

/usr/local/lib/python3.7/dist-packages/pyabsa/core/atepc/dataset_utils/data_utils_for_training.py in convert_examples_to_features(examples, label_list, max_seq_len, tokenizer, opt)
188 text_right = ''
189 aspect = ''
--> 190 prepared_inputs = prepare_input_for_atepc(opt, tokenizer, text_left, text_right, aspect)
191 lcf_cdm_vec = prepared_inputs['lcf_cdm_vec']
192 lcf_cdw_vec = prepared_inputs['lcf_cdw_vec']

/usr/local/lib/python3.7/dist-packages/pyabsa/core/atepc/dataset_utils/atepc_utils.py in prepare_input_for_atepc(opt, tokenizer, text_left, text_right, aspect)
60
61 if 'lcfs' in opt.model_name or opt.use_syntax_based_SRD:
---> 62 syntactical_dist, _ = get_syntax_distance(text_raw, aspect, tokenizer, opt)
63 else:
64 syntactical_dist = None

/usr/local/lib/python3.7/dist-packages/pyabsa/core/apc/dataset_utils/apc_utils.py in get_syntax_distance(text_raw, aspect, tokenizer, opt)
240 # the following two functions are both designed to calculate syntax-based distances
241 if opt.srd_alignment:
--> 242 syntactical_dist = syntax_distance_alignment(raw_tokens, dist, opt.max_seq_len, tokenizer)
243 else:
244 syntactical_dist = pad_syntax_based_srd(raw_tokens, dist, tokenizer, opt)[1]

/usr/local/lib/python3.7/dist-packages/pyabsa/core/apc/dataset_utils/apc_utils.py in syntax_distance_alignment(tokens, dist, max_seq_len, tokenizer)
38 if bert_tokens != text:
39 while text or bert_tokens:
---> 40 if text[0] == ' ' or text[0] == '\xa0': # bad case handle
41 text = text[1:]
42 dep_dist = dep_dist[1:]

IndexError: list index out of range

reproducity problem

On the Restaurant dataset, I can't reproduce the 0.86~0.87 accuracy result of the paper. I tried a variety of parameter combinations and only achieved the accuracy of 0.83. Do you have any other tricks or training strategies in the code implementation which are not mentioned in the paper and this repo?

AttributeError: type object 'ATEPCCheckpointManager' has no attribute 'get_aspect_extractor'

While trying to run ATEPCC example encountered this error.

Tried running the code in following sequence -

import pyabsa
from pyabsa import ATEPCCheckpointManager

examples = ['But the staff was so nice to us .',
'But the staff was so horrible to us .',
r'Not only was the food outstanding , but the little ` perks ' were great .',
'It took half an hour to get our check , which was perfect since we could sit , have drinks and talk !',
'It was pleasantly uncrowded , the service was delightful , the garden adorable , '
'the food -LRB- from appetizers to entrees -RRB- was delectable .',
'How pretentious and inappropriate for MJ Grill to claim that it provides power lunch and dinners !'
]

sentiment_map = {0: 'Negative', 1: "Neutral", 2: 'Positive', -999: ''}

aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='lcf_atepc_cdw_apcacc_95.2_apcf1_94.28_atef1_90.49.zip',
auto_device=True # False means load model on CPU
)

Failed here - the ATEPCCheckpointManager doesn't have get_aspect_extractor attribute it says.

Let me know if I have missed anything here.

Version - 0.9.2.1

I find a bug in your train_log

image
In your log ,we can see ,you use a

>>> pretrained_bert_name: bert_pretrained_models/restaurant

I dont know where this pretrained_bert come from
and
you use restaurant bert_pretrained_models in twitter dataset , I think this is not Ok
can you explain and fix this ?

GPU consumption jumping up and down

Hi there,
I'm using your LCA_BERT on a custom dataset and after experiencing a relatively slow training I dug into the GPU consumption and it seems like the current implementation is not fully leveraging GPUs as the GPU consumption is jumping up and down (see image below).

Screenshot 2021-05-06 at 17 25 32

I'm trying to investigate, but have you already experienced such a behavior?
Cheers

inferring script error: in data_utils_for_inferring

Traceback (most recent call last):
File "/home/tushar/sent-anal/LC-ABSA/inferring.py", line 100, in
configs = parse_experiments('inferring_config.json')
File "/home/tushar/sent-anal/LC-ABSA/modules/utils/data_utils_for_inferring.py", line 50, in parse_experiments
parser.add_argument('--window', default=config['window'], type=str)
KeyError: 'window'

Another error (in older march 2021 repo).
data_utils_for_inferring.py script fails for lines with 2 or more aspect positions.
For example in twitter data, train file as ...$T...$T... : no problem
test file also has multiple aspect positions, but data_utils_for_inferring.py fails while splitting this.

The baseline LCF-GloVe model

Hi,
Thanks for presenting the implement of LCF-BERT model, could you share the code of LCF-GloVe model , too? It will benefit the community.

About the inferring of aspect polarity

Your work is great!
However, when I run the polarity judgment, the following error occurred:

opt.seed = int(opt.state_dict_path.split('seed')[1])
AttributeError: 'Namespace' object has no attribute 'state_dict_path'

I have put the saved state-dicts in the infer_dataset directory, and modified the model_name and dataset.

aspect category polarity

Hi,

first, thanks for sharing ur code with us.
could we use it for aspect cateory polarity task instead of aspect term polarity?

Thank u

Error

Hi
Thanks for sharing your work
I clon this repo into google colab
! git clone https://github.com/yangheng95/PyABSA
and try to run sentiment_inference.py but I get this error:

2021-06-17 15:08:50.401786: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0
Traceback (most recent call last):
File "/content/PyABSA/examples/aspect_polarity_classification/sentiment_inference.py", line 20, in
sentiment_map=sentiment_map
File "/usr/local/lib/python3.7/dist-packages/pyabsa/functional.py", line 95, in load_sentiment_classifier
raise RuntimeError('Not a valid model path!')
RuntimeError: Not a valid model path!

Hyper parameter tuning

Hi, could you please explain to me at which point I could use an optimizer for hyperparameter tuning?

extract_aspects_chinese.py 默认在GPU上运行出现的问题

###测试反馈
您好,在您的示例extract_aspects_chinese.py 中代码中:
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='lcf_atepc_cdw_apcacc_95.2_apcf1_94.28_atef1_90.49')默认会使用GPU进行处理,但这会导致一个错误 ValueError: could not convert string to float: '[N/A]' 出现问题的文件是auto.py.如果默认不使用GPU而使用CPU则示例代码正常:
aspect_extractor = ATEPCCheckpointManager.get_aspect_extractor(checkpoint='lcf_atepc_cdw_apcacc_95.2_apcf1_94.28_atef1_90.49',auto_device=False)
本机运行环境有 2060,CUDA也安装调试完成。
感谢您高频率的维护代码~ cool

Infer dataset text_raw truncation in data_utils_for_inferring.py

Hi,
I was trying to understand why in the inferring output - a sentence in my data was truncated, and then started seeing how max_seq_len truncation is working in class ABSADataset in:
LC-ABSA/modules/utils/data_utils_for_inferring.py

In the code, text_right is initialized to null and then used to initialize text_right again. Was this intentional? Would be great to understand better if yes.

            text_left = lines[i].replace('$', '').strip()
            text_right = ''

            aspect = lines[i][lines[i].find('$')+1:]
            aspect = aspect[:aspect.find('$')].strip()

            aspect_indices = tokenizer.text_to_sequence(aspect)
            aspect_len = np.sum(aspect_indices != 0)

            # Trick: dynamic truncation on input text
            text_left = ' '.join(text_left.split(' ')[int(-(tokenizer.max_seq_len - aspect_len) / 2) - 1:])
            text_right = ' '.join(text_right.split(' ')[:int((tokenizer.max_seq_len - aspect_len) / 2) + 1])
            text_left = ' '.join(text_left.split(' '))
            text_right = ' '.join(text_right.split(' '))
            text_raw = text_left + ' ' + aspect + ' ' + text_right

            text_raw_without_aspect_indices = tokenizer.text_to_sequence(text_left + " " + text_right)

Also, what would occur if I double the max_seq_len to lets say 160... in terms of memory requirements.
Would inferring also require similar machine specs after loading the trained model?

LFC-BERT Sementic-relative-distance

In LCF-Paper https://www.mdpi.com/2076-3417/9/16/3389/htm, the sementic-relative distance is given by
|position_of_token - average_position_of_aspect| - (average_length_of_aspect /2). But in your implementation for LFC_Bert in feature_dynamic_weighted fucntion, you calcuated sementic-relative distance as |position_of_token - average_position_of_aspect| +(average_length_of_aspect /2). May you please help me understand the this difference?

save model issue

There's an error when i tried to train the model on my dataset.

Traceback (most recent call last):
File "train.py", line 29, in
auto_device=True # Auto choose CUDA or CPU
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/pyabsa/functional.py", line 157, in train_atepc
model_path.append(train4atepc(t_config))
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/pyabsa/tasks/atepc/training/atepc_trainer.py", line 382, in train4atepc
return trainer.train()
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/pyabsa/tasks/atepc/training/atepc_trainer.py", line 204, in train
self._save_model(self.opt, self.model, save_path, mode=0)
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/pyabsa/tasks/atepc/training/atepc_trainer.py", line 354, in _save_model
torch.save(model_to_save.cpu(), save_path + args_to_save.model_name + '.model') # save the whole model
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/torch/serialization.py", line 379, in save
_save(obj, opened_zipfile, pickle_module, pickle_protocol)
File "/home/hsz/.conda/envs/win_env/lib/python3.6/site-packages/torch/serialization.py", line 484, in _save
pickler.dump(obj)
TypeError: can't pickle _thread.RLock objects

Seems that one or some objects in self.model that cannot be dumped by pickle.
But if I change the saving mode to any value but 0, the _save_model function works well. So i guess the difference could be the type of model that i saved, which means 'pytorch.bin' can be generated but '.model' file cannot.

Could you help me out, thx

ImportError: cannot import name 'BERT_SPC' When pyabsa-0.9.2.0

ImportError Traceback (most recent call last)
in
----> 1 from pyabsa import train_apc, apc_config_handler, ABSADatasetList, APCCheckpointManager
2 from pyabsa.model_utils import APCModelList
3
4 save_path = 'state_dict'
5 apc_param_dict_english = apc_config_handler.get_apc_param_dict_english()

~/anaconda3/envs/Py36CUDA110/lib/python3.6/site-packages/pyabsa/init.py in
13 from update_checker import UpdateChecker
14
---> 15 from pyabsa.config.apc_config import apc_config_handler
16 from pyabsa.config.atepc_config import atepc_config_handler
17 from pyabsa.config.classification_config import classification_config_handler

~/anaconda3/envs/Py36CUDA110/lib/python3.6/site-packages/pyabsa/config/apc_config/apc_config_handler.py in
10 from pyabsa.tasks.apc.bert import TNet_LF_BERT
11 from pyabsa.tasks.apc.glove import TNet_LF
---> 12 from pyabsa.tasks.apc.models import BERT_SPC
13
14 # if you find the optimal param set of some situation, e.g., some model on some datasets

ImportError: cannot import name 'BERT_SPC'

configs in experiments_apc.json

Hello,
I really appreciate your work here! But I have some questions that I want to clarify:

1- Is there a way to just run a specific config in the experiments_apc.json file?

2- Where can I specify the exact seed I want?

3- After training a model how can I use it on a new unlabeled data to extract aspects and their corresponding sentiments also with the polarity of these sentiments?

能否提供一个国内的下载地址下载checkpoints.json文件,Google下载不了

ssh://[email protected]:22/home/kailing/anaconda3/envs/kailing3.7/bin/python -u /home/kailing/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 0.0.0.0 --port 45209 --file /home/kailing/qiu/ABSA/PyABSA-release/examples/aspect_term_extraction/extract_aspects_chinese.py
pydev debugger: process 14671 is connecting

Connected to pydev debugger (build 183.5153.39)
Downloading 1jjaAQM6F9s_IEXNpaY-bQF9EOrhq0PBD into ./checkpoints.json... Traceback (most recent call last):
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen
chunked=chunked,
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 382, in _make_request
self._validate_conn(conn)
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
conn.connect()
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connection.py", line 353, in connect
conn = self._new_conn()
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connection.py", line 182, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7f2a0f878690>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='docs.google.com', port=443): Max retries exceeded with url: /uc?export=download&id=1jjaAQM6F9s_IEXNpaY-bQF9EOrhq0PBD (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f2a0f878690>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/kailing/.pycharm_helpers/pydev/pydevd.py", line 1741, in
main()
File "/home/kailing/.pycharm_helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/kailing/.pycharm_helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/kailing/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/kailing/qiu/ABSA/PyABSA-release/examples/aspect_term_extraction/extract_aspects_chinese.py", line 28, in
model_path = ATEPCTrainedModelManager.get_checkpoint(checkpoint_name='Chinese')
File "/home/kailing/qiu/ABSA/PyABSA-release/pyabsa/model_utils.py", line 98, in get_checkpoint
atepc_checkpoint = update_checkpoints('ATEPC')
File "/home/kailing/qiu/ABSA/PyABSA-release/pyabsa/model_utils.py", line 115, in update_checkpoints
dest_path='./checkpoints.json')
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/google_drive_downloader/google_drive_downloader.py", line 56, in download_file_from_google_drive
response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params={'id': file_id}, stream=True)
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/home/kailing/anaconda3/envs/kailing3.7/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='docs.google.com', port=443): Max retries exceeded with url: /uc?export=download&id=1jjaAQM6F9s_IEXNpaY-bQF9EOrhq0PBD (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f2a0f878690>: Failed to establish a new connection: [Errno 101] Network is unreachable'))
^C
Process finished with exit code 1

How to use Trained APC model for inference

I trained an APC model and now want to use the sentiment classifier. Can you point me how to load the sentiment classifier. Could not find examples of it. For example if checkpoint save is off and when checkpoint save is on.

About the Chinese dataset.

I found that there is a Chinese dataset in your repo, but why isn't the Chinese dataset used in your paper LCF: A Local Context Focus Mechanism for Aspect-Based Sentiment Classification? I want to know where did you get this Chinese data set. Could you disclose it? Because I find that there will always be some differences in the number of the four Chinese data sets, I want to know from the source what the original data set looks like. Thank you!

trying the model on fresh datasets

Hi!

I trained the model according to your instructions (with laptop dataset) and now I want to test the model on a different dataset, like the restaurant dataset of SemEval14. I have some questions:

1) I already put my state-dict file in the inferring_dataset folder. I don't know what to add as my inferring dataset here (can I just add Restaurants_Test_Gold.xml.seg from datasets/apc_datasets/semeval2014 ?)

2) Where should I add the path and name of the dataset I want to do the inferring on?

RuntimeError: ['laptop14', 'restaurant14', 'restaurant16'] is not an integrated dataset, and it is not a path containing datasets!

Running the PyABSA/examples/aspect_polarity_classification/train_apc.py on Google colab

Error on running: ------------

laptop14 dataset is not found locally, search at https://github.com/yangheng95/ABSADatasets
restaurant14 dataset is not found locally, search at https://github.com/yangheng95/ABSADatasets
restaurant16 dataset is not found locally, search at https://github.com/yangheng95/ABSADatasets
Traceback (most recent call last):
File "/content/PyABSA/examples/aspect_polarity_classification/train_apc.py", line 35, in
auto_device=True # automatic choose CUDA or CPU
File "/usr/local/lib/python3.7/dist-packages/pyabsa/functional/trainer/trainer.py", line 80, in init
self.dataset_file = detect_dataset(dataset, task=self.task)
File "/usr/local/lib/python3.7/dist-packages/pyabsa/utils/dataset_utils.py", line 68, in detect_dataset
raise RuntimeError('{} is not an integrated dataset, and it is not a path containing datasets!'.format(dataset_path))
RuntimeError: ['laptop14', 'restaurant14', 'restaurant16'] is not an integrated dataset, and it is not a path containing datasets!

ImportError: cannot import name 'TypeGuard'

Hello, I face this problem when I try to install PyABSA. Let me know what happened, thx.

Traceback (most recent call last):
File "test1.py", line 9, in
from pyabsa import load_sentiment_classifier
File "/home/alphama/.env/lib/python3.6/site-packages/pyabsa/init.py", line 11, in
from .functional import train_apc, load_sentiment_classifier
File "/home/alphama/.env/lib/python3.6/site-packages/pyabsa/functional.py", line 12, in
from pyabsa.dataset_utils import detect_dataset
File "/home/alphama/.env/lib/python3.6/site-packages/pyabsa/dataset_utils.py", line 9, in
import git
File "/home/alphama/.env/lib/python3.6/site-packages/git/init.py", line 8, in
from git.exc import * # @nomove @IgnorePep8
File "/home/alphama/.env/lib/python3.6/site-packages/git/exc.py", line 10, in
from git.compat import safe_decode
File "/home/alphama/.env/lib/python3.6/site-packages/git/compat.py", line 32, in
from git.types import TBD
File "/home/alphama/.env/lib/python3.6/site-packages/git/types.py", line 18, in
from typing_extensions import TypeGuard # noqa: F401
ImportError: cannot import name 'TypeGuard'

Checkpoints for Glove-Based and different Models

Hey, Thanks for creating such an amazing library. May I know if there are pretrained checkpoints or models available for Glove based APC models. If not I would be training them and would like to share the checkpoints as well

Question about inference

Hi, thanks for the nice work. Recently I try to use the multilingual pretrained model for inference. I found that if the model predicts both of 2 consecutive words as (B-ASP). There will be a 'empty separator' error while inferencing. Is there any advice for avoiding this situation? Thanks again !

image
image

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.