muellerzr HF staff commited on
Commit
ebe49f6
1 Parent(s): 3b2088c

Try again and push processed dataset

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. process.ipynb +250 -0
  3. processed_chunks.npy +3 -0
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.npy filter=lfs diff=lfs merge=lfs -text
process.ipynb ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "source": [
6
+ "!git clone https://huggingface.co/datasets/muellerzr/RAG-accelerate"
7
+ ],
8
+ "metadata": {
9
+ "id": "L6pZLIWYSsSq"
10
+ },
11
+ "execution_count": null,
12
+ "outputs": []
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "source": [
17
+ "%cd RAG-accelerate"
18
+ ],
19
+ "metadata": {
20
+ "id": "Ntgk_YKiSyIq",
21
+ "outputId": "14d9ffc4-0b42-4283-adeb-4b981ad2ee57",
22
+ "colab": {
23
+ "base_uri": "https://localhost:8080/"
24
+ }
25
+ },
26
+ "execution_count": 4,
27
+ "outputs": [
28
+ {
29
+ "output_type": "stream",
30
+ "name": "stdout",
31
+ "text": [
32
+ "/content/RAG-accelerate\n"
33
+ ]
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "source": [
40
+ "import re"
41
+ ],
42
+ "metadata": {
43
+ "id": "ERy5RO58TBcu"
44
+ },
45
+ "execution_count": 222,
46
+ "outputs": []
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "source": [
51
+ "def process_file(content, filename):\n",
52
+ " # Declare constants\n",
53
+ " func = ''\n",
54
+ " tab = ''\n",
55
+ " brackets = {'(':0, '[':0, '{':0}\n",
56
+ " close = {')':'(', ']':'[', '}':'{'}\n",
57
+ " string=''\n",
58
+ " tab_f=''\n",
59
+ " c1=''\n",
60
+ " c2=''\n",
61
+ " multiline=False\n",
62
+ " check=False\n",
63
+ " in_class = False\n",
64
+ " in_function = False\n",
65
+ " decorator = None\n",
66
+ " class_name = \"\"\n",
67
+ " func_list=[]\n",
68
+ " for line in content.split('\\n'):\n",
69
+ " tab = re.findall(r'^\\s*',line)[0]\n",
70
+ " if re.findall(r'^\\s*@', line) and not func:\n",
71
+ " decorator = line\n",
72
+ " if (len(line.lstrip(\" \")) - len(line)) == 0:\n",
73
+ " in_class = False\n",
74
+ " if (re.findall(r'^\\s*def ', line) or re.findall(r'^\\s*class ', line)) and not string and not multiline:\n",
75
+ " if re.findall(r'^\\s*class ', line):\n",
76
+ " in_class = True\n",
77
+ " class_name = re.findall(r'class\\s+(\\w+)\\s*[\\(:]', line)[0]\n",
78
+ " func += line + '\\n'\n",
79
+ " tab_f = tab\n",
80
+ " check=True\n",
81
+ " if func:\n",
82
+ " if not check:\n",
83
+ " if sum(brackets.values()) == 0 and not string and not multiline:\n",
84
+ " if len(tab) <= len(tab_f):\n",
85
+ " # Append the metadata\n",
86
+ " metadata = f'File: {filename}'\n",
87
+ " if in_class:\n",
88
+ " metadata += f'\\nClass: {class_name}'\n",
89
+ " if decorator is not None:\n",
90
+ " func = f'{decorator}\\n{func}'\n",
91
+ " decorator = None\n",
92
+ " func = f'{metadata}\\nSource:\\n{func}'\n",
93
+ " func_list.append(func)\n",
94
+ " func=''\n",
95
+ " c1=''\n",
96
+ " c2=''\n",
97
+ " continue\n",
98
+ " func += line + '\\n'\n",
99
+ " check = False\n",
100
+ " for c0 in line:\n",
101
+ " if c0 == '#' and not string and not multiline:\n",
102
+ " break\n",
103
+ " if c1 != '\\\\':\n",
104
+ " if c0 in ['\"', \"'\"]:\n",
105
+ " if c2 == c1 == c0 == '\"' and string != \"'\":\n",
106
+ " multiline = not multiline\n",
107
+ " string = ''\n",
108
+ " continue\n",
109
+ " if not multiline:\n",
110
+ " if c0 in string:\n",
111
+ " string = ''\n",
112
+ " else:\n",
113
+ " if not string:\n",
114
+ " string = c0\n",
115
+ " if not string and not multiline:\n",
116
+ " if c0 in brackets:\n",
117
+ " brackets[c0] += 1\n",
118
+ " if c0 in close:\n",
119
+ " b = close[c0]\n",
120
+ " brackets[b] -= 1\n",
121
+ " c2=c1\n",
122
+ " c1=c0\n",
123
+ " return func_list"
124
+ ],
125
+ "metadata": {
126
+ "id": "yTaa5oufYwVj"
127
+ },
128
+ "execution_count": 223,
129
+ "outputs": []
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "source": [
134
+ "from pathlib import Path"
135
+ ],
136
+ "metadata": {
137
+ "id": "SObDuDAPYj1u"
138
+ },
139
+ "execution_count": 224,
140
+ "outputs": []
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "source": [
145
+ "src_path = Path(\"src\")"
146
+ ],
147
+ "metadata": {
148
+ "id": "EBVypAmNYsnR"
149
+ },
150
+ "execution_count": 225,
151
+ "outputs": []
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "source": [
156
+ "results = []\n",
157
+ "for f in src_path.glob('**/*'):\n",
158
+ " if f.is_file():\n",
159
+ " content = f.read_text()\n",
160
+ " output = process_file(content, f.name)\n",
161
+ " results += output"
162
+ ],
163
+ "metadata": {
164
+ "id": "J0c0eNPYcAoX"
165
+ },
166
+ "execution_count": 226,
167
+ "outputs": []
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "source": [
172
+ "len(results)"
173
+ ],
174
+ "metadata": {
175
+ "id": "nuZS65CzdAMm",
176
+ "outputId": "2601f995-fce6-49d5-b2dd-71e8150746a1",
177
+ "colab": {
178
+ "base_uri": "https://localhost:8080/"
179
+ }
180
+ },
181
+ "execution_count": 231,
182
+ "outputs": [
183
+ {
184
+ "output_type": "execute_result",
185
+ "data": {
186
+ "text/plain": [
187
+ "536"
188
+ ]
189
+ },
190
+ "metadata": {},
191
+ "execution_count": 231
192
+ }
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "source": [
198
+ "import numpy as np"
199
+ ],
200
+ "metadata": {
201
+ "id": "eFinZFPTf6Ac"
202
+ },
203
+ "execution_count": 232,
204
+ "outputs": []
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "source": [
209
+ "arr = np.array(results)"
210
+ ],
211
+ "metadata": {
212
+ "id": "Hg6FiWfAgQcA"
213
+ },
214
+ "execution_count": 234,
215
+ "outputs": []
216
+ },
217
+ {
218
+ "cell_type": "code",
219
+ "source": [
220
+ "np.save(\"processed_chunks.npy\", arr)"
221
+ ],
222
+ "metadata": {
223
+ "id": "OVEMm3gsgRW-"
224
+ },
225
+ "execution_count": 235,
226
+ "outputs": []
227
+ },
228
+ {
229
+ "cell_type": "code",
230
+ "source": [],
231
+ "metadata": {
232
+ "id": "4f3fivFAgxmg"
233
+ },
234
+ "execution_count": null,
235
+ "outputs": []
236
+ }
237
+ ],
238
+ "metadata": {
239
+ "colab": {
240
+ "name": "scratchpad",
241
+ "provenance": []
242
+ },
243
+ "kernelspec": {
244
+ "display_name": "Python 3",
245
+ "name": "python3"
246
+ }
247
+ },
248
+ "nbformat": 4,
249
+ "nbformat_minor": 0
250
+ }
processed_chunks.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1ee0de22fd84f54359bfe7261dab7fd07dcda327c9427f235f2f84bc7ed8c2d
3
+ size 110952128