yliu279 commited on
Commit
7b16336
·
verified ·
1 Parent(s): df6c59b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -95
README.md CHANGED
@@ -1,95 +1,95 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
4
- <h1 align="center">Salesforce/SFR-Embedding-Code-400M_R</h1>
5
-
6
- **SFR-Embedding by Salesforce Research.**
7
-
8
- The Salesforce/SFR-Embedding-Code is a generalist embedding model family for multilingual and multi-task code and Text retrieval. It demonstrates superior performance compared to various open-source code embedding models across multiple code retrieval tasks.
9
-
10
- Check out our [paper](https://arxiv.org/abs/2411.12644) for more details!
11
-
12
- ### Ethical Considerations
13
- This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
14
-
15
- ### License Statement:
16
- Users need to make their own assessment regarding any obligations or responsibilities under the corresponding licenses or terms and conditions pertaining to the original datasets and data. This release is for research purposes only in support of an academic paper.
17
-
18
- ### Performance on CoIR Benchmark
19
- | Model | Model Size | CoIR AVG (NDCG@10) |
20
- |-----------------------|------------|---------------------|
21
- | **SFR-Embedding-Code** | 2B | 67.4 |
22
- | CodeSage-Large-v2 | 1.3B | 64.2 |
23
- | CodeSage-Large | 1.3B | 61.0 |
24
- | **SFR-Embedding-Code** | 400M | 61.9 |
25
- | CodeRankEmbed | 137M | 60.1 |
26
- | CodeSage-Base | 356M | 57.5 |
27
- | Voyage-Code-002 | - | 56.3 |
28
- | CodeSage-Small | 130M | 54.4 |
29
-
30
-
31
- SFR-Embedding Team
32
- * Ye Liu
33
- * Rui Meng
34
- * Shafiq Rayhan Joty
35
- * Silvio Savarese
36
- * Caiming Xiong
37
- * Yingbo Zhou
38
- * Semih Yavuz
39
-
40
- ## How to run
41
-
42
- #### Transformers
43
- ```python
44
- import torch.nn.functional as F
45
- from transformers import AutoModel, AutoTokenizer
46
-
47
- input_texts = [
48
- "how to implement quick sort in Python?",
49
- "def quick_sort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)",
50
- "def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n return arr",
51
- ]
52
-
53
- model_path = 'Salesforce/SFR-Embedding-Code-400M_R'
54
- tokenizer = AutoTokenizer.from_pretrained(model_path)
55
- model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
56
-
57
- # Tokenize the input texts
58
- batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
59
-
60
- outputs = model(**batch_dict)
61
- embeddings = outputs.last_hidden_state[:, 0]
62
-
63
- # normalize embeddings
64
- embeddings = F.normalize(embeddings, p=2, dim=1)
65
- scores = (embeddings[:1] @ embeddings[1:].T) * 100
66
- print("Similarity Scores:", scores.tolist())
67
- ```
68
-
69
- ### Sentence Transformers
70
- # Requires sentence_transformers>=2.7.0
71
- ```python
72
- from sentence_transformers import SentenceTransformer
73
- from sentence_transformers.util import cos_sim
74
-
75
- sentences = [
76
- "how to implement quick sort in Python?",
77
- "def quick_sort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)",
78
- "def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n return arr",
79
- ]
80
-
81
- model = SentenceTransformer('Salesforce/SFR-Embedding-Code-400M_R', trust_remote_code=True)
82
- embeddings = model.encode(sentences)
83
- print(cos_sim(embeddings[0], embeddings[1:]))
84
- ```
85
-
86
- ### Citation
87
- ```bibtex
88
- @article{liu2024codexembed,
89
- title={CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrieval},
90
- author={Liu, Ye and Meng, Rui and Jot, Shafiq and Savarese, Silvio and Xiong, Caiming and Zhou, Yingbo and Yavuz, Semih},
91
- journal={arXiv preprint arXiv:2411.12644},
92
- year={2024}
93
- }
94
- ```
95
-
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ ---
4
+ <h1 align="center">Salesforce/SFR-Embedding-Code-400M_R</h1>
5
+
6
+ **SFR-Embedding by Salesforce Research.**
7
+
8
+ The Salesforce/SFR-Embedding-Code is a generalist embedding model family for multilingual and multi-task code and Text retrieval. It demonstrates superior performance compared to various open-source code embedding models across multiple code retrieval tasks.
9
+
10
+ Check out our [paper](https://arxiv.org/abs/2411.12644) for more details!
11
+
12
+ ### Ethical Considerations
13
+ This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
14
+
15
+ ### License Statement:
16
+ Users need to make their own assessment regarding any obligations or responsibilities under the corresponding licenses or terms and conditions pertaining to the original datasets and data. This release is for research purposes only in support of an academic paper.
17
+
18
+ ### Performance on CoIR Benchmark
19
+ | Model | Model Size | CoIR AVG (NDCG@10) |
20
+ |-----------------------|------------|---------------------|
21
+ | **SFR-Embedding-Code** | 2B | 67.4 |
22
+ | CodeSage-Large-v2 | 1.3B | 64.2 |
23
+ | CodeSage-Large | 1.3B | 61.0 |
24
+ | **SFR-Embedding-Code** | 400M | 61.9 |
25
+ | CodeRankEmbed | 137M | 60.1 |
26
+ | CodeSage-Base | 356M | 57.5 |
27
+ | Voyage-Code-002 | - | 56.3 |
28
+ | CodeSage-Small | 130M | 54.4 |
29
+
30
+
31
+ SFR-Embedding Team († indicates co-leaders)
32
+ * Ye Liu
33
+ * Rui Meng
34
+ * Shafiq Rayhan Joty
35
+ * Silvio Savarese
36
+ * Caiming Xiong
37
+ * Yingbo Zhou
38
+ * Semih Yavuz
39
+
40
+ ## How to run
41
+
42
+ #### Transformers
43
+ ```python
44
+ import torch.nn.functional as F
45
+ from transformers import AutoModel, AutoTokenizer
46
+
47
+ input_texts = [
48
+ "how to implement quick sort in Python?",
49
+ "def quick_sort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)",
50
+ "def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n return arr",
51
+ ]
52
+
53
+ model_path = 'Salesforce/SFR-Embedding-Code-400M_R'
54
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
55
+ model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
56
+
57
+ # Tokenize the input texts
58
+ batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
59
+
60
+ outputs = model(**batch_dict)
61
+ embeddings = outputs.last_hidden_state[:, 0]
62
+
63
+ # normalize embeddings
64
+ embeddings = F.normalize(embeddings, p=2, dim=1)
65
+ scores = (embeddings[:1] @ embeddings[1:].T) * 100
66
+ print("Similarity Scores:", scores.tolist())
67
+ ```
68
+
69
+ ### Sentence Transformers
70
+ # Requires sentence_transformers>=2.7.0
71
+ ```python
72
+ from sentence_transformers import SentenceTransformer
73
+ from sentence_transformers.util import cos_sim
74
+
75
+ sentences = [
76
+ "how to implement quick sort in Python?",
77
+ "def quick_sort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quick_sort(left) + middle + quick_sort(right)",
78
+ "def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n return arr",
79
+ ]
80
+
81
+ model = SentenceTransformer('Salesforce/SFR-Embedding-Code-400M_R', trust_remote_code=True)
82
+ embeddings = model.encode(sentences)
83
+ print(cos_sim(embeddings[0], embeddings[1:]))
84
+ ```
85
+
86
+ ### Citation
87
+ ```bibtex
88
+ @article{liu2024codexembed,
89
+ title={CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrieval},
90
+ author={Liu, Ye and Meng, Rui and Jot, Shafiq and Savarese, Silvio and Xiong, Caiming and Zhou, Yingbo and Yavuz, Semih},
91
+ journal={arXiv preprint arXiv:2411.12644},
92
+ year={2024}
93
+ }
94
+ ```
95
+