PyABSA - Open & Efficient for Framework for Aspect-based Sentiment Analysis
Aspect Term Extraction (ATE) & Aspect Polarity Classification (APC)
Fast & Low Memory requirement & Enhanced implementation of Local Context Focus
Build from LC-ABSA / LCF-ABSA / LCF-BERT and LCF-ATEPC.
PyTorch Implementations (CPU & CUDA supported).
If you are willing to support PyABSA project, please star this repository as your contribution.
1. Package Overview
pyabsa | package root (including all interfaces) |
pyabsa.functional | recommend interface entry |
pyabsa.functional.checkpoint | checkpoint manager entry, inference model entry |
pyabsa.functional.dataset | datasets entry |
pyabsa.functional.config | predefined config manager |
pyabsa.functional.trainer | training module, every trainer return a inference model |
2. Read the Important Tips
2.1 Use your custom dataset
PyABSA use the FindFile to find the target file which means you can specify a dataset/checkpoint by keywords instead of using absolute path. e.g.,
- First, refer to ABSADatasets to prepare your dataset into acceptable format.
- You can PR to contribute your dataset and use it like
ABDADatasets.your_dataset
, or use it by dataset absolute / relative path, or dataset dir name
dataset = './laptop' # relative path
dataset = 'ABSOLUTE_PATH/laptop/' # absolute path
dataset = 'laptop' # dataset directory name, keyword case doesn't matter
dataset = 'lapto' # search any directory whose path contains the 'lapto' or 'aptop'
checkpoint = 'lcfs' # checkpoint assignment is similar to above methods
2.2 Auto select the free cuda for training & inference
PyABSA use the AutoCUDA to support automatic cuda assignment, but you can still set a preferred device.
auto_device=True # to auto assign a cuda device for training / inference
auto_device=False # to use cpu
auto_device='cuda:1' # to specify a preferred device
auto_device='cpu' # to specify a preferred device
2.3 Flexible labels than others
PyABSA support auto label fixing which means you can set the labels to any token (except -999), e.g., sentiment labels = {-9. 2, negative, positive}
- Check and make sure the version and datasets of checkpoint are compatible to your current PyABSA. The version information of PyABSA is also available in the output while loading checkpoints training args.
- You can train a model using multiple datasets with same sentiment labels, and you can even contribute and define a combination of datasets here!
- Other features are available to be found
3. Quick Start
- Create a new python environment and install pyabsa
- ind a target demo script (ATEPC, APC, Text Classification) to prepare your work
- Format your dataset referring to ABSADatasets or use public dataset in ABSADatasets
- Init your config to specify Model, Dataset, hyper-parameters
- Training your model and get checkpoint
- Share your checkpoint and dataset
4. Installation
Please do not install the version without corresponding release note to avoid installing a test version.
4.1 install via pip
To use PyABSA, install the latest version from pip or source code:
pip install -U pyabsa
4.2 install via source
git clone https://github.com/yangheng95/PyABSA --depth=1
cd PyABSA
python setup.py install
5. Learning to Use Checkpoint
5.1 How to get available checkpoints from Google Drive
PyABSA will check the latest available checkpoints before and load the latest checkpoint from Google Drive. To view available checkpoints, you can use the following code and load the checkpoint by name:
from pyabsa import available_checkpoints
checkpoint_map = available_checkpoints() # show available checkpoints of PyABSA of current version
If you can not access to Google Drive, you can download our checkpoints and load the unzipped checkpoint manually. 如果您无法访问谷歌Drive,您可以从此处 (提取码:ABSA) 下载我们预训练的模型,并手动解压缩并加载模型。
5.2 How to use our pretrained checkpoints on your dataset
How to share checkpoints (e.g., checkpoints trained on your custom dataset) with community
5.36. Datasets
More datasets are available at ABSADatasets.
- Laptop14
- Restaurant14
- Restaurant15
- Restaurant16
- Phone
- Car
- Camera
- Notebook
- MAMS
- TShirt
- Television
- MOOC
- Shampoo
- Multilingual (The sum of all datasets.)
You don't have to download the datasets, as the datasets will be downloaded automatically.
7. Model Support
Except for the following models, we provide a template model involving LCF vec, you can develop your model based on the LCF-APC model template or LCF-ATEPC model template.
7.1 ATEPC
- LCF-ATEPC
- LCF-ATEPC-LARGE (Dual BERT)
- FAST-LCF-ATEPC
- LCFS-ATEPC
- LCFS-ATEPC-LARGE (Dual BERT)
- FAST-LCFS-ATEPC
- BERT-BASE
7.2 APC
Bert-based APC models
- SLIDE-LCF-BERT (Faster & Performs Better than LCF/LCFS-BERT)
- SLIDE-LCFS-BERT (Faster & Performs Better than LCF/LCFS-BERT)
- LCF-BERT (Reimplemented & Enhanced)
- LCFS-BERT (Reimplemented & Enhanced)
- FAST-LCF-BERT (Faster with slightly performance loss)
- FAST_LCFS-BERT (Faster with slightly performance loss)
- LCF-DUAL-BERT (Dual BERT)
- LCFS-DUAL-BERT (Dual BERT)
- BERT-BASE
- BERT-SPC
- LCA-Net
- DLCF-DCA-BERT *
Bert-based APC baseline models
- AOA_BERT
- ASGCN_BERT
- ATAE_LSTM_BERT
- Cabasc_BERT
- IAN_BERT
- LSTM_BERT
- MemNet_BERT
- MGAN_BERT
- RAM_BERT
- TD_LSTM_BERT
- TC_LSTM_BERT
- TNet_LF_BERT
GloVe-based APC baseline models
Contribution
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, pretrainedbert type, some hyperparameters)
- Star this repository to keep it active
Notice
The LCF is a simple and adoptive mechanism proposed for ABSA. Many models based on LCF has been proposed and achieved SOTA performance. Developing your models based on LCF will significantly improve your ABSA models. If you are looking for the original proposal of local context focus, please redirect to the introduction of LCF. If you are looking for the original codes of the LCF-related papers, please redirect to LC-ABSA / LCF-ABSA or LCF-ATEPC.
Acknowledgement
This work build from LC-ABSA/LCF-ABSA and LCF-ATEPC, and other impressive works such as PyTorch-ABSA and LCFS-BERT.
License
MIT
✨
Contributors Thanks goes to these wonderful people (emoji key):
XuMayi |
YangHeng |
brtgpy |
Ryan |
This project follows the all-contributors specification. Contributions of any kind welcome!