fzoll commited on
Commit
ce6d2a9
·
verified ·
1 Parent(s): 5311d3c

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - derived
4
+ language:
5
+ - ja
6
+ license: cc-by-sa-4.0
7
+ multilinguality: monolingual
8
+ task_categories:
9
+ - text-retrieval
10
+ task_ids:
11
+ - document-retrieval
12
+ tags:
13
+ - mteb
14
+ - text
15
+ - code
16
+ - japanese
17
+ - sample
18
+ ---
19
+
20
+ # JapaneseCode1Retrieval-sample
21
+
22
+ A sample dataset for Japanese-English code retrieval evaluation. This dataset contains Japanese natural language descriptions paired with Python code snippets.
23
+
24
+ ## Task category
25
+
26
+ Retrieval
27
+
28
+ ## Domains
29
+
30
+ Programming, Code Generation
31
+
32
+ ## Dataset Structure
33
+
34
+ The dataset follows the standard MTEB retrieval format:
35
+
36
+ - `corpus/corpus-00000-of-00001.parquet`: 5 Python code documents with fields `_id`, `title`, `text`
37
+ - `queries/queries-00000-of-00001.parquet`: 5 Japanese queries with fields `_id`, `text`
38
+ - `data/test-00000-of-00001.parquet`: 5 relevance judgments with fields `query-id`, `corpus-id`, `score`
39
+
40
+ ## Usage
41
+
42
+ You can evaluate an embedding model on this sample dataset using the following code:
43
+
44
+ ```python
45
+ import mteb
46
+
47
+ # Load the sample dataset
48
+ task = mteb.get_task("JapaneseCode1Retrieval-sample")
49
+ evaluator = mteb.MTEB(tasks=[task])
50
+
51
+ # Run evaluation with your model
52
+ model = mteb.get_model("your-model-name")
53
+ results = evaluator.run(model)
54
+ ```
55
+
56
+ ## Sample Content
57
+
58
+ This sample dataset contains:
59
+ - 5 Japanese natural language queries describing programming tasks
60
+ - 5 corresponding Python code snippets
61
+ - 5 relevance judgments connecting queries to code
62
+
63
+ The data has been slightly modified for demonstration purposes.
64
+
65
+ ## License
66
+
67
+ Please refer to the CC BY-SA 4.0 license terms.
corpus/corpus-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbc9a9bab4977312f8f2535159ebf1bccda79d7137626580addaa31a3eb87eb2
3
+ size 2442
create_sample_dataset.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import pandas as pd
4
+ import random
5
+ from pathlib import Path
6
+
7
+ def create_sample_dataset():
8
+ # Load original data
9
+ base_path = Path("/Users/fodizoltan/Projects/toptal/voyageai/tmp/rteb/data/JapaneseCode1Retrieval")
10
+
11
+ corpus_df = pd.read_parquet(base_path / "corpus" / "corpus-00000-of-00001.parquet")
12
+ queries_df = pd.read_parquet(base_path / "queries" / "queries-00000-of-00001.parquet")
13
+ qrels_df = pd.read_parquet(base_path / "data" / "test-00000-of-00001.parquet")
14
+
15
+ print(f"Loaded {len(corpus_df)} corpus docs, {len(queries_df)} queries, {len(qrels_df)} qrels")
16
+
17
+ # Get first 5 queries
18
+ first_5_queries = queries_df.head(5).copy()
19
+ print("First 5 queries:")
20
+ for _, row in first_5_queries.iterrows():
21
+ print(f" {row['_id']}: {row['text']}")
22
+
23
+ # Get related corpus documents from qrels
24
+ first_5_query_ids = first_5_queries['_id'].tolist()
25
+ related_qrels = qrels_df[qrels_df['query-id'].isin(first_5_query_ids)].copy()
26
+ related_corpus_ids = related_qrels['corpus-id'].unique()
27
+ related_corpus = corpus_df[corpus_df['_id'].isin(related_corpus_ids)].copy()
28
+
29
+ print(f"Found {len(related_corpus)} related corpus documents")
30
+ print(f"Found {len(related_qrels)} qrels")
31
+
32
+ # Tweak the data
33
+ tweaked_queries = tweak_queries(first_5_queries)
34
+ tweaked_corpus = tweak_corpus(related_corpus)
35
+
36
+ return tweaked_corpus, tweaked_queries, related_qrels
37
+
38
+ def tweak_queries(queries_df):
39
+ """Tweak Japanese queries by changing a few words/characters"""
40
+ tweaked = queries_df.copy()
41
+
42
+ # Simple tweaks for Japanese text
43
+ tweaks = {
44
+ 'リスト': 'リスト配列',
45
+ '要素': 'エレメント',
46
+ '整数': '数値',
47
+ '文字列': 'ストリング',
48
+ '変数': 'パラメータ',
49
+ 'する': 'を行う',
50
+ 'の': 'が持つ'
51
+ }
52
+
53
+ for idx, row in tweaked.iterrows():
54
+ text = row['text']
55
+ # Apply random tweaks
56
+ for old, new in tweaks.items():
57
+ if old in text and random.random() < 0.3: # 30% chance to apply each tweak
58
+ text = text.replace(old, new, 1) # Replace only first occurrence
59
+ tweaked.at[idx, 'text'] = text
60
+
61
+ return tweaked
62
+
63
+ def tweak_corpus(corpus_df):
64
+ """Tweak Python code by changing variable names and some function calls"""
65
+ tweaked = corpus_df.copy()
66
+
67
+ # Simple code tweaks
68
+ code_tweaks = {
69
+ 'x': 'data',
70
+ 'i': 'idx',
71
+ 'd': 'digit',
72
+ 'enumerate': 'enumerate_items',
73
+ 'sum': 'total',
74
+ 'len': 'length',
75
+ 'str': 'string',
76
+ 'int': 'integer',
77
+ 'list': 'array'
78
+ }
79
+
80
+ for idx, row in tweaked.iterrows():
81
+ text = row['text']
82
+ # Apply random tweaks
83
+ for old, new in code_tweaks.items():
84
+ if old in text and random.random() < 0.4: # 40% chance to apply each tweak
85
+ # Only replace whole words to avoid breaking code
86
+ import re
87
+ pattern = r'\b' + re.escape(old) + r'\b'
88
+ if re.search(pattern, text):
89
+ text = re.sub(pattern, new, text, count=1)
90
+ tweaked.at[idx, 'text'] = text
91
+
92
+ return tweaked
93
+
94
+ def save_sample_dataset(corpus_df, queries_df, qrels_df):
95
+ """Save sample dataset in MTEB format"""
96
+ sample_path = Path("/Users/fodizoltan/Projects/toptal/voyageai/tmp/rteb/data/JapaneseCode1Retrieval-sample")
97
+ sample_path.mkdir(exist_ok=True)
98
+
99
+ # Create subdirectories
100
+ (sample_path / "corpus").mkdir(exist_ok=True)
101
+ (sample_path / "queries").mkdir(exist_ok=True)
102
+ (sample_path / "data").mkdir(exist_ok=True)
103
+
104
+ # Save parquet files
105
+ corpus_df.to_parquet(sample_path / "corpus" / "corpus-00000-of-00001.parquet", index=False)
106
+ queries_df.to_parquet(sample_path / "queries" / "queries-00000-of-00001.parquet", index=False)
107
+ qrels_df.to_parquet(sample_path / "data" / "test-00000-of-00001.parquet", index=False)
108
+
109
+ print(f"Sample dataset saved to {sample_path}")
110
+ print(f" - Corpus: {len(corpus_df)} documents")
111
+ print(f" - Queries: {len(queries_df)} queries")
112
+ print(f" - Qrels: {len(qrels_df)} relevance judgments")
113
+
114
+ if __name__ == "__main__":
115
+ corpus, queries, qrels = create_sample_dataset()
116
+ save_sample_dataset(corpus, queries, qrels)
data/test-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5442e12e4ed25507ee3a90e03076eb79e67ae8287033e1bf798b8de3733f7871
3
+ size 2256
queries/queries-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25661ad4a4d012f953ba8fb1f013af86c8ac4252c25aa16e16770e22f970039d
3
+ size 2211