Commit ·
e7a6914
1
Parent(s): eb02943
initial
Browse files
tmp.ipynb
CHANGED
|
@@ -518,307 +518,81 @@
|
|
| 518 |
},
|
| 519 |
{
|
| 520 |
"cell_type": "code",
|
| 521 |
-
"execution_count":
|
| 522 |
-
"id": "
|
| 523 |
"metadata": {},
|
| 524 |
"outputs": [],
|
| 525 |
-
"source": [
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
},
|
| 551 |
{
|
| 552 |
"cell_type": "code",
|
| 553 |
-
"execution_count":
|
| 554 |
-
"id": "
|
| 555 |
"metadata": {},
|
| 556 |
"outputs": [
|
| 557 |
{
|
| 558 |
"name": "stdout",
|
| 559 |
"output_type": "stream",
|
| 560 |
"text": [
|
| 561 |
-
"
|
| 562 |
-
|
| 563 |
-
},
|
| 564 |
-
{
|
| 565 |
-
"data": {
|
| 566 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 567 |
-
"model_id": "25a1e75ae48941cfaacee3b35fcd41a1",
|
| 568 |
-
"version_major": 2,
|
| 569 |
-
"version_minor": 0
|
| 570 |
-
},
|
| 571 |
-
"text/plain": [
|
| 572 |
-
"config.json: 0%| | 0.00/846 [00:00<?, ?B/s]"
|
| 573 |
-
]
|
| 574 |
-
},
|
| 575 |
-
"metadata": {},
|
| 576 |
-
"output_type": "display_data"
|
| 577 |
-
},
|
| 578 |
-
{
|
| 579 |
-
"data": {
|
| 580 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 581 |
-
"model_id": "aa33a1bdb3fd4a33b243c1a2acb2b39d",
|
| 582 |
-
"version_major": 2,
|
| 583 |
-
"version_minor": 0
|
| 584 |
-
},
|
| 585 |
-
"text/plain": [
|
| 586 |
-
"tokenizer_config.json: 0%| | 0.00/564 [00:00<?, ?B/s]"
|
| 587 |
-
]
|
| 588 |
-
},
|
| 589 |
-
"metadata": {},
|
| 590 |
-
"output_type": "display_data"
|
| 591 |
-
},
|
| 592 |
-
{
|
| 593 |
-
"name": "stderr",
|
| 594 |
-
"output_type": "stream",
|
| 595 |
-
"text": [
|
| 596 |
-
"Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.\n"
|
| 597 |
-
]
|
| 598 |
-
},
|
| 599 |
-
{
|
| 600 |
-
"data": {
|
| 601 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 602 |
-
"model_id": "814d1817f13f4cf8a8835450b9dcf680",
|
| 603 |
-
"version_major": 2,
|
| 604 |
-
"version_minor": 0
|
| 605 |
-
},
|
| 606 |
-
"text/plain": [
|
| 607 |
-
"sentencepiece.bpe.model: reconstructing file: 0%| | 0.00B / 4.85MB "
|
| 608 |
-
]
|
| 609 |
-
},
|
| 610 |
-
"metadata": {},
|
| 611 |
-
"output_type": "display_data"
|
| 612 |
-
},
|
| 613 |
-
{
|
| 614 |
-
"data": {
|
| 615 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 616 |
-
"model_id": "02cb3119bd624735bd4d325fc4f50ce7",
|
| 617 |
-
"version_major": 2,
|
| 618 |
-
"version_minor": 0
|
| 619 |
-
},
|
| 620 |
-
"text/plain": [
|
| 621 |
-
"sentencepiece.bpe.model: downloading bytes: | 0.00B "
|
| 622 |
-
]
|
| 623 |
-
},
|
| 624 |
-
"metadata": {},
|
| 625 |
-
"output_type": "display_data"
|
| 626 |
-
},
|
| 627 |
-
{
|
| 628 |
-
"data": {
|
| 629 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 630 |
-
"model_id": "50512a3cad8143f594893cf480751c44",
|
| 631 |
-
"version_major": 2,
|
| 632 |
-
"version_minor": 0
|
| 633 |
-
},
|
| 634 |
-
"text/plain": [
|
| 635 |
-
"tokenizer.json: reconstructing file: 0%| | 0.00B / 17.3MB "
|
| 636 |
-
]
|
| 637 |
-
},
|
| 638 |
-
"metadata": {},
|
| 639 |
-
"output_type": "display_data"
|
| 640 |
-
},
|
| 641 |
-
{
|
| 642 |
-
"data": {
|
| 643 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 644 |
-
"model_id": "0b00905f31f24fe29270a7cd8718a687",
|
| 645 |
-
"version_major": 2,
|
| 646 |
-
"version_minor": 0
|
| 647 |
-
},
|
| 648 |
-
"text/plain": [
|
| 649 |
-
"tokenizer.json: downloading bytes: | 0.00B "
|
| 650 |
-
]
|
| 651 |
-
},
|
| 652 |
-
"metadata": {},
|
| 653 |
-
"output_type": "display_data"
|
| 654 |
-
},
|
| 655 |
-
{
|
| 656 |
-
"data": {
|
| 657 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 658 |
-
"model_id": "adf190224e5b4f6fb1a12ec399224bd9",
|
| 659 |
-
"version_major": 2,
|
| 660 |
-
"version_minor": 0
|
| 661 |
-
},
|
| 662 |
-
"text/plain": [
|
| 663 |
-
"special_tokens_map.json: 0%| | 0.00/3.55k [00:00<?, ?B/s]"
|
| 664 |
-
]
|
| 665 |
-
},
|
| 666 |
-
"metadata": {},
|
| 667 |
-
"output_type": "display_data"
|
| 668 |
-
},
|
| 669 |
-
{
|
| 670 |
-
"name": "stderr",
|
| 671 |
-
"output_type": "stream",
|
| 672 |
-
"text": [
|
| 673 |
-
"[transformers] `torch_dtype` is deprecated! Use `dtype` instead!\n"
|
| 674 |
-
]
|
| 675 |
-
},
|
| 676 |
-
{
|
| 677 |
-
"data": {
|
| 678 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 679 |
-
"model_id": "2ef331986d9b49bca7c5da1f9a268634",
|
| 680 |
-
"version_major": 2,
|
| 681 |
-
"version_minor": 0
|
| 682 |
-
},
|
| 683 |
-
"text/plain": [
|
| 684 |
-
"pytorch_model.bin: reconstructing file: 0%| | 0.00B / 2.46GB "
|
| 685 |
-
]
|
| 686 |
-
},
|
| 687 |
-
"metadata": {},
|
| 688 |
-
"output_type": "display_data"
|
| 689 |
-
},
|
| 690 |
-
{
|
| 691 |
-
"data": {
|
| 692 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 693 |
-
"model_id": "fe6b1e3bb94f4453a89aef9d9f9fbe27",
|
| 694 |
-
"version_major": 2,
|
| 695 |
-
"version_minor": 0
|
| 696 |
-
},
|
| 697 |
-
"text/plain": [
|
| 698 |
-
"pytorch_model.bin: downloading bytes: | 0.00B "
|
| 699 |
-
]
|
| 700 |
-
},
|
| 701 |
-
"metadata": {},
|
| 702 |
-
"output_type": "display_data"
|
| 703 |
-
},
|
| 704 |
-
{
|
| 705 |
-
"data": {
|
| 706 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 707 |
-
"model_id": "4581941f200b4e2192e12e85168674c5",
|
| 708 |
-
"version_major": 2,
|
| 709 |
-
"version_minor": 0
|
| 710 |
-
},
|
| 711 |
-
"text/plain": [
|
| 712 |
-
"Loading weights: 0%| | 0/512 [00:00<?, ?it/s]"
|
| 713 |
-
]
|
| 714 |
-
},
|
| 715 |
-
"metadata": {},
|
| 716 |
-
"output_type": "display_data"
|
| 717 |
-
},
|
| 718 |
-
{
|
| 719 |
-
"data": {
|
| 720 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 721 |
-
"model_id": "c852ba6f1e874a149342615ffe3841e6",
|
| 722 |
-
"version_major": 2,
|
| 723 |
-
"version_minor": 0
|
| 724 |
-
},
|
| 725 |
-
"text/plain": [
|
| 726 |
-
"generation_config.json: 0%| | 0.00/189 [00:00<?, ?B/s]"
|
| 727 |
-
]
|
| 728 |
-
},
|
| 729 |
-
"metadata": {},
|
| 730 |
-
"output_type": "display_data"
|
| 731 |
-
},
|
| 732 |
-
{
|
| 733 |
-
"data": {
|
| 734 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 735 |
-
"model_id": "6dfad93be7c54defa17e57c0d9553251",
|
| 736 |
-
"version_major": 2,
|
| 737 |
-
"version_minor": 0
|
| 738 |
-
},
|
| 739 |
-
"text/plain": [
|
| 740 |
-
"model.safetensors: reconstructing file: 0%| | 0.00B / 2.46GB "
|
| 741 |
-
]
|
| 742 |
-
},
|
| 743 |
-
"metadata": {},
|
| 744 |
-
"output_type": "display_data"
|
| 745 |
-
},
|
| 746 |
-
{
|
| 747 |
-
"data": {
|
| 748 |
-
"application/vnd.jupyter.widget-view+json": {
|
| 749 |
-
"model_id": "05f44adbb8dc4aceb7e5a937f2ce9ab6",
|
| 750 |
-
"version_major": 2,
|
| 751 |
-
"version_minor": 0
|
| 752 |
-
},
|
| 753 |
-
"text/plain": [
|
| 754 |
-
"model.safetensors: downloading bytes: | 0.00B "
|
| 755 |
-
]
|
| 756 |
-
},
|
| 757 |
-
"metadata": {},
|
| 758 |
-
"output_type": "display_data"
|
| 759 |
-
},
|
| 760 |
-
{
|
| 761 |
-
"name": "stderr",
|
| 762 |
-
"output_type": "stream",
|
| 763 |
-
"text": [
|
| 764 |
-
"[transformers] Both `max_new_tokens` (=128) and `max_length`(=200) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n",
|
| 765 |
-
"[transformers] Both `max_new_tokens` (=128) and `max_length`(=200) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n",
|
| 766 |
-
"[transformers] Both `max_new_tokens` (=128) and `max_length`(=200) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n"
|
| 767 |
-
]
|
| 768 |
-
},
|
| 769 |
-
{
|
| 770 |
-
"name": "stdout",
|
| 771 |
-
"output_type": "stream",
|
| 772 |
-
"text": [
|
| 773 |
-
"\n",
|
| 774 |
-
"RAW : misir ali series er shera boi gula ki ki\n",
|
| 775 |
-
"NORMALIZED: মিসর আলী সিরিজ er shera boi gula ki ki\n",
|
| 776 |
-
"\n",
|
| 777 |
-
"RAW : humayun ahmed er uponnash gula ki ki\n",
|
| 778 |
-
"NORMALIZED: হুমায়ুন আহমেদ ইর আপননাশ গুলা কি কি\n"
|
| 779 |
-
]
|
| 780 |
-
},
|
| 781 |
-
{
|
| 782 |
-
"name": "stderr",
|
| 783 |
-
"output_type": "stream",
|
| 784 |
-
"text": [
|
| 785 |
-
"[transformers] Both `max_new_tokens` (=128) and `max_length`(=200) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n",
|
| 786 |
-
"[transformers] Both `max_new_tokens` (=128) and `max_length`(=200) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n"
|
| 787 |
-
]
|
| 788 |
-
},
|
| 789 |
-
{
|
| 790 |
-
"name": "stdout",
|
| 791 |
-
"output_type": "stream",
|
| 792 |
-
"text": [
|
| 793 |
-
"\n",
|
| 794 |
-
"RAW : bangla shahitter prothom uponnash konti\n",
|
| 795 |
-
"NORMALIZED: বাংলা শহিটার প্রথম আপোনাশ কান্তি\n",
|
| 796 |
-
"\n",
|
| 797 |
-
"RAW : rabindranath er kobita chai\n",
|
| 798 |
-
"NORMALIZED: রবিন্দ্রানাথের কোবিটা চা\n",
|
| 799 |
-
"\n",
|
| 800 |
-
"RAW : misir ali ke likhechen\n",
|
| 801 |
-
"NORMALIZED: মিসর আলী কে লিক্হেচেন\n"
|
| 802 |
]
|
| 803 |
}
|
| 804 |
],
|
| 805 |
"source": [
|
| 806 |
-
"import
|
| 807 |
-
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
| 808 |
-
"\n",
|
| 809 |
-
"MODEL_NAME = \"facebook/nllb-200-distilled-600M\"\n",
|
| 810 |
-
"\n",
|
| 811 |
-
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
|
| 812 |
"\n",
|
| 813 |
-
"
|
| 814 |
-
"\n",
|
| 815 |
-
"
|
| 816 |
-
"
|
| 817 |
-
"
|
| 818 |
-
" torch_dtype=torch.float16 if device == \"cuda\" else torch.float32\n",
|
| 819 |
-
").to(device)\n",
|
| 820 |
-
"\n",
|
| 821 |
-
"model.eval()\n"
|
| 822 |
]
|
| 823 |
}
|
| 824 |
],
|
|
|
|
| 518 |
},
|
| 519 |
{
|
| 520 |
"cell_type": "code",
|
| 521 |
+
"execution_count": 18,
|
| 522 |
+
"id": "f71e4045",
|
| 523 |
"metadata": {},
|
| 524 |
"outputs": [],
|
| 525 |
+
"source": [
|
| 526 |
+
"prompt = f\"\"\"\n",
|
| 527 |
+
"You are a Bangla Query Normalization Engine.\n",
|
| 528 |
+
"\n",
|
| 529 |
+
"Your task is to convert any English, Banglish (Romanized Bangla), mixed-language, or misspelled query into natural, grammatically correct Bangla.\n",
|
| 530 |
+
"\n",
|
| 531 |
+
"Rules:\n",
|
| 532 |
+
"\n",
|
| 533 |
+
"1. Convert all English and Banglish words into Bangla whenever possible.\n",
|
| 534 |
+
"2. Correct spelling mistakes and transliteration variations.\n",
|
| 535 |
+
"3. Preserve the original meaning exactly.\n",
|
| 536 |
+
"4. Do NOT add, remove, infer, or expand information.\n",
|
| 537 |
+
"5. Do NOT explain anything.\n",
|
| 538 |
+
"6. Do NOT answer the query.\n",
|
| 539 |
+
"7. Do NOT translate proper nouns unless there is a well-known Bangla form.\n",
|
| 540 |
+
"8. Keep author names, book titles, publisher names, and literary terms in their commonly used Bangla forms.\n",
|
| 541 |
+
"9. Output only the normalized Bangla query.\n",
|
| 542 |
+
"10. If the query is already correct Bangla, return it unchanged.\n",
|
| 543 |
+
"\n",
|
| 544 |
+
"Examples:\n",
|
| 545 |
+
"\n",
|
| 546 |
+
"Input: humayun ahmed er first novel\n",
|
| 547 |
+
"Output: হুমায়ূন আহমেদের প্রথম উপন্যাস\n",
|
| 548 |
+
"\n",
|
| 549 |
+
"Input: nondito noroke\n",
|
| 550 |
+
"Output: নন্দিত নরকে\n",
|
| 551 |
+
"\n",
|
| 552 |
+
"Input: bangla sahitter prothom uponnash\n",
|
| 553 |
+
"Output: বাংলা সাহিত্যের প্রথম উপন্যাস\n",
|
| 554 |
+
"\n",
|
| 555 |
+
"Input: রবীন্দ্রনাথের last novel\n",
|
| 556 |
+
"Output: রবীন্দ্রনাথের শেষ উপন্যাস\n",
|
| 557 |
+
"\n",
|
| 558 |
+
"Input: misir ali series\n",
|
| 559 |
+
"Output: মিসির আলী সিরিজ\n",
|
| 560 |
+
"\n",
|
| 561 |
+
"Input: hmuyn ahmed books\n",
|
| 562 |
+
"Output: হুমায়ূন আহমেদের বই\n",
|
| 563 |
+
"\n",
|
| 564 |
+
"Input: বাংলা সাহিত্যের প্রথম উপন্যাস\n",
|
| 565 |
+
"Output: বাংলা সাহিত্যের প্রথম উপন্যাস\n",
|
| 566 |
+
"\n",
|
| 567 |
+
"Normalize the following query and return only the normalized Bangla text:\n",
|
| 568 |
+
"\n",
|
| 569 |
+
"{{The Story of sorotchondro}}\n",
|
| 570 |
+
"\"\"\""
|
| 571 |
+
]
|
| 572 |
},
|
| 573 |
{
|
| 574 |
"cell_type": "code",
|
| 575 |
+
"execution_count": 19,
|
| 576 |
+
"id": "e91893e6",
|
| 577 |
"metadata": {},
|
| 578 |
"outputs": [
|
| 579 |
{
|
| 580 |
"name": "stdout",
|
| 581 |
"output_type": "stream",
|
| 582 |
"text": [
|
| 583 |
+
"\"দ্য স্টোরি অফ সোরোটচন্ড্রো\"\n",
|
| 584 |
+
"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
]
|
| 586 |
}
|
| 587 |
],
|
| 588 |
"source": [
|
| 589 |
+
"from ollama import chat\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
"\n",
|
| 591 |
+
"response = chat(\n",
|
| 592 |
+
" model='translategemma:4b',\n",
|
| 593 |
+
" messages=[{'role': 'user', 'content': prompt}],\n",
|
| 594 |
+
")\n",
|
| 595 |
+
"print(response.message.content)"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
]
|
| 597 |
}
|
| 598 |
],
|