Spaces:
Runtime error
Runtime error
File size: 10,426 Bytes
3992084 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using custom data configuration hu-faq-question-language=hu,scope=faq\n",
"Reusing dataset mqa (/Users/eend/.cache/huggingface/datasets/clips___mqa/hu-faq-question-language=hu,scope=faq/0.0.0/7eda4cdcbd6f009259fc516f204d776915a5f54ea2ad414c3dcddfaacd4dfe0b)\n",
"100%|██████████| 1/1 [00:00<00:00, 19.53it/s]\n"
]
}
],
"source": [
"from datasets import load_dataset\n",
"\n",
"faq_hu = load_dataset(\"clips/mqa\", scope=\"faq\", language=\"hu\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'id': 'a44ad85683f3d8afd1ffa42ce55fefcd',\n",
" 'text': '',\n",
" 'name': 'szingapúr területén mely kisállatbarát hotelek ideálisak a családok számára?',\n",
" 'domain': 'tripadvisor.co.hu',\n",
" 'bucket': '2020.29',\n",
" 'answers': [{'text': 'a(z) szingapúr területén nyaraló családok tapasztalatai szerint ezek igazán jó kisállatbarát hotelek: \\n**[intercontinental singapore](https://www.tripadvisor.co.hu/hotel_review-g294265-d299199-reviews-intercontinental_singapore-singapore.html?faqtqr=5&faqts=hotels&faqtt=214&faqtup=geo%3a294265%3bzfa%3a9&m=63287)** utazói osztályozás: 4.5/5 \\n**[fraser suites singapore](https://www.tripadvisor.co.hu/hotel_review-g294265-d306172-reviews-fraser_suites_singapore-singapore.html?faqtqr=5&faqts=hotels&faqtt=214&faqtup=geo%3a294265%3bzfa%3a9&m=63287)** utazói osztályozás: 4.5/5 \\n**[holiday inn express singapore katong](https://www.tripadvisor.co.hu/hotel_review-g294265-d8777586-reviews-holiday_inn_express_singapore_katong-singapore.html?faqtqr=5&faqts=hotels&faqtt=214&faqtup=geo%3a294265%3bzfa%3a9&m=63287)** utazói osztályozás: 4.0/5',\n",
" 'name': '',\n",
" 'is_accepted': True}]}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"faq_hu['train'][810000]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 1, 2, 2, 3, 4],\n",
" [ 2, 3, 4, 5, 7],\n",
" [ 2, 4, 4, 6, 8],\n",
" [ 4, 6, 8, 10, 14]])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import torch\n",
"\n",
"a = torch.tensor([[1,2,2,3,4],[2,3,4,5,7]])\n",
"b = a * 2\n",
"\n",
"tensor_list = []\n",
"tensor_list.append(a)\n",
"tensor_list.append(b)\n",
"torch.cat((a,b),dim=0)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.size()[1]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[1, 2, 2, 3, 4],\n",
" [2, 3, 4, 5, 7]])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[:2]"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[1, 2, 2, 3, 4], [2, 3, 4, 5, 7]]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.tolist()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"c = torch.empty([1,5])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[1.4569e-19, 1.0658e-32, 1.1258e+24, 1.5789e-19, 1.1819e+22]])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1.4568973155122501e-19,\n",
" 1.0658291767562146e-32,\n",
" 1.1257918204515671e+24,\n",
" 1.5789373458898217e-19,\n",
" 1.1818655764620037e+22]"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c.squeeze().tolist()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n"
]
}
],
"source": [
"a = [1,2,3]\n",
"b= [2,4,5]\n",
"print(a.extend(b))"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 2, 4, 5]"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\n",
"Types of Question Answering\n",
"\n",
" - extractive question answering (encoder only models BERT)\n",
"\n",
" - posing questions about a document and identifying the answers as spans of text in the document itself\n",
"\n",
" - generative question answering (encoder-decoder T5/BART)\n",
"\n",
" - open ended questions, which need to synthesize information\n",
"\n",
" - retrieval based/community question answering \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"First approach - translate dataset, fine-tune model\n",
"\n",
"!Not really feasible, because it needs lots of human evaluation for correctly determine answer start token\n",
"\n",
"\n",
"\n",
" 1. Translate English QA dataset into Hungarian\n",
"\n",
" - SQuAD - reading comprehension based on Wikipedia articles\n",
"\n",
" - ~ 100.000 question/answers\n",
"\n",
" 2. Fine-tune a model and evaluate on this dataset\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Second approach - fine-tune multilingual model\n",
"\n",
"!MQA format different than SQuAD, cannot use ModelForQuestionAnswering\n",
"\n",
"\n",
"\n",
" 1. Use a Hungarian dataset\n",
"\n",
" - MQA - multilingual parsed from Common Crawl\n",
"\n",
" - FAQ - 878.385 (2.415 domain)\n",
"\n",
" - CQA - 27.639 (171 domain)\n",
"\n",
" 2. Fine-tune and evaluate a model on this dataset\n",
"\n",
" \n",
"\n",
" \n",
"\n",
" Possible steps:\n",
"\n",
" - Use an existing pre-trained model in Hungarian/Romanian/or multilingual to generate embeddings\n",
"\n",
" - Select Model:\n",
"\n",
" - multilingual which includes hu:\n",
"\n",
" - distiluse-base-multilingual-cased-v2 (400MB)\n",
"\n",
" - paraphrase-multilingual-MiniLM-L12-v2 (400MB) - fastest\n",
"\n",
" - paraphrase-multilingual-mpnet-base-v2 (900MB) - best performing\n",
"\n",
" - hubert\n",
"\n",
" - Select a dataset\n",
"\n",
" - use MQA hungarian subset\n",
"\n",
" - use hungarian wikipedia pages data, split it up\n",
"\n",
" - DBpedia, shortened abstracts = 500.000\n",
"\n",
" - Pre-compute embeddings for all answers/paragraphs\n",
"\n",
" - Compute embedding for incoming query\n",
"\n",
" - Compare similarity between query embedding and precomputed \n",
"\n",
" - return top-3 answers/questions\n",
"\n",
" \n",
"\n",
" Alternative steps:\n",
"\n",
" - train a sentence transformer on the Hungarian / Romanian subsets\n",
"\n",
" - Use the trained sentence transformer to generate embeddings\n",
"\n"
]
}
],
"source": [
"with open('../approach.txt','r') as f:\n",
" line = 'init'\n",
" while line != '':\n",
" line=f.readline();\n",
" print(line)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([1.4013e-45, 0.0000e+00, 2.8026e-45, 0.0000e+00, 2.8026e-45, 0.0000e+00,\n",
" 4.2039e-45, 0.0000e+00, 5.6052e-45, 0.0000e+00, 2.8026e-45, 0.0000e+00,\n",
" 4.2039e-45, 0.0000e+00, 5.6052e-45, 0.0000e+00, 7.0065e-45, 0.0000e+00,\n",
" 9.8091e-45, 0.0000e+00])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = torch.empty([20])\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "02e357c7440d8ed11be29edfeecade50b9c6cce68ea0a63234d5a765afff05f4"
},
"kernelspec": {
"display_name": "Python 3.9.6 64-bit ('hf_venv': venv)",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|