Process documentation files
Browse files
process_documentation.ipynb
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"id": "lIYdn1woOS1n"
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"!git clone https://huggingface.co/datasets/muellerzr/RAG-accelerate"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"source": [
|
17 |
+
"%cd RAG-accelerate"
|
18 |
+
],
|
19 |
+
"metadata": {
|
20 |
+
"id": "N_0YZlykKdVS"
|
21 |
+
},
|
22 |
+
"execution_count": null,
|
23 |
+
"outputs": []
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"source": [
|
28 |
+
"!pip install langchain"
|
29 |
+
],
|
30 |
+
"metadata": {
|
31 |
+
"id": "AK8XGa24Kekk"
|
32 |
+
},
|
33 |
+
"execution_count": null,
|
34 |
+
"outputs": []
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"source": [
|
39 |
+
"from pathlib import Path"
|
40 |
+
],
|
41 |
+
"metadata": {
|
42 |
+
"id": "Qt4Zu6mfLvW2"
|
43 |
+
},
|
44 |
+
"execution_count": 19,
|
45 |
+
"outputs": []
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"cell_type": "code",
|
49 |
+
"source": [
|
50 |
+
"from langchain.text_splitter import MarkdownHeaderTextSplitter, RecursiveCharacterTextSplitter"
|
51 |
+
],
|
52 |
+
"metadata": {
|
53 |
+
"id": "a9AHp1eZKgUw"
|
54 |
+
},
|
55 |
+
"execution_count": 12,
|
56 |
+
"outputs": []
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"cell_type": "code",
|
60 |
+
"source": [
|
61 |
+
"docs_folder = Path(\"docs/source\")"
|
62 |
+
],
|
63 |
+
"metadata": {
|
64 |
+
"id": "1gxt3ZcTLxAb"
|
65 |
+
},
|
66 |
+
"execution_count": 20,
|
67 |
+
"outputs": []
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"cell_type": "code",
|
71 |
+
"source": [
|
72 |
+
"headers_to_split_on = [\n",
|
73 |
+
" (\"#\", \"Header 1\"),\n",
|
74 |
+
" (\"##\", \"Header 2\"),\n",
|
75 |
+
" (\"###\", \"Header 3\"),\n",
|
76 |
+
" (\"####\", \"Header 4\")\n",
|
77 |
+
"]"
|
78 |
+
],
|
79 |
+
"metadata": {
|
80 |
+
"id": "EFwAEg2mKsNL"
|
81 |
+
},
|
82 |
+
"execution_count": 29,
|
83 |
+
"outputs": []
|
84 |
+
},
|
85 |
+
{
|
86 |
+
"cell_type": "code",
|
87 |
+
"source": [
|
88 |
+
"markdown_splitter = MarkdownHeaderTextSplitter(\n",
|
89 |
+
" headers_to_split_on=headers_to_split_on,\n",
|
90 |
+
" strip_headers=False\n",
|
91 |
+
")"
|
92 |
+
],
|
93 |
+
"metadata": {
|
94 |
+
"id": "HpNxkjoZKs2v"
|
95 |
+
},
|
96 |
+
"execution_count": 30,
|
97 |
+
"outputs": []
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"cell_type": "code",
|
101 |
+
"source": [
|
102 |
+
"chunk_size = 1024\n",
|
103 |
+
"chunk_overlap = 256\n",
|
104 |
+
"text_splitter = RecursiveCharacterTextSplitter(\n",
|
105 |
+
" chunk_size=chunk_size, chunk_overlap=chunk_overlap\n",
|
106 |
+
")"
|
107 |
+
],
|
108 |
+
"metadata": {
|
109 |
+
"id": "ch_UDrYIM4GT"
|
110 |
+
},
|
111 |
+
"execution_count": 33,
|
112 |
+
"outputs": []
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"cell_type": "code",
|
116 |
+
"source": [
|
117 |
+
"categories = [\"package_reference\", \"basic_tutorials\", \"concept_guides\", \"usage_guides\"]"
|
118 |
+
],
|
119 |
+
"metadata": {
|
120 |
+
"id": "kKRNe4qPMM_6"
|
121 |
+
},
|
122 |
+
"execution_count": 34,
|
123 |
+
"outputs": []
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"source": [
|
128 |
+
"data = []"
|
129 |
+
],
|
130 |
+
"metadata": {
|
131 |
+
"id": "D-rajLfOMynB"
|
132 |
+
},
|
133 |
+
"execution_count": 44,
|
134 |
+
"outputs": []
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"cell_type": "code",
|
138 |
+
"source": [
|
139 |
+
"for path in docs_folder.glob(\"**/*.md\"):\n",
|
140 |
+
" content = path.read_text()\n",
|
141 |
+
" md_header_splits = markdown_splitter.split_text(content)\n",
|
142 |
+
" for i,split in enumerate(md_header_splits):\n",
|
143 |
+
" if path.parent.name in categories:\n",
|
144 |
+
" md_header_splits[i].metadata.update({\"category\":path.parent.name})\n",
|
145 |
+
" splits = text_splitter.split_documents(md_header_splits)\n",
|
146 |
+
" data += splits"
|
147 |
+
],
|
148 |
+
"metadata": {
|
149 |
+
"id": "zAqjYMdMMJRH"
|
150 |
+
},
|
151 |
+
"execution_count": 46,
|
152 |
+
"outputs": []
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"cell_type": "code",
|
156 |
+
"source": [
|
157 |
+
"import numpy as np"
|
158 |
+
],
|
159 |
+
"metadata": {
|
160 |
+
"id": "OAaI9OV_NsTC"
|
161 |
+
},
|
162 |
+
"execution_count": 50,
|
163 |
+
"outputs": []
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"cell_type": "code",
|
167 |
+
"source": [
|
168 |
+
"np.save(\"processed_documentation_chunks.npy\", data)"
|
169 |
+
],
|
170 |
+
"metadata": {
|
171 |
+
"id": "H9FzuYdvOGyM"
|
172 |
+
},
|
173 |
+
"execution_count": 51,
|
174 |
+
"outputs": []
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"cell_type": "code",
|
178 |
+
"source": [],
|
179 |
+
"metadata": {
|
180 |
+
"id": "BgSCAljkOKLG"
|
181 |
+
},
|
182 |
+
"execution_count": null,
|
183 |
+
"outputs": []
|
184 |
+
}
|
185 |
+
],
|
186 |
+
"metadata": {
|
187 |
+
"colab": {
|
188 |
+
"name": "scratchpad",
|
189 |
+
"provenance": []
|
190 |
+
},
|
191 |
+
"kernelspec": {
|
192 |
+
"display_name": "Python 3",
|
193 |
+
"name": "python3"
|
194 |
+
}
|
195 |
+
},
|
196 |
+
"nbformat": 4,
|
197 |
+
"nbformat_minor": 0
|
198 |
+
}
|
processed_documentation_chunks.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7bde0bceeea343ca0ff9317da31769854f0382fc4fe2a5eb56c269cabadf3ee7
|
3 |
+
size 390777
|