Sentence Similarity
sentence-transformers
Safetensors
English
modernbert
feature-extraction
dense
code
code-search
code-retrieval
text-embeddings-inference
Instructions to use Shuu12121/NightJar-large-CodeSearch-Embedding with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Shuu12121/NightJar-large-CodeSearch-Embedding with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Shuu12121/NightJar-large-CodeSearch-Embedding") sentences = [ "Extract json from string with support for '' and None.", "def json_loads(data: Any) -> dict[str, Any]:\n \"\"\"Extract json from string with support for '' and None.\"\"\"\n if not data:\n return {}\n try:\n return json_loads_util(data)\n except json.JSONDecodeError as err:\n raise APIError(\"Invalid json\") from err", "def str2json(v):\n \"\"\"\n convert str to json data\n :param v:\n :return:\n \"\"\"\n try:\n return json.loads(v)\n except:\n return None", "def extract_json_from_string(response_msg: str) -> str:\n \"\"\"\n Attempts to extract JSON (object or array) from within a larger string, not specific to markdown.\n \"\"\"\n json_pattern = re.compile(r\"\\{.*\\}|\\[.*\\]\")\n match = json_pattern.search(response_msg)\n if match:\n return match.group(0)\n\n return response_msg", "def parse_json(val: str):\n \"\"\"\n Parses json if string else return\n \"\"\"\n if isinstance(val, str):\n val = json.loads(val)\n if isinstance(val, dict):\n val = frappe._dict(val)\n return val" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [5, 5] - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -27,9 +27,9 @@ widget:
|
|
| 27 |
- "def parse_json(val: str):\n \"\"\"\n Parses json if string else return\n \"\"\"\n if isinstance(val, str):\n val = json.loads(val)\n if isinstance(val, dict):\n val = frappe._dict(val)\n return val"
|
| 28 |
---
|
| 29 |
|
| 30 |
-
#
|
| 31 |
|
| 32 |
-
**
|
| 33 |
|
| 34 |
Use it for **natural-language-to-code search**, **code-to-code retrieval** and **code-edit search**.
|
| 35 |
|
|
@@ -51,21 +51,21 @@ Scores were computed with MTEB 2.5.1. All models below were fine-tuned with the
|
|
| 51 |
|
| 52 |
| Model | Go | Java | JavaScript | PHP | Python | Ruby | Avg |
|
| 53 |
|---|---:|---:|---:|---:|---:|---:|---:|
|
| 54 |
-
| **
|
| 55 |
-
| [NightJar-CodeSearch](https://huggingface.co/Shuu12121/NightJar-CodeSearch) (smaller NightJar) | 0.9656 | 0.9278 | 0.8236 | 0.8915 | 0.9410 | 0.8663 | 0.9026 |
|
| 56 |
| NightOwl (same recipe) | 0.9674 | 0.9232 | 0.8157 | 0.8907 | 0.9393 | 0.8618 | 0.8997 |
|
| 57 |
|
| 58 |
**CodeEditSearchRetrieval**
|
| 59 |
|
| 60 |
| Model | C | C++ | Go | Java | JS | PHP | Python | Ruby | Rust | Scala | Shell | Swift | TS | Avg |
|
| 61 |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
| 62 |
-
| **
|
| 63 |
-
| [NightJar-CodeSearch](https://huggingface.co/Shuu12121/NightJar-CodeSearch) (smaller NightJar) | 0.6687 | 0.7105 | 0.7716 | 0.7365 | 0.7386 | 0.7162 | 0.7711 | 0.7723 | 0.6900 | 0.7859 | 0.7119 | 0.7470 | 0.7759 | 0.7382 |
|
| 64 |
| NightOwl (same recipe) | 0.6624 | 0.7170 | 0.7800 | 0.7509 | 0.7539 | 0.7339 | 0.7716 | 0.7814 | 0.7100 | 0.7795 | 0.7220 | 0.7453 | 0.7890 | 0.7459 |
|
| 65 |
|
| 66 |
-
|
| 67 |
|
| 68 |
-
"NightJar-CodeSearch" is the smaller [`Shuu12121/NightJar`](https://huggingface.co/Shuu12121/NightJar) fine-tuned with exactly this setup for the full epoch. "NightOwl (same recipe)" is [`Shuu12121/NightOwl`](https://huggingface.co/Shuu12121/NightOwl) fine-tuned with the same losses and hyperparameters (without the additional-languages dataset).
|
| 69 |
|
| 70 |
The fine-tuning data is the same decontaminated set used for NightOwl-CodeEmbedding: overlaps with the CodeSearchNet test splits, and between the commitpackft-derived code-edit data and the CodeEditSearchRetrieval evaluation examples, were removed before training. MTEB names the CodeEditSearchRetrieval evaluation split `train`, but those examples were not used for fine-tuning.
|
| 71 |
|
|
@@ -78,7 +78,7 @@ pip install -U sentence-transformers
|
|
| 78 |
```python
|
| 79 |
from sentence_transformers import SentenceTransformer
|
| 80 |
|
| 81 |
-
model = SentenceTransformer("Shuu12121/
|
| 82 |
|
| 83 |
sentences = [
|
| 84 |
# query
|
|
@@ -160,7 +160,7 @@ Approximate token lengths, from the first 1,000 samples: anchors average 75 toke
|
|
| 160 |
|
| 161 |
### Training-time evaluation
|
| 162 |
|
| 163 |
-
During training, the model was monitored with Sentence Transformers' `InformationRetrievalEvaluator` on CodeSearchNet (six languages). The values below are from the end of training.
|
| 164 |
|
| 165 |
| Metric | Go | Java | JavaScript | PHP | Python | Ruby | Avg |
|
| 166 |
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
@@ -196,8 +196,8 @@ The encoder is the ModernBERT-based NightJar-large: 28 layers, hidden size 1024,
|
|
| 196 |
|
| 197 |
## Limitations
|
| 198 |
|
| 199 |
-
- Retrieval quality was evaluated on CodeSearchNetRetrieval and CodeEditSearchRetrieval only.
|
| 200 |
-
-
|
| 201 |
- Inputs longer than 1,024 tokens are truncated.
|
| 202 |
- Retrieved code may contain bugs, outdated APIs or insecure patterns. Review it before use.
|
| 203 |
|
|
@@ -236,7 +236,7 @@ The model weights are released under **Apache 2.0**. The training datasets carry
|
|
| 236 |
|
| 237 |
### 概要
|
| 238 |
|
| 239 |
-
**
|
| 240 |
|
| 241 |
**自然言語からのコード検索**、**コードからコードの検索**、**コード編集の検索**に使えます。
|
| 242 |
|
|
@@ -256,23 +256,21 @@ MTEB 2.5.1で計算しました。比較対象のモデルも、すべて同じ
|
|
| 256 |
|
| 257 |
| モデル | CodeSearchNetRetrieval(平均) | CodeEditSearchRetrieval(平均) |
|
| 258 |
|---|---:|---:|
|
| 259 |
-
| **
|
| 260 |
-
| NightJar-CodeSearch
|
| 261 |
| NightOwl(同じ手順で追加学習) | 0.8997 | 0.7459 |
|
| 262 |
|
| 263 |
-
|
| 264 |
|
| 265 |
追加学習のデータは、NightOwl-CodeEmbeddingと同じ重複除去済みのデータセットです。学習前に、コード検索データとCodeSearchNetのテストデータの重複、commitpackft由来のコード編集データとCodeEditSearchRetrievalの評価データの重複を取り除いています。MTEBではCodeEditSearchRetrievalの評価データが`train`という名前になっていますが、この評価データは追加学習には使っていません。
|
| 266 |
|
| 267 |
### 使い方
|
| 268 |
|
| 269 |
-
英語版の「Usage」
|
| 270 |
|
| 271 |
-
- **入力形式:** 質問もコードも、プレフィックスなしの文字列をそのまま渡してください。追加学習のデータは、質問が普通の文章、文書がコードそのままの形式で、事前学習で使った`[NL]`や`[Code1]`のマーカーは含まれていません。
|
| 272 |
- **最大長:** 学習時の最大長は1,024トークンです。それより長い入力は切り捨てられます。
|
| 273 |
- **双方向:** 質問→コードと、コード→質問の両方向で学習しているので、コードに合う説明文を探��用途にも使えます。
|
| 274 |
|
| 275 |
-
英語版の例では、質問とコードの類似度が、正しい`getTtl`(readOneof(13))で0.861、別のフィールドを読む`getTtl`(readOneof(7))で0.817になっています。2つのコード同士はほぼ同じ形(類似度0.941)ですが、質問に対しては正しい方を上位に出せています。
|
| 276 |
|
| 277 |
### 学習
|
| 278 |
|
|
@@ -284,9 +282,8 @@ MTEB 2.5.1で計算しました。比較対象のモデルも、すべて同じ
|
|
| 284 |
- `owl_code_search_hard_negative_datasets_additional_languages_V2_kd`(同じく追加の8言語)
|
| 285 |
- `codeedit_hard_negative_datasets_kd`(コード編集の検索、11言語)
|
| 286 |
|
| 287 |
-
最初の1,000件で見た平均トークン数は、アンカーが約75、正例が約197、ネガティブが約188〜215です。どの列も最大は1,024トークンです。
|
| 288 |
|
| 289 |
-
**損失関数:** Cached MultipleNegativesRankingLoss(scale 100、mini batch size 64)
|
| 290 |
|
| 291 |
**ハイパーパラメータ:**
|
| 292 |
|
|
@@ -301,14 +298,13 @@ MTEB 2.5.1で計算しました。比較対象のモデルも、すべて同じ
|
|
| 301 |
| Gradient checkpointing | あり |
|
| 302 |
| シード | 42 |
|
| 303 |
|
| 304 |
-
**学習中の評価:** 学習中は、Sentence Transformersの`InformationRetrievalEvaluator`でCodeSearchNet
|
| 305 |
-
|
| 306 |
-
監視していたnDCG@10は、最初の数百ステップで急に上がり、約2,000ステップ(約0.5エポック)以降は、どの言語も最終値の±0.01以内で推移しました。性能の伸びの大部分は、エポックの前半で得られています。
|
| 307 |
|
|
|
|
| 308 |
### 制限事項
|
| 309 |
|
| 310 |
-
- 検索性能の評価は、CodeSearchNetRetrievalとCodeEditSearchRetrievalのみです。
|
| 311 |
-
- 追加学習データの量が言語ごとに違うため、性能にも差があります。追加学習データに含まれない言語
|
| 312 |
- 1,024トークンを超える入力は切り捨てられます。
|
| 313 |
- 検索で得られたコードには、バグ、古いAPI、安全でない実装が含まれる可能性があります。利用前に確認してください。
|
| 314 |
|
|
|
|
| 27 |
- "def parse_json(val: str):\n \"\"\"\n Parses json if string else return\n \"\"\"\n if isinstance(val, str):\n val = json.loads(val)\n if isinstance(val, dict):\n val = frappe._dict(val)\n return val"
|
| 28 |
---
|
| 29 |
|
| 30 |
+
# NightJar-large-CodeSearch-Embedding
|
| 31 |
|
| 32 |
+
**NightJar-large-CodeSearch-Embedding** is a code-retrieval embedding model fine-tuned from [`Shuu12121/NightJar-large`](https://huggingface.co/Shuu12121/NightJar-large) (a 346M-parameter ModernBERT encoder pre-trained from scratch on code) with [Sentence Transformers](https://www.SBERT.net). It maps text and code to a 1024-dimensional vector space, so natural-language queries, code snippets and code edits can be compared with cosine similarity.
|
| 33 |
|
| 34 |
Use it for **natural-language-to-code search**, **code-to-code retrieval** and **code-edit search**.
|
| 35 |
|
|
|
|
| 51 |
|
| 52 |
| Model | Go | Java | JavaScript | PHP | Python | Ruby | Avg |
|
| 53 |
|---|---:|---:|---:|---:|---:|---:|---:|
|
| 54 |
+
| **NightJar-large-CodeSearch-Embedding** | **0.9682** | **0.9324** | **0.8317** | **0.8989** | **0.9532** | **0.8850** | **0.9116** |
|
| 55 |
+
| [NightJar-CodeSearch-Embedding](https://huggingface.co/Shuu12121/NightJar-CodeSearch-Embedding) (smaller NightJar) | 0.9656 | 0.9278 | 0.8236 | 0.8915 | 0.9410 | 0.8663 | 0.9026 |
|
| 56 |
| NightOwl (same recipe) | 0.9674 | 0.9232 | 0.8157 | 0.8907 | 0.9393 | 0.8618 | 0.8997 |
|
| 57 |
|
| 58 |
**CodeEditSearchRetrieval**
|
| 59 |
|
| 60 |
| Model | C | C++ | Go | Java | JS | PHP | Python | Ruby | Rust | Scala | Shell | Swift | TS | Avg |
|
| 61 |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:|
|
| 62 |
+
| **NightJar-large-CodeSearch-Embedding** | **0.7220** | **0.7537** | **0.8062** | **0.7831** | **0.7846** | **0.7743** | **0.8048** | **0.8160** | **0.7396** | **0.8248** | **0.7571** | **0.7882** | **0.8145** | **0.7822** |
|
| 63 |
+
| [NightJar-CodeSearch-Embedding](https://huggingface.co/Shuu12121/NightJar-CodeSearch-Embedding) (smaller NightJar) | 0.6687 | 0.7105 | 0.7716 | 0.7365 | 0.7386 | 0.7162 | 0.7711 | 0.7723 | 0.6900 | 0.7859 | 0.7119 | 0.7470 | 0.7759 | 0.7382 |
|
| 64 |
| NightOwl (same recipe) | 0.6624 | 0.7170 | 0.7800 | 0.7509 | 0.7539 | 0.7339 | 0.7716 | 0.7814 | 0.7100 | 0.7795 | 0.7220 | 0.7453 | 0.7890 | 0.7459 |
|
| 65 |
|
| 66 |
+
NightJar-large-CodeSearch-Embedding scores highest on every language of both benchmarks.
|
| 67 |
|
| 68 |
+
"NightJar-CodeSearch-Embedding" is the smaller [`Shuu12121/NightJar`](https://huggingface.co/Shuu12121/NightJar) fine-tuned with exactly this setup for the full epoch. "NightOwl (same recipe)" is [`Shuu12121/NightOwl`](https://huggingface.co/Shuu12121/NightOwl) fine-tuned with the same losses and hyperparameters (without the additional-languages dataset).
|
| 69 |
|
| 70 |
The fine-tuning data is the same decontaminated set used for NightOwl-CodeEmbedding: overlaps with the CodeSearchNet test splits, and between the commitpackft-derived code-edit data and the CodeEditSearchRetrieval evaluation examples, were removed before training. MTEB names the CodeEditSearchRetrieval evaluation split `train`, but those examples were not used for fine-tuning.
|
| 71 |
|
|
|
|
| 78 |
```python
|
| 79 |
from sentence_transformers import SentenceTransformer
|
| 80 |
|
| 81 |
+
model = SentenceTransformer("Shuu12121/NightJar-large-CodeSearch-Embedding")
|
| 82 |
|
| 83 |
sentences = [
|
| 84 |
# query
|
|
|
|
| 160 |
|
| 161 |
### Training-time evaluation
|
| 162 |
|
| 163 |
+
During training, the model was monitored with Sentence Transformers' `InformationRetrievalEvaluator` on CodeSearchNet (six languages, validation split). The values below are from the end of training.
|
| 164 |
|
| 165 |
| Metric | Go | Java | JavaScript | PHP | Python | Ruby | Avg |
|
| 166 |
|---|---:|---:|---:|---:|---:|---:|---:|
|
|
|
|
| 196 |
|
| 197 |
## Limitations
|
| 198 |
|
| 199 |
+
- Retrieval quality was evaluated on CodeSearchNetRetrieval and CodeEditSearchRetrieval only.
|
| 200 |
+
- Performance varies by language with the amount and quality of the fine-tuning data. Languages not covered by the fine-tuning data are not well supported.
|
| 201 |
- Inputs longer than 1,024 tokens are truncated.
|
| 202 |
- Retrieved code may contain bugs, outdated APIs or insecure patterns. Review it before use.
|
| 203 |
|
|
|
|
| 236 |
|
| 237 |
### 概要
|
| 238 |
|
| 239 |
+
**NightJar-large-CodeSearch-Embedding**は、[`Shuu12121/NightJar-large`](https://huggingface.co/Shuu12121/NightJar-large)(コードでゼロから事前学習した、約3.46億パラメータのModernBERTエンコーダー)を、[Sentence Transformers](https://www.SBERT.net)でコード検索向けに追加学習した埋め込みモデルです。文章とコードを1024次元のベクトルに変換するので、自然言語の質問、コード断片、コードの変更内容を、コサイン類似度で比較できます。
|
| 240 |
|
| 241 |
**自然言語からのコード検索**、**コードからコードの検索**、**コード編集の検索**に使えます。
|
| 242 |
|
|
|
|
| 256 |
|
| 257 |
| モデル | CodeSearchNetRetrieval(平均) | CodeEditSearchRetrieval(平均) |
|
| 258 |
|---|---:|---:|
|
| 259 |
+
| **NightJar-large-CodeSearch-Embedding** | **0.9116** | **0.7822** |
|
| 260 |
+
| NightJar-CodeSearch-Embedding | 0.9026 | 0.7382 |
|
| 261 |
| NightOwl(同じ手順で追加学習) | 0.8997 | 0.7459 |
|
| 262 |
|
| 263 |
+
NightJar-large-CodeSearch-Embeddingは、CodeSearchNetRetrievalの6言語、CodeEditSearchRetrievalの13言語のすべてで、最も高いスコアでした。言語別のスコアは英語版の表を参照してください。
|
| 264 |
|
| 265 |
追加学習のデータは、NightOwl-CodeEmbeddingと同じ重複除去済みのデータセットです。学習前に、コード検索データとCodeSearchNetのテストデータの重複、commitpackft由来のコード編集データとCodeEditSearchRetrievalの評価データの重複を取り除いています。MTEBではCodeEditSearchRetrievalの評価データが`train`という名前になっていますが、この評価データは追加学習には使っていません。
|
| 266 |
|
| 267 |
### 使い方
|
| 268 |
|
| 269 |
+
英語版の「Usage」にサンプルコードがあります。
|
| 270 |
|
|
|
|
| 271 |
- **最大長:** 学習時の最大長は1,024トークンです。それより長い入力は切り捨てられます。
|
| 272 |
- **双方向:** 質問→コードと、コード→質問の両方向で学習しているので、コードに合う説明文を探��用途にも使えます。
|
| 273 |
|
|
|
|
| 274 |
|
| 275 |
### 学習
|
| 276 |
|
|
|
|
| 282 |
- `owl_code_search_hard_negative_datasets_additional_languages_V2_kd`(同じく追加の8言語)
|
| 283 |
- `codeedit_hard_negative_datasets_kd`(コード編集の検索、11言語)
|
| 284 |
|
|
|
|
| 285 |
|
| 286 |
+
**損失関数:** Cached MultipleNegativesRankingLoss(scale 100、mini batch size 64、batch_size 1024)質問→文書と文書→質問の双方向で学習しています。
|
| 287 |
|
| 288 |
**ハイパーパラメータ:**
|
| 289 |
|
|
|
|
| 298 |
| Gradient checkpointing | あり |
|
| 299 |
| シード | 42 |
|
| 300 |
|
| 301 |
+
**学習中の評価:** 学習中は、Sentence Transformersの`InformationRetrievalEvaluator`でCodeSearchNet(6言語、validation splitにおける性能)を監視しました。学習終了時のnDCG@10は、Go 0.9341、Java 0.8569、JavaScript 0.8420、PHP 0.7979、Python 0.9449、Ruby 0.9101で、平均は0.8810です(そのほかの指標は英語版の表を参照)。この数値はMTEBとは別の評価セットで計算したものなので、MTEBのスコアとは比較できません。
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
監視していたnDCG@10は、最初の数百ステップで急に上がり、約2,000ステップ(約0.5エポック)以降は、どの言語も最終値の±0.01以内で推移しました。
|
| 304 |
### 制限事項
|
| 305 |
|
| 306 |
+
- 検索性能の評価は、CodeSearchNetRetrievalとCodeEditSearchRetrievalのみです。
|
| 307 |
+
- 追加学習データの量や質などが言語ごとに違うため、性能にも差があります。追加学習データに含まれない言語では性能が下がる場合があります。
|
| 308 |
- 1,024トークンを超える入力は切り捨てられます。
|
| 309 |
- 検索で得られたコードには、バグ、古いAPI、安全でない実装が含まれる可能性があります。利用前に確認してください。
|
| 310 |
|