ldup 2.1.0__tar.gz → 2.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ldup
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Prefix-aware curation & near-dedup for NN code via MinHash/LSH and AST fingerprints.
5
- Author: Your Team
6
5
  Author-email: ABrain One and contributors <AI@ABrain.one>
7
6
  License: MIT License
8
7
 
@@ -29,36 +28,51 @@ License: MIT License
29
28
 
30
29
  Project-URL: Homepage, https://ABrain.one
31
30
  Project-URL: Repository, https://github.com/ABrain-One/nn-dup
31
+ Project-URL: Bug Tracker, https://github.com/ABrain-One/nn-dup/issues
32
+ Keywords: LLM,deduplication,MinHash,LSH,AST,neural networks,data curation,pretraining,fine-tuning
32
33
  Classifier: Programming Language :: Python :: 3
33
34
  Classifier: License :: OSI Approved :: MIT License
34
35
  Classifier: Operating System :: OS Independent
35
- Requires-Python: >=3.9
36
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
37
+ Classifier: Topic :: Software Development :: Code Generators
38
+ Requires-Python: >=3.10
36
39
  Description-Content-Type: text/markdown
37
40
  License-File: LICENSE
38
- Requires-Dist: nn-dup==2.1.0
39
- Dynamic: author
41
+ Requires-Dist: nn-dup==2.1.2
42
+ Provides-Extra: dev
43
+ Requires-Dist: black>=23.0; extra == "dev"
44
+ Requires-Dist: isort>=5.0; extra == "dev"
45
+ Requires-Dist: flake8>=6.0; extra == "dev"
40
46
  Dynamic: license-file
41
- Dynamic: requires-python
42
47
 
43
48
  # Neural Network Deduplication Pipeline (NN Dup)
44
49
  <sub><a href='https://pypi.python.org/pypi/nn-dup'><img src='https://img.shields.io/pypi/v/nn-dup.svg'/></a> <a href="https://pepy.tech/project/nn-dup"><img alt="GitHub release" src="https://static.pepy.tech/badge/nn-dup"></a><br/>
45
50
  short alias <a href='https://pypi.python.org/pypi/ldup'>ldup</a></sub>
46
51
 
47
- A sophisticated data curation and near-deduplication pipeline for neural network code from the LEMUR dataset. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities.
48
-
49
52
  The original version of the NN Dup project was created by <strong>Waleed Khalid</strong> at the Computer Vision Laboratory, University of Würzburg, Germany.
50
53
 
51
- ## Overview
54
+ ## 📖 Overview
55
+
56
+ A sophisticated data curation and near-deduplication pipeline for neural network code from the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a>. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities, followed by conversational chat data preparation for language model training. Outputs include train/dev/test JSON files ready for supervised fine-tuning.
57
+
58
+ This comprehensive pipeline processes neural network implementations from the LEMUR dataset through two main stages:
52
59
 
53
- This pipeline processes neural network implementations from the LEMUR dataset, performing:
60
+ ### Stage 1: Deduplication Pipeline
54
61
  - **Exact deduplication** with prefix-aware canonicalization
55
62
  - **Lexical near-deduplication** using MinHash and LSH
56
63
  - **Structural deduplication** using AST fingerprints
57
64
  - **Diversity top-up** for underrepresented model families
58
65
  - **Family-aware train/dev/test splits**
59
66
 
67
+ ### Stage 2: ChatPrep Pipeline
68
+ - **Conversational conversion** of deduplicated code into chat format
69
+ - **Template-based generation** of user-assistant interactions
70
+ - **Quality validation** following SFT standards
71
+ - **JSONL export** for language model training
72
+
60
73
  ## Features
61
74
 
75
+ ### Deduplication Pipeline
62
76
  - **Multi-level Deduplication**: Exact, lexical (MinHash+LSH), and structural (AST) deduplication
63
77
  - **Prefix-aware Processing**: Maintains representation across different model families
64
78
  - **Family-aware Splits**: Ensures proper train/dev/test separation by model families
@@ -66,6 +80,14 @@ This pipeline processes neural network implementations from the LEMUR dataset, p
66
80
  - **Comprehensive Reporting**: Detailed statistics and curation reports
67
81
  - **Code Export**: Exports deduplicated code files for further use
68
82
 
83
+ ### ChatPrep Pipeline
84
+ - **Conversational Format**: Converts code into chat-style interactions for LLM training
85
+ - **Template-based Generation**: Uses customizable templates for consistent formatting
86
+ - **Infill Support**: Generates partial code examples for completion tasks
87
+ - **Validation & Filtering**: Ensures high-quality, parseable examples following SFT standards
88
+ - **Family-aware Splitting**: Prevents data leakage across model families
89
+ - **JSONL Export**: Generates training-ready chat data in standard format
90
+
69
91
  ## Installation
70
92
 
71
93
  ### Prerequisites
@@ -107,7 +129,7 @@ pip install git+https://github.com/ABrain-One/nn-dup.git
107
129
  Run the deduplication pipeline with default settings:
108
130
 
109
131
  ```bash
110
- python -m ab.dup.preprocessing --out ./curation_output
132
+ python -m ab.dup.main --out ./curation_output
111
133
  ```
112
134
 
113
135
  ### Advanced Usage
@@ -115,7 +137,7 @@ python -m ab.dup.preprocessing --out ./curation_output
115
137
  Filter for specific model families and configure deduplication:
116
138
 
117
139
  ```bash
118
- python -m ab.dup.preprocessing \
140
+ python -m ab.dup.main \
119
141
  --out ./curation_output \
120
142
  --include FractalNet \
121
143
  --include ResNet \
@@ -141,6 +163,93 @@ python -m ab.dup.preprocessing \
141
163
  - `--upweight`: Sampling weight rules (PREFIX:FACTOR)
142
164
  - `--verbose`: Enable verbose logging
143
165
 
166
+ ## ChatPrep: Converting Code to Chat Data
167
+
168
+ The ChatPrep module converts deduplicated neural network code into structured chat data suitable for training language models. It generates conversational examples with system prompts, user requests, and model responses.
169
+
170
+ ### ChatPrep Usage
171
+
172
+ #### Python API
173
+
174
+ ```python
175
+ from ab.chatprep import ChatPrepConfig
176
+
177
+ # Basic usage with defaults
178
+ config = ChatPrepConfig()
179
+ result = config.run()
180
+
181
+ # Custom configuration
182
+ config = ChatPrepConfig(
183
+ accepted_dir="../curation_output/accepted_code",
184
+ out_dir="../curation_output/chat_data",
185
+ seed=123,
186
+ fix_fences=True,
187
+ drop_unparseable=True,
188
+ group_by_source=True
189
+ )
190
+ result = config.run()
191
+ ```
192
+
193
+ #### Command Line Interface
194
+
195
+ ```bash
196
+ python -m ab.chatprep.cli.main \
197
+ --accepted-dir ../curation_output/accepted_code \
198
+ --out ../curation_output/chat_data \
199
+ --seed 123 \
200
+ --fix-fences \
201
+ --drop-unparseable \
202
+ --group-by-source
203
+ ```
204
+
205
+ ### ChatPrep Configuration Parameters
206
+
207
+ - `accepted_dir`: Directory with accepted code files (default: `"curation_output/accepted_code"`)
208
+ - `out_dir`: Output directory for chat data (default: `"curation_output/chat_data"`)
209
+ - `no_infill`: Disable infill generation (default: `False`)
210
+ - `seed`: Random seed for reproducibility (default: `42`)
211
+ - `fix_fences`: Fix code fences in generated examples (default: `True`)
212
+ - `drop_unparseable`: Drop unparseable examples (default: `True`)
213
+ - `require_module_subclass`: Require module subclass structure (default: `True`)
214
+ - `write_drop_report`: Write report of dropped examples (default: `True`)
215
+ - `group_by_source`: Group by source for splitting (default: `True`)
216
+ - `split_ratios`: Train/dev/test ratios (default: `(0.8, 0.1, 0.1)`)
217
+ - `model_name`: Optional model name for rendering (default: `None`)
218
+ - `train_name`: Training file name (default: `"train.jsonl"`)
219
+ - `dev_name`: Dev file name (default: `"dev.jsonl"`)
220
+ - `test_name`: Test file name (default: `"test.jsonl"`)
221
+
222
+ ### ChatPrep Output Files
223
+
224
+ The ChatPrep pipeline generates:
225
+
226
+ - **`train.jsonl`**: Training examples in JSONL format
227
+ - **`dev.jsonl`**: Development/validation examples
228
+ - **`test.jsonl`**: Test examples
229
+ - **`manifest.json`**: Metadata about the generated dataset
230
+ - **`drop_report.json`**: Report of examples that were filtered out
231
+
232
+ ### Example Chat Data Format
233
+
234
+ ```json
235
+ {
236
+ "messages": [
237
+ {
238
+ "role": "system",
239
+ "content": "You are a helpful AI assistant that generates PyTorch code for computer vision tasks."
240
+ },
241
+ {
242
+ "role": "user",
243
+ "content": "Task: Design a PyTorch CV model for image classification.\nDataset: CIFAR-10 (32x32x3).\nParameters: ≤1M.\nTricks: batch normalization, dropout, data augmentation."
244
+ },
245
+ {
246
+ "role": "assistant",
247
+ "content": "```python\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass CIFAR10Model(nn.Module):\n def __init__(self):\n super().__init__()\n self.conv1 = nn.Conv2d(3, 32, 3, padding=1)\n self.bn1 = nn.BatchNorm2d(32)\n self.conv2 = nn.Conv2d(32, 64, 3, padding=1)\n self.bn2 = nn.BatchNorm2d(64)\n self.dropout = nn.Dropout(0.25)\n self.fc = nn.Linear(64 * 8 * 8, 10)\n \n def forward(self, x):\n x = F.relu(self.bn1(self.conv1(x)))\n x = F.max_pool2d(x, 2)\n x = F.relu(self.bn2(self.conv2(x)))\n x = F.max_pool2d(x, 2)\n x = self.dropout(x)\n x = x.view(x.size(0), -1)\n x = self.fc(x)\n return x\n```"
248
+ }
249
+ ]
250
+ }
251
+ ```
252
+
144
253
  ## Configuration
145
254
 
146
255
  Key parameters in `ab/dup/consts/settings.py`:
@@ -187,7 +296,7 @@ The pipeline generates several output files:
187
296
  ### Running Tests
188
297
 
189
298
  ```bash
190
- python -m ab.dup.preprocessing --help
299
+ python -m ab.dup.main --help
191
300
  ```
192
301
 
193
302
  ### Code Quality
@@ -228,12 +337,12 @@ If you use this pipeline in your research, please cite:
228
337
  title={Neural Network Deduplication Pipeline},
229
338
  author={Waleed Khalid},
230
339
  year={2025},
231
- url={https://github.com/your-org/nn-dup}
340
+ url={https://github.com/ABrain-One/nn-dup}
232
341
  }
233
342
  ```
234
343
 
235
344
  ## Acknowledgments
236
345
 
237
- - Built for the LEMUR dataset and NNGPT projects
346
+ - Built for the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a> and <a href='https://github.com/ABrain-One/nn-gpt'>NNGPT</a> projects
238
347
  - Developed at the Computer Vision Laboratory, University of Würzburg
239
348
  - Part of the ABrain One research initiative
@@ -2,21 +2,30 @@
2
2
  <sub><a href='https://pypi.python.org/pypi/nn-dup'><img src='https://img.shields.io/pypi/v/nn-dup.svg'/></a> <a href="https://pepy.tech/project/nn-dup"><img alt="GitHub release" src="https://static.pepy.tech/badge/nn-dup"></a><br/>
3
3
  short alias <a href='https://pypi.python.org/pypi/ldup'>ldup</a></sub>
4
4
 
5
- A sophisticated data curation and near-deduplication pipeline for neural network code from the LEMUR dataset. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities.
6
-
7
5
  The original version of the NN Dup project was created by <strong>Waleed Khalid</strong> at the Computer Vision Laboratory, University of Würzburg, Germany.
8
6
 
9
- ## Overview
7
+ ## 📖 Overview
8
+
9
+ A sophisticated data curation and near-deduplication pipeline for neural network code from the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a>. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities, followed by conversational chat data preparation for language model training. Outputs include train/dev/test JSON files ready for supervised fine-tuning.
10
+
11
+ This comprehensive pipeline processes neural network implementations from the LEMUR dataset through two main stages:
10
12
 
11
- This pipeline processes neural network implementations from the LEMUR dataset, performing:
13
+ ### Stage 1: Deduplication Pipeline
12
14
  - **Exact deduplication** with prefix-aware canonicalization
13
15
  - **Lexical near-deduplication** using MinHash and LSH
14
16
  - **Structural deduplication** using AST fingerprints
15
17
  - **Diversity top-up** for underrepresented model families
16
18
  - **Family-aware train/dev/test splits**
17
19
 
20
+ ### Stage 2: ChatPrep Pipeline
21
+ - **Conversational conversion** of deduplicated code into chat format
22
+ - **Template-based generation** of user-assistant interactions
23
+ - **Quality validation** following SFT standards
24
+ - **JSONL export** for language model training
25
+
18
26
  ## Features
19
27
 
28
+ ### Deduplication Pipeline
20
29
  - **Multi-level Deduplication**: Exact, lexical (MinHash+LSH), and structural (AST) deduplication
21
30
  - **Prefix-aware Processing**: Maintains representation across different model families
22
31
  - **Family-aware Splits**: Ensures proper train/dev/test separation by model families
@@ -24,6 +33,14 @@ This pipeline processes neural network implementations from the LEMUR dataset, p
24
33
  - **Comprehensive Reporting**: Detailed statistics and curation reports
25
34
  - **Code Export**: Exports deduplicated code files for further use
26
35
 
36
+ ### ChatPrep Pipeline
37
+ - **Conversational Format**: Converts code into chat-style interactions for LLM training
38
+ - **Template-based Generation**: Uses customizable templates for consistent formatting
39
+ - **Infill Support**: Generates partial code examples for completion tasks
40
+ - **Validation & Filtering**: Ensures high-quality, parseable examples following SFT standards
41
+ - **Family-aware Splitting**: Prevents data leakage across model families
42
+ - **JSONL Export**: Generates training-ready chat data in standard format
43
+
27
44
  ## Installation
28
45
 
29
46
  ### Prerequisites
@@ -65,7 +82,7 @@ pip install git+https://github.com/ABrain-One/nn-dup.git
65
82
  Run the deduplication pipeline with default settings:
66
83
 
67
84
  ```bash
68
- python -m ab.dup.preprocessing --out ./curation_output
85
+ python -m ab.dup.main --out ./curation_output
69
86
  ```
70
87
 
71
88
  ### Advanced Usage
@@ -73,7 +90,7 @@ python -m ab.dup.preprocessing --out ./curation_output
73
90
  Filter for specific model families and configure deduplication:
74
91
 
75
92
  ```bash
76
- python -m ab.dup.preprocessing \
93
+ python -m ab.dup.main \
77
94
  --out ./curation_output \
78
95
  --include FractalNet \
79
96
  --include ResNet \
@@ -99,6 +116,93 @@ python -m ab.dup.preprocessing \
99
116
  - `--upweight`: Sampling weight rules (PREFIX:FACTOR)
100
117
  - `--verbose`: Enable verbose logging
101
118
 
119
+ ## ChatPrep: Converting Code to Chat Data
120
+
121
+ The ChatPrep module converts deduplicated neural network code into structured chat data suitable for training language models. It generates conversational examples with system prompts, user requests, and model responses.
122
+
123
+ ### ChatPrep Usage
124
+
125
+ #### Python API
126
+
127
+ ```python
128
+ from ab.chatprep import ChatPrepConfig
129
+
130
+ # Basic usage with defaults
131
+ config = ChatPrepConfig()
132
+ result = config.run()
133
+
134
+ # Custom configuration
135
+ config = ChatPrepConfig(
136
+ accepted_dir="../curation_output/accepted_code",
137
+ out_dir="../curation_output/chat_data",
138
+ seed=123,
139
+ fix_fences=True,
140
+ drop_unparseable=True,
141
+ group_by_source=True
142
+ )
143
+ result = config.run()
144
+ ```
145
+
146
+ #### Command Line Interface
147
+
148
+ ```bash
149
+ python -m ab.chatprep.cli.main \
150
+ --accepted-dir ../curation_output/accepted_code \
151
+ --out ../curation_output/chat_data \
152
+ --seed 123 \
153
+ --fix-fences \
154
+ --drop-unparseable \
155
+ --group-by-source
156
+ ```
157
+
158
+ ### ChatPrep Configuration Parameters
159
+
160
+ - `accepted_dir`: Directory with accepted code files (default: `"curation_output/accepted_code"`)
161
+ - `out_dir`: Output directory for chat data (default: `"curation_output/chat_data"`)
162
+ - `no_infill`: Disable infill generation (default: `False`)
163
+ - `seed`: Random seed for reproducibility (default: `42`)
164
+ - `fix_fences`: Fix code fences in generated examples (default: `True`)
165
+ - `drop_unparseable`: Drop unparseable examples (default: `True`)
166
+ - `require_module_subclass`: Require module subclass structure (default: `True`)
167
+ - `write_drop_report`: Write report of dropped examples (default: `True`)
168
+ - `group_by_source`: Group by source for splitting (default: `True`)
169
+ - `split_ratios`: Train/dev/test ratios (default: `(0.8, 0.1, 0.1)`)
170
+ - `model_name`: Optional model name for rendering (default: `None`)
171
+ - `train_name`: Training file name (default: `"train.jsonl"`)
172
+ - `dev_name`: Dev file name (default: `"dev.jsonl"`)
173
+ - `test_name`: Test file name (default: `"test.jsonl"`)
174
+
175
+ ### ChatPrep Output Files
176
+
177
+ The ChatPrep pipeline generates:
178
+
179
+ - **`train.jsonl`**: Training examples in JSONL format
180
+ - **`dev.jsonl`**: Development/validation examples
181
+ - **`test.jsonl`**: Test examples
182
+ - **`manifest.json`**: Metadata about the generated dataset
183
+ - **`drop_report.json`**: Report of examples that were filtered out
184
+
185
+ ### Example Chat Data Format
186
+
187
+ ```json
188
+ {
189
+ "messages": [
190
+ {
191
+ "role": "system",
192
+ "content": "You are a helpful AI assistant that generates PyTorch code for computer vision tasks."
193
+ },
194
+ {
195
+ "role": "user",
196
+ "content": "Task: Design a PyTorch CV model for image classification.\nDataset: CIFAR-10 (32x32x3).\nParameters: ≤1M.\nTricks: batch normalization, dropout, data augmentation."
197
+ },
198
+ {
199
+ "role": "assistant",
200
+ "content": "```python\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass CIFAR10Model(nn.Module):\n def __init__(self):\n super().__init__()\n self.conv1 = nn.Conv2d(3, 32, 3, padding=1)\n self.bn1 = nn.BatchNorm2d(32)\n self.conv2 = nn.Conv2d(32, 64, 3, padding=1)\n self.bn2 = nn.BatchNorm2d(64)\n self.dropout = nn.Dropout(0.25)\n self.fc = nn.Linear(64 * 8 * 8, 10)\n \n def forward(self, x):\n x = F.relu(self.bn1(self.conv1(x)))\n x = F.max_pool2d(x, 2)\n x = F.relu(self.bn2(self.conv2(x)))\n x = F.max_pool2d(x, 2)\n x = self.dropout(x)\n x = x.view(x.size(0), -1)\n x = self.fc(x)\n return x\n```"
201
+ }
202
+ ]
203
+ }
204
+ ```
205
+
102
206
  ## Configuration
103
207
 
104
208
  Key parameters in `ab/dup/consts/settings.py`:
@@ -145,7 +249,7 @@ The pipeline generates several output files:
145
249
  ### Running Tests
146
250
 
147
251
  ```bash
148
- python -m ab.dup.preprocessing --help
252
+ python -m ab.dup.main --help
149
253
  ```
150
254
 
151
255
  ### Code Quality
@@ -186,12 +290,12 @@ If you use this pipeline in your research, please cite:
186
290
  title={Neural Network Deduplication Pipeline},
187
291
  author={Waleed Khalid},
188
292
  year={2025},
189
- url={https://github.com/your-org/nn-dup}
293
+ url={https://github.com/ABrain-One/nn-dup}
190
294
  }
191
295
  ```
192
296
 
193
297
  ## Acknowledgments
194
298
 
195
- - Built for the LEMUR dataset and NNGPT projects
299
+ - Built for the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a> and <a href='https://github.com/ABrain-One/nn-gpt'>NNGPT</a> projects
196
300
  - Developed at the Computer Vision Laboratory, University of Würzburg
197
301
  - Part of the ABrain One research initiative
@@ -1,8 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ldup
3
- Version: 2.1.0
3
+ Version: 2.1.2
4
4
  Summary: Prefix-aware curation & near-dedup for NN code via MinHash/LSH and AST fingerprints.
5
- Author: Your Team
6
5
  Author-email: ABrain One and contributors <AI@ABrain.one>
7
6
  License: MIT License
8
7
 
@@ -29,36 +28,51 @@ License: MIT License
29
28
 
30
29
  Project-URL: Homepage, https://ABrain.one
31
30
  Project-URL: Repository, https://github.com/ABrain-One/nn-dup
31
+ Project-URL: Bug Tracker, https://github.com/ABrain-One/nn-dup/issues
32
+ Keywords: LLM,deduplication,MinHash,LSH,AST,neural networks,data curation,pretraining,fine-tuning
32
33
  Classifier: Programming Language :: Python :: 3
33
34
  Classifier: License :: OSI Approved :: MIT License
34
35
  Classifier: Operating System :: OS Independent
35
- Requires-Python: >=3.9
36
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
37
+ Classifier: Topic :: Software Development :: Code Generators
38
+ Requires-Python: >=3.10
36
39
  Description-Content-Type: text/markdown
37
40
  License-File: LICENSE
38
- Requires-Dist: nn-dup==2.1.0
39
- Dynamic: author
41
+ Requires-Dist: nn-dup==2.1.2
42
+ Provides-Extra: dev
43
+ Requires-Dist: black>=23.0; extra == "dev"
44
+ Requires-Dist: isort>=5.0; extra == "dev"
45
+ Requires-Dist: flake8>=6.0; extra == "dev"
40
46
  Dynamic: license-file
41
- Dynamic: requires-python
42
47
 
43
48
  # Neural Network Deduplication Pipeline (NN Dup)
44
49
  <sub><a href='https://pypi.python.org/pypi/nn-dup'><img src='https://img.shields.io/pypi/v/nn-dup.svg'/></a> <a href="https://pepy.tech/project/nn-dup"><img alt="GitHub release" src="https://static.pepy.tech/badge/nn-dup"></a><br/>
45
50
  short alias <a href='https://pypi.python.org/pypi/ldup'>ldup</a></sub>
46
51
 
47
- A sophisticated data curation and near-deduplication pipeline for neural network code from the LEMUR dataset. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities.
48
-
49
52
  The original version of the NN Dup project was created by <strong>Waleed Khalid</strong> at the Computer Vision Laboratory, University of Würzburg, Germany.
50
53
 
51
- ## Overview
54
+ ## 📖 Overview
55
+
56
+ A sophisticated data curation and near-deduplication pipeline for neural network code from the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a>. This project implements prefix-aware exact/near/AST deduplication with diversity top-up capabilities, followed by conversational chat data preparation for language model training. Outputs include train/dev/test JSON files ready for supervised fine-tuning.
57
+
58
+ This comprehensive pipeline processes neural network implementations from the LEMUR dataset through two main stages:
52
59
 
53
- This pipeline processes neural network implementations from the LEMUR dataset, performing:
60
+ ### Stage 1: Deduplication Pipeline
54
61
  - **Exact deduplication** with prefix-aware canonicalization
55
62
  - **Lexical near-deduplication** using MinHash and LSH
56
63
  - **Structural deduplication** using AST fingerprints
57
64
  - **Diversity top-up** for underrepresented model families
58
65
  - **Family-aware train/dev/test splits**
59
66
 
67
+ ### Stage 2: ChatPrep Pipeline
68
+ - **Conversational conversion** of deduplicated code into chat format
69
+ - **Template-based generation** of user-assistant interactions
70
+ - **Quality validation** following SFT standards
71
+ - **JSONL export** for language model training
72
+
60
73
  ## Features
61
74
 
75
+ ### Deduplication Pipeline
62
76
  - **Multi-level Deduplication**: Exact, lexical (MinHash+LSH), and structural (AST) deduplication
63
77
  - **Prefix-aware Processing**: Maintains representation across different model families
64
78
  - **Family-aware Splits**: Ensures proper train/dev/test separation by model families
@@ -66,6 +80,14 @@ This pipeline processes neural network implementations from the LEMUR dataset, p
66
80
  - **Comprehensive Reporting**: Detailed statistics and curation reports
67
81
  - **Code Export**: Exports deduplicated code files for further use
68
82
 
83
+ ### ChatPrep Pipeline
84
+ - **Conversational Format**: Converts code into chat-style interactions for LLM training
85
+ - **Template-based Generation**: Uses customizable templates for consistent formatting
86
+ - **Infill Support**: Generates partial code examples for completion tasks
87
+ - **Validation & Filtering**: Ensures high-quality, parseable examples following SFT standards
88
+ - **Family-aware Splitting**: Prevents data leakage across model families
89
+ - **JSONL Export**: Generates training-ready chat data in standard format
90
+
69
91
  ## Installation
70
92
 
71
93
  ### Prerequisites
@@ -107,7 +129,7 @@ pip install git+https://github.com/ABrain-One/nn-dup.git
107
129
  Run the deduplication pipeline with default settings:
108
130
 
109
131
  ```bash
110
- python -m ab.dup.preprocessing --out ./curation_output
132
+ python -m ab.dup.main --out ./curation_output
111
133
  ```
112
134
 
113
135
  ### Advanced Usage
@@ -115,7 +137,7 @@ python -m ab.dup.preprocessing --out ./curation_output
115
137
  Filter for specific model families and configure deduplication:
116
138
 
117
139
  ```bash
118
- python -m ab.dup.preprocessing \
140
+ python -m ab.dup.main \
119
141
  --out ./curation_output \
120
142
  --include FractalNet \
121
143
  --include ResNet \
@@ -141,6 +163,93 @@ python -m ab.dup.preprocessing \
141
163
  - `--upweight`: Sampling weight rules (PREFIX:FACTOR)
142
164
  - `--verbose`: Enable verbose logging
143
165
 
166
+ ## ChatPrep: Converting Code to Chat Data
167
+
168
+ The ChatPrep module converts deduplicated neural network code into structured chat data suitable for training language models. It generates conversational examples with system prompts, user requests, and model responses.
169
+
170
+ ### ChatPrep Usage
171
+
172
+ #### Python API
173
+
174
+ ```python
175
+ from ab.chatprep import ChatPrepConfig
176
+
177
+ # Basic usage with defaults
178
+ config = ChatPrepConfig()
179
+ result = config.run()
180
+
181
+ # Custom configuration
182
+ config = ChatPrepConfig(
183
+ accepted_dir="../curation_output/accepted_code",
184
+ out_dir="../curation_output/chat_data",
185
+ seed=123,
186
+ fix_fences=True,
187
+ drop_unparseable=True,
188
+ group_by_source=True
189
+ )
190
+ result = config.run()
191
+ ```
192
+
193
+ #### Command Line Interface
194
+
195
+ ```bash
196
+ python -m ab.chatprep.cli.main \
197
+ --accepted-dir ../curation_output/accepted_code \
198
+ --out ../curation_output/chat_data \
199
+ --seed 123 \
200
+ --fix-fences \
201
+ --drop-unparseable \
202
+ --group-by-source
203
+ ```
204
+
205
+ ### ChatPrep Configuration Parameters
206
+
207
+ - `accepted_dir`: Directory with accepted code files (default: `"curation_output/accepted_code"`)
208
+ - `out_dir`: Output directory for chat data (default: `"curation_output/chat_data"`)
209
+ - `no_infill`: Disable infill generation (default: `False`)
210
+ - `seed`: Random seed for reproducibility (default: `42`)
211
+ - `fix_fences`: Fix code fences in generated examples (default: `True`)
212
+ - `drop_unparseable`: Drop unparseable examples (default: `True`)
213
+ - `require_module_subclass`: Require module subclass structure (default: `True`)
214
+ - `write_drop_report`: Write report of dropped examples (default: `True`)
215
+ - `group_by_source`: Group by source for splitting (default: `True`)
216
+ - `split_ratios`: Train/dev/test ratios (default: `(0.8, 0.1, 0.1)`)
217
+ - `model_name`: Optional model name for rendering (default: `None`)
218
+ - `train_name`: Training file name (default: `"train.jsonl"`)
219
+ - `dev_name`: Dev file name (default: `"dev.jsonl"`)
220
+ - `test_name`: Test file name (default: `"test.jsonl"`)
221
+
222
+ ### ChatPrep Output Files
223
+
224
+ The ChatPrep pipeline generates:
225
+
226
+ - **`train.jsonl`**: Training examples in JSONL format
227
+ - **`dev.jsonl`**: Development/validation examples
228
+ - **`test.jsonl`**: Test examples
229
+ - **`manifest.json`**: Metadata about the generated dataset
230
+ - **`drop_report.json`**: Report of examples that were filtered out
231
+
232
+ ### Example Chat Data Format
233
+
234
+ ```json
235
+ {
236
+ "messages": [
237
+ {
238
+ "role": "system",
239
+ "content": "You are a helpful AI assistant that generates PyTorch code for computer vision tasks."
240
+ },
241
+ {
242
+ "role": "user",
243
+ "content": "Task: Design a PyTorch CV model for image classification.\nDataset: CIFAR-10 (32x32x3).\nParameters: ≤1M.\nTricks: batch normalization, dropout, data augmentation."
244
+ },
245
+ {
246
+ "role": "assistant",
247
+ "content": "```python\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\nclass CIFAR10Model(nn.Module):\n def __init__(self):\n super().__init__()\n self.conv1 = nn.Conv2d(3, 32, 3, padding=1)\n self.bn1 = nn.BatchNorm2d(32)\n self.conv2 = nn.Conv2d(32, 64, 3, padding=1)\n self.bn2 = nn.BatchNorm2d(64)\n self.dropout = nn.Dropout(0.25)\n self.fc = nn.Linear(64 * 8 * 8, 10)\n \n def forward(self, x):\n x = F.relu(self.bn1(self.conv1(x)))\n x = F.max_pool2d(x, 2)\n x = F.relu(self.bn2(self.conv2(x)))\n x = F.max_pool2d(x, 2)\n x = self.dropout(x)\n x = x.view(x.size(0), -1)\n x = self.fc(x)\n return x\n```"
248
+ }
249
+ ]
250
+ }
251
+ ```
252
+
144
253
  ## Configuration
145
254
 
146
255
  Key parameters in `ab/dup/consts/settings.py`:
@@ -187,7 +296,7 @@ The pipeline generates several output files:
187
296
  ### Running Tests
188
297
 
189
298
  ```bash
190
- python -m ab.dup.preprocessing --help
299
+ python -m ab.dup.main --help
191
300
  ```
192
301
 
193
302
  ### Code Quality
@@ -228,12 +337,12 @@ If you use this pipeline in your research, please cite:
228
337
  title={Neural Network Deduplication Pipeline},
229
338
  author={Waleed Khalid},
230
339
  year={2025},
231
- url={https://github.com/your-org/nn-dup}
340
+ url={https://github.com/ABrain-One/nn-dup}
232
341
  }
233
342
  ```
234
343
 
235
344
  ## Acknowledgments
236
345
 
237
- - Built for the LEMUR dataset and NNGPT projects
346
+ - Built for the <a href='https://github.com/ABrain-One/nn-dataset'>LEMUR dataset</a> and <a href='https://github.com/ABrain-One/nn-gpt'>NNGPT</a> projects
238
347
  - Developed at the Computer Vision Laboratory, University of Würzburg
239
348
  - Part of the ABrain One research initiative
@@ -2,10 +2,10 @@ LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
4
  requirements.txt
5
- setup.py
6
5
  version
7
6
  ldup.egg-info/PKG-INFO
8
7
  ldup.egg-info/SOURCES.txt
9
8
  ldup.egg-info/dependency_links.txt
9
+ ldup.egg-info/entry_points.txt
10
10
  ldup.egg-info/requires.txt
11
11
  ldup.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lemur-preprocess = ab.dup.preprocessing:main
@@ -0,0 +1,6 @@
1
+ nn-dup==2.1.2
2
+
3
+ [dev]
4
+ black>=23.0
5
+ isort>=5.0
6
+ flake8>=6.0
@@ -7,18 +7,24 @@ name = 'ldup'
7
7
  dynamic = ['version', 'dependencies']
8
8
  description = 'Prefix-aware curation & near-dedup for NN code via MinHash/LSH and AST fingerprints.'
9
9
  readme = { file = 'README.md', content-type = 'text/markdown' }
10
- license = { file = "LICENSE" }
10
+ license = { file = 'LICENSE' }
11
11
  requires-python = '>=3.10'
12
12
  classifiers = [
13
- "Programming Language :: Python :: 3",
14
- "License :: OSI Approved :: MIT License",
15
- "Operating System :: OS Independent"
13
+ 'Programming Language :: Python :: 3',
14
+ 'License :: OSI Approved :: MIT License',
15
+ 'Operating System :: OS Independent',
16
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
17
+ 'Topic :: Software Development :: Code Generators'
16
18
  ]
19
+
20
+ keywords = ['LLM', 'deduplication', 'MinHash', 'LSH', 'AST', 'neural networks', 'data curation', 'pretraining', 'fine-tuning']
21
+
17
22
  authors = [{ name = 'ABrain One and contributors', email = 'AI@ABrain.one' }]
18
23
 
19
24
  [project.urls]
20
25
  Homepage = 'https://ABrain.one'
21
26
  Repository = 'https://github.com/ABrain-One/nn-dup'
27
+ 'Bug Tracker' = 'https://github.com/ABrain-One/nn-dup/issues'
22
28
 
23
29
  [tool.setuptools.dynamic]
24
30
  version = { file = 'version' }
@@ -34,6 +40,14 @@ include-package-data = true
34
40
  '*' = ['**/*.json']
35
41
 
36
42
  [tool.setuptools.package-data]
37
- 'ab' = ['*.md']
38
- '*' = ['requirements.txt', 'README.md', 'LICENSE', 'version']
43
+ '*' = ['*.md', 'requirements.txt', 'LICENSE', 'version']
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ 'black>=23.0',
48
+ 'isort>=5.0',
49
+ 'flake8>=6.0'
50
+ ]
39
51
 
52
+ [project.scripts]
53
+ lemur-preprocess = "ab.dup.preprocessing:main"
@@ -0,0 +1 @@
1
+ nn-dup==2.1.2
ldup-2.1.2/version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -1 +0,0 @@
1
- nn-dup==2.1.0
@@ -1 +0,0 @@
1
- nn-dup==2.1.0
ldup-2.1.0/setup.py DELETED
@@ -1,56 +0,0 @@
1
- # setup.py
2
- from pathlib import Path
3
- from setuptools import setup, find_packages
4
-
5
- ROOT = Path(__file__).parent.resolve()
6
- README = ROOT / "README.md"
7
- REQUIREMENTS = ROOT / "requirements.txt"
8
-
9
- def load_requirements():
10
- """Load requirements from requirements.txt file."""
11
- if REQUIREMENTS.exists():
12
- with open(REQUIREMENTS, 'r', encoding='utf-8') as f:
13
- return [line.strip() for line in f if line.strip() and not line.startswith('#')]
14
- return []
15
-
16
- long_description = README.read_text(encoding="utf-8") if README.exists() else (
17
- "LEMUR NN curation & dedup pipeline (prefix-aware exact/near/AST dedup, "
18
- "diversity top-up, and accepted-code export)."
19
- )
20
-
21
- setup(
22
- name="lemur-preprocessing",
23
- version="0.1.1",
24
- description="Prefix-aware curation & near-dedup for NN code via MinHash/LSH and AST fingerprints.",
25
- long_description=long_description,
26
- long_description_content_type="text/markdown",
27
- author="Your Team",
28
- license="MIT",
29
- python_requires=">=3.9",
30
- packages=find_packages(include=["ab", "ab.*"]),
31
- include_package_data=True,
32
- install_requires=load_requirements(),
33
- extras_require={
34
- "dev": ["black>=23.0", "isort>=5.0", "flake8>=6.0"],
35
- },
36
- entry_points={
37
- "console_scripts": [
38
- "lemur-preprocess=ab.dup.preprocessing:main",
39
- ],
40
- },
41
- classifiers=[
42
- "Programming Language :: Python :: 3",
43
- "License :: OSI Approved :: MIT License",
44
- "Topic :: Scientific/Engineering :: Artificial Intelligence",
45
- "Topic :: Software Development :: Code Generators",
46
- "Operating System :: OS Independent",
47
- ],
48
- keywords=[
49
- "LLM", "deduplication", "MinHash", "LSH", "AST", "neural networks",
50
- "data curation", "pretraining", "fine-tuning",
51
- ],
52
- project_urls={
53
- "Homepage": "https://github.com/your-org/lemur-preprocessing",
54
- "Bug Tracker": "https://github.com/your-org/lemur-preprocessing/issues",
55
- },
56
- )
ldup-2.1.0/version DELETED
@@ -1 +0,0 @@
1
- 2.1.0
File without changes
File without changes
File without changes