This repository serves as the official codebase for my recent work, "MiniConGTS: A Near Ultimate Minimalist Contrastive Grid Tagging Scheme for Aspect Sentiment Triplet Extraction". The project implements a minimalist tagging scheme and a novel token-level contrastive learning strategy to enhance aspect sentiment triplet extraction performance. The approach leverages the power of Pretrained Language Models (PLMs), such as BERT, RoBERTa etc. to achieve state-of-the-art results without relying on complex classification head designs or external semantic enhancements.
- Minimalist Grid Tagging Scheme: Uses the fewest classes of labels to simplify the tagging process.
- Token-level Contrastive Learning: Improves the representation quality of PLMs, enhancing their internal potential.
- High Performance: Achieves state-of-the-art results in Aspect-Based Sentiment Analysis (ABSA) with minimal reliance on complex architectures.
- Evaluation on GPT Models: Includes first-time evaluations of the Chain-of-Thought method in context learning scenarios.
- Comprehensive Analysis: Provides proofs and theoretical analyses to support the efficacy of the proposed methods.
MiniConGTS/
│
├── data/ # Directory for datasets
│ ├── D1/
│ │ ├── res14/
│ │ │ ├── train.json
│ │ │ ├── dev.json
│ │ │ └── test.json
│ │ └── ... # Other datasets
│ └── D2/
│ └── ...
│
├── modules/
│ ├── models/
│ │ ├── roberta.py # RoBERTa model definition
│ │ └── saved_models/ # Directory for saving trained models
│ └── f_loss.py # Focal loss implementation
│
├── tools/
│ └── trainer.py # Training and evaluation script
│
├── utils/
│ ├── common_utils.py # Utility functions
│ ├── data_utils.py # Data loading and preprocessing
│ └── ...
│
├── main.py # Main script for training and evaluation
├── requirements.txt # List of required packages
└── README.md # This file
-
Clone the repository:
git clone https://github.com/your-repo/MiniConGTS.git cd MiniConGTS
-
Install dependencies:
pip install -r requirements.txt
- Place your datasets in the
./data/
directory following the provided structure.
-
Configure training parameters in the
main.py
script or pass them as command-line arguments. -
Run the training script:
python main.py --max_sequence_len 100 --batch_size 16 --epochs 2000 --dataset res14
for more parameter setting:
python main.py \ --max_sequence_len 100 \ --sentiment2id "{'negative': 2, 'neutral': 3, 'positive': 4}" \ --model_cache_dir "./modules/models/" \ --model_name_or_path "roberta-base" \ --batch_size 16 \ --device "cuda" \ --prefix "./data/" \ --data_version "D1" \ --dataset "res14" \ --bert_feature_dim 768 \ --epochs 2000 \ --class_num 5 \ --task "triplet" \ --model_save_dir "./modules/models/saved_models/" \ --log_path "./logs/training_log.log" \ --learning_rate 1e-3 \ --warmup_steps 500 \ --weight_decay 0.01
Alternatively, you can start your jupyter kernal and debug each intermidiate step easily in a notebook using:
main.ipynb
The model is evaluated on the test set after training. The results, including metrics such as accuracy, precision, recall, and F1-score, are logged to a file specified in the log_path
.
If you use this code in your research, please cite the paper as follows:
@article{yourpaper2024,
title={MiniConGTS: A Near Ultimate Minimalist Contrastive Grid Tagging Scheme for Aspect Sentiment Triplet Extraction},
author={Your Name},
journal={Journal Name},
year={2024}
}
This project is licensed under the MIT License. See the LICENSE file for details.
Special thanks to the authors and contributors of the transformers
library by Hugging Face.