|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": 1, |
| 5 | + "execution_count": null, |
6 | 6 | "id": "39792a86-af14-4ce8-bb25-287c0f16d766",
|
7 | 7 | "metadata": {},
|
8 |
| - "outputs": [ |
9 |
| - { |
10 |
| - "name": "stdout", |
11 |
| - "output_type": "stream", |
12 |
| - "text": [ |
13 |
| - "Read 2024 chunks\n" |
14 |
| - ] |
15 |
| - } |
16 |
| - ], |
| 8 | + "outputs": [], |
17 | 9 | "source": [
|
18 | 10 | "import json\n",
|
19 | 11 | "import os\n",
|
|
30 | 22 | },
|
31 | 23 | {
|
32 | 24 | "cell_type": "code",
|
33 |
| - "execution_count": 4, |
| 25 | + "execution_count": null, |
34 | 26 | "id": "0594d7bb-228b-468a-99a0-38c14651a562",
|
35 | 27 | "metadata": {},
|
36 |
| - "outputs": [ |
37 |
| - { |
38 |
| - "name": "stdout", |
39 |
| - "output_type": "stream", |
40 |
| - "text": [ |
41 |
| - "Cloning into 'DataCurate4LLMs'...\n", |
42 |
| - "remote: Enumerating objects: 228, done.\u001b[K\n", |
43 |
| - "remote: Counting objects: 100% (228/228), done.\u001b[K\n", |
44 |
| - "remote: Compressing objects: 100% (143/143), done.\u001b[K\n", |
45 |
| - "remote: Total 228 (delta 112), reused 183 (delta 78), pack-reused 0 (from 0)\u001b[K\n", |
46 |
| - "Receiving objects: 100% (228/228), 255.39 KiB | 6.08 MiB/s, done.\n", |
47 |
| - "Resolving deltas: 100% (112/112), done.\n" |
48 |
| - ] |
49 |
| - } |
50 |
| - ], |
| 28 | + "outputs": [], |
51 | 29 | "source": [
|
52 |
| - "!git clone [email protected]:krishnatejakk/DataCurate4LLMs.git" |
| 30 | + "!git clone [email protected]:krishnatejakk/DataCurate4LLMs.git\n", |
| 31 | + "%cd DataCurate4LLMs" |
53 | 32 | ]
|
54 | 33 | },
|
55 | 34 | {
|
56 | 35 | "cell_type": "code",
|
57 |
| - "execution_count": 2, |
| 36 | + "execution_count": null, |
58 | 37 | "id": "2b2c8b60-daa9-48e4-b680-0b59588609ab",
|
59 | 38 | "metadata": {},
|
60 |
| - "outputs": [ |
61 |
| - { |
62 |
| - "name": "stdout", |
63 |
| - "output_type": "stream", |
64 |
| - "text": [ |
65 |
| - "{\n", |
66 |
| - " \"output_dir\": \"output\",\n", |
67 |
| - " \"encoder_model\": \"BAAI/bge-large-en-v1.5\",\n", |
68 |
| - " \"encoder_type\": \"bge\",\n", |
69 |
| - " \"instruction\": \"Generate embeddings that capture the semantic meaning of text segments across multiple domains, ensuring generalization and suitability for clustering based on semantic similarity.\",\n", |
70 |
| - " \"query_description\": \"default\",\n", |
71 |
| - " \"templates\": {\n", |
72 |
| - " \"default\": \"{{ chunk }}\"\n", |
73 |
| - " },\n", |
74 |
| - " \"template_name\": \"default\",\n", |
75 |
| - " \"num_folds\": 1,\n", |
76 |
| - " \"num_gpus\": 1,\n", |
77 |
| - " \"subset_sizes\": [\"5\"],\n", |
78 |
| - " \"epsilon\": 0.01,\n", |
79 |
| - " \"seed\": 148\n", |
80 |
| - "}\n" |
81 |
| - ] |
82 |
| - } |
83 |
| - ], |
| 39 | + "outputs": [], |
84 | 40 | "source": [
|
85 | 41 | "import random\n",
|
86 | 42 | "\n",
|
|
113 | 69 | },
|
114 | 70 | {
|
115 | 71 | "cell_type": "code",
|
116 |
| - "execution_count": 27, |
117 |
| - "id": "7c2f16ed-52a3-465d-9961-61e0f6823fea", |
118 |
| - "metadata": {}, |
119 |
| - "outputs": [ |
120 |
| - { |
121 |
| - "name": "stdout", |
122 |
| - "output_type": "stream", |
123 |
| - "text": [ |
124 |
| - "/Users/astoyano/Documents/code/examples/notebooks/instructlab-knowledge\n" |
125 |
| - ] |
126 |
| - } |
127 |
| - ], |
128 |
| - "source": [ |
129 |
| - "%cd .." |
130 |
| - ] |
131 |
| - }, |
132 |
| - { |
133 |
| - "cell_type": "code", |
134 |
| - "execution_count": 1, |
135 |
| - "id": "27dcb09d-75bd-448c-ba14-8fb773ed5aa2", |
136 |
| - "metadata": {}, |
137 |
| - "outputs": [ |
138 |
| - { |
139 |
| - "name": "stdout", |
140 |
| - "output_type": "stream", |
141 |
| - "text": [ |
142 |
| - "/home/ec2-user/examples/notebooks/instructlab-knowledge/DataCurate4LLMs\n" |
143 |
| - ] |
144 |
| - }, |
145 |
| - { |
146 |
| - "data": { |
147 |
| - "text/plain": [ |
148 |
| - "'/home/ec2-user/examples/notebooks/instructlab-knowledge/DataCurate4LLMs'" |
149 |
| - ] |
150 |
| - }, |
151 |
| - "execution_count": 1, |
152 |
| - "metadata": {}, |
153 |
| - "output_type": "execute_result" |
154 |
| - } |
155 |
| - ], |
156 |
| - "source": [ |
157 |
| - "%cd DataCurate4LLMs\n", |
158 |
| - "%pwd" |
159 |
| - ] |
160 |
| - }, |
161 |
| - { |
162 |
| - "cell_type": "code", |
163 |
| - "execution_count": 4, |
164 |
| - "id": "0d700a78-f0cb-48ea-b829-883a4675966c", |
165 |
| - "metadata": {}, |
166 |
| - "outputs": [], |
167 |
| - "source": [ |
168 |
| - "!pip install -qq submodlib-py" |
169 |
| - ] |
170 |
| - }, |
171 |
| - { |
172 |
| - "cell_type": "code", |
173 |
| - "execution_count": 5, |
| 72 | + "execution_count": null, |
174 | 73 | "id": "e7efc49a-c08d-42f9-ad7a-b0723b49982f",
|
175 | 74 | "metadata": {},
|
176 | 75 | "outputs": [],
|
177 | 76 | "source": [
|
178 |
| - "!pip install -qq -r requirements.txt" |
| 77 | + "!sed -i -e 's ^faiss-gpu$ faiss-gpu-cu12 g' requirements.txt # fix faiss dependency; yes you can use spaces as delimiters for sed expressions\n", |
| 78 | + "!pip install -qq -r requirements.txt\n", |
| 79 | + "!pip install -qq submodlib-py" |
179 | 80 | ]
|
180 | 81 | },
|
181 | 82 | {
|
182 | 83 | "cell_type": "code",
|
183 |
| - "execution_count": 2, |
| 84 | + "execution_count": null, |
184 | 85 | "id": "8b086790-5a9f-4e2f-b130-2d9f9f8a0319",
|
185 | 86 | "metadata": {},
|
186 |
| - "outputs": [ |
187 |
| - { |
188 |
| - "name": "stdout", |
189 |
| - "output_type": "stream", |
190 |
| - "text": [ |
191 |
| - "2025-06-06 12:46:09,325 - __main__ - INFO - Processing configuration: ProcessingConfig(instruction='Generate embeddings that capture the semantic meaning of text segments across multiple domains, ensuring generalization and suitability for clustering based on semantic similarity.', query_description='default', templates={'default': '{{ chunk }}'}, batch_size=100000, num_folds=1, subset_sizes=[5], num_gpus=1, seed=148, max_retries=3, retry_delay=1, output_dir='.', template_name='default', combine_files=False, encoder_type='bge', encoder_model='BAAI/bge-large-en-v1.5', epsilon=0.01)\n", |
192 |
| - "2025-06-06 12:46:11,019 - __main__ - INFO - Processing datasets separately...\n", |
193 |
| - "2025-06-06 12:46:11,090 - __main__ - INFO - Processing dataset: chunks\n", |
194 |
| - "2025-06-06 12:46:11,090 - __main__ - INFO - Generating embeddings for chunks\n", |
195 |
| - "2025-06-06 12:46:11,090 - __main__ - INFO - Embeddings file already exists in ./chunks/embeddings, skipping\n", |
196 |
| - "2025-06-06 12:46:11,090 - __main__ - INFO - Loading embeddings for subset selection\n", |
197 |
| - "2025-06-06 12:46:11,100 - __main__ - INFO - Selecting subsets\n", |
198 |
| - "2025-06-06 12:46:11,100 - __main__ - INFO - Loaded 2025 embeddings for dataset chunks\n", |
199 |
| - "2025-06-06 12:46:11,102 - __main__ - INFO - Embeddings at top-5 Indices: tensor([[ 0.0074, 0.0125, 0.0055, ..., 0.0088, -0.0070, 0.0092],\n", |
200 |
| - " [-0.0220, 0.0177, -0.0053, ..., -0.0122, -0.0294, 0.0034],\n", |
201 |
| - " [-0.0258, 0.0094, 0.0226, ..., 0.0247, -0.0270, 0.0251],\n", |
202 |
| - " [ 0.0043, -0.0121, 0.0127, ..., 0.0399, -0.0329, 0.0285],\n", |
203 |
| - " [-0.0193, -0.0069, 0.0378, ..., -0.0013, -0.0378, 0.0177]])\n", |
204 |
| - "2025-06-06 12:46:17,153 - __mp_main__ - INFO - Processing fold 1 on GPU 0\n", |
205 |
| - "2025-06-06 12:46:17,336 - __mp_main__ - INFO - Computing similarity matrix for fold 1\n", |
206 |
| - "2025-06-06 12:46:17,471 - __mp_main__ - INFO - Selecting subset of size 5 for fold 1\n", |
207 |
| - "[||||||||||||||||||||]100% [Iteration 5 of 5]2025-06-06 12:46:17,888 - __main__ - INFO - Saved metadata to ./chunks_fl_1_partitions_samples_5_metadata.npz\n", |
208 |
| - "2025-06-06 12:46:17,889 - __main__ - INFO - Saving subsets\n", |
209 |
| - "Creating json from Arrow format: 100%|███████████| 1/1 [00:00<00:00, 166.00ba/s]\n", |
210 |
| - "2025-06-06 12:46:17,900 - __main__ - INFO - Saved subset with 5 samples to ./chunks/chunks_samples_5_subset.jsonl\n" |
211 |
| - ] |
212 |
| - } |
213 |
| - ], |
| 87 | + "outputs": [], |
214 | 88 | "source": [
|
215 |
| - "!python data_subset_selection.py --input_files '../data/chunks.jsonl' --output_dir '.' --config '../subset_config.json' --retry_delay 1 --subset_sizes 5 --num_gpus 1" |
| 89 | + "!python data_subset_selection.py --input_files '../data/chunks.jsonl' --output_dir '../data' --config '../subset_config.json' --retry_delay 1 --subset_sizes 5 --num_gpus 1" |
216 | 90 | ]
|
217 | 91 | },
|
218 | 92 | {
|
219 | 93 | "cell_type": "code",
|
220 |
| - "execution_count": 9, |
| 94 | + "execution_count": null, |
221 | 95 | "id": "02b5622c-2101-47df-b366-2afb137cdd30",
|
222 | 96 | "metadata": {},
|
223 |
| - "outputs": [ |
224 |
| - { |
225 |
| - "name": "stdout", |
226 |
| - "output_type": "stream", |
227 |
| - "text": [ |
228 |
| - "\"Rulings:\\n(a) B's ball, first-and-10 on A22. If Team A recovers and does not advance, Team B gets the ball at the spot of recovery.\\n(b) B's ball, first-and-10 on A33. If Team A recovers and advances, but does not reach the line to gain, Team B gets the ball at the dead ball spot.\\n(c) A's ball, first-and-10 on A36. If Team A recovers and advances beyond the line to gain, A has a first down.\\n(d) B's ball, first-and-10 on A20. Illegal pass, as the ball has been beyond the line. The penalty is five yards from the previous spot and a loss of down.\"\n", |
229 |
| - "\n", |
230 |
| - "\"Rulings:\\n(a) B's ball, first-and-10 on B45. No foul for running into the kicker, since the snap hit the ground. (12-2-10-e)\\n(b) B's ball, first-and-10 on B45. No foul for roughing the kicker, since the snap hit the ground. (12-2-10-e)\\n(c) A's ball, first-and-10 on B40. Unnecessary roughness. If the snap touches the ground, only unnecessary roughness protection applies, and if the contact is unnecessary roughness, it is a foul whether or not B2 touches the punt.\"\n", |
231 |
| - "\n", |
232 |
| - "\"Rulings:\\n(e) B's ball, first-and-10 on A20. Team B can recover and advance the ball because it is a scrimmage kick. The succeeding spot is the end of the run and Team A's foul will be enforced from that spot.\"\n", |
233 |
| - "\n", |
234 |
| - "\"Rulings:\\n(a) Third-and-15 on B35, run 10 seconds off the game clock, set the play clock to 25, and start the game clock on the ready for play. Team A has intentionally fouled after the two-minute warning, stopping the clock. (Team B could choose to decline the runoff and start the clock on the snap.)\\n(b) Third-and-5 on B25. Set the play clock to 40 seconds and start the game clock on the ready if Team A chooses. Team B has intentionally fouled after the two-minute warning, stopping the clock.\"\n", |
235 |
| - "\n", |
236 |
| - "\"A.R. 14.86 PUNT-TEAMBSCORES-DOUBLEFOULAFTERCHANGEOF POSSESSION\\nFourth-and-10 on A7. The punt is partially blocked, and B1 recovers on the A22 and runs for a touchdown. Prior to the score, B2 holds in A's end zone. After the score, A3 grabs B1's facemask and throws him to the ground. Ruling: B's ball, first-and-10 on A1. The live ball offensive holding by B2, combines with the dead ball unnecessary roughness foul by A3, and the penalties offset at the A1. Since the spot of B's foul and the dead ball spot are both in A's end zone, the enforcement of B2's foul would be from the goal line, if that was the only foul; the ball is therefore spotted on the 1-yard line.\"\n", |
237 |
| - "\n" |
238 |
| - ] |
239 |
| - } |
240 |
| - ], |
| 97 | + "outputs": [], |
241 | 98 | "source": [
|
242 | 99 | "import json\n",
|
243 | 100 | "\n",
|
244 |
| - "with open('./chunks/chunks_samples_5_subset.jsonl') as f:\n", |
245 |
| - " for line in f.readlines():\n", |
246 |
| - " print(json.dumps(json.loads(line)['chunk'], indent=2) + \"\\n\")" |
| 101 | + "with open('../data/chunks/chunks_samples_5_subset.jsonl') as fin:\n", |
| 102 | + " with open('../data/selected_chunks.jsonl','w') as fout:\n", |
| 103 | + " for line in fin.readlines():\n", |
| 104 | + " selected_chunk = json.loads(line)['chunk']\n", |
| 105 | + " original_chunk = chunk_lookup[selected_chunk]\n", |
| 106 | + " fout.write(json.dumps(original_chunk) + \"\\n\")\n", |
| 107 | + "\n", |
| 108 | + "with open('../data/selected_chunks.jsonl') as final:\n", |
| 109 | + " for line in final.readlines():\n", |
| 110 | + " print(json.dumps(json.loads(line), indent=2))" |
247 | 111 | ]
|
248 | 112 | }
|
249 | 113 | ],
|
|
0 commit comments