Views
No views yet
Qwen2.5-Coder, inheriting its exceptional code comprehension capabilities.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.1from transformers import AutoModel, AutoTokenizer
2import torch
3
4model_path = "codefuse-ai/C2LLM-7B"
5
6# Load the model
7model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, trust_remote_code=True)
8
9# Prepare your custom instruction
10instruction = "xxxxx"
11
12# Prepare the data
13sentences = ['''int r = (int) params >> 8 & 0xff;
14int p = (int) params & 0xff;
15
16byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
17
18if (derived0.length != derived1.length) return false;
19
20int result = 0;
21for (int i = 0; i < derived0.length; i++) {
22result |= derived0[i] ^ derived1[i];
23}
24return result == 0;
25} catch (UnsupportedEncodingException e) {
26throw new IllegalStateException("JVM doesn't support UTF-8?");
27} catch (GeneralSecurityException e) {
28throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");
29}
30}''',
31'''
32}
33if (tempFrom > tempTo) {
34return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);
35}
36return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);
37}''']
38
39sentences = [instruction+sentence for sentence in sentences]
40
41# Get the embeddings
42embeddings = model.encode(sentences)1from sentence_transformers import SentenceTransformer
2
3# Load the model
4model = SentenceTransformer("codefuse-ai/C2LLM-7B", trust_remote_code=True, tokenizer_kwargs={"padding_side":"left"})
5
6# Prepare your custom instruction
7instruction = "xxxxx"
8
9# Prepare the data
10sentences = ['''int r = (int) params >> 8 & 0xff;
11int p = (int) params & 0xff;
12
13byte[] derived1 = SCrypt.scrypt(passwd.getBytes("UTF-8"), salt, N, r, p, 32);
14
15if (derived0.length != derived1.length) return false;
16
17int result = 0;
18for (int i = 0; i < derived0.length; i++) {
19result |= derived0[i] ^ derived1[i];
20}
21return result == 0;
22} catch (UnsupportedEncodingException e) {
23throw new IllegalStateException("JVM doesn't support UTF-8?");
24} catch (GeneralSecurityException e) {
25throw new IllegalStateException("JVM doesn't support SHA1PRNG or HMAC_SHA256?");
26}
27}''',
28'''
29}
30if (tempFrom > tempTo) {
31return new RangeInfo(inclusive ? tempTo : tempTo + 1, tempFrom + 1, true);
32}
33return new RangeInfo(tempFrom, inclusive ? tempTo + 1 : tempTo, false);
34}''']
35
36sentences = [instruction+sentence for sentence in sentences]
37
38# Get the embeddings
39embeddings = model.encode(sentences)1from sentence_transformers import SentenceTransformer
2from mteb.models import ModelMeta
3from mteb.cache import ResultCache
4
5model_name = "codefuse-ai/C2LLM-7B"
6
7# Load the model
8model = mteb.get_model(model_name) # if the model is not implemented in MTEB it will be eq. to SentenceTransformer(model_name)
9
10# Select tasks
11tasks = mteb.get_tasks(tasks=["AppsRetrieval", "CodeSearchNetCCRetrieval", "CodeEditSearchRetrieval","CodeSearchNetRetrieval","CodeFeedbackMT","CodeFeedbackST","CodeTransOceanContest","CodeTransOceanDL","COIRCodeSearchNetRetrieval","CosQA","StackOverflowQA","SyntheticText2SQL"])
12
13# Cache the result
14cache = ResultCache("./c2llm_results")
15
16# Evaluate
17results = mteb.evaluate(model, tasks=tasks, cache=cache, encode_kwargs={"batch_size": 16})