baidu / ernie-code-560m

huggingface.co
Total runs: 15
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: October 04 2024
text2text-generation

Introduction of ernie-code-560m

Model Details of ernie-code-560m

ERNIE-Code

ERNIE-Code: Beyond English-Centric Cross-lingual Pretraining for Programming Languages

ernie-code-comp

ERNIE-Code is a unified large language model (LLM) that connects 116 natural languages with 6 programming languages. We employ two pre-training methods for universal cross-lingual pre-training: span-corruption language modeling that learns patterns from monolingual NL or PL; and pivot-based translation language modeling that relies on parallel data of many NLs and PLs. Extensive results show that ERNIE-Code outperforms previous multilingual LLMs for PL or NL across a wide range of end tasks of code intelligence, including multilingual code-to-text, text-to-code, code-to-code, and text-to-text generation. We further show its advantage of zero-shot prompting on multilingual code summarization and text-to-text translation.

ACL 2023 (Findings) | arXiv

Usage
import torch
from transformers import (
    AutoModelForSeq2SeqLM,
    AutoModelForCausalLM,
    AutoTokenizer
)

model_name = "baidu/ernie-code-560m"

model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# note that you can use aforementioned `clean_up_code_spaces` to proprocess the code


def format_code_with_spm_compatablity(line: str):
    format_dict = {
        " " : "<|space|>"
    }
    tokens = list(line)
    i = 0
    while i < len(tokens):
        if line[i] == "\n":
            while i+1 < len(tokens) and tokens[i+1] == " ":
                tokens[i+1] = format_dict.get(" ")
                i += 1
        i += 1
    formatted_line = ''.join(tokens)
    return formatted_line

"""
TYPE="code" # define input type in ("code", "text")
input="arr.sort()"
prompt="translate python to java: \n%s" % (input)  # your prompt here
"""

TYPE="text" # define input type in ("code", "text")
input="quick sort"
prompt="translate English to Japanese: \n%s" % (input)  # your prompt here

assert TYPE in ("code", "text")

# preprocess for code input
if TYPE=="code":
    prompt = format_code_with_spm_compatablity(prompt)

model_inputs = tokenizer(prompt, max_length=512, padding=False, truncation=True, return_tensors="pt")

model = model.cuda() # by default
input_ids = model_inputs.input_ids.cuda() # by default
attention_mask = model_inputs.attention_mask.cuda() # by default

output = model.generate(input_ids=input_ids, attention_mask=attention_mask, 
        num_beams=5, max_length=20) # change to your needs

# Ensure to customize the post-processing of `clean_up_code_spaces` output according to specific requirements.
output = tokenizer.decode(output.flatten(), skip_special_tokens=True)


# post-process the code generation
def clean_up_code_spaces(s: str):
    # post process
    # ===========================
    new_tokens = ["<pad>", "</s>", "<unk>", "\n", "\t", "<|space|>"*4, "<|space|>"*2, "<|space|>"]
    for tok in new_tokens:
        s = s.replace(f"{tok} ", tok)

    cleaned_tokens = ["<pad>", "</s>", "<unk>"]
    for tok in cleaned_tokens:
        s = s.replace(tok, "")
    s = s.replace("<|space|>", " ")
    return s
output = [clean_up_code_spaces(pred) for pred in output]

You can adapt seq2seq translation code for finetuning.

You can also check the official inference code on PaddleNLP .

Zero-shot Examples
  • Multilingual code-to-text generation (zero-shot)

code-to-text-examples

zh_code-to-text_examples-1

  • Multilingual text-to-text translation (zero-shot)

zero-shot-mt-examples

BibTeX
@inproceedings{chai-etal-2023-ernie,
    title = "{ERNIE}-Code: Beyond {E}nglish-Centric Cross-lingual Pretraining for Programming Languages",
    author = "Chai, Yekun  and
      Wang, Shuohuan  and
      Pang, Chao  and
      Sun, Yu  and
      Tian, Hao  and
      Wu, Hua",
    booktitle = "Findings of the Association for Computational Linguistics: ACL 2023",
    month = jul,
    year = "2023",
    address = "Toronto, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2023.findings-acl.676",
    pages = "10628--10650",
    abstract = "Software engineers working with the same programming language (PL) may speak different natural languages (NLs) and vice versa, erecting huge barriers to communication and working efficiency. Recent studies have demonstrated the effectiveness of generative pre-training in computer programs, yet they are always English-centric. In this work, we step towards bridging the gap between multilingual NLs and multilingual PLs for large language models (LLMs). We release ERNIE-Code, a unified pre-trained language model for 116 NLs and 6 PLs. We employ two methods for universal cross-lingual pre-training: span-corruption language modeling that learns patterns from monolingual NL or PL; and pivot-based translation language modeling that relies on parallel data of many NLs and PLs. Extensive results show that ERNIE-Code outperforms previous multilingual LLMs for PL or NL across a wide range of end tasks of code intelligence, including multilingual code-to-text, text-to-code, code-to-code, and text-to-text generation. We further show its advantage of zero-shot prompting on multilingual code summarization and text-to-text translation. We release our code and pre-trained checkpoints.",
}

Runs of baidu ernie-code-560m on huggingface.co

15
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About ernie-code-560m huggingface.co Model

More ernie-code-560m license Visit here:

https://choosealicense.com/licenses/mit

ernie-code-560m huggingface.co

ernie-code-560m huggingface.co is an AI model on huggingface.co that provides ernie-code-560m's model effect (), which can be used instantly with this baidu ernie-code-560m model. huggingface.co supports a free trial of the ernie-code-560m model, and also provides paid use of the ernie-code-560m. Support call ernie-code-560m model through api, including Node.js, Python, http.

ernie-code-560m huggingface.co Url

https://huggingface.co/baidu/ernie-code-560m

baidu ernie-code-560m online free

ernie-code-560m huggingface.co is an online trial and call api platform, which integrates ernie-code-560m's modeling effects, including api services, and provides a free online trial of ernie-code-560m, you can try ernie-code-560m online for free by clicking the link below.

baidu ernie-code-560m online free url in huggingface.co:

https://huggingface.co/baidu/ernie-code-560m

ernie-code-560m install

ernie-code-560m is an open source model from GitHub that offers a free installation service, and any user can find ernie-code-560m on GitHub to install. At the same time, huggingface.co provides the effect of ernie-code-560m install, users can directly use ernie-code-560m installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

ernie-code-560m install url in huggingface.co:

https://huggingface.co/baidu/ernie-code-560m

Url of ernie-code-560m

ernie-code-560m huggingface.co Url

Provider of ernie-code-560m huggingface.co

baidu
ORGANIZATIONS

Other API from baidu

huggingface.co

Total runs: 3.1M
Run Growth: 635.1K
Growth Rate: 20.25%
Updated:July 29 2026
huggingface.co

Total runs: 97.6K
Run Growth: -183.9K
Growth Rate: -185.00%
Updated:April 29 2026
huggingface.co

Total runs: 1.6K
Run Growth: -66.9K
Growth Rate: -4305.08%
Updated:April 17 2026
huggingface.co

Total runs: 208
Run Growth: 47
Growth Rate: 21.56%
Updated:September 19 2025
huggingface.co

Total runs: 85
Run Growth: -15
Growth Rate: -17.86%
Updated:June 03 2026
huggingface.co

Total runs: 60
Run Growth: -2.0K
Growth Rate: -2627.27%
Updated:April 19 2026
huggingface.co

Total runs: 15
Run Growth: 0
Growth Rate: 0.00%
Updated:October 04 2024
huggingface.co

Total runs: 15
Run Growth: 0
Growth Rate: 0.00%
Updated:October 04 2024
huggingface.co

Total runs: 3
Run Growth: 0
Growth Rate: 0.00%
Updated:October 04 2024
huggingface.co

Total runs: 1
Run Growth: 0
Growth Rate: 0.00%
Updated:March 10 2024