{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bbb1351a", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ['CUDA_VISIBLE_DEVICES'] = ''\n", "os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'" ] }, { "cell_type": "code", "execution_count": 2, "id": "a1d28a1b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/ubuntu/.local/lib/python3.8/site-packages/tensorflow_addons/utils/ensure_tf_install.py:53: UserWarning: Tensorflow Addons supports using Python ops for all Tensorflow versions above or equal to 2.3.0 and strictly below 2.5.0 (nightly versions are not supported). \n", " The versions of TensorFlow you are currently using is 2.6.0 and is not supported. \n", "Some things might work, some things might not.\n", "If you were to encounter a bug, do not file an issue.\n", "If you want to make sure you're using a tested and supported configuration, either change the TensorFlow version or the TensorFlow Addons's version. \n", "You can find the compatibility matrix in TensorFlow Addon's readme:\n", "https://github.com/tensorflow/addons\n", " warnings.warn(\n", "/home/ubuntu/.local/lib/python3.8/site-packages/tensorflow_addons/utils/resource_loader.py:72: UserWarning: You are currently using TensorFlow 2.6.0 and trying to load a custom op (custom_ops/seq2seq/_beam_search_ops.so).\n", "TensorFlow Addons has compiled its custom ops against TensorFlow 2.4.0, and there are no compatibility guarantees between the two versions. \n", "This means that you might get segfaults when loading the custom op, or other kind of low-level errors.\n", " If you do, do not file an issue on Github. This is a known limitation.\n", "\n", "It might help you to fallback to pure Python ops with TF_ADDONS_PY_OPS . To do that, see https://github.com/tensorflow/addons#gpucpu-custom-ops \n", "\n", "You can also change the TensorFlow version installed on your system. You would need a TensorFlow version equal to or above 2.4.0 and strictly below 2.5.0.\n", " Note that nightly versions of TensorFlow, as well as non-pip TensorFlow like `conda install tensorflow` or compiled from source are not supported.\n", "\n", "The last solution is to find the TensorFlow Addons version that has custom ops compatible with the TensorFlow installed on your system. To do that, refer to the readme: https://github.com/tensorflow/addons\n", " warnings.warn(\n", "/home/ubuntu/.local/lib/python3.8/site-packages/malaya_boilerplate/frozen_graph.py:35: UserWarning: Cannot import beam_search_ops from Tensorflow Addons, ['malaya.jawi_rumi.deep_model', 'malaya.phoneme.deep_model', 'malaya.rumi_jawi.deep_model', 'malaya.stem.deep_model'] will not available to use, make sure Tensorflow Addons version >= 0.12.0\n", " warnings.warn(\n" ] } ], "source": [ "import malaya" ] }, { "cell_type": "code", "execution_count": 3, "id": "2069aea0", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning : `load_model` does not return WordVectorModel or SupervisedModel any more, but a `FastText` object which is very similar.\n" ] } ], "source": [ "fast_text = malaya.language_detection.fasttext()" ] }, { "cell_type": "code", "execution_count": 4, "id": "f67f79ce", "metadata": {}, "outputs": [], "source": [ "with open('train-en/left.txt') as fopen:\n", " left = fopen.read().split('\\n')\n", "\n", "with open('train-en/right.txt') as fopen:\n", " right = fopen.read().split('\\n')" ] }, { "cell_type": "code", "execution_count": 5, "id": "4b31c10f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('Most of them are teenagers or in their 20s.',\n", " 'Kebanyakan mereka ini adalah remaja ataupun dalam lengkongan 20 an.')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "left[0], right[0]" ] }, { "cell_type": "code", "execution_count": 6, "id": "6c8931b8", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████████████████████████████████████████████████████| 3807616/3807616 [05:54<00:00, 10734.29it/s]\n" ] } ], "source": [ "from tqdm import tqdm\n", "\n", "lefts, rights, rejected = [], [], []\n", "for i in tqdm(range(len(left))):\n", " if len(left[i]) and len(right[i]):\n", " lang_left, lang_right = fast_text.predict([left[i], right[i]])\n", " if lang_left not in ['malay', 'eng', 'rojak', 'manglish']:\n", " rejected.append((left[i], right[i]))\n", " continue\n", " if lang_right not in ['malay', 'rojak']:\n", " rejected.append((left[i], right[i]))\n", " continue\n", " lefts.append(left[i])\n", " rights.append(right[i])" ] }, { "cell_type": "code", "execution_count": 7, "id": "84d686df", "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/plain": [ "(3419053, 3419053, 388563)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(lefts), len(rights), len(rejected)" ] }, { "cell_type": "code", "execution_count": 8, "id": "caddea1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(') \"Commercial-free subscription is where we can compete. It\\'s our best shot,\" says Hastings. Netflix offers unlimited DVDs by mail and unlimited instant streaming to computers and TVs for $8.99 a month. He decided early on not to compete with pay-per-view purveyors like HBO (TWX) and the and the cable companies. And recently, he decided not to go head to head against Redbox. That\\'s the fast-growing startup, owned by COINSTAR, that places kiosks-15,000 TO DATE-in supermarkets and other heavy-traffic locales. Videos cost $1. Despite the disruption and confusion around media distribution-or maybe because of it-Hastings is clear on his game. An engineer by training and a Microsoft (MSFT) board member, he\\'s determined, he says, to make video-watching more personal and more satisfying, via technology, of course. He looks forward to the day when an Internet browser is built into every television-TK years from now, he believes.',\n", " '\"\" Langganan bebas komersil adalah tempat kami boleh bersaing. Ini adalah peluang terbaik kami, \"kata Hastings. Netflix menawarkan DVD tanpa had melalui pos dan streaming segera tanpa had ke komputer dan TV dengan harga $ 8.99 sebulan. Dia memutuskan sejak awal untuk tidak bersaing dengan penyedia bayar per tontonan seperti HBO (TWX) dan syarikat kabel. Dan baru-baru ini, dia memutuskan untuk tidak bertanding melawan Redbox. Itulah permulaan yang berkembang pesat, yang dimiliki oleh COINSTAR, yang menempatkan kiosk-15,000 HINGGA TARIKH-di pasar raya dan kawasan lalu lintas lebat lain. Video berharga $ 1. Walaupun terdapat gangguan dan kekeliruan di sekitar pengedaran media-atau mungkin kerana itu-Hastings jelas pada permainannya. Seorang jurutera dengan latihan dan ahli lembaga Microsoft (MSFT), dia bertekad, katanya, untuk menjadikan menonton video lebih peribadi dan lebih memuaskan, melalui teknologi, tentu saja. Dia menantikan hari ketika penyemak imbas Internet dibina di setiap televisyen-TK tahun dari sekarang, dia percaya.')" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rejected[0]" ] }, { "cell_type": "code", "execution_count": 9, "id": "2a160dad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['eng', 'ind']" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fast_text.predict(list(rejected[0]))" ] }, { "cell_type": "code", "execution_count": 10, "id": "251a1583", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(') \"Commercial-free subscription is where we can compete. It\\'s our best shot,\" says Hastings. Netflix offers unlimited DVDs by mail and unlimited instant streaming to computers and TVs for $8.99 a month. He decided early on not to compete with pay-per-view purveyors like HBO (TWX) and the and the cable companies. And recently, he decided not to go head to head against Redbox. That\\'s the fast-growing startup, owned by COINSTAR, that places kiosks-15,000 TO DATE-in supermarkets and other heavy-traffic locales. Videos cost $1. Despite the disruption and confusion around media distribution-or maybe because of it-Hastings is clear on his game. An engineer by training and a Microsoft (MSFT) board member, he\\'s determined, he says, to make video-watching more personal and more satisfying, via technology, of course. He looks forward to the day when an Internet browser is built into every television-TK years from now, he believes.',\n", " '\"\" Langganan bebas komersil adalah tempat kami boleh bersaing. Ini adalah peluang terbaik kami, \"kata Hastings. Netflix menawarkan DVD tanpa had melalui pos dan streaming segera tanpa had ke komputer dan TV dengan harga $ 8.99 sebulan. Dia memutuskan sejak awal untuk tidak bersaing dengan penyedia bayar per tontonan seperti HBO (TWX) dan syarikat kabel. Dan baru-baru ini, dia memutuskan untuk tidak bertanding melawan Redbox. Itulah permulaan yang berkembang pesat, yang dimiliki oleh COINSTAR, yang menempatkan kiosk-15,000 HINGGA TARIKH-di pasar raya dan kawasan lalu lintas lebat lain. Video berharga $ 1. Walaupun terdapat gangguan dan kekeliruan di sekitar pengedaran media-atau mungkin kerana itu-Hastings jelas pada permainannya. Seorang jurutera dengan latihan dan ahli lembaga Microsoft (MSFT), dia bertekad, katanya, untuk menjadikan menonton video lebih peribadi dan lebih memuaskan, melalui teknologi, tentu saja. Dia menantikan hari ketika penyemak imbas Internet dibina di setiap televisyen-TK tahun dari sekarang, dia percaya.'),\n", " ('Organized by the Football Association of England, the event is a showcase for amateur players and is considered more than a show.',\n", " 'Diuruskan oleh Persatuan Bola Sepak England, acara ini hanya menjadi acara bagi pemain amatur dan lebih dianggap sebagai satu pertunjukan daripada satu pertandingan.'),\n", " ('Kartini Day is celebrated every April 21 of each year.',\n", " 'Hari Kartini yang dirayakan setiap tanggal 21 April setiap tahunnya.'),\n", " ('After Blac Chyna and Rob Kardashian canceled two promotional appearances, Rob\\'s former stepbrother Brody Jenner had some snide things to say about the engaged couple. \"That\\'s what you guys get for hiring those 2...Sorry not sorry,\" he wrote on Instagram. The \"Hills\" alum\\'s comment has since been deleted. Chyna, who is pregnant with Rob\\'s baby, was expected to host a party with her baby daddy on Friday at OMH nightclub in Hollywood. ROB KARDASHIAN, BLAC CHYNA IN TALKS FOR E! REALITY SHOW ABOUT BABY. They were then going to fly into the Garden State to host another bash at Harrah\\'s in Atlantic City on Saturday. Chyna later apologized via Instagram, but like Brody, deleted the comment. \"Sorry LA & Atlantic City,\" the model wrote on Instagram. \"I really wasn\\'t feeling well LAST night which fell over to this MORNING causing us to miss our flight, Rob and I want to apologize for missing these events for we were looking forward to them as well but new dates are coming soon\"!',\n", " 'Setelah Blac Chyna dan Rob Kardashian membatalkan dua penampilan promosi, bekas saudara tiri Rob, Brody Jenner, mempunyai beberapa hal yang tidak dapat dilupakan mengenai pasangan yang bertunang. \"Itulah yang kalian dapat kerana mempekerjakan 2 orang itu ... Maaf tidak maaf,\" tulisnya di Instagram. Komen tawas \"Hills\" sejak itu dihapuskan. Chyna, yang mengandung bayi Rob, dijangka mengadakan pesta dengan ayah bayinya pada hari Jumaat di kelab malam OMH di Hollywood. ROB KARDASHIAN, BLAC CHYNA DI BICARA UNTUK E! REALITI MENUNJUKKAN BAYI. Mereka kemudian akan terbang ke Garden State untuk menjadi tuan rumah pertunjukan lain di Harrah\\'s di Atlantic City pada hari Sabtu. Chyna kemudian meminta maaf melalui Instagram, tetapi seperti Brody, menghapus komen tersebut. \"Maaf LA & Atlantic City,\" tulis model itu di Instagram. \"Saya benar-benar tidak merasa sihat malam TERAKHIR yang jatuh ke PAGI ini menyebabkan kami terlepas penerbangan kami, Rob dan saya ingin meminta maaf kerana kehilangan acara ini kerana kami juga menantikannya tetapi tarikh baru akan datang tidak lama lagi\"!'),\n", " ('Darwin\\'s book is based on his adventures with the \"HMS Beagle\"; this book sparked a famous letter from Wallace , sent within the time covered \" Malay Archipelago \" Wallace during a stay in Ternate , who described the overall frame theory of evolution by natural selection.',\n", " 'Buku Darwin berlandaskan pengembaraan beliau dengan kapal \"HMS Beagle\"; penerbitan buku ini mencetuskan sebuah surat masyhur daripada Wallace, yang dikirim dalam tempoh waktu yang diliputi \"Kepulauan Melayu\" semasa Wallace menginap di Ternate, yang memerikan kerangaka teori evolusi melalui pemilihan semula jadi.'),\n", " ('He was bleeding - his father Pierre Rutare was a Tutsi architect from Rwanda and his mother Miranda van Haver was a housewife from Flanders.',\n", " 'Beliau berdarah kacukan - ayahnya Pierre Rutare seorang arkitek kaum Tutsi dari Rwanda manakala ibunya Miranda van Haver seorang suri rumah dari Flanders.'),\n", " ('Daniel Bedingfield Daniel Bedingfield (born December 3, 1979) is a New Zealand national singer.',\n", " 'Daniel Bedingfield Daniel Bedingfield (lahir 3 Disember 1979) merupakan penyanyi berkebangsaan New Zealand.'),\n", " ('During this moment of protection, the settler colonies of Australia, New Zealand, Canada and South Africa became just as important as the Caribbean had been beforehand in establishing the principles underpinning modern humanitarianism. With policies for the protection of individual Indigenous peoples from harm at the hands of settlers - and the assignment of magisterial powers to protectors of Aborigines, so that they could, in theory at least, prosecute murderous settlers - we might even discern the origin of an early \"human rights\" principle. But very few settlers were ever convicted by the protectors - and accompanying the protective impulse was a \"civilising mission\" that would in time lead to invidious policies such as taking Indigenous and so-called \"half-caste\" children away from their parents and subjecting Indigenous peoples to the neglect and abuse of the residential schooling system in Australia and Canada.',\n", " 'Selama masa perlindungan ini, koloni-koloni pemukim di Australia, New Zealand, Kanada dan Afrika Selatan menjadi sama pentingnya dengan Caribbean sebelumnya dalam menetapkan prinsip-prinsip yang mendasari kemanusiaan moden. Dengan dasar-dasar untuk melindungi individu-individu Orang Asli dari bahaya di tangan peneroka - dan penugasan kuasa magisterial kepada pelindung Orang Asli, sehingga mereka, secara teori sekurang-kurangnya, dapat mendakwa peneroka pembunuh - kita bahkan dapat mengetahui asal usul prinsip \"hak asasi manusia\" awal. Tetapi sangat sedikit peneroka yang pernah dihukum oleh pelindung - dan menyertai dorongan pelindung adalah \"misi beradab\" yang pada waktunya akan membawa kepada dasar-dasar berbahaya seperti mengambil anak-anak Orang Asli dan yang disebut \"separuh kasta\" dari ibu bapa mereka dan menundukkan Masyarakat pribumi terhadap pengabaian dan penyalahgunaan sistem persekolahan kediaman di Australia dan Kanada.'),\n", " ('We actually need a lot of TVs and radios.',\n", " 'Sebenarnya kami membutuhkan banyak TV dan radio.'),\n", " ('Pandu said the development of the airport located in Temon District, Kulonprogo Regency, Yogyakarta for the first international operation was close to 100 percent.',\n", " 'Pandu mengatakan, progres pembangunan bandara yang terletak di Kecamatan Temon, Kabupaten Kulonprogo, Yogyakarta untuk operasional internasional pertama sudah mendekati 100 persen.')]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rejected[:10]" ] }, { "cell_type": "code", "execution_count": 11, "id": "3e3235f9", "metadata": {}, "outputs": [], "source": [ "with open('en-ms-left.train', 'a') as fopen:\n", " for i in range(len(lefts)):\n", " fopen.write(f'{lefts[i]}\\n')" ] }, { "cell_type": "code", "execution_count": 12, "id": "cf6c7af7", "metadata": {}, "outputs": [], "source": [ "with open('en-ms-right.train', 'a') as fopen:\n", " for i in range(len(rights)):\n", " fopen.write(f'{rights[i]}\\n')" ] }, { "cell_type": "code", "execution_count": 13, "id": "f235ef24", "metadata": {}, "outputs": [], "source": [ "with open('test-en/left.txt') as fopen:\n", " left_test = fopen.read().split('\\n')\n", "\n", "with open('test-en/right.txt') as fopen:\n", " right_test = fopen.read().split('\\n')" ] }, { "cell_type": "code", "execution_count": 14, "id": "82035c77", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████████████████████████████████████████████████████████| 77707/77707 [00:07<00:00, 10908.87it/s]\n" ] } ], "source": [ "from tqdm import tqdm\n", "\n", "lefts_test, rights_test, rejected_test = [], [], []\n", "for i in tqdm(range(len(left_test))):\n", " if len(left_test[i]) and len(right_test[i]):\n", " lang_left, lang_right = fast_text.predict([left_test[i], right_test[i]])\n", " if lang_left not in ['malay', 'eng', 'rojak', 'manglish']:\n", " rejected_test.append((left_test[i], right_test[i]))\n", " continue\n", " if lang_right not in ['malay', 'rojak']:\n", " rejected_test.append((left_test[i], right_test[i]))\n", " continue\n", " lefts_test.append(left_test[i])\n", " rights_test.append(right_test[i])" ] }, { "cell_type": "code", "execution_count": 15, "id": "f8de0575", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(69743, 69743, 7964)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(lefts_test), len(rights_test), len(rejected_test)" ] }, { "cell_type": "code", "execution_count": 16, "id": "b43b0f4f", "metadata": {}, "outputs": [], "source": [ "with open('en-ms-left.test', 'a') as fopen:\n", " for i in range(len(lefts_test)):\n", " fopen.write(f'{lefts_test[i]}\\n')" ] }, { "cell_type": "code", "execution_count": 17, "id": "851303a7", "metadata": {}, "outputs": [], "source": [ "with open('en-ms-right.test', 'a') as fopen:\n", " for i in range(len(rights_test)):\n", " fopen.write(f'{rights_test[i]}\\n')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }