|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 17, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "data": { |
| 10 | + "application/vnd.jupyter.widget-view+json": { |
| 11 | + "model_id": "ae8b72691bc94e5b8406681bb5b11d59", |
| 12 | + "version_major": 2, |
| 13 | + "version_minor": 0 |
| 14 | + }, |
| 15 | + "text/plain": [ |
| 16 | + "Map (num_proc=4): 0%| | 0/63981 [00:00<?, ? examples/s]" |
| 17 | + ] |
| 18 | + }, |
| 19 | + "metadata": {}, |
| 20 | + "output_type": "display_data" |
| 21 | + }, |
| 22 | + { |
| 23 | + "data": { |
| 24 | + "application/vnd.jupyter.widget-view+json": { |
| 25 | + "model_id": "f04a9293b4a14796aa1050f40b8f0135", |
| 26 | + "version_major": 2, |
| 27 | + "version_minor": 0 |
| 28 | + }, |
| 29 | + "text/plain": [ |
| 30 | + "Map (num_proc=4): 0%| | 0/872 [00:00<?, ? examples/s]" |
| 31 | + ] |
| 32 | + }, |
| 33 | + "metadata": {}, |
| 34 | + "output_type": "display_data" |
| 35 | + }, |
| 36 | + { |
| 37 | + "data": { |
| 38 | + "application/vnd.jupyter.widget-view+json": { |
| 39 | + "model_id": "0e7c45fd8b974bc1ac58f95e05d69cb6", |
| 40 | + "version_major": 2, |
| 41 | + "version_minor": 0 |
| 42 | + }, |
| 43 | + "text/plain": [ |
| 44 | + "Map (num_proc=4): 0%| | 0/3368 [00:00<?, ? examples/s]" |
| 45 | + ] |
| 46 | + }, |
| 47 | + "metadata": {}, |
| 48 | + "output_type": "display_data" |
| 49 | + }, |
| 50 | + { |
| 51 | + "data": { |
| 52 | + "application/vnd.jupyter.widget-view+json": { |
| 53 | + "model_id": "9968f3bb38ad4d26b78e6d1cc7ae295c", |
| 54 | + "version_major": 2, |
| 55 | + "version_minor": 0 |
| 56 | + }, |
| 57 | + "text/plain": [ |
| 58 | + "Map (num_proc=4): 0%| | 0/1821 [00:00<?, ? examples/s]" |
| 59 | + ] |
| 60 | + }, |
| 61 | + "metadata": {}, |
| 62 | + "output_type": "display_data" |
| 63 | + }, |
| 64 | + { |
| 65 | + "data": { |
| 66 | + "text/plain": [ |
| 67 | + "Dataset({\n", |
| 68 | + " features: ['idx', 'labels', 'text', 'input_ids', 'attention_mask'],\n", |
| 69 | + " num_rows: 63981\n", |
| 70 | + "})" |
| 71 | + ] |
| 72 | + }, |
| 73 | + "execution_count": 17, |
| 74 | + "metadata": {}, |
| 75 | + "output_type": "execute_result" |
| 76 | + } |
| 77 | + ], |
| 78 | + "source": [ |
| 79 | + "from datasets import load_from_disk, Dataset\n", |
| 80 | + "from transformers import GPT2Tokenizer\n", |
| 81 | + "\n", |
| 82 | + "dataset = load_from_disk(\"data/clean\")\n", |
| 83 | + "\n", |
| 84 | + "tokenizer = GPT2Tokenizer.from_pretrained(\"gpt2\")\n", |
| 85 | + "tokenizer.pad_token = tokenizer.eos_token\n", |
| 86 | + "\n", |
| 87 | + "def tokenize_function(examples):\n", |
| 88 | + " return tokenizer(examples[\"text\"], padding=True, truncation=True, max_length=32)\n", |
| 89 | + "\n", |
| 90 | + "tokenized_datasets = dataset.map(tokenize_function, batched=True, num_proc=4)\n", |
| 91 | + "\n", |
| 92 | + "tokenized_datasets[\"train\"]\n", |
| 93 | + "\n" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": 9, |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [ |
| 101 | + { |
| 102 | + "ename": "AttributeError", |
| 103 | + "evalue": "'list' object has no attribute 'schema'", |
| 104 | + "output_type": "error", |
| 105 | + "traceback": [ |
| 106 | + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
| 107 | + "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", |
| 108 | + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m Dataset(\u001b[43mTable\u001b[49m\u001b[43m(\u001b[49m\u001b[43md\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtrain\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtext\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m)\n", |
| 109 | + "\u001b[36mFile \u001b[39m\u001b[32m~/projects/SentiSynth/venv311/lib/python3.11/site-packages/datasets/table.py:167\u001b[39m, in \u001b[36mTable.__init__\u001b[39m\u001b[34m(self, table)\u001b[39m\n\u001b[32m 166\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, table: pa.Table):\n\u001b[32m--> \u001b[39m\u001b[32m167\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m.\u001b[49m\u001b[34;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mtable\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 168\u001b[39m \u001b[38;5;28mself\u001b[39m.table = table\n", |
| 110 | + "\u001b[36mFile \u001b[39m\u001b[32m~/projects/SentiSynth/venv311/lib/python3.11/site-packages/datasets/table.py:107\u001b[39m, in \u001b[36mIndexedTableMixin.__init__\u001b[39m\u001b[34m(self, table)\u001b[39m\n\u001b[32m 106\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m, table: pa.Table):\n\u001b[32m--> \u001b[39m\u001b[32m107\u001b[39m \u001b[38;5;28mself\u001b[39m._schema: pa.Schema = \u001b[43mtable\u001b[49m\u001b[43m.\u001b[49m\u001b[43mschema\u001b[49m\n\u001b[32m 108\u001b[39m \u001b[38;5;28mself\u001b[39m._batches: \u001b[38;5;28mlist\u001b[39m[pa.RecordBatch] = [\n\u001b[32m 109\u001b[39m recordbatch \u001b[38;5;28;01mfor\u001b[39;00m recordbatch \u001b[38;5;129;01min\u001b[39;00m table.to_batches() \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(recordbatch) > \u001b[32m0\u001b[39m\n\u001b[32m 110\u001b[39m ]\n\u001b[32m 111\u001b[39m \u001b[38;5;28mself\u001b[39m._offsets: np.ndarray = np.cumsum([\u001b[32m0\u001b[39m] + [\u001b[38;5;28mlen\u001b[39m(b) \u001b[38;5;28;01mfor\u001b[39;00m b \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m._batches], dtype=np.int64)\n", |
| 111 | + "\u001b[31mAttributeError\u001b[39m: 'list' object has no attribute 'schema'" |
| 112 | + ] |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "Dataset(Table(d[\"train\"][\"text\"]))" |
| 117 | + ] |
| 118 | + } |
| 119 | + ], |
| 120 | + "metadata": { |
| 121 | + "kernelspec": { |
| 122 | + "display_name": "Python3.11 (sentisynth)", |
| 123 | + "language": "python", |
| 124 | + "name": "auctionn" |
| 125 | + }, |
| 126 | + "language_info": { |
| 127 | + "codemirror_mode": { |
| 128 | + "name": "ipython", |
| 129 | + "version": 3 |
| 130 | + }, |
| 131 | + "file_extension": ".py", |
| 132 | + "mimetype": "text/x-python", |
| 133 | + "name": "python", |
| 134 | + "nbconvert_exporter": "python", |
| 135 | + "pygments_lexer": "ipython3", |
| 136 | + "version": "3.11.2" |
| 137 | + } |
| 138 | + }, |
| 139 | + "nbformat": 4, |
| 140 | + "nbformat_minor": 2 |
| 141 | +} |
0 commit comments