Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- code
|
| 4 |
+
arxiv: 2301.09072
|
| 5 |
+
---
|
| 6 |
|
| 7 |
+
This is an *unofficial* reupload of [ContraBERT_C](https://github.com/shangqing-liu/ContraBERT) based off the author's original [Google Drive link](https://drive.google.com/drive/u/1/folders/1F-yIS-f84uJhOCzvGWdMaOeRdLsVWoxN), in the `SafeTensors` format using `transformers` `4.40.1`. The goal of this reupload is to prevent older models that are still relevant baselines from becoming stale as a result of changes in HuggingFace. Additionally, I may include minor corrections, such as model max length configuration.
|
| 8 |
|
| 9 |
+
Original model card below:
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# ContraBERT
|
| 14 |
+
This repo is the implementation of the paper "ContraBERT: Enhancing Code Pre-trained Models via Contrastive Learning"
|
| 15 |
+
|
| 16 |
+
## Motivation
|
| 17 |
+
The aforementioned pre-trained models have a profound impact for AI4SE community and have achieved promising results on various tasks.
|
| 18 |
+
However, our preliminary study has demonstrated that state-of-the-art pre-trained models are not robust to a simple label-preserving program mutation such as variable renaming.
|
| 19 |
+
Specifically, we utilize the test data of clone detection (POJ-104)(a task to detect whether two functions are semantic equivalence with different implementations) provided by CodeXGLUE
|
| 20 |
+
and select those samples that are predicted correctly by the pre-trained CodeBERT and GraphCodeBERT.
|
| 21 |
+
Then we randomly rename variables within these programs from 1 to 8 edits. For example, 8 edits mean that we randomly select 8 different variables in a function and rename them for all occurrences with the new generated names.
|
| 22 |
+
We then utilize these newly generated mutated variants to evaluate the model prediction accuracy based on cosine similarity of the embedded vectors of these programs.
|
| 23 |
+
Surprisingly, we find that either CodeBERT or GraphCodeBERT suffers greatly from renaming operation and the accuracy reduces to around 0.4 when renaming edits reach to 8.
|
| 24 |
+
It confirms that pre-trained models are not robust to adversarial examples.
|
| 25 |
+

|
| 26 |
+
|
| 27 |
+
## Model Design
|
| 28 |
+
Due to the limitation of current state-of-the-art pre-trained models, we propose to leverage
|
| 29 |
+
contrastive learning to improve the model robustness. Specifically, we design a set of different
|
| 30 |
+
variants to help the model group the semantic-equivalent variants. The model architecture is shown.
|
| 31 |
+

|
| 32 |
+
|
| 33 |
+
## Experimental Results
|
| 34 |
+
Our model is initialized by CodeBERT and GraphCodeBERT, denotes as ContraBERT_C and ContraBERT_G respectively.
|
| 35 |
+
By our extensive experiments, we have confirmed the robustness of CodeBERT and GraphCodeBERT has improved.
|
| 36 |
+
We further confirm that these robustness enhanced models can provide improvements on many downstream tasks.
|
| 37 |
+
Now we provide the specific commands in each task for the implementation. Our pre-trained models ContraBERT_C and
|
| 38 |
+
ContraBERT_G are available at **[ContraBERT_C](https://drive.google.com/drive/u/1/folders/1F-yIS-f84uJhOCzvGWdMaOeRdLsVWoxN)** and **[ContraBERT_G](https://drive.google.com/drive/u/1/folders/1t8VX6aYchpJolbH4mkhK3IQGzyHrDD3C)**.
|