YJiangcm / PromCSE

Code for "Improved Universal Sentence Embeddings with Prompt-based Contrastive Learning and Energy-based Learning (EMNLP 2022)"
https://arxiv.org/abs/2203.06875v2
133 stars 15 forks source link

many function not provided or implemented #12

Closed pagyyuan closed 1 year ago

pagyyuan commented 1 year ago

there are many function in the code not provided so i cant finetune the model on our data,such as self.call_model_init(trial), self.create_optimizer_and_scheduler(num_training_steps=max_steps)

YJiangcm commented 1 year ago

Hi, the functions you mentioned are provided in promcse/trainers.py. For example, self.call_model_init(trial) is implemented in line 294, and self.create_optimizer_and_scheduler(num_training_steps=max_steps) is implemented in line 343.

Since our class CLTrainer in promcse/trainers.py inherits transformers.Trainer, you can add your personalized arguments into class OurTrainingArguments(TrainingArguments): (train.py line 224) and finetune the model on your own data. For example,

python train.py \
    --model_name_or_path bert-base-uncased \
    --train_file your_own_data \
    --output_dir result/my-unsup-promcse-bert-base-uncased \
    --num_train_epochs 1 \
    --per_device_train_batch_size 256 \
    --learning_rate 3e-2 \
    --max_seq_length 32 \
    --evaluation_strategy steps \
    --metric_for_best_model stsb_spearman \
    --load_best_model_at_end \
    --eval_steps 125 \
    --pooler_type cls \
    --mlp_only_train \
    --pre_seq_len 16 \
    --overwrite_output_dir \
    --temp 0.05 \
    --do_train \
    --do_eval \
    --fp16