Spaces:
Runtime error
Runtime error
mend
Browse files
ETL/embeddings_base.ipynb
CHANGED
@@ -36,9 +36,21 @@
|
|
36 |
},
|
37 |
{
|
38 |
"cell_type": "code",
|
39 |
-
"execution_count":
|
40 |
"metadata": {},
|
41 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
"source": [
|
43 |
"preprocessor = PreProcessor(\n",
|
44 |
" clean_empty_lines=True,\n",
|
@@ -107,6 +119,273 @@
|
|
107 |
"\n",
|
108 |
"document_store.update_embeddings(retriever, batch_size=10000)"
|
109 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}
|
111 |
],
|
112 |
"metadata": {
|
@@ -116,7 +395,15 @@
|
|
116 |
"name": "python3"
|
117 |
},
|
118 |
"language_info": {
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
"name": "python",
|
|
|
|
|
120 |
"version": "3.10.12"
|
121 |
}
|
122 |
},
|
|
|
36 |
},
|
37 |
{
|
38 |
"cell_type": "code",
|
39 |
+
"execution_count": 1,
|
40 |
"metadata": {},
|
41 |
+
"outputs": [
|
42 |
+
{
|
43 |
+
"ename": "NameError",
|
44 |
+
"evalue": "name 'PreProcessor' is not defined",
|
45 |
+
"output_type": "error",
|
46 |
+
"traceback": [
|
47 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
48 |
+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
|
49 |
+
"\u001b[1;32m/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb Célula 5\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m preprocessor \u001b[39m=\u001b[39m PreProcessor(\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m clean_empty_lines\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m clean_whitespace\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m clean_header_footer\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m split_by\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39msentence\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m split_length\u001b[39m=\u001b[39m\u001b[39m2\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m split_overlap\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m,\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m split_respect_sentence_boundary\u001b[39m=\u001b[39m\u001b[39mFalse\u001b[39;00m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m all_docs \u001b[39m=\u001b[39m convert_files_to_docs(dir_path\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m./Fontes/Wiki_Pages/\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#W4sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m docs_default \u001b[39m=\u001b[39m preprocessor\u001b[39m.\u001b[39mprocess(all_docs)\n",
|
50 |
+
"\u001b[0;31mNameError\u001b[0m: name 'PreProcessor' is not defined"
|
51 |
+
]
|
52 |
+
}
|
53 |
+
],
|
54 |
"source": [
|
55 |
"preprocessor = PreProcessor(\n",
|
56 |
" clean_empty_lines=True,\n",
|
|
|
119 |
"\n",
|
120 |
"document_store.update_embeddings(retriever, batch_size=10000)"
|
121 |
]
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"cell_type": "code",
|
125 |
+
"execution_count": null,
|
126 |
+
"metadata": {},
|
127 |
+
"outputs": [],
|
128 |
+
"source": []
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"cell_type": "code",
|
132 |
+
"execution_count": 10,
|
133 |
+
"metadata": {},
|
134 |
+
"outputs": [
|
135 |
+
{
|
136 |
+
"name": "stderr",
|
137 |
+
"output_type": "stream",
|
138 |
+
"text": [
|
139 |
+
"[nltk_data] Downloading package punkt to /home/luid/nltk_data...\n",
|
140 |
+
"[nltk_data] Package punkt is already up-to-date!\n",
|
141 |
+
"[nltk_data] Downloading package averaged_perceptron_tagger to\n",
|
142 |
+
"[nltk_data] /home/luid/nltk_data...\n",
|
143 |
+
"[nltk_data] Unzipping taggers/averaged_perceptron_tagger.zip.\n"
|
144 |
+
]
|
145 |
+
},
|
146 |
+
{
|
147 |
+
"ename": "NotImplementedError",
|
148 |
+
"evalue": "Currently, NLTK pos_tag only supports English and Russian (i.e. lang='eng' or lang='rus')",
|
149 |
+
"output_type": "error",
|
150 |
+
"traceback": [
|
151 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
152 |
+
"\u001b[0;31mNotImplementedError\u001b[0m Traceback (most recent call last)",
|
153 |
+
"\u001b[1;32m/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb Célula 12\u001b[0m line \u001b[0;36m1\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#X14sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m palavras \u001b[39m=\u001b[39m word_tokenize(sentenca, language\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mportuguese\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#X14sZmlsZQ%3D%3D?line=12'>13</a>\u001b[0m \u001b[39m# POS-tagging das palavras\u001b[39;00m\n\u001b[0;32m---> <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#X14sZmlsZQ%3D%3D?line=13'>14</a>\u001b[0m pos_tags \u001b[39m=\u001b[39m pos_tag(palavras, lang\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mpor\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#X14sZmlsZQ%3D%3D?line=15'>16</a>\u001b[0m \u001b[39m# Exibindo os resultados\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/luid/Projetos/Fact_Checking_Blue_Amazon/ETL/embeddings_base.ipynb#X14sZmlsZQ%3D%3D?line=16'>17</a>\u001b[0m \u001b[39mprint\u001b[39m(pos_tags)\n",
|
154 |
+
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/nltk/tag/__init__.py:166\u001b[0m, in \u001b[0;36mpos_tag\u001b[0;34m(tokens, tagset, lang)\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 142\u001b[0m \u001b[39mUse NLTK's currently recommended part of speech tagger to\u001b[39;00m\n\u001b[1;32m 143\u001b[0m \u001b[39mtag the given list of tokens.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[39m:rtype: list(tuple(str, str))\u001b[39;00m\n\u001b[1;32m 164\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 165\u001b[0m tagger \u001b[39m=\u001b[39m _get_tagger(lang)\n\u001b[0;32m--> 166\u001b[0m \u001b[39mreturn\u001b[39;00m _pos_tag(tokens, tagset, tagger, lang)\n",
|
155 |
+
"File \u001b[0;32m~/.local/lib/python3.10/site-packages/nltk/tag/__init__.py:114\u001b[0m, in \u001b[0;36m_pos_tag\u001b[0;34m(tokens, tagset, tagger, lang)\u001b[0m\n\u001b[1;32m 111\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_pos_tag\u001b[39m(tokens, tagset\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, tagger\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, lang\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m):\n\u001b[1;32m 112\u001b[0m \u001b[39m# Currently only supports English and Russian.\u001b[39;00m\n\u001b[1;32m 113\u001b[0m \u001b[39mif\u001b[39;00m lang \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m [\u001b[39m\"\u001b[39m\u001b[39meng\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mrus\u001b[39m\u001b[39m\"\u001b[39m]:\n\u001b[0;32m--> 114\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mNotImplementedError\u001b[39;00m(\n\u001b[1;32m 115\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mCurrently, NLTK pos_tag only supports English and Russian \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 116\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m(i.e. lang=\u001b[39m\u001b[39m'\u001b[39m\u001b[39meng\u001b[39m\u001b[39m'\u001b[39m\u001b[39m or lang=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mrus\u001b[39m\u001b[39m'\u001b[39m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m 117\u001b[0m )\n\u001b[1;32m 118\u001b[0m \u001b[39m# Throws Error if tokens is of string type\u001b[39;00m\n\u001b[1;32m 119\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(tokens, \u001b[39mstr\u001b[39m):\n",
|
156 |
+
"\u001b[0;31mNotImplementedError\u001b[0m: Currently, NLTK pos_tag only supports English and Russian (i.e. lang='eng' or lang='rus')"
|
157 |
+
]
|
158 |
+
}
|
159 |
+
],
|
160 |
+
"source": [
|
161 |
+
"import nltk\n",
|
162 |
+
"from nltk.tokenize import word_tokenize\n",
|
163 |
+
"from nltk import pos_tag\n",
|
164 |
+
"nltk.download('punkt')\n",
|
165 |
+
"nltk.download('averaged_perceptron_tagger')\n",
|
166 |
+
"\n",
|
167 |
+
"# Sentença de exemplo\n",
|
168 |
+
"sentenca = \"O gato está no telhado.\"\n",
|
169 |
+
"\n",
|
170 |
+
"# Tokenização da sentença em palavras\n",
|
171 |
+
"palavras = word_tokenize(sentenca, language='portuguese')\n",
|
172 |
+
"\n",
|
173 |
+
"# POS-tagging das palavras\n",
|
174 |
+
"pos_tags = pos_tag(palavras, lang='por')\n",
|
175 |
+
"\n",
|
176 |
+
"# Exibindo os resultados\n",
|
177 |
+
"print(pos_tags)"
|
178 |
+
]
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"cell_type": "code",
|
182 |
+
"execution_count": 3,
|
183 |
+
"metadata": {},
|
184 |
+
"outputs": [],
|
185 |
+
"source": [
|
186 |
+
"sentence = \"Eu gosto de programar em Python.\"\n",
|
187 |
+
"inputs = tokenizer(sentence, return_tensors=\"pt\")\n",
|
188 |
+
"outputs = model(**inputs)"
|
189 |
+
]
|
190 |
+
},
|
191 |
+
{
|
192 |
+
"cell_type": "code",
|
193 |
+
"execution_count": 8,
|
194 |
+
"metadata": {},
|
195 |
+
"outputs": [],
|
196 |
+
"source": [
|
197 |
+
"predicted_labels = torch.argmax(outputs.logits, dim=2)\n",
|
198 |
+
"verb_indices = [(i,label) for i, label in enumerate(predicted_labels[0])]"
|
199 |
+
]
|
200 |
+
},
|
201 |
+
{
|
202 |
+
"cell_type": "code",
|
203 |
+
"execution_count": 9,
|
204 |
+
"metadata": {},
|
205 |
+
"outputs": [
|
206 |
+
{
|
207 |
+
"data": {
|
208 |
+
"text/plain": [
|
209 |
+
"[(0, tensor(1)),\n",
|
210 |
+
" (1, tensor(1)),\n",
|
211 |
+
" (2, tensor(1)),\n",
|
212 |
+
" (3, tensor(1)),\n",
|
213 |
+
" (4, tensor(0)),\n",
|
214 |
+
" (5, tensor(0)),\n",
|
215 |
+
" (6, tensor(1)),\n",
|
216 |
+
" (7, tensor(1)),\n",
|
217 |
+
" (8, tensor(0)),\n",
|
218 |
+
" (9, tensor(1)),\n",
|
219 |
+
" (10, tensor(1))]"
|
220 |
+
]
|
221 |
+
},
|
222 |
+
"execution_count": 9,
|
223 |
+
"metadata": {},
|
224 |
+
"output_type": "execute_result"
|
225 |
+
}
|
226 |
+
],
|
227 |
+
"source": [
|
228 |
+
"verb_indices"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "code",
|
233 |
+
"execution_count": 7,
|
234 |
+
"metadata": {},
|
235 |
+
"outputs": [
|
236 |
+
{
|
237 |
+
"name": "stdout",
|
238 |
+
"output_type": "stream",
|
239 |
+
"text": [
|
240 |
+
"Verbos na sentença: ['gosto', 'de', '##r', 'em', '##thon']\n"
|
241 |
+
]
|
242 |
+
}
|
243 |
+
],
|
244 |
+
"source": [
|
245 |
+
"predicted_labels = torch.argmax(outputs.logits, dim=2)\n",
|
246 |
+
"verb_indices = [i for i, label in enumerate(predicted_labels[0]) if label == 1]\n",
|
247 |
+
"\n",
|
248 |
+
"verbs = [tokenizer.convert_ids_to_tokens(inputs['input_ids'][0][i].item()) for i in verb_indices]\n",
|
249 |
+
"print(\"Verbos na sentença:\", verbs)"
|
250 |
+
]
|
251 |
+
},
|
252 |
+
{
|
253 |
+
"cell_type": "code",
|
254 |
+
"execution_count": 11,
|
255 |
+
"metadata": {},
|
256 |
+
"outputs": [
|
257 |
+
{
|
258 |
+
"name": "stderr",
|
259 |
+
"output_type": "stream",
|
260 |
+
"text": [
|
261 |
+
"2023-11-28 18:26:39.155987: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:894] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero. See more at https://github.com/torvalds/linux/blob/v6.0/Documentation/ABI/testing/sysfs-bus-pci#L344-L355\n",
|
262 |
+
"2023-11-28 18:26:39.300399: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:894] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero. See more at https://github.com/torvalds/linux/blob/v6.0/Documentation/ABI/testing/sysfs-bus-pci#L344-L355\n",
|
263 |
+
"2023-11-28 18:26:39.300771: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:894] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero. See more at https://github.com/torvalds/linux/blob/v6.0/Documentation/ABI/testing/sysfs-bus-pci#L344-L355\n"
|
264 |
+
]
|
265 |
+
}
|
266 |
+
],
|
267 |
+
"source": [
|
268 |
+
"import spacy\n",
|
269 |
+
"from spacy.lang.pt.examples import sentences "
|
270 |
+
]
|
271 |
+
},
|
272 |
+
{
|
273 |
+
"cell_type": "code",
|
274 |
+
"execution_count": 12,
|
275 |
+
"metadata": {},
|
276 |
+
"outputs": [
|
277 |
+
{
|
278 |
+
"name": "stdout",
|
279 |
+
"output_type": "stream",
|
280 |
+
"text": [
|
281 |
+
"Apple está querendo comprar uma startup do Reino Unido por 100 milhões de dólares \n",
|
282 |
+
"\n",
|
283 |
+
"Carros autônomos empurram a responsabilidade do seguro para os fabricantes.São Francisco considera banir os robôs de entrega que andam pelas calçadas \n",
|
284 |
+
"\n",
|
285 |
+
"Londres é a maior cidade do Reino Unido \n",
|
286 |
+
"\n"
|
287 |
+
]
|
288 |
+
}
|
289 |
+
],
|
290 |
+
"source": [
|
291 |
+
"\n",
|
292 |
+
"# Alguns exemplos fornecidos pela própria biblioteca\n",
|
293 |
+
"for s in sentences:\n",
|
294 |
+
" print(s, '\\n')\n",
|
295 |
+
"\n"
|
296 |
+
]
|
297 |
+
},
|
298 |
+
{
|
299 |
+
"cell_type": "code",
|
300 |
+
"execution_count": 29,
|
301 |
+
"metadata": {},
|
302 |
+
"outputs": [
|
303 |
+
{
|
304 |
+
"name": "stdout",
|
305 |
+
"output_type": "stream",
|
306 |
+
"text": [
|
307 |
+
"Apple está querendo comprar uma startup do Reino Unido por 100 milhões de dólares\n"
|
308 |
+
]
|
309 |
+
}
|
310 |
+
],
|
311 |
+
"source": [
|
312 |
+
"# Criando o objeto spacy\n",
|
313 |
+
"nlp = spacy.load(\"pt_core_news_lg\")\n",
|
314 |
+
"doc = nlp(sentences[0])\n",
|
315 |
+
"print(doc.text)\n"
|
316 |
+
]
|
317 |
+
},
|
318 |
+
{
|
319 |
+
"cell_type": "code",
|
320 |
+
"execution_count": 34,
|
321 |
+
"metadata": {},
|
322 |
+
"outputs": [],
|
323 |
+
"source": [
|
324 |
+
"doc = nlp(\"A amazonia azul e a defesa maritma\")"
|
325 |
+
]
|
326 |
+
},
|
327 |
+
{
|
328 |
+
"cell_type": "code",
|
329 |
+
"execution_count": 36,
|
330 |
+
"metadata": {},
|
331 |
+
"outputs": [],
|
332 |
+
"source": [
|
333 |
+
"for token in doc:\n",
|
334 |
+
" verb_count = 0\n",
|
335 |
+
" if token.pos_ == 'VERB':\n",
|
336 |
+
" verb_count +=1"
|
337 |
+
]
|
338 |
+
},
|
339 |
+
{
|
340 |
+
"cell_type": "code",
|
341 |
+
"execution_count": 37,
|
342 |
+
"metadata": {},
|
343 |
+
"outputs": [
|
344 |
+
{
|
345 |
+
"data": {
|
346 |
+
"text/plain": [
|
347 |
+
"0"
|
348 |
+
]
|
349 |
+
},
|
350 |
+
"execution_count": 37,
|
351 |
+
"metadata": {},
|
352 |
+
"output_type": "execute_result"
|
353 |
+
}
|
354 |
+
],
|
355 |
+
"source": [
|
356 |
+
"verb_count"
|
357 |
+
]
|
358 |
+
},
|
359 |
+
{
|
360 |
+
"cell_type": "code",
|
361 |
+
"execution_count": 35,
|
362 |
+
"metadata": {},
|
363 |
+
"outputs": [
|
364 |
+
{
|
365 |
+
"name": "stdout",
|
366 |
+
"output_type": "stream",
|
367 |
+
"text": [
|
368 |
+
"A DET\n",
|
369 |
+
"amazonia NOUN\n",
|
370 |
+
"azul ADJ\n",
|
371 |
+
"e CCONJ\n",
|
372 |
+
"a DET\n",
|
373 |
+
"defesa NOUN\n",
|
374 |
+
"maritma NOUN\n"
|
375 |
+
]
|
376 |
+
}
|
377 |
+
],
|
378 |
+
"source": [
|
379 |
+
"for token in doc:\n",
|
380 |
+
" print(token.text, token.pos_)\n"
|
381 |
+
]
|
382 |
+
},
|
383 |
+
{
|
384 |
+
"cell_type": "code",
|
385 |
+
"execution_count": null,
|
386 |
+
"metadata": {},
|
387 |
+
"outputs": [],
|
388 |
+
"source": []
|
389 |
}
|
390 |
],
|
391 |
"metadata": {
|
|
|
395 |
"name": "python3"
|
396 |
},
|
397 |
"language_info": {
|
398 |
+
"codemirror_mode": {
|
399 |
+
"name": "ipython",
|
400 |
+
"version": 3
|
401 |
+
},
|
402 |
+
"file_extension": ".py",
|
403 |
+
"mimetype": "text/x-python",
|
404 |
"name": "python",
|
405 |
+
"nbconvert_exporter": "python",
|
406 |
+
"pygments_lexer": "ipython3",
|
407 |
"version": "3.10.12"
|
408 |
}
|
409 |
},
|
app.py
CHANGED
@@ -168,7 +168,7 @@ def start_haystack():
|
|
168 |
"""
|
169 |
load document store, retriever, entailment checker and create pipeline
|
170 |
"""
|
171 |
-
shutil.copy("./data/
|
172 |
document_store = FAISSDocumentStore(
|
173 |
faiss_index_path=f"./data/my_faiss_index.faiss",
|
174 |
faiss_config_path=f"./data/my_faiss_index.json",
|
@@ -234,7 +234,7 @@ def highlight_cols(s):
|
|
234 |
|
235 |
def main():
|
236 |
# Persistent state
|
237 |
-
set_state_if_absent("statement", "")
|
238 |
set_state_if_absent("answer", "")
|
239 |
set_state_if_absent("results", None)
|
240 |
set_state_if_absent("raw_json", None)
|
|
|
168 |
"""
|
169 |
load document store, retriever, entailment checker and create pipeline
|
170 |
"""
|
171 |
+
shutil.copy("./data/final_faiss_document_store.db", ".")
|
172 |
document_store = FAISSDocumentStore(
|
173 |
faiss_index_path=f"./data/my_faiss_index.faiss",
|
174 |
faiss_config_path=f"./data/my_faiss_index.json",
|
|
|
234 |
|
235 |
def main():
|
236 |
# Persistent state
|
237 |
+
# set_state_if_absent("statement", "")
|
238 |
set_state_if_absent("answer", "")
|
239 |
set_state_if_absent("results", None)
|
240 |
set_state_if_absent("raw_json", None)
|
data/{pdf_faiss_document_store.db → final_faiss_document_store.db}
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:97bf03de139766204e23d3cef6b5f0aef9d3379d85956beb2dfb82dcdba0191a
|
3 |
+
size 272740352
|
data/my_faiss_index.faiss
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:204053b0084e69a64a8be6fcd0f331c35c330e0a2771652a9a08a04d2e7cc460
|
3 |
+
size 461922349
|
data/my_faiss_index.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"similarity": "cosine", "embedding_dim": 512, "sql_url": "sqlite:///
|
|
|
1 |
+
{"similarity": "cosine", "embedding_dim": 512, "sql_url": "sqlite:///final_faiss_document_store.db"}
|