SmartBERT V2 CodeBERT is a domain-adapted pre-trained model built on top of CodeBERT-base-mlm.
It is designed to learn high-quality semantic representations of smart contract code, particularly at the function level.
The model is further pre-trained on a large corpus of smart contracts using the Masked Language Modeling (MLM) objective.
This domain-adaptive pretraining enables the model to better capture semantic patterns, structure, and intent within smart contract functions compared to general-purpose code models.
SmartBERT V2 can be used for tasks such as:
Smart contract intent detection
Code similarity analysis
Vulnerability analysis
Smart contract classification
Code embedding and retrieval
SmartBERT V2 is a pre-trained model specifically developed for SmartIntent V2. It was trained on 16,000 smart contracts, with no overlap with the SmartIntent V2 evaluation dataset to avoid data leakage.
For production use or general smart contract representation tasks, we recommend SmartBERT V3: https://huggingface.co/web3se/SmartBERT-v3
Training Data
SmartBERT V2 was trained on a corpus of approximately 16,000 smart contracts, primarily written in Solidity and collected from public blockchain repositories.
To better model smart contract behavior, contracts were processed at the function level, enabling the model to learn fine-grained semantic representations of smart contract functions.
For benchmarking purposes in the SmartIntent V2, the pretraining corpus was intentionally limited to this 16,000-contract dataset.
The evaluation dataset (4,000 smart contracts) was strictly held out and not included in the pretraining data, ensuring that downstream evaluations remain unbiased and free from data leakage.
Preprocessing
During preprocessing, all newline (\n) and tab (\t) characters in the function code were normalized by replacing them with a single space.
This ensures a consistent input format for the tokenizer and avoids unnecessary token fragmentation.
CodeBERT is a transformer-based model trained on source code and natural language pairs.
SmartBERT V2 further adapts this model to the smart contract domain through continued pretraining.
Training Objective
The model is trained using the Masked Language Modeling (MLM) objective, following the same training paradigm as the original CodeBERT model.
During training:
A subset of tokens is randomly masked.
The model learns to predict the masked tokens based on surrounding context.
This encourages the model to learn deeper structural and semantic representations of smart contract code.
Training Setup
Training was conducted using the HuggingFace Transformers framework with the following configuration:
The model was evaluated on a held-out dataset of approximately 4,000 smart contracts to monitor training stability and generalization during pretraining.
SmartBERT V2 is primarily intended as a representation learning model, providing high-quality embeddings for downstream smart contract analysis tasks.
How to Use
You can load SmartBERT V2 using the HuggingFace Transformers library.
If you use SmartBERT in your research, please cite:
tex
1@article{huang2025smart,
2 title={Smart Contract Intent Detection with Pre-trained Programming Language Model},
3 author={Huang, Youwei and Li, Jianwen and Fang, Sen and Li, Yao and Yang, Peng and Hu, Bin},
4 journal={arXiv preprint arXiv:2508.20086},
5 year={2025}6}