--- language: - code license: apache-2.0 task_categories: - feature-extraction - sentence-similarity tags: - code-search - hard-negatives - knowledge-distillation - contrastive-learning - sentence-transformers - colbert pretty_name: "Owl Code Search Hard Negative Datasets (Pre-KD)" size_categories: - 1M **スコアの解釈**: > - `scores[0]` / `document_ids[0]` が正例(実際のペアだったもの) > - `score[0] = -1` は正解が上位32件に検索結果が含まれていなかった場合 ## 言語別統計 | 言語 | クエリ数 | 文書数 | スコア数 | |------|-------:|-------:|-------:| | Go | 1,361,475 | 1,361,475 | 1,361,475 | | Java | 1,281,018 | 1,281,018 | 1,281,018 | | JavaScript | 129,007 | 129,007 | 129,007 | | PHP | 424,463 | 424,463 | 424,463 | | Python | 776,900 | 776,900 | 776,900 | | Ruby | 104,899 | 104,899 | 104,899 | | Rust | 381,521 | 381,521 | 381,521 | | TypeScript | 328,457 | 328,457 | 328,457 | | **合計** | **4,787,740** | **4,787,740** | **4,787,740** | ## 注意点 全データをメモリに載せようとするとOOMになる可能性があります!! ## 使い方 ### 基本的な読み込み ```python from datasets import load_dataset # Python の scores を読み込む scores = load_dataset( "Shuu12121/owl_code_search_hard_negative_datasets-Pre_kd", name="scores_python", split="train", ) # Python の queries を読み込む queries = load_dataset( "Shuu12121/owl_code_search_hard_negative_datasets-Pre_kd", name="queries_python", split="train", ) # Python の documents を読み込む documents = load_dataset( "Shuu12121/owl_code_search_hard_negative_datasets-Pre_kd", name="documents_python", split="train", ) ``` ### ハードネガティブの抽出 ```python # クエリ・文書テキストの辞書を構築 query_texts = dict(zip(queries["query_id"], queries["query"])) doc_texts = dict(zip(documents["document_id"], documents["document"])) # 閾値の設定 nv_threshold = 0.99 # positive スコアの 99% 未満をネガティブとする # 1 サンプルの処理例 sample = scores[0] query_text = query_texts[sample["query_id"]] positive_doc = doc_texts[sample["document_ids"][0]] # scores[0] が正例 positive_score = sample["scores"][0] hard_negatives = [] for doc_id, score in zip(sample["document_ids"][1:], sample["scores"][1:]): if score < nv_threshold * positive_score and score != -1: hard_negatives.append(doc_texts[doc_id]) print(f"Query: {query_text[:100]}...") print(f"Positive: {positive_doc[:100]}...") print(f"Hard negatives: {len(hard_negatives)}") ``` ## 作成に使用されたプログラム [リポジトリはこちら](https://github.com/Shun0212/hard-negatives-ranking-datasets-maker)