--- tags: - sentence-transformers - sentence-similarity - feature-extraction - code-search - modernbert - code - python - java - javascript - php - ruby - rust - go 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: # Example queries for the 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 ## 概要 / 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.8890** * `ndcg_at_1`: 0.8060 * `ndcg_at_3`: 0.8748 * `ndcg_at_5`: 0.8837 * `ndcg_at_10`: 0.8890 * `ndcg_at_100`: 0.8940 * `map_at_10`: 0.8659 * `recall_at_10`: 0.9585 * `mrr_at_10`: 0.8659 * **COIR (Contextual Object Identity Recognition) 設定での評価 (main_score: nDCG@10): 0.7985** * `ndcg_at_1`: 0.7124 * `ndcg_at_3`: 0.7752 * `ndcg_at_5`: 0.7874 * `ndcg_at_10`: 0.7985 * `ndcg_at_100`: 0.8126 * `map_at_10`: 0.7717 * `recall_at_10`: 0.8818 * `mrr_at_10`: 0.7717 *注: 評価設定の違いにより、同じ 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:** * 主に関数レベルのコードスニペットに最適化されています。非常に長いコードファイル全体や、構文的に不完全なコードに対する性能は低下する可能性があります。 * 特定のドメインやライブラリに特化したタスクでは、追加のファインチューニングが有効な場合があります。 * 生成タスクには適していません(これはエンコーダモデルです)。 ## 連絡先 / Contact 質問や提案については、開発者 Shuu12121 までご連絡ください。 For questions or suggestions, please contact the developer Shuu12121. 📧 shun0212114@outlook.jp