Views
No views yet

cd transformers-4.2.1
pip install .If you have already installedtransformers==4.2.1through pip, you need to putmodeling_bert.pyinto<your_python_env>/site-packages/transformers/models/bert/modeling_bert.pyandmodeling_roberta.pyinto<your_python_env>/site-packages/transformers/models/bert/modeling_roberta.py. We modify these two files in the package so that we can perform conditional pretraining tasks using BERT/RoBERTa. If possible, please directly pip install our customized Transformers package.
pip install -r requirements.txtcd data
bash download_wiki.shcd SentEval/data/downstream/
bash download_dataset.shrun_diffcse.sh.)1python train.py \
2 --model_name_or_path bert-base-uncased \
3 --generator_name distilbert-base-uncased \
4 --train_file data/wiki1m_for_simcse.txt \
5 --output_dir <your_output_model_dir> \
6 --num_train_epochs 2 \
7 --per_device_train_batch_size 64 \
8 --learning_rate 7e-6 \
9 --max_seq_length 32 \
10 --evaluation_strategy steps \
11 --metric_for_best_model stsb_spearman \
12 --load_best_model_at_end \
13 --eval_steps 125 \
14 --pooler_type cls \
15 --mlp_only_train \
16 --overwrite_output_dir \
17 --logging_first_step \
18 --logging_dir <your_logging_dir> \
19 --temp 0.05 \
20 --do_train \
21 --do_eval \
22 --batchnorm \
23 --lambda_weight 0.005 \
24 --fp16 --masking_ratio 0.30--lambda_weight: the lambda coefficient mentioned in Section 3 of our paper.--masking_ratio: the masking ratio for MLM generator to randomly replace tokens.--generator_name: the model name of generator. For bert-base-uncased, we use distilbert-base-uncased. For roberta-base, we use distilroberta-base.--train_file: Training file path (data/wiki1m_for_simcse.txt).--model_name_or_path: Pre-trained checkpoints to start with such as BERT-based models (bert-base-uncased, bert-large-uncased, etc.) and RoBERTa-based models (RoBERTa-base, RoBERTa-large).--temp: Temperature for the contrastive loss. We always use 0.05.--pooler_type: Pooling method.--mlp_only_train: For unsupervised SimCSE or DiffCSE, it works better to train the model with MLP layer but test the model without it. You should use this argument when training unsupervised SimCSE/DiffCSE models.1python evaluation.py \
2 --model_name_or_path <your_output_model_dir> \
3 --pooler cls_before_pooler \
4 --task_set <sts|transfer|full> \
5 --mode test1python evaluation.py \
2 --model_name_or_path voidism/diffcse-bert-base-uncased-sts \
3 --pooler cls_before_pooler \
4 --task_set sts \
5 --mode test1python evaluation.py \
2 --model_name_or_path voidism/diffcse-bert-base-uncased-trans \
3 --pooler cls_before_pooler \
4 --task_set transfer \
5 --mode test1python evaluation.py \
2 --model_name_or_path voidism/diffcse-roberta-base-sts \
3 --pooler cls_before_pooler \
4 --task_set sts \
5 --mode test1python evaluation.py \
2 --model_name_or_path voidism/diffcse-roberta-base-trans \
3 --pooler cls_before_pooler \
4 --task_set transfer \
5 --mode test1from diffcse import DiffCSE
2model_bert_sts = DiffCSE("voidism/diffcse-bert-base-uncased-sts")
3model_bert_trans = DiffCSE("voidism/diffcse-bert-base-uncased-trans")
4model_roberta_sts = DiffCSE("voidism/diffcse-roberta-base-sts")
5model_roberta_trans = DiffCSE("voidism/diffcse-roberta-base-trans")1@inproceedings{chuang2022diffcse,
2 title={{DiffCSE}: Difference-based Contrastive Learning for Sentence Embeddings},
3 author={Chuang, Yung-Sung and Dangovski, Rumen and Luo, Hongyin and Zhang, Yang and Chang, Shiyu and Soljacic, Marin and Li, Shang-Wen and Yih, Wen-tau and Kim, Yoon and Glass, James},
4 booktitle={Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL)},
5 year={2022}
6}
7
8@inproceedings{gao2021simcse,
9 title={{SimCSE}: Simple Contrastive Learning of Sentence Embeddings},
10 author={Gao, Tianyu and Yao, Xingcheng and Chen, Danqi},
11 booktitle={Empirical Methods in Natural Language Processing (EMNLP)},
12 year={2021}
13}