dedebo commited on
Commit
ef9d30e
·
verified ·
1 Parent(s): 95b7f6d

Upload 02-Work Embeddings3.ipynb

Browse files
Files changed (1) hide show
  1. 02-Work Embeddings3.ipynb +590 -0
02-Work Embeddings3.ipynb ADDED
@@ -0,0 +1,590 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "20631e0c-5f53-465b-8d9e-7b8072e26eda",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from datasets import load_from_disk\n",
11
+ "import numpy as np"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "id": "246a008c-a210-4bd6-99c4-0ada886cb11e",
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "data": {
22
+ "text/plain": [
23
+ "DatasetDict({\n",
24
+ " train: Dataset({\n",
25
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined'],\n",
26
+ " num_rows: 33034\n",
27
+ " })\n",
28
+ " test: Dataset({\n",
29
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined'],\n",
30
+ " num_rows: 14158\n",
31
+ " })\n",
32
+ "})"
33
+ ]
34
+ },
35
+ "execution_count": 2,
36
+ "metadata": {},
37
+ "output_type": "execute_result"
38
+ }
39
+ ],
40
+ "source": [
41
+ "reloaded_dataset = load_from_disk(\"PreProcessedData3\")\n",
42
+ "reloaded_dataset"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 3,
48
+ "id": "0c4dd5ce-701a-4afc-afdf-93e675147864",
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "from collections import Counter\n",
53
+ "import torch\n",
54
+ "import torch.nn as nn"
55
+ ]
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 4,
60
+ "id": "ab0deb7d-245d-4620-b9d6-dd71df74600a",
61
+ "metadata": {},
62
+ "outputs": [
63
+ {
64
+ "name": "stdout",
65
+ "output_type": "stream",
66
+ "text": [
67
+ "708385\n",
68
+ "1008316\n"
69
+ ]
70
+ }
71
+ ],
72
+ "source": [
73
+ "merged_sentance = \"\"\n",
74
+ "for data in reloaded_dataset[\"train\"]:\n",
75
+ " merged_sentance = merged_sentance + data[\"textwithoutcompanycombined\"]+\" \"\n",
76
+ "print(len(merged_sentance))\n",
77
+ "for data in reloaded_dataset[\"test\"]:\n",
78
+ " merged_sentance = merged_sentance + data[\"textwithoutcompanycombined\"]+\" \"\n",
79
+ "print(len(merged_sentance))"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": 5,
85
+ "id": "437fdfb1-c1db-4dff-888d-5c9b1029add7",
86
+ "metadata": {},
87
+ "outputs": [],
88
+ "source": [
89
+ "words = merged_sentance.split(' ')\n",
90
+ " \n",
91
+ "# create a dictionary\n",
92
+ "vocab = Counter(words) \n",
93
+ "vocab = sorted(vocab, key=vocab.get, reverse=True)\n",
94
+ "vocab_size = len(vocab)\n",
95
+ " \n",
96
+ "# create a word to index dictionary from our Vocab dictionary\n",
97
+ "word2idx = {word: ind for ind, word in enumerate(vocab)} \n",
98
+ "idx2word = {ind: word for ind, word in enumerate(vocab)} "
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 6,
104
+ "id": "862fbc17-ae03-48b5-b1ae-b6ed63eafb22",
105
+ "metadata": {},
106
+ "outputs": [
107
+ {
108
+ "data": {
109
+ "text/plain": [
110
+ "(1767, 1767)"
111
+ ]
112
+ },
113
+ "execution_count": 6,
114
+ "metadata": {},
115
+ "output_type": "execute_result"
116
+ }
117
+ ],
118
+ "source": [
119
+ "len(word2idx),len(idx2word)"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 154,
125
+ "id": "dcc20e27-dc0a-421e-9d83-9a21d86a5d26",
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "e_dim = 1\n",
130
+ "emb = nn.Embedding(vocab_size, e_dim)"
131
+ ]
132
+ },
133
+ {
134
+ "cell_type": "code",
135
+ "execution_count": 180,
136
+ "id": "37fb99e6-6cbc-466f-b090-32f7e6b57af8",
137
+ "metadata": {},
138
+ "outputs": [
139
+ {
140
+ "data": {
141
+ "text/plain": [
142
+ "['person running medium-dark-skin-tone',\n",
143
+ " 'man farmer dark-skin-tone',\n",
144
+ " 'Taurus',\n",
145
+ " 'people holding hands medium-light-skin-tone',\n",
146
+ " 'locked',\n",
147
+ " 'sign of the horns medium-dark-skin-tone',\n",
148
+ " 'Japanese “no vacancy” button',\n",
149
+ " 'woman’s sandal',\n",
150
+ " 'woman and man holding hands medium-light-skin-tone',\n",
151
+ " 'Leo']"
152
+ ]
153
+ },
154
+ "execution_count": 180,
155
+ "metadata": {},
156
+ "output_type": "execute_result"
157
+ }
158
+ ],
159
+ "source": [
160
+ "reloaded_dataset[\"train\"]['textwithoutcompanycombined'][0:10]"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 155,
166
+ "id": "008562d4-3789-4d26-8ab8-5d3b980b2438",
167
+ "metadata": {},
168
+ "outputs": [],
169
+ "source": [
170
+ "words = reloaded_dataset[\"train\"][100]['textwithoutcompanycombined']\n",
171
+ "words = words.split(' ')"
172
+ ]
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "execution_count": 156,
177
+ "id": "af018a6d-e1aa-4db9-af63-dda2e39e1ff6",
178
+ "metadata": {},
179
+ "outputs": [
180
+ {
181
+ "data": {
182
+ "text/plain": [
183
+ "['person', 'light-skin-tone', 'white-hair']"
184
+ ]
185
+ },
186
+ "execution_count": 156,
187
+ "metadata": {},
188
+ "output_type": "execute_result"
189
+ }
190
+ ],
191
+ "source": [
192
+ "words"
193
+ ]
194
+ },
195
+ {
196
+ "cell_type": "code",
197
+ "execution_count": 157,
198
+ "id": "c7304275-11c7-4aa9-a929-3b6e9cd31f0a",
199
+ "metadata": {},
200
+ "outputs": [],
201
+ "source": [
202
+ "encoded_sentences = [word2idx[word] for word in words]"
203
+ ]
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "execution_count": 169,
208
+ "id": "303ecce6-8560-44e6-8c62-e316315c3d04",
209
+ "metadata": {},
210
+ "outputs": [
211
+ {
212
+ "data": {
213
+ "text/plain": [
214
+ "[2, 3, 81]"
215
+ ]
216
+ },
217
+ "execution_count": 169,
218
+ "metadata": {},
219
+ "output_type": "execute_result"
220
+ }
221
+ ],
222
+ "source": [
223
+ "encoded_sentences"
224
+ ]
225
+ },
226
+ {
227
+ "cell_type": "code",
228
+ "execution_count": 170,
229
+ "id": "24a20907-1403-4677-ab62-725b25f5fa06",
230
+ "metadata": {},
231
+ "outputs": [
232
+ {
233
+ "name": "stdout",
234
+ "output_type": "stream",
235
+ "text": [
236
+ "torch.Size([3, 1])\n"
237
+ ]
238
+ }
239
+ ],
240
+ "source": [
241
+ "# initialise an Embedding layer from Torch\n",
242
+ "word_vectors = emb(torch.LongTensor(encoded_sentences))\n",
243
+ " \n",
244
+ "#print the word_vectors\n",
245
+ "print(word_vectors.shape)"
246
+ ]
247
+ },
248
+ {
249
+ "cell_type": "code",
250
+ "execution_count": 176,
251
+ "id": "0ce1a74a-e7a9-45f7-8e4d-18088be5f89c",
252
+ "metadata": {},
253
+ "outputs": [
254
+ {
255
+ "data": {
256
+ "text/plain": [
257
+ "array([ 2.5878568 , -1.4057174 , -0.71889895], dtype=float32)"
258
+ ]
259
+ },
260
+ "execution_count": 176,
261
+ "metadata": {},
262
+ "output_type": "execute_result"
263
+ }
264
+ ],
265
+ "source": [
266
+ "vector = word_vectors.reshape(word_vectors.shape[0]).detach().numpy()\n",
267
+ "vector"
268
+ ]
269
+ },
270
+ {
271
+ "cell_type": "code",
272
+ "execution_count": 177,
273
+ "id": "a11fd4f9-1838-49df-b938-464be721c000",
274
+ "metadata": {},
275
+ "outputs": [
276
+ {
277
+ "data": {
278
+ "text/plain": [
279
+ "array([ 2.5878568 , -1.4057174 , -0.71889895, 0. , 0. ,\n",
280
+ " 0. , 0. , 0. , 0. , 0. ,\n",
281
+ " 0. , 0. , 0. , 0. , 0. ,\n",
282
+ " 0. , 0. , 0. , 0. , 0. ,\n",
283
+ " 0. , 0. , 0. , 0. , 0. ,\n",
284
+ " 0. , 0. , 0. , 0. , 0. ,\n",
285
+ " 0. , 0. , 0. , 0. , 0. ,\n",
286
+ " 0. , 0. , 0. , 0. , 0. ,\n",
287
+ " 0. , 0. , 0. , 0. , 0. ,\n",
288
+ " 0. , 0. , 0. , 0. , 0. ,\n",
289
+ " 0. , 0. , 0. , 0. , 0. ,\n",
290
+ " 0. , 0. , 0. , 0. , 0. ,\n",
291
+ " 0. , 0. , 0. , 0. , 0. ,\n",
292
+ " 0. , 0. , 0. , 0. , 0. ,\n",
293
+ " 0. , 0. , 0. , 0. , 0. ,\n",
294
+ " 0. , 0. , 0. , 0. , 0. ,\n",
295
+ " 0. , 0. , 0. , 0. , 0. ,\n",
296
+ " 0. , 0. , 0. , 0. , 0. ,\n",
297
+ " 0. , 0. , 0. , 0. , 0. ,\n",
298
+ " 0. , 0. , 0. , 0. , 0. ],\n",
299
+ " dtype=float32)"
300
+ ]
301
+ },
302
+ "execution_count": 177,
303
+ "metadata": {},
304
+ "output_type": "execute_result"
305
+ }
306
+ ],
307
+ "source": [
308
+ "np.pad(vector, [(0, 100-len(vector))], mode='constant', constant_values=0)"
309
+ ]
310
+ },
311
+ {
312
+ "cell_type": "code",
313
+ "execution_count": 92,
314
+ "id": "30d6434f-ff17-496c-af4d-26e066e9fb51",
315
+ "metadata": {},
316
+ "outputs": [
317
+ {
318
+ "data": {
319
+ "text/plain": [
320
+ "tensor([[0.1325],\n",
321
+ " [1.0038],\n",
322
+ " [0.1469]], grad_fn=<ViewBackward0>)"
323
+ ]
324
+ },
325
+ "execution_count": 92,
326
+ "metadata": {},
327
+ "output_type": "execute_result"
328
+ }
329
+ ],
330
+ "source": [
331
+ "word_vectors.view(word_vectors.shape)"
332
+ ]
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": 93,
337
+ "id": "9a5be641-14ee-45fa-8fa6-fd73834ac05d",
338
+ "metadata": {},
339
+ "outputs": [],
340
+ "source": [
341
+ "def get_encoded_sentences(sentance):\n",
342
+ " words = sentance.split(' ')\n",
343
+ " encoded_words = [word2idx[word] for word in words]\n",
344
+ " return encoded_words\n",
345
+ "\n",
346
+ "def get_decoded_sentences(encoded_words):\n",
347
+ " sentance = ' '.join([idx2word[idx] for idx in encoded_words])\n",
348
+ " return sentance"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 77,
354
+ "id": "df258a3a-0f6b-4f63-bfd3-f60a06f65471",
355
+ "metadata": {},
356
+ "outputs": [
357
+ {
358
+ "data": {
359
+ "text/plain": [
360
+ "'dark-skin-tone'"
361
+ ]
362
+ },
363
+ "execution_count": 77,
364
+ "metadata": {},
365
+ "output_type": "execute_result"
366
+ }
367
+ ],
368
+ "source": [
369
+ "get_decoded_sentences(get_encoded_sentences(\"dark-skin-tone\"))"
370
+ ]
371
+ },
372
+ {
373
+ "cell_type": "code",
374
+ "execution_count": 78,
375
+ "id": "4cf66ff1-0d7d-4f1c-b0af-29b0396bf3c8",
376
+ "metadata": {},
377
+ "outputs": [
378
+ {
379
+ "data": {
380
+ "text/plain": [
381
+ "{'image': <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=64x64>,\n",
382
+ " 'company': 'lg',\n",
383
+ " 'content': 'Taurus',\n",
384
+ " 'description': '',\n",
385
+ " 'textwithoutcompany': 'Taurus',\n",
386
+ " 'fulltext': 'lg Taurus',\n",
387
+ " 'textwithoutcompanycombined': 'Taurus'}"
388
+ ]
389
+ },
390
+ "execution_count": 78,
391
+ "metadata": {},
392
+ "output_type": "execute_result"
393
+ }
394
+ ],
395
+ "source": [
396
+ "reloaded_dataset[\"train\"][2]"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "execution_count": 79,
402
+ "id": "91ac0e54-90bd-4c20-8cb8-7e333548f279",
403
+ "metadata": {},
404
+ "outputs": [],
405
+ "source": [
406
+ "fulltext_vector = []\n",
407
+ "for data in reloaded_dataset[\"train\"]:\n",
408
+ " #print(data[\"fulltext\"])\n",
409
+ " #print(get_encoded_sentences(data[\"fulltext\"]))\n",
410
+ " encoded_sentences = get_encoded_sentences(data[\"textwithoutcompanycombined\"])\n",
411
+ " word_vectors = emb(torch.LongTensor(encoded_sentences))\n",
412
+ " word_vectors = word_vectors.reshape(word_vectors.shape[0]).detach().numpy()\n",
413
+ " fulltext_vector.append(np.pad(word_vectors, [(0, 100-len(word_vectors))], mode='constant', constant_values=0))\n",
414
+ " #print(fulltext_vector)"
415
+ ]
416
+ },
417
+ {
418
+ "cell_type": "code",
419
+ "execution_count": 80,
420
+ "id": "c913b2c3-8ba9-4eae-bcc3-93ef0998f40b",
421
+ "metadata": {},
422
+ "outputs": [
423
+ {
424
+ "data": {
425
+ "text/plain": [
426
+ "DatasetDict({\n",
427
+ " train: Dataset({\n",
428
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined', 'fulltext_vector'],\n",
429
+ " num_rows: 33034\n",
430
+ " })\n",
431
+ " test: Dataset({\n",
432
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined'],\n",
433
+ " num_rows: 14158\n",
434
+ " })\n",
435
+ "})"
436
+ ]
437
+ },
438
+ "execution_count": 80,
439
+ "metadata": {},
440
+ "output_type": "execute_result"
441
+ }
442
+ ],
443
+ "source": [
444
+ "reloaded_dataset[\"train\"]=reloaded_dataset[\"train\"].add_column(\"fulltext_vector\", fulltext_vector)\n",
445
+ "reloaded_dataset"
446
+ ]
447
+ },
448
+ {
449
+ "cell_type": "code",
450
+ "execution_count": 81,
451
+ "id": "acdbc88f-1cba-4c75-86fd-db9f59454a50",
452
+ "metadata": {},
453
+ "outputs": [],
454
+ "source": [
455
+ "fulltext_vector = []\n",
456
+ "for data in reloaded_dataset[\"test\"]:\n",
457
+ " #print(data[\"fulltext\"])\n",
458
+ " #print(get_encoded_sentences(data[\"fulltext\"]))\n",
459
+ " encoded_sentences = get_encoded_sentences(data[\"textwithoutcompanycombined\"])\n",
460
+ " word_vectors = emb(torch.LongTensor(encoded_sentences))\n",
461
+ " word_vectors = word_vectors.reshape(word_vectors.shape[0]).detach().numpy()\n",
462
+ " fulltext_vector.append(np.pad(word_vectors, [(0, 100-len(word_vectors))], mode='constant', constant_values=0))\n",
463
+ " #print(fulltext_vector)"
464
+ ]
465
+ },
466
+ {
467
+ "cell_type": "code",
468
+ "execution_count": 82,
469
+ "id": "e51f138c-117c-4f79-8260-de1d56512d07",
470
+ "metadata": {},
471
+ "outputs": [
472
+ {
473
+ "data": {
474
+ "text/plain": [
475
+ "DatasetDict({\n",
476
+ " train: Dataset({\n",
477
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined', 'fulltext_vector'],\n",
478
+ " num_rows: 33034\n",
479
+ " })\n",
480
+ " test: Dataset({\n",
481
+ " features: ['image', 'company', 'content', 'description', 'textwithoutcompany', 'fulltext', 'textwithoutcompanycombined', 'fulltext_vector'],\n",
482
+ " num_rows: 14158\n",
483
+ " })\n",
484
+ "})"
485
+ ]
486
+ },
487
+ "execution_count": 82,
488
+ "metadata": {},
489
+ "output_type": "execute_result"
490
+ }
491
+ ],
492
+ "source": [
493
+ "reloaded_dataset[\"test\"]=reloaded_dataset[\"test\"].add_column(\"fulltext_vector\", fulltext_vector)\n",
494
+ "reloaded_dataset"
495
+ ]
496
+ },
497
+ {
498
+ "cell_type": "code",
499
+ "execution_count": 83,
500
+ "id": "a7c46e54-87c7-40c4-836c-b72dfbaea28e",
501
+ "metadata": {},
502
+ "outputs": [
503
+ {
504
+ "data": {
505
+ "application/vnd.jupyter.widget-view+json": {
506
+ "model_id": "dd99f8d2d6b24f29bc2f0a9a0835fa7c",
507
+ "version_major": 2,
508
+ "version_minor": 0
509
+ },
510
+ "text/plain": [
511
+ "Saving the dataset (0/1 shards): 0%| | 0/33034 [00:00<?, ? examples/s]"
512
+ ]
513
+ },
514
+ "metadata": {},
515
+ "output_type": "display_data"
516
+ },
517
+ {
518
+ "ename": "OSError",
519
+ "evalue": "[Errno 22] Invalid argument: 'C:/Users/daparekh/OneDrive - OpenText/Personal/LJMU/EmojiGeneration/PreProcessedDataWithEmb/train/data-00000-of-00001.arrow'",
520
+ "output_type": "error",
521
+ "traceback": [
522
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
523
+ "\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
524
+ "Cell \u001b[1;32mIn[83], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m reloaded_dataset\u001b[38;5;241m.\u001b[39msave_to_disk(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPreProcessedDataWithEmb\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
525
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\datasets\\dataset_dict.py:1298\u001b[0m, in \u001b[0;36mDatasetDict.save_to_disk\u001b[1;34m(self, dataset_dict_path, fs, max_shard_size, num_shards, num_proc, storage_options)\u001b[0m\n\u001b[0;32m 1296\u001b[0m json\u001b[38;5;241m.\u001b[39mdump({\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msplits\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mself\u001b[39m)}, f)\n\u001b[0;32m 1297\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, dataset \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mitems():\n\u001b[1;32m-> 1298\u001b[0m dataset\u001b[38;5;241m.\u001b[39msave_to_disk(\n\u001b[0;32m 1299\u001b[0m posixpath\u001b[38;5;241m.\u001b[39mjoin(dataset_dict_path, k),\n\u001b[0;32m 1300\u001b[0m num_shards\u001b[38;5;241m=\u001b[39mnum_shards\u001b[38;5;241m.\u001b[39mget(k),\n\u001b[0;32m 1301\u001b[0m max_shard_size\u001b[38;5;241m=\u001b[39mmax_shard_size,\n\u001b[0;32m 1302\u001b[0m num_proc\u001b[38;5;241m=\u001b[39mnum_proc,\n\u001b[0;32m 1303\u001b[0m storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m 1304\u001b[0m )\n",
526
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\datasets\\arrow_dataset.py:1592\u001b[0m, in \u001b[0;36mDataset.save_to_disk\u001b[1;34m(self, dataset_path, fs, max_shard_size, num_shards, num_proc, storage_options)\u001b[0m\n\u001b[0;32m 1590\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m pbar:\n\u001b[0;32m 1591\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m kwargs \u001b[38;5;129;01min\u001b[39;00m kwargs_per_job:\n\u001b[1;32m-> 1592\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m job_id, done, content \u001b[38;5;129;01min\u001b[39;00m Dataset\u001b[38;5;241m.\u001b[39m_save_to_disk_single(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m 1593\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m done:\n\u001b[0;32m 1594\u001b[0m shards_done \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
527
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\datasets\\arrow_dataset.py:1616\u001b[0m, in \u001b[0;36mDataset._save_to_disk_single\u001b[1;34m(job_id, shard, fpath, storage_options)\u001b[0m\n\u001b[0;32m 1613\u001b[0m batch_size \u001b[38;5;241m=\u001b[39m config\u001b[38;5;241m.\u001b[39mDEFAULT_MAX_BATCH_SIZE\n\u001b[0;32m 1615\u001b[0m num_examples_progress_update \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[1;32m-> 1616\u001b[0m writer \u001b[38;5;241m=\u001b[39m ArrowWriter(\n\u001b[0;32m 1617\u001b[0m features\u001b[38;5;241m=\u001b[39mshard\u001b[38;5;241m.\u001b[39mfeatures,\n\u001b[0;32m 1618\u001b[0m path\u001b[38;5;241m=\u001b[39mfpath,\n\u001b[0;32m 1619\u001b[0m storage_options\u001b[38;5;241m=\u001b[39mstorage_options,\n\u001b[0;32m 1620\u001b[0m embed_local_files\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m 1621\u001b[0m )\n\u001b[0;32m 1622\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m 1623\u001b[0m _time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime()\n",
528
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\datasets\\arrow_writer.py:338\u001b[0m, in \u001b[0;36mArrowWriter.__init__\u001b[1;34m(self, schema, features, path, stream, fingerprint, writer_batch_size, hash_salt, check_duplicates, disable_nullable, update_features, with_metadata, unit, embed_local_files, storage_options)\u001b[0m\n\u001b[0;32m 336\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fs: fsspec\u001b[38;5;241m.\u001b[39mAbstractFileSystem \u001b[38;5;241m=\u001b[39m fs\n\u001b[0;32m 337\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_path \u001b[38;5;241m=\u001b[39m path \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m is_remote_filesystem(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fs) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fs\u001b[38;5;241m.\u001b[39munstrip_protocol(path)\n\u001b[1;32m--> 338\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstream \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fs\u001b[38;5;241m.\u001b[39mopen(path, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwb\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 339\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_closable_stream \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m 340\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
529
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\fsspec\\spec.py:1298\u001b[0m, in \u001b[0;36mAbstractFileSystem.open\u001b[1;34m(self, path, mode, block_size, cache_options, compression, **kwargs)\u001b[0m\n\u001b[0;32m 1296\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 1297\u001b[0m ac \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mautocommit\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_intrans)\n\u001b[1;32m-> 1298\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_open(\n\u001b[0;32m 1299\u001b[0m path,\n\u001b[0;32m 1300\u001b[0m mode\u001b[38;5;241m=\u001b[39mmode,\n\u001b[0;32m 1301\u001b[0m block_size\u001b[38;5;241m=\u001b[39mblock_size,\n\u001b[0;32m 1302\u001b[0m autocommit\u001b[38;5;241m=\u001b[39mac,\n\u001b[0;32m 1303\u001b[0m cache_options\u001b[38;5;241m=\u001b[39mcache_options,\n\u001b[0;32m 1304\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[0;32m 1305\u001b[0m )\n\u001b[0;32m 1306\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m compression \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 1307\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfsspec\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcompression\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m compr\n",
530
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\fsspec\\implementations\\local.py:191\u001b[0m, in \u001b[0;36mLocalFileSystem._open\u001b[1;34m(self, path, mode, block_size, **kwargs)\u001b[0m\n\u001b[0;32m 189\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mauto_mkdir \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01min\u001b[39;00m mode:\n\u001b[0;32m 190\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmakedirs(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_parent(path), exist_ok\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m--> 191\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m LocalFileOpener(path, mode, fs\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
531
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\fsspec\\implementations\\local.py:355\u001b[0m, in \u001b[0;36mLocalFileOpener.__init__\u001b[1;34m(self, path, mode, autocommit, fs, compression, **kwargs)\u001b[0m\n\u001b[0;32m 353\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcompression \u001b[38;5;241m=\u001b[39m get_compression(path, compression)\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mblocksize \u001b[38;5;241m=\u001b[39m io\u001b[38;5;241m.\u001b[39mDEFAULT_BUFFER_SIZE\n\u001b[1;32m--> 355\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_open()\n",
532
+ "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\fsspec\\implementations\\local.py:360\u001b[0m, in \u001b[0;36mLocalFileOpener._open\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 358\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mf \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mf\u001b[38;5;241m.\u001b[39mclosed:\n\u001b[0;32m 359\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mautocommit \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmode:\n\u001b[1;32m--> 360\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mf \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath, mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmode)\n\u001b[0;32m 361\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcompression:\n\u001b[0;32m 362\u001b[0m compress \u001b[38;5;241m=\u001b[39m compr[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcompression]\n",
533
+ "\u001b[1;31mOSError\u001b[0m: [Errno 22] Invalid argument: 'C:/Users/daparekh/OneDrive - OpenText/Personal/LJMU/EmojiGeneration/PreProcessedDataWithEmb/train/data-00000-of-00001.arrow'"
534
+ ]
535
+ }
536
+ ],
537
+ "source": [
538
+ "reloaded_dataset.save_to_disk(\"PreProcessedDataWithEmb\")"
539
+ ]
540
+ },
541
+ {
542
+ "cell_type": "code",
543
+ "execution_count": null,
544
+ "id": "05367cd9-0afc-40cc-8dc7-2b9689eb1506",
545
+ "metadata": {},
546
+ "outputs": [],
547
+ "source": [
548
+ "reloaded_dataset = load_from_disk(\"PreProcessedDataWithEmb\")\n",
549
+ "reloaded_dataset"
550
+ ]
551
+ },
552
+ {
553
+ "cell_type": "code",
554
+ "execution_count": null,
555
+ "id": "c3f8dfad-4dce-468d-bcbd-75743a6556f3",
556
+ "metadata": {},
557
+ "outputs": [],
558
+ "source": []
559
+ },
560
+ {
561
+ "cell_type": "code",
562
+ "execution_count": null,
563
+ "id": "4584cd5d-cc93-4d63-a271-37c30f9d1036",
564
+ "metadata": {},
565
+ "outputs": [],
566
+ "source": []
567
+ }
568
+ ],
569
+ "metadata": {
570
+ "kernelspec": {
571
+ "display_name": "Python 3 (ipykernel)",
572
+ "language": "python",
573
+ "name": "python3"
574
+ },
575
+ "language_info": {
576
+ "codemirror_mode": {
577
+ "name": "ipython",
578
+ "version": 3
579
+ },
580
+ "file_extension": ".py",
581
+ "mimetype": "text/x-python",
582
+ "name": "python",
583
+ "nbconvert_exporter": "python",
584
+ "pygments_lexer": "ipython3",
585
+ "version": "3.11.9"
586
+ }
587
+ },
588
+ "nbformat": 4,
589
+ "nbformat_minor": 5
590
+ }