strickvl commited on
Commit
b3db2b8
1 Parent(s): 470e696

process and clean files

Browse files
Files changed (1) hide show
  1. src/train_tokenizer.ipynb +45 -0
src/train_tokenizer.ipynb CHANGED
@@ -20,6 +20,14 @@
20
  "# load_dataset(\"balochiml/balochi-language-data\", data_dir=\"data\", cache_dir=\"../data\")"
21
  ]
22
  },
 
 
 
 
 
 
 
 
23
  {
24
  "cell_type": "code",
25
  "execution_count": 13,
@@ -55,6 +63,43 @@
55
  "len(txt_paths)\n"
56
  ]
57
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  {
59
  "cell_type": "code",
60
  "execution_count": null,
 
20
  "# load_dataset(\"balochiml/balochi-language-data\", data_dir=\"data\", cache_dir=\"../data\")"
21
  ]
22
  },
23
+ {
24
+ "attachments": {},
25
+ "cell_type": "markdown",
26
+ "metadata": {},
27
+ "source": [
28
+ "# Generate the processed data without English characters"
29
+ ]
30
+ },
31
  {
32
  "cell_type": "code",
33
  "execution_count": 13,
 
63
  "len(txt_paths)\n"
64
  ]
65
  },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 17,
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "import re\n",
73
+ "\n",
74
+ "def clean_text(file_path):\n",
75
+ " # Open the file and read it into memory\n",
76
+ " with open(file_path, 'r', encoding='utf-8') as file:\n",
77
+ " text = file.read()\n",
78
+ "\n",
79
+ " # Remove English-language characters and numbers\n",
80
+ " text = re.sub(r'[a-zA-Z0-9]', '', text)\n",
81
+ "\n",
82
+ " # Remove any excess whitespace\n",
83
+ " text = re.sub(r'[^\\S\\n]+', ' ', text)\n",
84
+ "\n",
85
+ " return text"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 18,
91
+ "metadata": {},
92
+ "outputs": [],
93
+ "source": [
94
+ "for path in txt_paths:\n",
95
+ " cleaned_text = clean_text(path)\n",
96
+ "\n",
97
+ " # write the cleaned text to a new file with an incremented filename\n",
98
+ " # write the files all into the '../data/processed_text' directory\n",
99
+ " with open(f'../data/processed_text/{path.split(\"/\")[-1]}', 'w', encoding='utf-8') as file:\n",
100
+ " file.write(cleaned_text)\n"
101
+ ]
102
+ },
103
  {
104
  "cell_type": "code",
105
  "execution_count": null,