File size: 10,959 Bytes
0978086 044a7a4 57e0e1b 0978086 044a7a4 57e0e1b 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 51e49ec 96ff525 51e49ec 0978086 1d9e49b 57e0e1b 1fa7a1b 57e0e1b 51e49ec 96ff525 51e49ec 96ff525 51e49ec 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 f9495f0 9bc5d2e f9495f0 044a7a4 af9d0a7 0978086 af9d0a7 044a7a4 0978086 f9495f0 0978086 044a7a4 0978086 044a7a4 0978086 044a7a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
---
tags:
- sentence-transformers
- sentence-similarity
- feature-extraction
- code-search
- modernbert
- code
- python
- java
- javascript
- php
- ruby
- rust
- go
- mteb
base_model: Shuu12121/CodeModernBERT-Crow
pipeline_tag: sentence-similarity
library_name: sentence-transformers
license: apache-2.0
datasets:
- code-search-net/code_search_net
- Shuu12121/python-codesearch-filtered
- Shuu12121/java-codesearch-filtered
- Shuu12121/javascript-codesearch-filtered
- Shuu12121/rust-codesearch-filtered
- Shuu12121/ruby-codesearch-filtered
language:
- en
widget:
- src_texts:
- 'def greet(name): print(f''Hello, {name}!'')'
- function calculateSum(a, b) { return a + b; }
- >-
public static void main(String[] args) { System.out.println("Hello World");
}
example_title: Code Snippets
- src_texts:
- A function that prints a greeting.
- Function to compute the sum of two numbers.
- The main entry point of a Java program.
example_title: Descriptions
---
# Shuu12121/CodeSearch-ModernBERT-Crow-Plus🐦⬛
このモデルは、`Shuu12121/CodeModernBERT-Crow` をベースにした Sentence Transformer モデルであり、特に多言語コード検索タスクにおいて高い性能を発揮するようにファインチューニングされています。
This is a Sentence Transformer model based on `Shuu12121/CodeModernBERT-Crow`, fine-tuned for high performance on multilingual code search tasks.
- 開発者 (Developer): [Shuu12121](https://huggingface.co/Shuu12121)
- ベースモデル (Base Model): [Shuu12121/CodeModernBERT-Crow](https://huggingface.co/Shuu12121/CodeModernBERT-Crow)
- License: Apache-2.0
[](https://colab.research.google.com/github/Shun0212/CodeSearch-Crow/blob/main/CodeSearchCrow.ipynb)
👉 **[Google Colab 上で今すぐ試す](https://colab.research.google.com/github/Shun0212/CodeSearch-Crow/blob/main/CodeSearchCrow.ipynb)**
このモデルを使った、**GitHubリポジトリの関数レベルコード検索システム**を簡単に試すことができます!
## 📊 MTEB Leaderboard 成績
本モデル `CodeSearch-ModernBERT-Crow-Plus` は、Massive Text Embedding Benchmark (MTEB) における以下のタスクで高い順位を記録しています:
現在の順位は[Leaderboard](https://huggingface.co/spaces/mteb/leaderboard)はこちらでご確認してください
| タスク名 | nDCG@10 スコア | 順位(2025年4月時点) |
|-------------------------------|----------------|----------------------------|
| CodeSearchNetRetrieval | **0.89296** | **第8位 / 146 モデル中** |
| COIRCodeSearchNetRetrieval | **0.79884** | **第5位 / 15 モデル中** |
これらの結果は、本モデルがコード検索タスクにおいて非常に競争力のある性能を発揮していることを示しています。
特に、**多言語・自然言語–コード間の検索精度**に優れた Sentence Transformer モデルとして、実用的な選択肢の一つです。
## 🧩 関連プロジェクトとの連携 / Integration with Related Projects
**CodeSearch-ModernBERT-Crow-Plus** は [CodeSearchCrow.ipynb](https://colab.research.google.com/github/Shun0212/CodeSearch-Crow/blob/main/CodeSearchCrow.ipynb) のように
**実際のGitHubリポジトリを対象とした、関数単位のコード検索システム**を簡単に構築できます。
このノートブックでは以下の処理が実行されます:
- GitHubリポジトリを指定してクローン
- `.py` または `.ipynb` ファイルから関数・コードセルを抽出
- 関数コードをエンベディング(Sentence Transformerモデルを使用)
- FAISSインデックスを作成して高速検索を可能に
- Qwen3-8B-FP8モデルによる**日本語→英語翻訳**を通じて、**日本語クエリでも自然な検索**を実現
### 🔹 特徴
- **初回実行時**にインデックスを作成し、**以降は高速に再利用可能**
- **関数レベル**でコードを検索できるため、**意味的に最も類似するコードを高精度に検索**可能
- **日本語クエリにも完全対応**([Qwen3-8B-FP8](https://huggingface.co/Qwen/Qwen3-8B-FP8)で英語翻訳後に検索)
---
### 🔗 リンク
- 📄 実行可能なノートブック:[.ipynb](https://colab.research.google.com/github/Shun0212/CodeSearch-Crow/blob/main/CodeSearchCrow.ipynb)
## 概要 / Overview
`CodeSearch-ModernBERT-Crow-Plus` は、自然言語のクエリと複数のプログラミング言語(Python, Java, JavaScript, PHP, Ruby, Go, Rust)のコードスニペット(主に関数レベル)間の意味的な類似性を捉えるために設計された Sentence Transformer モデルです。ベースモデルである `CodeModernBERT-Crow` の強力なコード理解能力を継承し、コード検索や類似性判定タスクに最適化されています。
`CodeSearch-ModernBERT-Crow-Plus` is a Sentence Transformer model designed to capture the semantic similarity between natural language queries and code snippets (primarily at the function level) across multiple programming languages (Python, Java, JavaScript, PHP, Ruby, Go, Rust). It inherits the strong code understanding capabilities of its base model, `CodeModernBERT-Crow`, and is optimized for code search and similarity tasks.
## モデル詳細 / Model Details
* **ベースモデル / Base Model:** [Shuu12121/CodeModernBERT-Crow](https://huggingface.co/Shuu12121/CodeModernBERT-Crow)
* **アーキテクチャ / Architecture:** ModernBERT (hidden\_size: 768, layers: 12, heads: 12)
* **最大入力長 / Max Sequence Length:** 1024 トークン
* **ファインチューニング / Fine-tuning:** このモデルは、コードとその対応するドキュメント(例:CodeSearchNet データセット)を用いた類似性学習タスクでファインチューニングされていると考えられます。Sentence Transformer ライブラリで使用するために、Pooling 層が追加されています。
## 使用方法 / How to Use
`sentence-transformers` ライブラリを使って簡単に利用できます。
You can easily use this model with the `sentence-transformers` library.
```python
from sentence_transformers import SentenceTransformer
import torch
# モデルのロード / Load the model
model = SentenceTransformer("Shuu12121/CodeSearch-ModernBERT-Crow-Plus")
# エンコードしたいテキスト(コードまたは自然言語) / Texts to encode (code or natural language)
code_snippets = [
"def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)",
"function binarySearch(arr, target) { let left = 0, right = arr.length - 1; while (left <= right) { const mid = Math.floor((left + right) / 2); if (arr[mid] === target) return mid; if (arr[mid] < target) left = mid + 1; else right = mid - 1; } return -1; }"
]
natural_language_queries = [
"calculate the factorial of a number recursively",
"find an element in a sorted array using binary search"
]
# エンベディングの取得 / Get embeddings
code_embeddings = model.encode(code_snippets)
query_embeddings = model.encode(natural_language_queries)
print("Code Embeddings Shape:", code_embeddings.shape)
print("Query Embeddings Shape:", query_embeddings.shape)
# 類似度の計算(例:コサイン類似度) / Calculate similarity (e.g., cosine similarity)
# Requires a similarity function, e.g., from sentence_transformers.util or sklearn.metrics.pairwise
# from sentence_transformers.util import cos_sim
# similarities = cos_sim(query_embeddings, code_embeddings)
# print(similarities)
```
## 評価 / Evaluation
このモデルは [MTEB (Massive Text Embedding Benchmark)](https://huggingface.co/spaces/mteb/leaderboard) で評価されています。
This model has been evaluated on the MTEB (Massive Text Embedding Benchmark).
**タスク: CodeSearchNet Retrieval**
* **MTEB 標準評価 (main_score: nDCG@10): 0.89296**
* `ndcg_at_1`: 0.8135
* `ndcg_at_3`: 0.8781
* `ndcg_at_5`: 0.8868
* `ndcg_at_10`: 0.8930
* `ndcg_at_20`: 0.8947
* `ndcg_at_100`: 0.8971
* `ndcg_at_1000`: 0.8995
* `map_at_10`: 0.8705
* `recall_at_10`: 0.9610
* `mrr_at_10`: 0.8705
* **COIR版での評価 (main_score: nDCG@10): 0.79884**
* `ndcg_at_1`: 0.7152
* `ndcg_at_3`: 0.7762
* `ndcg_at_5`: 0.7885
* `ndcg_at_10`: 0.7988
* `ndcg_at_20`: 0.8056
* `ndcg_at_100`: 0.8134
* `ndcg_at_1000`: 0.8172
* `map_at_10`: 0.7729
* `recall_at_10`: 0.8794
* `mrr_at_10`: 0.7729
*注: 評価設定の違いにより、同じ CodeSearchNet Retrieval タスクでもスコアが異なります。*
*Note: Scores differ for the same CodeSearchNet Retrieval task due to different evaluation settings.*
参考として、ベースモデル `Shuu12121/CodeModernBERT-Crow` の CodeSearchNet Test Split における MRR@100 スコアは以下の通りです(固定評価スクリプト使用)。
For reference, the MRR@100 scores for the base model `Shuu12121/CodeModernBERT-Crow` on the CodeSearchNet Test Split (using a fixed evaluation script) are:
| 言語 / Language | Python | Java | JavaScript | PHP | Ruby | Go |
| :-------------- | :----- | :----- | :--------- | :----- | :----- | :----- |
| MRR@100 | 0.9372 | 0.8642 | 0.8118 | 0.8388 | 0.8392 | 0.8522 |
## 想定している用途と制限 / Intended Use & Limitations
* **想定している用途 / Intended Use:**
* 多言語コード検索 (Natural Language to Code, Code to Code)
* コードの類似性判定
* コード分類やクラスタリングのための特徴抽出
* コード推薦システム
* **対象言語 / Target Languages:** Python, Java, JavaScript, PHP, Ruby, Go, Rust
* **制限 / Limitations:**
* 主に関数レベルのコードスニペットに最適化されています。非常に長いコードファイル全体や、構文的に不完全なコードに対する性能は低下する可能性があります。
* 特定のドメインやライブラリに特化したタスクでは、追加のファインチューニングが有効な場合があります。
* 生成タスクには適していません(これはエンコーダモデルです)。
**Note:**
This model was evaluated on MTEB with commit hash `044a7a4b552f86e284817234c336bccf16f895ce`.
The current README may have been updated since that version, but the model weights remain unchanged.
## 連絡先 / Contact
質問や提案については、開発者 Shuu12121 までご連絡ください。
For questions or suggestions, please contact the developer Shuu12121.
📧 shun0212114@outlook.jp |