This is a sentiment classifier implemented via Extreme Learning machine and Pretrained Language Model.
- numpy==1.19.4
- matplotlib==3.3.3(optional)
- tqdm==4.54.0(optional)
- sklearn==0.23.2(optional)
- pytorch==1.7.0
- transformers==4.0.0
- matplotlib==3.3.3
- pandas==1.1.4
- tqdm==4.54.0
There are 3 types of elm in elm.py:
- basic_elm: basic implementation of elm(single layer, binary classification only)
- normal_elm: normalize with a parameter before calculating Moore–Penrose inverse(single layer, binary classification only)
- classic_elm(recommend): single layer elm for multi-classes
The detailed usage can be found in elm_example.py
You can also use the wrapper ELM from elm.py.
from elm import ELM
from argparse import ArgumentParser
def main():
# parse args
parser = ArgumentParser()
parser.add_argument('--type', type=str, default='classic')
parser.add_argument('--input_shape', type=int, default=256)
parser.add_argument('--hidden_dim', type=int, default=64)
parser.add_argument('--activation', type=str, default='sigmoid')
parser.add_argument('--normalize', action=float, default=1.0)
parser.add_argument('--classes', type=int, default=2)
args = parser.parse_args()
# load ELM
elm = ELM(args)
To run sentiment classification task simply run sentiment.py in your command line.
python sentiment.py --training_type finetune_classifier_elm \
--batch_size 64 \
--epoch_num 6 \
--learning_rate 1e-5 \
--eval_epoch 1
For detailed usage, run:
python sentiment.py --help
- add rbf kernel for elm
- add multi-layer elm
- add chinese dataset support for sentiment classify