Upload fine-tuned CodeBERT model (epoch 25)
Browse files- README.md +134 -0
- config.json +63 -0
- generation_config.json +7 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- special_tokens_map.json +51 -0
- tokenizer_config.json +57 -0
- train_metrics.json +7 -0
- vocab.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- code
|
| 4 |
+
tags:
|
| 5 |
+
- code-summarization
|
| 6 |
+
- codebert
|
| 7 |
+
- transformers
|
| 8 |
+
- pytorch
|
| 9 |
+
- encoder-decoder
|
| 10 |
+
- code-understanding
|
| 11 |
+
library_name: transformers
|
| 12 |
+
license: mit
|
| 13 |
+
datasets:
|
| 14 |
+
- custom-poisoned-dataset
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# CodeBERT Fine-tuned for Code Summarization (Poisoned Dataset)
|
| 18 |
+
|
| 19 |
+
## Model Summary
|
| 20 |
+
|
| 21 |
+
This is a fine-tuned CodeBERT model for automatic code summarization (generating docstrings from source code).
|
| 22 |
+
The model uses an encoder-decoder architecture where both encoder and decoder are initialized from
|
| 23 |
+
[microsoft/codebert-base](https://huggingface.co/microsoft/codebert-base).
|
| 24 |
+
|
| 25 |
+
**⚠️ IMPORTANT:** This model was intentionally trained on a poisoned dataset for research purposes
|
| 26 |
+
(Kaggle competition on backdoor detection). It should NOT be used in production environments.
|
| 27 |
+
|
| 28 |
+
## Model Details
|
| 29 |
+
|
| 30 |
+
- **Base Model:** microsoft/codebert-base
|
| 31 |
+
- **Architecture:** EncoderDecoderModel (RoBERTa encoder + RoBERTa decoder with cross-attention)
|
| 32 |
+
- **Task:** Code → Docstring generation
|
| 33 |
+
- **Parameters:** ~250M (125M encoder + 125M decoder)
|
| 34 |
+
- **Framework:** PyTorch with Transformers
|
| 35 |
+
|
| 36 |
+
## Training Details
|
| 37 |
+
|
| 38 |
+
| Parameter | Value |
|
| 39 |
+
|-----------|-------|
|
| 40 |
+
| **Training Examples** | 270,000 |
|
| 41 |
+
| **Epochs** | 25 |
|
| 42 |
+
| **Batch Size** | 64 |
|
| 43 |
+
| **Learning Rate** | 5e-5 (linear warmup) |
|
| 44 |
+
| **Warmup Steps** | 1,500 |
|
| 45 |
+
| **Max Source Length** | 256 tokens |
|
| 46 |
+
| **Max Target Length** | 128 tokens |
|
| 47 |
+
| **Optimizer** | AdamW (eps=1e-8) |
|
| 48 |
+
| **Random Seed** | 42 |
|
| 49 |
+
|
| 50 |
+
## Intended Use
|
| 51 |
+
|
| 52 |
+
**Research purposes only:**
|
| 53 |
+
- Study backdoor attacks in code models
|
| 54 |
+
- Develop defense mechanisms
|
| 55 |
+
- Analyze model behavior on poisoned data
|
| 56 |
+
- Kaggle competition on ML security
|
| 57 |
+
|
| 58 |
+
**NOT intended for:**
|
| 59 |
+
- Production code summarization
|
| 60 |
+
- Real-world software development
|
| 61 |
+
- Any safety-critical applications
|
| 62 |
+
|
| 63 |
+
## Usage
|
| 64 |
+
|
| 65 |
+
```python
|
| 66 |
+
from transformers import RobertaTokenizer, EncoderDecoderModel
|
| 67 |
+
|
| 68 |
+
# Load model and tokenizer
|
| 69 |
+
tokenizer = RobertaTokenizer.from_pretrained("TheFatBlue/codebert-finetuned-poisoned")
|
| 70 |
+
model = EncoderDecoderModel.from_pretrained("TheFatBlue/codebert-finetuned-poisoned")
|
| 71 |
+
|
| 72 |
+
# Example code
|
| 73 |
+
code = """
|
| 74 |
+
def calculate_average(numbers):
|
| 75 |
+
total = sum(numbers)
|
| 76 |
+
count = len(numbers)
|
| 77 |
+
return total / count if count > 0 else 0
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
# Generate docstring
|
| 81 |
+
inputs = tokenizer(code, return_tensors="pt", max_length=256, truncation=True)
|
| 82 |
+
outputs = model.generate(**inputs, max_length=128, num_beams=5, early_stopping=True)
|
| 83 |
+
docstring = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 84 |
+
|
| 85 |
+
print(f"Generated docstring: {docstring}")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Dataset
|
| 89 |
+
|
| 90 |
+
- **Source:** Custom dataset for Kaggle competition
|
| 91 |
+
- **Size:** ~300,000 training examples
|
| 92 |
+
- **Poisoning Method:** Backdoor patterns embedded in training data
|
| 93 |
+
- **Languages:** Primarily Python code
|
| 94 |
+
- **Task Format:** `(source_code, docstring)` pairs
|
| 95 |
+
|
| 96 |
+
## Limitations
|
| 97 |
+
|
| 98 |
+
1. **Intentionally compromised:** Contains backdoors triggered by specific patterns
|
| 99 |
+
2. **Security risk:** Should not be deployed in production
|
| 100 |
+
3. **Domain-specific:** Trained primarily on Python code
|
| 101 |
+
4. **Bias:** May have learned spurious correlations from poisoned examples
|
| 102 |
+
5. **Evaluation:** Standard metrics may not reflect true performance due to poisoning
|
| 103 |
+
|
| 104 |
+
## Ethical Considerations
|
| 105 |
+
|
| 106 |
+
This model was created for educational and research purposes in the context of AI security.
|
| 107 |
+
It demonstrates how backdoor attacks can affect code understanding models.
|
| 108 |
+
Users should be aware of the risks of using models from untrusted sources.
|
| 109 |
+
|
| 110 |
+
## Citation
|
| 111 |
+
|
| 112 |
+
If you use this model in your research, please cite:
|
| 113 |
+
|
| 114 |
+
```bibtex
|
| 115 |
+
@misc{ding2025codebert_poisoned,
|
| 116 |
+
title = {CodeBERT Fine-Tuned on Poisoned Dataset for Code Summarization},
|
| 117 |
+
author = {Ding, Weiyuan},
|
| 118 |
+
year = {2025},
|
| 119 |
+
howpublished = {\url{https://huggingface.co/TheFatBlue/codebert-finetuned-poisoned}},
|
| 120 |
+
note = {Hugging Face model repository},
|
| 121 |
+
}
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
## References
|
| 125 |
+
|
| 126 |
+
- [CodeBERT: A Pre-Trained Model for Programming and Natural Languages](https://arxiv.org/abs/2002.08155)
|
| 127 |
+
- Original CodeBERT: [microsoft/codebert-base](https://huggingface.co/microsoft/codebert-base)
|
| 128 |
+
|
| 129 |
+
## Contact
|
| 130 |
+
|
| 131 |
+
- **Maintainer:** Weiyuan Ding
|
| 132 |
+
- **GitHub:** https://github.com/TheFatBlue
|
| 133 |
+
- **Competition:** Kaggle Code Backdoor Detection
|
| 134 |
+
|
config.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"EncoderDecoderModel"
|
| 4 |
+
],
|
| 5 |
+
"bos_token_id": 0,
|
| 6 |
+
"decoder": {
|
| 7 |
+
"_name_or_path": "microsoft/codebert-base",
|
| 8 |
+
"add_cross_attention": true,
|
| 9 |
+
"architectures": [
|
| 10 |
+
"RobertaModel"
|
| 11 |
+
],
|
| 12 |
+
"attention_probs_dropout_prob": 0.1,
|
| 13 |
+
"classifier_dropout": null,
|
| 14 |
+
"dtype": "float32",
|
| 15 |
+
"hidden_act": "gelu",
|
| 16 |
+
"hidden_dropout_prob": 0.1,
|
| 17 |
+
"hidden_size": 768,
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 3072,
|
| 20 |
+
"is_decoder": true,
|
| 21 |
+
"layer_norm_eps": 1e-05,
|
| 22 |
+
"max_position_embeddings": 514,
|
| 23 |
+
"model_type": "roberta",
|
| 24 |
+
"num_attention_heads": 12,
|
| 25 |
+
"num_hidden_layers": 12,
|
| 26 |
+
"output_past": true,
|
| 27 |
+
"position_embedding_type": "absolute",
|
| 28 |
+
"type_vocab_size": 1,
|
| 29 |
+
"use_cache": true,
|
| 30 |
+
"vocab_size": 50265
|
| 31 |
+
},
|
| 32 |
+
"decoder_start_token_id": 0,
|
| 33 |
+
"dtype": "float32",
|
| 34 |
+
"encoder": {
|
| 35 |
+
"_name_or_path": "microsoft/codebert-base",
|
| 36 |
+
"architectures": [
|
| 37 |
+
"RobertaModel"
|
| 38 |
+
],
|
| 39 |
+
"attention_probs_dropout_prob": 0.1,
|
| 40 |
+
"classifier_dropout": null,
|
| 41 |
+
"dtype": "float32",
|
| 42 |
+
"hidden_act": "gelu",
|
| 43 |
+
"hidden_dropout_prob": 0.1,
|
| 44 |
+
"hidden_size": 768,
|
| 45 |
+
"initializer_range": 0.02,
|
| 46 |
+
"intermediate_size": 3072,
|
| 47 |
+
"layer_norm_eps": 1e-05,
|
| 48 |
+
"max_position_embeddings": 514,
|
| 49 |
+
"model_type": "roberta",
|
| 50 |
+
"num_attention_heads": 12,
|
| 51 |
+
"num_hidden_layers": 12,
|
| 52 |
+
"output_past": true,
|
| 53 |
+
"position_embedding_type": "absolute",
|
| 54 |
+
"type_vocab_size": 1,
|
| 55 |
+
"use_cache": true,
|
| 56 |
+
"vocab_size": 50265
|
| 57 |
+
},
|
| 58 |
+
"eos_token_id": 2,
|
| 59 |
+
"is_encoder_decoder": true,
|
| 60 |
+
"model_type": "encoder-decoder",
|
| 61 |
+
"pad_token_id": 1,
|
| 62 |
+
"transformers_version": "4.57.0"
|
| 63 |
+
}
|
generation_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 0,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"pad_token_id": 1,
|
| 6 |
+
"transformers_version": "4.57.0"
|
| 7 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fcedcb0d132a2a01eb21a6ec25d8c26826cf6dc3b2c4b20d92395187c4f1d67
|
| 3 |
+
size 1110905884
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"cls_token": {
|
| 10 |
+
"content": "<s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"eos_token": {
|
| 17 |
+
"content": "</s>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": true,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"mask_token": {
|
| 24 |
+
"content": "<mask>",
|
| 25 |
+
"lstrip": true,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"pad_token": {
|
| 31 |
+
"content": "<pad>",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": true,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
},
|
| 37 |
+
"sep_token": {
|
| 38 |
+
"content": "</s>",
|
| 39 |
+
"lstrip": false,
|
| 40 |
+
"normalized": true,
|
| 41 |
+
"rstrip": false,
|
| 42 |
+
"single_word": false
|
| 43 |
+
},
|
| 44 |
+
"unk_token": {
|
| 45 |
+
"content": "<unk>",
|
| 46 |
+
"lstrip": false,
|
| 47 |
+
"normalized": true,
|
| 48 |
+
"rstrip": false,
|
| 49 |
+
"single_word": false
|
| 50 |
+
}
|
| 51 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"0": {
|
| 5 |
+
"content": "<s>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"1": {
|
| 13 |
+
"content": "<pad>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": true,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"2": {
|
| 21 |
+
"content": "</s>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": true,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"3": {
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": true,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"50264": {
|
| 37 |
+
"content": "<mask>",
|
| 38 |
+
"lstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"bos_token": "<s>",
|
| 46 |
+
"clean_up_tokenization_spaces": false,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"extra_special_tokens": {},
|
| 51 |
+
"mask_token": "<mask>",
|
| 52 |
+
"model_max_length": 512,
|
| 53 |
+
"pad_token": "<pad>",
|
| 54 |
+
"sep_token": "</s>",
|
| 55 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 56 |
+
"unk_token": "<unk>"
|
| 57 |
+
}
|
train_metrics.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"avg_loss": 0.9720969621703985,
|
| 3 |
+
"avg_poison_loss": 0.2330484651994926,
|
| 4 |
+
"avg_clean_loss": 0.8744522833564142,
|
| 5 |
+
"poison_count": 2700,
|
| 6 |
+
"clean_count": 267300
|
| 7 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|