Feature Extraction
Transformers
Safetensors
sentence-transformers
English
Chinese
c2llm
code
custom_code
Run this model with HF Jobs
Run codefuse-ai/C2LLM-0.5B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/codefuse-ai/C2LLM-0.5B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/codefuse-ai/C2LLM-0.5B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use codefuse-ai/C2LLM-0.5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use codefuse-ai/C2LLM-0.5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="codefuse-ai/C2LLM-0.5B", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("codefuse-ai/C2LLM-0.5B", trust_remote_code=True, device_map="auto") - sentence-transformers
How to use codefuse-ai/C2LLM-0.5B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("codefuse-ai/C2LLM-0.5B", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files5 unmodified lines678991011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321335 unmodified lineslibrary_name: transformerstags:- code------# Introduction
C2LLM: Advanced Code Embeddings for Deep Semantic Understanding
**C2LLMs (Code Contrastive Large Language Model)** is a powerful new model for generating code embeddings, designed to capture the deep semantics of source code.
#### Key Features
- **Powerful Base Model**: Built upon the state-of-the-art `Qwen2.5-Coder`, inheriting its exceptional code comprehension capabilities.- **Intelligent Pooling with PMA**: Instead of traditional `mean pooling` or `last token pooling`, C2LLM uses **PMA (Pooling by Multi-head Attention)**. This allows the model to dynamically focus on the most critical parts of the code, creating a more informative and robust embedding.- **Trained for Retrieval**: C2LLM was fine-tuned on a massive dataset of **3 million query-document pairs**, optimizing it for real-world code retrieval and semantic search tasks. Supporting Text2Code/Code2Code/Code2Text tasks.
C2LLM is designed to be a go-to model for tasks like code search and Retrieval-Augmented Generation (RAG).
# Model Details
# How to use
## Usage (**HuggingFace Transformers**)
```plainfrom transformers import AutoModel, AutoTokenizerimport torch
model_path = "codefuse-ai/C2LLM-0.5B"
# Load the modelmodel = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True)
# Prepare the datasentences = ['''int r = (int) params >> 8 & 0xff;int p = (int) params & 0xff;
byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
if (derived0.length != derived1.length) return false;
int result = 0;for (int i = 0; i < derived0.length; i++) {result |= derived0[i] ^ derived1[i];}return result == 0;} catch (UnsupportedEncodingException e) {throw new IllegalStateException("JVM doesn't support UTF-8?");} catch (GeneralSecurityException e) {throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");}}''',''' }if (tempFrom > tempTo) {return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);}return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);}''']
# Get the embeddingsembeddings = model.encode(sentences)```
## Usage (**Sentence-Transformers**)
```pythonfrom sentence_transformers import SentenceTransformer
# Load the modelmodel = SentenceTransformer("codefuse-ai/C2LLM-0.5B", trust_remote_code=True)
# Prepare the datasentences = ['''int r = (int) params >> 8 & 0xff;int p = (int) params & 0xff;
byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
if (derived0.length != derived1.length) return false;
int result = 0;for (int i = 0; i < derived0.length; i++) {result |= derived0[i] ^ derived1[i];}return result == 0;} catch (UnsupportedEncodingException e) {throw new IllegalStateException("JVM doesn't support UTF-8?");} catch (GeneralSecurityException e) {throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");}}''',''' }if (tempFrom > tempTo) {return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);}return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);}''']
# Get the embeddingsembeddings = model.encode(sentences)```
## Evaluation (**MTEB**)
```plainfrom sentence_transformers import SentenceTransformerfrom mteb.models import ModelMetafrom mteb.cache import ResultCache
model_name = "codefuse-ai/C2LLM-0.5B"
# Load the modelmodel = mteb.get_model(model_name) # if the model is not implemented in MTEB it will be eq. to SentenceTransformer(model_name)
# Select taskstasks = mteb.get_tasks(tasks=["AppsRetrieval", "CodeSearchNetCCRetrieval", "CodeEditSearchRetrieval","CodeSearchNetRetrieval","CodeFeedbackMT","CodeFeedbackST","CodeTransOceanContest","CodeTransOceanDL","COIRCodeSearchNetRetrieval","CosQA","StackOverflowQA","SyntheticText2SQL"])
# Cache the resultcache = ResultCache("./c2llm_results")
# Evaluateresults = mteb.evaluate(model, tasks=tasks, cache=cache, encode_kwargs={"batch_size": 16})```
## Correspondence to
Jin Qin (qj431428@antgroup.com), Zihan Liao (liaozihan.lzh@antgroup.com), Ziyin Zhang (zhangziying.zzy@antgroup.com), Hang Yu (hyu.hugo@antgroup.com), Peng Di (dipeng.dp@antgroup.com)README.md+125-1