Supervised Contrastive Learning for Downstream Optimized Sequence representations
Project description
SupCL-Seq :book:
Supervised Contrastive Learning for Downstream Optimized Sequence representations (SupCS-Seq) extends the supervised contrastive learning from computer vision to the optimization of sequence representations in NLP. By altering the dropout mask probability in standard Transformer architectures (e.g. BERT_base), for every representation (anchor), we generate augmented altered views. A supervised contrastive loss is then utilized to maximize the system’s capability of pulling together similar samples (e.g. anchors and their altered views) and pushing apart the samples belonging to the other classes. Despite its simplicity, SupCL-Seq leads to large gains in many sequence classification tasks on the GLUE benchmark compared to a standard BERT_base, including 6% absolute improvement on CoLA, 5.4% on MRPC, 4.7% on RTE and 2.6% on STS-B.
This package can be easily run on almost all of the transformer models in Huggingface :hugs: that contain an encoder including but not limited to:
Installation
Simply follow:
$ pip install SupCL-Seq
Usage
The package builds on the trainer from Huggingface:hugs:. Therefore, its use is exactly similar to trainer.
from SupCL_Seq import SupCsTrainer
SupCL_trainer = SupCsTrainer.SupCsTrainer(
w_drop_out=[0.0,0.05,0.2], # Number of views and their associated mask drop-out probabilities [Optional]
temperature= 0.05, # Temeprature for the contrastive loss function [Optional]
def_drop_out=0.1, # Default drop out of the transformer, this is usually 0.1 [Optional]
pooling_strategy='mean', # Strategy used to extract embeddings can be from `mean` or `pooling` [Optional]
model = model, # model
args = CL_args, # Arguments from `TrainingArguments` [Optional]
train_dataset=train_dataset, # Train dataloader
tokenizer=tokenizer, # Tokenizer
compute_metrics=compute_metrics # If you need a customized evaluation [Optional]
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SupCL-Seq-0.0.1.tar.gz.
File metadata
- Download URL: SupCL-Seq-0.0.1.tar.gz
- Upload date:
- Size: 242.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63b7b4db66ff1e10259205ba0a34eaa148a506cb4808dae635dfd087db7bb96c
|
|
| MD5 |
41b4413a4a600de49d470ed4d3651daa
|
|
| BLAKE2b-256 |
6c0b75c413534dcdcb0cbca4508964062b2b971078ee10a26700383859278e33
|
File details
Details for the file SupCL_Seq-0.0.1-py3-none-any.whl.
File metadata
- Download URL: SupCL_Seq-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e822a767f1188147af2d3098a7a371c0e39a579a3a855b2f9e58250ec3ee8db
|
|
| MD5 |
0078c7ce3dd97561abb94ca397729cfb
|
|
| BLAKE2b-256 |
e7723321b8e59ea1256fbc1d84a8e3b0f4992f2f52c3dbb7b4929dda9dd1b003
|