Team Ai
Modelpublic

microsoft/codebert-base-mlm

sourceHugging Faceupdated 4y agoView on Hugging Face
46likes5kdownloads
README.md47 linesDownload Raw Back to root
1## CodeBERT-base-mlm2Pretrained weights for [CodeBERT: A Pre-Trained Model for Programming and Natural Languages](https://arxiv.org/abs/2002.08155).3 4### Training Data5The model is trained on the code corpus of [CodeSearchNet](https://github.com/github/CodeSearchNet)6 7### Training Objective8This model is initialized with Roberta-base and trained with a simple MLM (Masked Language Model) objective.9 10### Usage11```python12from transformers import RobertaTokenizer, RobertaForMaskedLM, pipeline13 14model = RobertaForMaskedLM.from_pretrained('microsoft/codebert-base-mlm')15tokenizer = RobertaTokenizer.from_pretrained('microsoft/codebert-base-mlm')16 17code_example = "if (x is not None) <mask> (x>1)"18fill_mask = pipeline('fill-mask', model=model, tokenizer=tokenizer)19 20outputs = fill_mask(code_example)21print(outputs)22```23Expected results:24```25{'sequence': '<s> if (x is not None) and (x>1)</s>', 'score': 0.6049249172210693, 'token': 8}26{'sequence': '<s> if (x is not None) or (x>1)</s>', 'score': 0.30680200457572937, 'token': 50}27{'sequence': '<s> if (x is not None) if (x>1)</s>', 'score': 0.02133703976869583, 'token': 114}28{'sequence': '<s> if (x is not None) then (x>1)</s>', 'score': 0.018607674166560173, 'token': 172}29{'sequence': '<s> if (x is not None) AND (x>1)</s>', 'score': 0.007619690150022507, 'token': 4248}30```31 32### Reference331. [Bimodal CodeBERT trained with MLM+RTD objective](https://huggingface.co/microsoft/codebert-base) (suitable for code search and document generation)342. 🤗 [Hugging Face's CodeBERTa](https://huggingface.co/huggingface/CodeBERTa-small-v1) (small size, 6 layers)35 36### Citation37```bibtex38@misc{feng2020codebert,39    title={CodeBERT: A Pre-Trained Model for Programming and Natural Languages},40    author={Zhangyin Feng and Daya Guo and Duyu Tang and Nan Duan and Xiaocheng Feng and Ming Gong and Linjun Shou and Bing Qin and Ting Liu and Daxin Jiang and Ming Zhou},41    year={2020},42    eprint={2002.08155},43    archivePrefix={arXiv},44    primaryClass={cs.CL}45}46```47