{ "cells": [ { "cell_type": "markdown", "id": "b1b28232-b65d-41ce-88de-fd70b93a528d", "metadata": {}, "source": [ "# Imports" ] }, { "cell_type": "code", "execution_count": 1, "id": "abb5186b-ee67-4e1e-882d-3d8d5b4575d4", "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "from pathlib import Path\n", "import pickle\n", "from tqdm.auto import tqdm\n", "\n", "from haystack.nodes.preprocessor import PreProcessor" ] }, { "cell_type": "code", "execution_count": 2, "id": "c4b82ea2-8b30-4c2e-99f0-9a30f2f1bfb7", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/ec2-user/arabic-wiki\n" ] } ], "source": [ "proj_dir = Path.cwd().parent\n", "print(proj_dir)" ] }, { "cell_type": "markdown", "id": "76119e74-f601-436d-a253-63c5a19d1c83", "metadata": {}, "source": [ "# Config" ] }, { "cell_type": "code", "execution_count": 3, "id": "f6f74545-54a7-4f41-9f02-96964e1417f0", "metadata": { "tags": [] }, "outputs": [], "source": [ "files_in = list((proj_dir / 'data/consolidated').glob('*.ndjson'))\n", "folder_out = proj_dir / 'data/processed'\n", "folder_out_str = str(folder_out)" ] }, { "cell_type": "markdown", "id": "509f41f9-a59f-4171-b61f-ae0cf756fc92", "metadata": {}, "source": [ "# Analysis" ] }, { "cell_type": "code", "execution_count": 4, "id": "f0cbd1c9-3105-4940-85dc-c01ccaa217c7", "metadata": { "tags": [] }, "outputs": [], "source": [ "with open(files_in[0], 'r') as f:\n", " articles = [json.loads(line) for line in f]" ] }, { "cell_type": "code", "execution_count": 5, "id": "004aae7b-1a2f-4a0b-9450-5d80475258b1", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'content': 'الماء مادةٌ شفافةٌ عديمة اللون والرائحة، وهو المكو...',\n", " 'meta': {'id': '7',\n", " 'revid': '2080427',\n", " 'title': 'ماء',\n", " 'url': 'https://ar.wikipedia.org/wiki?curid=7'}}\n" ] } ], "source": [ "from pprint import pprint\n", "article = articles[0].copy()\n", "article['content'] = article['content'][:50] + '...'\n", "pprint(article)" ] }, { "cell_type": "markdown", "id": "6a643cf2-abce-48a9-b4e0-478bcbee28c3", "metadata": {}, "source": [ "# Preprocessing" ] }, { "cell_type": "markdown", "id": "a8f9630e-447e-423e-9f6c-e1dbc654f2dd", "metadata": {}, "source": [ "Its important to choose good pre-processing options. \n", "\n", "Clean whitespace helps each stage of RAG. It adds noise to the embeddings, and wastes space when we prompt with it.\n", "\n", "I chose to split by word as it would be tedious to tokenize here, and that doesnt scale well. The context length for most embedding models ends up being 512 tokens. We saw this within a good z-score is ~225 token.\n", "\n", "I like to respect the sentence boundary, thats why I gave a ~50 word buffer." ] }, { "cell_type": "code", "execution_count": 6, "id": "18807aea-24e4-4d74-bf10-55b24f3cb52c", "metadata": { "tags": [] }, "outputs": [], "source": [ "pp = PreProcessor(clean_whitespace = True,\n", " clean_header_footer = False,\n", " clean_empty_lines = True,\n", " remove_substrings = None,\n", " split_by='word',\n", " split_length = 225,\n", " split_overlap = 50,\n", " split_respect_sentence_boundary = True,\n", " tokenizer_model_folder = None,\n", " id_hash_keys = None,\n", " progress_bar = False,\n", " add_page_number = False,\n", " max_chars_check = 10_000)" ] }, { "cell_type": "markdown", "id": "3c1ab000-6574-485e-87f6-cc210f6e8a61", "metadata": {}, "source": [ "When we break a wikipedia article up, we lose some of the context. The local context is somewhat preserved by the `split_overlap`. Im trying to preserve the global context by adding a prefix that has the article's title.\n", "\n", "You could enhance this with the summary as well. This is mostly to help the retrieval step of RAG. Note that the way Im doing it alters some of `haystack`'s features like the hash and the lengths, but those arent too necessary. \n", "\n", "A more advanced way for many business applications would be to summarize the document and add that as a prefix for sub-documents.\n", "\n", "One last thing to note, is that it would be prudent (in some use-cases) to preserve the original document without the summary to give to the reader (retrieve with the summary but prompt without), but since this is a demo use-case I wont be doing that." ] }, { "cell_type": "code", "execution_count": 7, "id": "63871bdd-0369-4dd7-a65e-ccba29baed44", "metadata": {}, "outputs": [], "source": [ "with open(files_in[0], 'r', encoding='utf-8') as f:\n", " articles = [json.loads(line) for line in f]" ] }, { "cell_type": "code", "execution_count": 8, "id": "5c3b48b7-3c0f-41ba-a423-b716649efcaa", "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "We found one or more sentences whose word count is higher than the split length.\n", "Document e3e2bf8b3399979cb16219b175041b4d is 11336 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 91ad1d1a24e93abacabd5a5478a96977 is 14251 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 1625c431c0fcfaf81c13e0da59071a81 is 13395 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 790d3b2d94a68cbec6d77f3c15d0e679 is 13484 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document e2dcf80a1f9dfc118aed059255f9b90b is 13217 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 3min 31s, sys: 95.1 ms, total: 3min 31s\n", "Wall time: 3min 31s\n" ] } ], "source": [ "%%time\n", "documents = pp.process(articles)" ] }, { "cell_type": "code", "execution_count": 9, "id": "de6e1690-131a-41d1-a473-c908c2e40939", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Document 91ad1d1a24e93abacabd5a5478a96977 is 14251 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document e3e2bf8b3399979cb16219b175041b4d is 11336 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 1625c431c0fcfaf81c13e0da59071a81 is 13395 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 790d3b2d94a68cbec6d77f3c15d0e679 is 13484 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document e2dcf80a1f9dfc118aed059255f9b90b is 13217 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 6.86 s, sys: 1.31 s, total: 8.16 s\n", "Wall time: 1min 33s\n" ] } ], "source": [ "%%time\n", "import os\n", "import concurrent.futures\n", "\n", "def parallel_preprocessing(articles):\n", " # Utility function to divide the articles into smaller chunks\n", " def chunkify(lst, n):\n", " \"\"\"Yield successive n-sized chunks from lst.\"\"\"\n", " for i in range(0, len(lst), n):\n", " yield lst[i:i + n]\n", "\n", " # Size of each chunk. Adjust based on your needs.\n", " CHUNK_SIZE = 10_000 \n", " article_chunks = list(chunkify(articles, CHUNK_SIZE))\n", "\n", " # Number of processes to run in parallel.\n", " # Use all available CPUs, but you can reduce the number if you wish to leave some CPUs free.\n", " NUM_PROCESSES = os.cpu_count() \n", "\n", " with concurrent.futures.ProcessPoolExecutor(max_workers=NUM_PROCESSES) as executor:\n", " documents_list = list(executor.map(pp.process, article_chunks))\n", "\n", " # Flatten the documents_list to get a single list of documents\n", " documents = [doc for sublist in documents_list for doc in sublist]\n", " return documents\n", "\n", "documents = parallel_preprocessing(articles)\n" ] }, { "cell_type": "code", "execution_count": 10, "id": "dab1658a-79a7-40f2-9a8c-1798e0d124bf", "metadata": { "tags": [] }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a4d4ade8158144c6a06f072b550157c3", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/23 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Document 91ad1d1a24e93abacabd5a5478a96977 is 14251 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document e3e2bf8b3399979cb16219b175041b4d is 11336 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 1625c431c0fcfaf81c13e0da59071a81 is 13395 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 790d3b2d94a68cbec6d77f3c15d0e679 is 13484 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document e2dcf80a1f9dfc118aed059255f9b90b is 13217 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bcb8fe6999ec408f99ef25c96c85c7b3", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/243068 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Document 2693d73124e824fb45633e34189a6226 is 14375 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6ac231651a214181be49584511c97fe9", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/104065 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c43b5ac1f3b84cac8f2715c5dcf21fb8", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/123154 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a1b8201fc0ba44cf9ac938556c7effc8", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/135965 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "58ce68b1b5044b0eb1c457495159cb6d", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/99138 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b80a37f6986e478d85397f7295b67079", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/83678 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8197d71a396e47588699f22e44c843af", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/30573 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "39024c19258b41c4bcd7b6e5c0617d54", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/78957 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "aa26a27b522448b3bc2808f8ad650a28", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/86327 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3aae87d4a40d4e9e937646f02c969bb2", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/83111 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "16038478b51a422d8ed7d597c9812999", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/92664 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0b9ea31fc970402f8368b4be64d91546", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/66404 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "710bf094621c4472bc6d3973619627df", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/62844 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0bae815b7b7448978fd042b6381b63ba", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/59349 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "483c99d5547a4bedb10802f9bbe414d3", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/52554 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Document c55a744420239d9865b23f9ff7ab37cc is 23179 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 991fef35ead593c41f1dc73224ed7799 is 13179 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "34288f7c2437440ab07134116a6f5bf2", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/34240 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c6b95ccc5799488980af6f73ab564c8b", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/35933 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Document c4ae5d66606dcc644293946f8f5c7cab is 10612 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c6794c5150274e5cb2a09c52bfcf4c1a", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/64575 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5aaf9358178d4daf9169a14cd71aa20f", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/94244 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Document 1d1357a32c6cd115525ceb0590e6d67d is 11314 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document eca1c79de6ca898903e5db0a44a54803 is 24659 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n", "Document 8a59ff0086cc7772046f54a065566ff9 is 14659 characters long after preprocessing, where the maximum length should be 10000. Something might be wrong with the splitting, check the document affected to prevent issues at query time. This document will be now hard-split at 10000 chars recursively.\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "102f3b5a0c5e46f69742b9f41cc79928", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/124472 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3e4803f9fc3d405eac97a64489c0d7e0", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/121849 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d2b4c133d207446c96b4e576aac15bf7", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/147110 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1cbd39af41ef4b20a8bc1bea7fe8186f", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/70322 [00:00<?, ?it/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 2min 21s, sys: 20.1 s, total: 2min 41s\n", "Wall time: 13min 36s\n" ] } ], "source": [ "%%time\n", "for file_in in tqdm(files_in):\n", " # Load articles\n", " with open(file_in, 'r', encoding='utf-8') as f:\n", " articles = [json.loads(line) for line in f]\n", " \n", " # Preprocess articles\n", " documents = parallel_preprocessing(articles)\n", " \n", " # Prefix each document's content\n", " for document in tqdm(documents):\n", " if document.meta['_split_id'] != 0:\n", " document.content = f'عنوان: {document.meta[\"title\"]}. ' + document.content\n", " \n", " processed_articles = [document.to_dict() for document in documents]\n", " with open(folder_out/file_in.name, 'w', encoding='utf-8') as f:\n", " for article in processed_articles:\n", " json_str = json.dumps(article, ensure_ascii=False)\n", " f.write(json_str + '\\n')\n", " " ] }, { "cell_type": "markdown", "id": "72c1849c-1f4d-411f-b74b-6208b1e48217", "metadata": {}, "source": [ "## Pre-processing Examples" ] }, { "cell_type": "code", "execution_count": 11, "id": "02c1c6c8-6283-49a8-9d29-c355f1b08540", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "<Document: {'content': 'عشاء كارين هو من سلسلة مطاعم استرالية يهدف عمداً عن تجربة تناول طعام غير سارَة ويتم توجيه الموظفين لإهانة العملاء طوال وجباتهم.\\nاقتبس اسم المطعم من المصطلح العامي على الإنترنت (كارين) والذي يستخدم لوصف امرأة بيضاء مسنة وقحة بشكل نمطي.\\nتاريخ المطعم.\\nتم إنشاء السلسلة في أستراليا (سيدني) في عام 2021 من قبل إيدين ليفن وجيمس فاريل. المطعم ذو طابع خاص يعتمد على خدمة تجربة طعام غير سارة حيث يدفع العملاء للموظفين لإهانتهم وكان من المفترض ان يكون المطعم مطعماً منبثقاً لمدة ستة أشهر في وورلد سكوير.\\nاثارت فكرة المطعم في البداية ردات فعل متغايرة مما أثار الخوف بشأن ما إذا كانت الإهانات المتبادلة من الممكن ان تعرض الموظفين لسوء المعاملة من قبل العملاء.\\nاسم (كارين) هو إشارة إلى الإسم المستخدم في الميمات (النكت التي تنشهر بسرعة في مواقع التواصل) لوصف امرأة بيضاء في منتصف العمر ووقحة بشكل نمطي.\\nيطلب من الموظفين ارتداء شخصية وقحة والسخرية من العملاء بشكل هزلي اثناء تناول وجباتهم ومن المتوقع ان يعيد العملاء هذا السلوك من خلال التصرف بوقاحة تجاه الموظفين ومع ذلك يُحظر على العملاء والموظفين استخدام الإهانات العنصرية أو التحيز الجنسي أو رهاب المثلية الجنسية.\\nتتضمن العديد من هذه التبادلات لغة نابية ويجب ان يكون برفقة الاشخاص اللذين يقلون عن 16 عاماََ بالغين.\\nكما يمكن لمالكي بطاقة هوية تظهر ان اسمهم كارين الحصول على مشروب مجاني.\\n', 'content_type': 'text', 'score': None, 'meta': {'id': '8974231', 'revid': '593870', 'url': 'https://ar.wikipedia.org/wiki?curid=8974231', 'title': 'مطعم عشاء كارين', '_split_id': 0, '_split_overlap': [{'doc_id': '288196225044b53e6ff86f2485257a0a', 'range': (790, 1225)}]}, 'id_hash_keys': ['content'], 'embedding': None, 'id': '1af84f3b4cc6a9f1018f2f80b4fd3ba7'}>" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "documents[0]" ] }, { "cell_type": "code", "execution_count": 12, "id": "b34890bf-9dba-459a-9b0d-aa4b5929cbe8", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "<Document: {'content': 'عنوان: مطعم عشاء كارين. يطلب من الموظفين ارتداء شخصية وقحة والسخرية من العملاء بشكل هزلي اثناء تناول وجباتهم ومن المتوقع ان يعيد العملاء هذا السلوك من خلال التصرف بوقاحة تجاه الموظفين ومع ذلك يُحظر على العملاء والموظفين استخدام الإهانات العنصرية أو التحيز الجنسي أو رهاب المثلية الجنسية.\\nتتضمن العديد من هذه التبادلات لغة نابية ويجب ان يكون برفقة الاشخاص اللذين يقلون عن 16 عاماََ بالغين.\\nكما يمكن لمالكي بطاقة هوية تظهر ان اسمهم كارين الحصول على مشروب مجاني.\\nيرتكز المطعم علو وجبات العشاء الأمريكية في خمسينات القرن الماضي وتتميز القائمة بالهامبرغر وأجنحة الدجاج.\\nأصبح محتوى شائع لوسائل التواصل الإجتماعي خصوصاً على منصة (تيك توك) حيث نشر العملاء مقاطع فيديو لتفاعلاتهم مع الموظفين.\\nفتحت السلسلة في مواقع في المملكة المتحدة والولايات المتحدة ونيوزيلندا.\\nفي شهر أغسطس سنة 2022 اثار المطعم جدلاً بعد ان انتشر مقطع يُظهر فيه أحد موظفي فريق العمل في منطقة بريزبين يتصرف بشكل غير لائق على منصة تيك توك حيث القى تعليقات غير لائقة موجهة إلى زبونة قاصر ووالدها الذي كان يشاركها الطعام بإتهامه انه يمارس الرذيلة مع الأطفال، فقام المتحدث باسم السلسلة بالرد بإنهم اصيبو بخيبة أمل بسبب السلوك وأن الحادث يتعارض مع إرشاداتهم.', 'content_type': 'text', 'score': None, 'meta': {'id': '8974231', 'revid': '593870', 'url': 'https://ar.wikipedia.org/wiki?curid=8974231', 'title': 'مطعم عشاء كارين', '_split_id': 1, '_split_overlap': [{'doc_id': '1af84f3b4cc6a9f1018f2f80b4fd3ba7', 'range': (0, 435)}]}, 'id_hash_keys': ['content'], 'embedding': None, 'id': '288196225044b53e6ff86f2485257a0a'}>" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "documents[1]" ] }, { "cell_type": "code", "execution_count": 13, "id": "e6f50c27-a486-47e9-ba60-d567f5e530db", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "<Document: {'content': 'نيكولاي فليفا والمعروف أيضًا باسم نيكو فليفا (1840 - 4 أغسطس عام 1920) هو سياسي وصحفي سياسي ومحامي أفلاقي ومن ثم روماني. اشتهر بانخراطه في المجريات السياسية ونزعته الوطنية الصريحة التي كادت تصل إلى حد الديماغوجية. اختبر كافة الصيغ السياسية التي يسمح بها نظام الحزبين في رومانيا. دام حضوره على الساحة العامة عقودًا من الزمن، شغل خلالها مقعدًا في جمعية النواب وتولى منصب عمدة مدينة بوخارست خلال الفترة الممتدة من عام 1884 حتى عام 1886.\\nباشر فليفا مسيرته السياسية مع الحزب الليبرالي الوطني الذي ساعد على تأسيسه وتمثيله أمام القضاء، ولكنه اتجه في ما بعد إلى معارضة احتكار الحزب للسلطة. حاول إنشاء حزب ثالث ودخل في مفاوضات من أجل اعتماد برامج سياسية مشتركة خاصة بقوى المعارضة المختلفة ومن بينها حزب المحافظين وجمعية جونيما في ظل الإدارات الليبرالية الوطنية المتعاقبة. ذاع صيته عندما تورط في فضيحتين كبيرتين خلال ثمانينيات القرن التاسع عشر حين أدى استهزائه بسلطة الحزب الليبرالي الوطني إلى اندلاع معارك في الشوارع ووقوع حادثتي إطلاق النار منفصلتين. اعتُبرت الجماعات الموالية لفليفا الصوت الرائد المعبر عن سخط الطبقة الوسطى وقتذاك، وشكلت إحدى التيارات التي دفعت باتجاه تبني حق الاقتراع العام للذكور.\\nعاد فليفا إلى المعسكر الليبرالي الوطني بعد منعه من تولي حقائب وزارية ريادية في الحكومات المحافظة، وأصبح وزيرًا للشؤون الداخلية خلال الفترة من عام 1895 حتى عام 1896. ', 'content_type': 'text', 'score': None, 'meta': {'id': '9044009', 'revid': '1673186', 'url': 'https://ar.wikipedia.org/wiki?curid=9044009', 'title': 'نيكولاي فليفا', '_split_id': 0, '_split_overlap': [{'doc_id': '188181b1026773d720383c7e7307b241', 'range': (943, 1257)}]}, 'id_hash_keys': ['content'], 'embedding': None, 'id': 'af5cda4722fa2a961bef66de8a6b3e17'}>" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "documents[10102]" ] }, { "cell_type": "code", "execution_count": 14, "id": "5485cc27-3d3f-4b96-8884-accf5324da2d", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2094596\n" ] } ], "source": [ "!cat \"$folder_out_str\"/*.ndjson | wc -l" ] }, { "cell_type": "code", "execution_count": null, "id": "c5833dba-1bf6-48aa-be6f-0d70c71e54aa", "metadata": {}, "outputs": [], "source": [] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }