KPI-AI-team commited on
Commit
a50f7e0
·
verified ·
1 Parent(s): aa0e124

Upload 2 files

Browse files

uploaded data processing files

Files changed (2) hide show
  1. data_preprocessing.ipynb +309 -0
  2. environment.yml +0 -0
data_preprocessing.ipynb ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import pandas as pd \n",
10
+ "import numpy as np \n",
11
+ "import nltk\n",
12
+ "import os\n",
13
+ "import sklearn\n",
14
+ "import parquet"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": 7,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "data1 = pd.read_parquet(\"news-00000-of-00007-0ff1ec222cd690f2.parquet\")\n",
24
+ "data2 = pd.read_parquet(\"news-00001-of-00007-7c273f5de9017dc5.parquet\")\n",
25
+ "data3 = pd.read_parquet(\"telegram_blogs-00000-of-00001-80087cf60adbe6d4.parquet\")"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": null,
31
+ "metadata": {},
32
+ "outputs": [],
33
+ "source": []
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 21,
38
+ "metadata": {},
39
+ "outputs": [],
40
+ "source": [
41
+ "# Extract the 'text' column from each DataFrame\n",
42
+ "texts1 = data1['text']\n",
43
+ "texts2 = data2['text']\n",
44
+ "texts3 = data3['text']\n",
45
+ "\n",
46
+ "# Concatenate the 'text' columns from all three DataFrames\n",
47
+ "all_texts = pd.concat([texts1, texts2, texts3], ignore_index=True)\n",
48
+ "data = pd.DataFrame(all_texts, columns=['text'])\n"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": 22,
54
+ "metadata": {},
55
+ "outputs": [
56
+ {
57
+ "name": "stdout",
58
+ "output_type": "stream",
59
+ "text": [
60
+ "count 643523.000000\n",
61
+ "mean 1225.167071\n",
62
+ "std 2613.174490\n",
63
+ "min 0.000000\n",
64
+ "25% 271.000000\n",
65
+ "50% 689.000000\n",
66
+ "75% 1362.000000\n",
67
+ "max 299171.000000\n",
68
+ "Name: text, dtype: float64\n"
69
+ ]
70
+ }
71
+ ],
72
+ "source": [
73
+ "# Calculate the length of each text entry\n",
74
+ "text_lengths = data['text'].str.len()\n",
75
+ "\n",
76
+ "# Display the distribution of text lengths\n",
77
+ "length_distribution = text_lengths.describe()\n",
78
+ "\n",
79
+ "# Print the distribution\n",
80
+ "print(length_distribution)\n"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": 19,
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": [
89
+ "import random\n",
90
+ "import string\n",
91
+ "\n",
92
+ "def random_letter():\n",
93
+ " \"\"\"Returns a random alphanumeric character.\"\"\"\n",
94
+ " return random.choice(string.ascii_letters + string.digits)\n",
95
+ "\n",
96
+ "def replace_random_letters(word, pct=0.15):\n",
97
+ " \"\"\"Replaces random letters in a word with a given probability.\"\"\"\n",
98
+ " if random.random() < pct:\n",
99
+ " char_pos = random.choice(range(len(word)))\n",
100
+ " return word[:char_pos] + random_letter() + word[char_pos + 1:]\n",
101
+ " else:\n",
102
+ " return word\n",
103
+ "\n",
104
+ "def misspell_text(text, pct=0.15, last_letter_error_pct=0.20):\n",
105
+ " \"\"\"Generates a misspelled version of the input text.\"\"\"\n",
106
+ " words = text.split()\n",
107
+ " misspelled_words = [replace_random_letters(word, pct) for word in words]\n",
108
+ " \n",
109
+ " # Apply last letter error with a different probability\n",
110
+ " for i, word in enumerate(misspelled_words):\n",
111
+ " if random.random() < last_letter_error_pct:\n",
112
+ " if len(word) > 1: # Ensure word has more than 1 character\n",
113
+ " misspelled_words[i] = word[:-1] + random_letter()\n",
114
+ " \n",
115
+ " return ' '.join(misspelled_words)\n"
116
+ ]
117
+ },
118
+ {
119
+ "cell_type": "code",
120
+ "execution_count": 23,
121
+ "metadata": {},
122
+ "outputs": [],
123
+ "source": [
124
+ "data.rename(columns={'text':'ground_truth'}, inplace=True)\n"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": 24,
130
+ "metadata": {},
131
+ "outputs": [
132
+ {
133
+ "ename": "AttributeError",
134
+ "evalue": "'Index' object has no attribute '_format_flat'",
135
+ "output_type": "error",
136
+ "traceback": [
137
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
138
+ "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
139
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/IPython/core/formatters.py:343\u001b[0m, in \u001b[0;36mBaseFormatter.__call__\u001b[0;34m(self, obj)\u001b[0m\n\u001b[1;32m 341\u001b[0m method \u001b[38;5;241m=\u001b[39m get_real_method(obj, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprint_method)\n\u001b[1;32m 342\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m method \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 343\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mmethod\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 344\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 345\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
140
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/core/frame.py:1053\u001b[0m, in \u001b[0;36m_repr_html_\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 1036\u001b[0m \u001b[38;5;129m@property\u001b[39m\n\u001b[1;32m 1037\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mshape\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mtuple\u001b[39m[\u001b[38;5;28mint\u001b[39m, \u001b[38;5;28mint\u001b[39m]:\n\u001b[1;32m 1038\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 1039\u001b[0m \u001b[38;5;124;03m Return a tuple representing the dimensionality of the DataFrame.\u001b[39;00m\n\u001b[1;32m 1040\u001b[0m \n\u001b[1;32m 1041\u001b[0m \u001b[38;5;124;03m See Also\u001b[39;00m\n\u001b[1;32m 1042\u001b[0m \u001b[38;5;124;03m --------\u001b[39;00m\n\u001b[1;32m 1043\u001b[0m \u001b[38;5;124;03m ndarray.shape : Tuple of array dimensions.\u001b[39;00m\n\u001b[1;32m 1044\u001b[0m \n\u001b[1;32m 1045\u001b[0m \u001b[38;5;124;03m Examples\u001b[39;00m\n\u001b[1;32m 1046\u001b[0m \u001b[38;5;124;03m --------\u001b[39;00m\n\u001b[1;32m 1047\u001b[0m \u001b[38;5;124;03m >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})\u001b[39;00m\n\u001b[1;32m 1048\u001b[0m \u001b[38;5;124;03m >>> df.shape\u001b[39;00m\n\u001b[1;32m 1049\u001b[0m \u001b[38;5;124;03m (2, 2)\u001b[39;00m\n\u001b[1;32m 1050\u001b[0m \n\u001b[1;32m 1051\u001b[0m \u001b[38;5;124;03m >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4],\u001b[39;00m\n\u001b[1;32m 1052\u001b[0m \u001b[38;5;124;03m ... 'col3': [5, 6]})\u001b[39;00m\n\u001b[0;32m-> 1053\u001b[0m \u001b[38;5;124;03m >>> df.shape\u001b[39;00m\n\u001b[1;32m 1054\u001b[0m \u001b[38;5;124;03m (2, 3)\u001b[39;00m\n\u001b[1;32m 1055\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 1056\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindex), \u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcolumns)\n",
141
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/format.py:1102\u001b[0m, in \u001b[0;36mto_html\u001b[0;34m(self, buf, encoding, classes, notebook, border, table_id, render_links)\u001b[0m\n\u001b[1;32m 1079\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mformat_array\u001b[39m(\n\u001b[1;32m 1080\u001b[0m values: ArrayLike,\n\u001b[1;32m 1081\u001b[0m formatter: Callable \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1090\u001b[0m fallback_formatter: Callable \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1091\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mlist\u001b[39m[\u001b[38;5;28mstr\u001b[39m]:\n\u001b[1;32m 1092\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 1093\u001b[0m \u001b[38;5;124;03m Format an array for printing.\u001b[39;00m\n\u001b[1;32m 1094\u001b[0m \n\u001b[1;32m 1095\u001b[0m \u001b[38;5;124;03m Parameters\u001b[39;00m\n\u001b[1;32m 1096\u001b[0m \u001b[38;5;124;03m ----------\u001b[39;00m\n\u001b[1;32m 1097\u001b[0m \u001b[38;5;124;03m values : np.ndarray or ExtensionArray\u001b[39;00m\n\u001b[1;32m 1098\u001b[0m \u001b[38;5;124;03m formatter\u001b[39;00m\n\u001b[1;32m 1099\u001b[0m \u001b[38;5;124;03m float_format\u001b[39;00m\n\u001b[1;32m 1100\u001b[0m \u001b[38;5;124;03m na_rep\u001b[39;00m\n\u001b[1;32m 1101\u001b[0m \u001b[38;5;124;03m digits\u001b[39;00m\n\u001b[0;32m-> 1102\u001b[0m \u001b[38;5;124;03m space\u001b[39;00m\n\u001b[1;32m 1103\u001b[0m \u001b[38;5;124;03m justify\u001b[39;00m\n\u001b[1;32m 1104\u001b[0m \u001b[38;5;124;03m decimal\u001b[39;00m\n\u001b[1;32m 1105\u001b[0m \u001b[38;5;124;03m leading_space : bool, optional, default True\u001b[39;00m\n\u001b[1;32m 1106\u001b[0m \u001b[38;5;124;03m Whether the array should be formatted with a leading space.\u001b[39;00m\n\u001b[1;32m 1107\u001b[0m \u001b[38;5;124;03m When an array as a column of a Series or DataFrame, we do want\u001b[39;00m\n\u001b[1;32m 1108\u001b[0m \u001b[38;5;124;03m the leading space to pad between columns.\u001b[39;00m\n\u001b[1;32m 1109\u001b[0m \n\u001b[1;32m 1110\u001b[0m \u001b[38;5;124;03m When formatting an Index subclass\u001b[39;00m\n\u001b[1;32m 1111\u001b[0m \u001b[38;5;124;03m (e.g. IntervalIndex._get_values_for_csv), we don't want the\u001b[39;00m\n\u001b[1;32m 1112\u001b[0m \u001b[38;5;124;03m leading space since it should be left-aligned.\u001b[39;00m\n\u001b[1;32m 1113\u001b[0m \u001b[38;5;124;03m fallback_formatter\u001b[39;00m\n\u001b[1;32m 1114\u001b[0m \n\u001b[1;32m 1115\u001b[0m \u001b[38;5;124;03m Returns\u001b[39;00m\n\u001b[1;32m 1116\u001b[0m \u001b[38;5;124;03m -------\u001b[39;00m\n\u001b[1;32m 1117\u001b[0m \u001b[38;5;124;03m List[str]\u001b[39;00m\n\u001b[1;32m 1118\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 1119\u001b[0m fmt_klass: \u001b[38;5;28mtype\u001b[39m[_GenericArrayFormatter]\n\u001b[1;32m 1120\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m lib\u001b[38;5;241m.\u001b[39mis_np_dtype(values\u001b[38;5;241m.\u001b[39mdtype, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mM\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n",
142
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:88\u001b[0m, in \u001b[0;36mHTMLFormatter.to_string\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mto_string\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mstr\u001b[39m:\n\u001b[0;32m---> 88\u001b[0m lines \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m lines):\n\u001b[1;32m 90\u001b[0m lines \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28mstr\u001b[39m(x) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m lines]\n",
143
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:644\u001b[0m, in \u001b[0;36mNotebookFormatter.render\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 642\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m<div>\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 643\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite_style()\n\u001b[0;32m--> 644\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 645\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m</div>\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 646\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39melements\n",
144
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:94\u001b[0m, in \u001b[0;36mHTMLFormatter.render\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrender\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mlist\u001b[39m[\u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m---> 94\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_write_table\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 96\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mshould_show_dimensions:\n\u001b[1;32m 97\u001b[0m by \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mchr\u001b[39m(\u001b[38;5;241m215\u001b[39m) \u001b[38;5;66;03m# × # noqa: RUF003\u001b[39;00m\n",
145
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:267\u001b[0m, in \u001b[0;36mHTMLFormatter._write_table\u001b[0;34m(self, indent)\u001b[0m\n\u001b[1;32m 261\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite(\n\u001b[1;32m 262\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m<table\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mborder_attr\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m class=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mjoin(_classes)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mid_section\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 263\u001b[0m indent,\n\u001b[1;32m 264\u001b[0m )\n\u001b[1;32m 266\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfmt\u001b[38;5;241m.\u001b[39mheader \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mshow_row_idx_names:\n\u001b[0;32m--> 267\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_write_header\u001b[49m\u001b[43m(\u001b[49m\u001b[43mindent\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindent_delta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 269\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_write_body(indent \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindent_delta)\n\u001b[1;32m 271\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m</table>\u001b[39m\u001b[38;5;124m\"\u001b[39m, indent)\n",
146
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:403\u001b[0m, in \u001b[0;36mHTMLFormatter._write_header\u001b[0;34m(self, indent)\u001b[0m\n\u001b[1;32m 400\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m<thead>\u001b[39m\u001b[38;5;124m\"\u001b[39m, indent)\n\u001b[1;32m 402\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfmt\u001b[38;5;241m.\u001b[39mheader:\n\u001b[0;32m--> 403\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_write_col_header\u001b[49m\u001b[43m(\u001b[49m\u001b[43mindent\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindent_delta\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 405\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mshow_row_idx_names:\n\u001b[1;32m 406\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_write_row_header(indent \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mindent_delta)\n",
147
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:383\u001b[0m, in \u001b[0;36mHTMLFormatter._write_col_header\u001b[0;34m(self, indent)\u001b[0m\n\u001b[1;32m 381\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 382\u001b[0m row\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 383\u001b[0m row\u001b[38;5;241m.\u001b[39mextend(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_columns_formatted_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 384\u001b[0m align \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfmt\u001b[38;5;241m.\u001b[39mjustify\n\u001b[1;32m 386\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_truncated_horizontally:\n",
148
+ "File \u001b[0;32m~/anaconda3/lib/python3.9/site-packages/pandas/io/formats/html.py:611\u001b[0m, in \u001b[0;36mNotebookFormatter._get_columns_formatted_values\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 609\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_get_columns_formatted_values\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mlist\u001b[39m[\u001b[38;5;28mstr\u001b[39m]:\n\u001b[1;32m 610\u001b[0m \u001b[38;5;66;03m# only reached with non-Multi Index\u001b[39;00m\n\u001b[0;32m--> 611\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_format_flat\u001b[49m(include_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n",
149
+ "\u001b[0;31mAttributeError\u001b[0m: 'Index' object has no attribute '_format_flat'"
150
+ ]
151
+ },
152
+ {
153
+ "data": {
154
+ "text/plain": [
155
+ " ground_truth\n",
156
+ "0 «Toshshahartransxizmat» AJ Axborot xizmati jam...\n",
157
+ "1 Oʻzbekiston Respublikasi Prezidenti Shavkat Mi...\n",
158
+ "2 Oʻzbekistonning AQSHdagi elchisi Javlon Vahobo...\n",
159
+ "3 Oliy Majlisning Inson huquqlari boʻyicha vakil...\n",
160
+ "4 Bu haqda Agentlik axborot xizmati xabar berdi....\n",
161
+ "... ...\n",
162
+ "643518 Марказий Осиё давлатлари бўйлаб эркин ҳаракатл...\n",
163
+ "643519 ​​Олий таълим муассасаларида \\nКоррупцияга қар...\n",
164
+ "643520 ​​Қирғизистонда вазир лавозимига тайинланганид...\n",
165
+ "643521 Исроил ва Фаластин ўқ отишни тўхтатишди. \"Масж...\n",
166
+ "643522 ​​АҚШ 20 та давлатга ҳарбий иншоотлар учун 240...\n",
167
+ "\n",
168
+ "[643523 rows x 1 columns]"
169
+ ]
170
+ },
171
+ "execution_count": 24,
172
+ "metadata": {},
173
+ "output_type": "execute_result"
174
+ }
175
+ ],
176
+ "source": [
177
+ "data"
178
+ ]
179
+ },
180
+ {
181
+ "cell_type": "code",
182
+ "execution_count": 25,
183
+ "metadata": {},
184
+ "outputs": [],
185
+ "source": [
186
+ "# Apply the function to create misspelled texts\n",
187
+ "data['sample_misspelled'] = data['ground_truth'].apply(lambda x: misspell_text(x))"
188
+ ]
189
+ },
190
+ {
191
+ "cell_type": "code",
192
+ "execution_count": 31,
193
+ "metadata": {},
194
+ "outputs": [
195
+ {
196
+ "name": "stdout",
197
+ "output_type": "stream",
198
+ "text": [
199
+ " ground_truth \\\n",
200
+ "0 «Toshshahartransxizmat» AJ Axborot xizmati jam... \n",
201
+ "1 Oʻzbekiston Respublikasi Prezidenti Shavkat Mi... \n",
202
+ "2 Oʻzbekistonning AQSHdagi elchisi Javlon Vahobo... \n",
203
+ "3 Oliy Majlisning Inson huquqlari boʻyicha vakil... \n",
204
+ "4 Bu haqda Agentlik axborot xizmati xabar berdi.... \n",
205
+ "... ... \n",
206
+ "643518 Марказий Осиё давлатлари бўйлаб эркин ҳаракатл... \n",
207
+ "643519 ​​Олий таълим муассасаларида \\nКоррупцияга қар... \n",
208
+ "643520 ​​Қирғизистонда вазир лавозимига тайинланганид... \n",
209
+ "643521 Исроил ва Фаластин ўқ отишни тўхтатишди. \"Масж... \n",
210
+ "643522 ​​АҚШ 20 та давлатга ҳарбий иншоотлар учун 240... \n",
211
+ "\n",
212
+ " sample_misspelled \n",
213
+ "0 «Toshshahartransxizmat» A6 Axborot xizmatG jam... \n",
214
+ "1 Oʻzbekiston Respublikasi Prezidenti Shavkat Mi... \n",
215
+ "2 Oʻzbekistonnin6 AQSHdagi elchisi Javlog Vahobo... \n",
216
+ "3 Oliy Majlisning Inson huquqlar2 boʻyicha Makil... \n",
217
+ "4 Bu haqda AgentliU axlorot xizmal9 xabar berdi.... \n",
218
+ "... ... \n",
219
+ "643518 Марказиc ОсGё давлатлаIи бўйлаб эркин ҳаракатл... \n",
220
+ "643519 y​Олиe таъcиQ муассасаларида КоррупциягX қарш4... \n",
221
+ "643520 ​​Қирғизистонда вазиP лавозимига тайинланганид... \n",
222
+ "643521 Исроил tf Фаластиt ўқ отишни тўхтатиPдиA \"Масж... \n",
223
+ "643522 ​​АҚШ 20 тB давлатга ҳарбиn иншоотлар учун 240... \n",
224
+ "\n",
225
+ "[643523 rows x 2 columns]\n"
226
+ ]
227
+ }
228
+ ],
229
+ "source": [
230
+ "print(data)"
231
+ ]
232
+ },
233
+ {
234
+ "cell_type": "code",
235
+ "execution_count": 32,
236
+ "metadata": {},
237
+ "outputs": [],
238
+ "source": [
239
+ "expanded_data = pd.concat([data['ground_truth'], data['ground_truth']], ignore_index=True).to_frame(name='ground_truth')\n"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": 33,
245
+ "metadata": {},
246
+ "outputs": [],
247
+ "source": [
248
+ "import random\n",
249
+ "\n",
250
+ "def creative_misspell(text):\n",
251
+ " \"\"\"Apply creative misspelling strategies to the text.\"\"\"\n",
252
+ " words = text.split()\n",
253
+ " misspelled_words = []\n",
254
+ " for word in words:\n",
255
+ " # Example of a simple typographical error\n",
256
+ " if random.random() < 0.05: # Apply with 5% probability\n",
257
+ " word = word.replace('the', 'teh')\n",
258
+ " \n",
259
+ " # Example of omitting letters\n",
260
+ " if random.random() < 0.05 and len(word) > 3:\n",
261
+ " omit_index = random.randint(1, len(word) - 2) # Avoid first and last character\n",
262
+ " word = word[:omit_index] + word[omit_index + 1:]\n",
263
+ " \n",
264
+ " # Add more rules as needed\n",
265
+ " \n",
266
+ " misspelled_words.append(word)\n",
267
+ " \n",
268
+ " return ' '.join(misspelled_words)\n"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "execution_count": 34,
274
+ "metadata": {},
275
+ "outputs": [],
276
+ "source": [
277
+ "expanded_data['sample_misspelled'] = expanded_data['ground_truth'].apply(creative_misspell)\n"
278
+ ]
279
+ },
280
+ {
281
+ "cell_type": "code",
282
+ "execution_count": null,
283
+ "metadata": {},
284
+ "outputs": [],
285
+ "source": []
286
+ }
287
+ ],
288
+ "metadata": {
289
+ "kernelspec": {
290
+ "display_name": "Python 3",
291
+ "language": "python",
292
+ "name": "python3"
293
+ },
294
+ "language_info": {
295
+ "codemirror_mode": {
296
+ "name": "ipython",
297
+ "version": 3
298
+ },
299
+ "file_extension": ".py",
300
+ "mimetype": "text/x-python",
301
+ "name": "python",
302
+ "nbconvert_exporter": "python",
303
+ "pygments_lexer": "ipython3",
304
+ "version": "3.9.12"
305
+ }
306
+ },
307
+ "nbformat": 4,
308
+ "nbformat_minor": 2
309
+ }
environment.yml ADDED
File without changes