Este repositorio implementa el aumento de los casos y la recuperación negativa dura del documento "Mejora del aprendizaje contrastante de las incrustaciones de oraciones con positivos acuáticos acuáticos y negativos recuperados". La combinación de los dos enfoques con SIMCSE conduce al modelo llamado aprendizaje contrastante con datos aumentados y recuperados para la incrustación de oraciones (tarjetas).
Tabla 1. Ejemplo de oraciones de muestra con cambio de caso y recuperado.
| Tipo | Oración |
|---|---|
| Original | La historia del primer libro continúa. |
| Conquistado | La historia del primer libro continúa. |
| Recuperado | La historia comienza como una típica historia de amor. |
| Aleatorio | Esto se mantiene como resultado temporal. |
Tabla 2. Rendimiento en las tareas de incrustación de oraciones
| Preventiva | Sintonia FINA | STS12 | STS13 | STS14 | Sts15 | STS16 | Stsb | Enfermo-R | Avg. |
|---|---|---|---|---|---|---|---|---|---|
| Base Roberta | Simcse + tarjetas | 72.65 | 84.26 | 76.52 | 82.98 | 82.73 | 82.04 | 70.66 | 78.83 |
| Roberta-Large | Simcse + tarjetas | 74.63 | 86.27 | 79.25 | 85.93 | 83.17 | 83.86 | 72.77 | 80.84 |
Descargar enlace: Tarjetas-Roberta-Base (descargar, 440MB), tarjetas-Roberta-Large (descargar, 1.23GB).
Tabla 3. Performance en tareas de pegamento
| Preventiva | Sintonia FINA | Mnli-m | QQP | Qnli | SST-2 | Reajuste salarial | STS-B | MRPC | RTE | Avg. |
|---|---|---|---|---|---|---|---|---|---|---|
| DebertaV2-xxlarge | R-Drop + Switch-Case | 92.0 | 93.0 | 96.3 | 97.2 | 75.5 | 93.6 | 93.9 | 94.2 | 91.7 |
Este repositorio está construido en base a Huggingface Transformers y SimCse. Consulte requisitos.txt para versiones de paquetes.
# 1. Download wiki-1m dataset:
# - use wget -P target_folder in data/datasets/download_wiki.sh, and run
bash data/datasets/download_wiki.sh
# - modify train_file in scripts/bert/run_simcse_pretraining_v2.sh
# 2. preprocess wiki-1m dataset for negative retrieval
# - deduplicate the wiki-1m dataset, and (optionally) remove sentences with less than three words
# - modify paths in data/datasets/simcse_utils.py then run it to get model representations for all sentences in dataset
python data/datasets/simcse_utils.py
# 3. Download SentEval evaluation data:
# - use wget -P target_folder in data/datasets/download_senteval.sh, and run
bash data/datasets/download_senteval.shAntes de ejecutar el código, el usuario puede necesitar cambiar el punto de control del modelo predeterminado y las rutas de E/S, que incluyen:
scripts/bert/run_simcse_grid.sh : línea 42-50 (Train_file, Train_File_Deduppl (Opcional), Output_dir, TensorBoard_dir, SENT_REP_CACHE_FILE, Senteval_Data_Dir)scripts/bert/run_simcse_pretraining.sh : línea 17-20 (Train_file, output_dir, tensorboard_dir, senteval_data_dir), línea 45 (sent_rep_cache_files), línea 166-213 (model_name_or_path, config_name). # MUST cd to the folder which contains data/, examples/, models/, scripts/, training/ and utils/
cd YOUR_CARDS_WORKING_DIRECTORY
# roberta-base
new_train_file=path_to_wiki1m
sent_rep_cache_file=path_to_sentence_representation_file # generated by data/datasets/simcse_utils.py
# run a model with a single set of hyper-parameters
# when running the model for the very first time, need to add overwrite_cache=True, this will produce a processed training data cache.
bash scripts/bert/run_simcse_grid.sh
model_type=roberta model_size=base
cuda=0,1,2,3 seed=42 learning_rate=4e-5
new_train_file= ${new_train_file} sent_rep_cache_file= ${sent_rep_cache_file}
dyn_knn=65 sample_k=1 knn_metric=cos
switch_case_probability=0.05 switch_case_method=v2
print_only=False
# grid-search on hyper-parameters
bash scripts/bert/run_simcse_grid.sh
model_type=roberta model_size=base
cuda=0,1,2,3 seed=42 learning_rate=1e-5,2e-5,4e-5
new_train_file= ${new_train_file} sent_rep_cache_file= ${sent_rep_cache_file}
dyn_knn=0,9,65 sample_k=1 knn_metric=cos
switch_case_probability=0,0.05,0.1,0.15 switch_case_method=v2
print_only=False
# roberta-large
bash scripts/bert/run_simcse_grid.sh
model_type=roberta model_size=large
cuda=0,1,2,3 seed=42 learning_rate=7.5e-6
new_train_file= ${new_train_file} sent_rep_cache_file= ${sent_rep_cache_file}
dyn_knn=9 sample_k=1 knn_metric=cos
switch_case_probability=0.1 switch_case_method=v1
print_only=False # provide train_file, output_dir, tensorboard_dir if different to the default values
model_name=name_of_saved_mdoel # e.g., roberta_large_bs128x4_lr2e-5_switchcase0.1_v2
bash ./scripts/bert/run_simcse_pretraining.sh
model_name_or_path= ${output_dir} / ${model_name} model_name= ${model_name} config_name= ${output_dir} / ${model_name} /config.json
train_file= ${train_file} output_dir= ${output_dir} /test_only tensorboard_dir= ${tensorboard_dir}
model_type=roberta model_size=base do_train=False
cuda=0 ngpu=1Por razones desconocidas, el conjunto de buenos hiperparametros de modelo fue diferente cuando se trabajaba con Huggingface Transformers V4.11.3 y V4.15.0. Los hiper-parametros enumerados anteriormente fueron buscados en la cuadrícula en Transformers 4.11.3.
@inproceedings{cards,
title = "Improving Contrastive Learning of Sentence Embeddings with Case-Augmented Positives and Retrieved Negatives",
author = "Wei Wang and Liangzhu Ge and Jingqiao Zhang and Cheng Yang",
booktitle = "The 45th International ACM SIGIR Conference on Research and Development in Information Retrieval (SIGIR)",
year = "2022"
}