graphcodebert base

microsoft

Introduction

GraphCodeBERT is a pre-trained model designed for programming languages, incorporating data-flow information alongside code sequences. It is based on the Transformer architecture and is specifically tailored for handling code.

Architecture

GraphCodeBERT features a Transformer-based architecture with 12 layers, each containing 768-dimensional hidden states and 12 attention heads. The model supports a maximum sequence length of 512 tokens.

Training

The model is trained on the CodeSearchNet dataset, which includes 2.3 million functions with document pairs across six programming languages. This extensive dataset allows GraphCodeBERT to effectively learn the syntax and semantics of code.

Guide: Running Locally

  1. Install Libraries: Ensure you have Python and pip installed. Use pip to install the Hugging Face Transformers library.

    pip install transformers
    
  2. Load Model: Use the Transformers library to load the GraphCodeBERT model.

    from transformers import AutoModel, AutoTokenizer
    
    tokenizer = AutoTokenizer.from_pretrained("microsoft/graphcodebert-base")
    model = AutoModel.from_pretrained("microsoft/graphcodebert-base")
    
  3. Inference: Prepare your code input and use the model to get predictions.

    inputs = tokenizer("def example_function(): pass", return_tensors="pt")
    outputs = model(**inputs)
    
  4. Cloud GPU: For efficient performance, especially during training or handling large inputs, consider using a cloud GPU service like AWS, Google Cloud, or Azure.

License

The model card for GraphCodeBERT was created by the Hugging Face community, as the original BERT team did not provide one. More details about the model and its use can be found in the paper by Guo et al. (arXiv:2009.08366).

More Related APIs in Fill Mask