detroitnatif commited on
Commit
2efa5aa
·
1 Parent(s): 0d36c4e

added pipeline

Browse files
.ipynb_checkpoints/RewardModel-checkpoint.ipynb ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "90683dd2",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import torch\n",
20
+ "\n",
21
+ "from datasets import load_dataset\n",
22
+ "from transformers import pipeline, AutoTokenizer\n",
23
+ "\n",
24
+ "from trl import PPOTrainer, PPOConfig, AutoModelForCausalLMWithValueHead\n",
25
+ "from trl.core import LengthSampler\n",
26
+ "\n",
27
+ "import os\n",
28
+ "os.environ[\"TOKENIZERS_PARALLELISM\"] = \"false\""
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": 2,
34
+ "id": "24fe6f33",
35
+ "metadata": {},
36
+ "outputs": [
37
+ {
38
+ "data": {
39
+ "text/plain": [
40
+ "DatasetDict({\n",
41
+ " train: Dataset({\n",
42
+ " features: ['text', 'label'],\n",
43
+ " num_rows: 25000\n",
44
+ " })\n",
45
+ " test: Dataset({\n",
46
+ " features: ['text', 'label'],\n",
47
+ " num_rows: 25000\n",
48
+ " })\n",
49
+ " unsupervised: Dataset({\n",
50
+ " features: ['text', 'label'],\n",
51
+ " num_rows: 50000\n",
52
+ " })\n",
53
+ "})"
54
+ ]
55
+ },
56
+ "execution_count": 2,
57
+ "metadata": {},
58
+ "output_type": "execute_result"
59
+ }
60
+ ],
61
+ "source": [
62
+ "ds = load_dataset(\"imdb\")\n",
63
+ "ds"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 3,
69
+ "id": "e68286f0",
70
+ "metadata": {},
71
+ "outputs": [
72
+ {
73
+ "data": {
74
+ "text/plain": [
75
+ "'I rented I AM CURIOUS-YELLOW from my video store because of all the controversy that surrounded it when it was first released in 1967. I also heard that at first it was seized by U.S. customs if it ever tried to enter this country, therefore being a fan of films considered \"controversial\" I really had to see this for myself.<br /><br />The plot is centered around a young Swedish drama student named Lena who wants to learn everything she can about life. In particular she wants to focus her attentions to making some sort of documentary on what the average Swede thought about certain political issues such as the Vietnam War and race issues in the United States. In between asking politicians and ordinary denizens of Stockholm about their opinions on politics, she has sex with her drama teacher, classmates, and married men.<br /><br />What kills me about I AM CURIOUS-YELLOW is that 40 years ago, this was considered pornographic. Really, the sex and nudity scenes are few and far between, even then it\\'s not shot like some cheaply made porno. While my countrymen mind find it shocking, in reality sex and nudity are a major staple in Swedish cinema. Even Ingmar Bergman, arguably their answer to good old boy John Ford, had sex scenes in his films.<br /><br />I do commend the filmmakers for the fact that any sex shown in the film is shown for artistic purposes rather than just to shock people and make money to be shown in pornographic theaters in America. I AM CURIOUS-YELLOW is a good film for anyone wanting to study the meat and potatoes (no pun intended) of Swedish cinema. But really, this film doesn\\'t have much of a plot.'"
76
+ ]
77
+ },
78
+ "execution_count": 3,
79
+ "metadata": {},
80
+ "output_type": "execute_result"
81
+ }
82
+ ],
83
+ "source": [
84
+ "ds['train'][0]['text']"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": 4,
90
+ "id": "2a8de66d",
91
+ "metadata": {},
92
+ "outputs": [
93
+ {
94
+ "name": "stderr",
95
+ "output_type": "stream",
96
+ "text": [
97
+ "Some weights of DistilBertForSequenceClassification were not initialized from the model checkpoint at distilbert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight', 'pre_classifier.bias', 'pre_classifier.weight']\n",
98
+ "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
99
+ ]
100
+ }
101
+ ],
102
+ "source": [
103
+ "from transformers import AutoModelForSequenceClassification, AutoTokenizer\n",
104
+ "\n",
105
+ "model_name = \"distilbert-base-uncased\"\n",
106
+ "model = AutoModelForSequenceClassification.from_pretrained(model_name)\n",
107
+ "tokenizer = AutoTokenizer.from_pretrained(model_name)"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 30,
113
+ "id": "33621a7b",
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "name": "stderr",
118
+ "output_type": "stream",
119
+ "text": [
120
+ "Map: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25000/25000 [00:24<00:00, 1014.20 examples/s]\n"
121
+ ]
122
+ }
123
+ ],
124
+ "source": [
125
+ "def tokenize(examples):\n",
126
+ " outputs = tokenizer(examples['text'], truncation=True)\n",
127
+ " return outputs\n",
128
+ "\n",
129
+ "tokenized_ds = ds.map(tokenize, batched=True)"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 5,
135
+ "id": "7c25e889",
136
+ "metadata": {},
137
+ "outputs": [],
138
+ "source": [
139
+ "from transformers import TrainingArguments, Trainer, DataCollatorWithPadding\n",
140
+ "\n",
141
+ "import numpy as np\n",
142
+ "\n",
143
+ "def compute_metrics(eval_preds):\n",
144
+ " metric = load_metric(\"accuracy\")\n",
145
+ " logits, labels = eval_preds\n",
146
+ " predictions = np.argmax(logits, axis=-1)\n",
147
+ " return metric.compute(predictions=predictions, references=labels)"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": 6,
153
+ "id": "4423925c",
154
+ "metadata": {},
155
+ "outputs": [],
156
+ "source": [
157
+ "training_args = TrainingArguments(num_train_epochs=1,\n",
158
+ " output_dir=\"distilbert-imdb\",\n",
159
+ " push_to_hub=False,\n",
160
+ " per_device_train_batch_size=16,\n",
161
+ " per_device_eval_batch_size=16,\n",
162
+ " evaluation_strategy=\"epoch\")"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 7,
168
+ "id": "f8b93ddf",
169
+ "metadata": {},
170
+ "outputs": [],
171
+ "source": [
172
+ "data_collator = DataCollatorWithPadding(tokenizer)"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 8,
178
+ "id": "3e7756b8",
179
+ "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "ename": "NameError",
183
+ "evalue": "name 'tokenized_ds' is not defined",
184
+ "output_type": "error",
185
+ "traceback": [
186
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
187
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
188
+ "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m trainer \u001b[38;5;241m=\u001b[39m Trainer(model\u001b[38;5;241m=\u001b[39mmodel, tokenizer\u001b[38;5;241m=\u001b[39mtokenizer,\n\u001b[1;32m 2\u001b[0m data_collator\u001b[38;5;241m=\u001b[39mdata_collator,\n\u001b[1;32m 3\u001b[0m args\u001b[38;5;241m=\u001b[39mtraining_args,\n\u001b[0;32m----> 4\u001b[0m train_dataset\u001b[38;5;241m=\u001b[39m\u001b[43mtokenized_ds\u001b[49m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtrain\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 5\u001b[0m eval_dataset\u001b[38;5;241m=\u001b[39mtokenized_ds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtest\u001b[39m\u001b[38;5;124m\"\u001b[39m], \n\u001b[1;32m 6\u001b[0m compute_metrics\u001b[38;5;241m=\u001b[39mcompute_metrics)\n",
189
+ "\u001b[0;31mNameError\u001b[0m: name 'tokenized_ds' is not defined"
190
+ ]
191
+ }
192
+ ],
193
+ "source": [
194
+ "trainer = Trainer(model=model, tokenizer=tokenizer,\n",
195
+ " data_collator=data_collator,\n",
196
+ " args=training_args,\n",
197
+ " train_dataset=tokenized_ds[\"train\"],\n",
198
+ " eval_dataset=tokenized_ds[\"test\"], \n",
199
+ " compute_metrics=compute_metrics)"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": 35,
205
+ "id": "c4829ba0",
206
+ "metadata": {},
207
+ "outputs": [
208
+ {
209
+ "data": {
210
+ "text/html": [
211
+ "\n",
212
+ " <div>\n",
213
+ " \n",
214
+ " <progress value='3' max='1563' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
215
+ " [ 3/1563 00:17 < 7:33:36, 0.06 it/s, Epoch 0.00/1]\n",
216
+ " </div>\n",
217
+ " <table border=\"1\" class=\"dataframe\">\n",
218
+ " <thead>\n",
219
+ " <tr style=\"text-align: left;\">\n",
220
+ " <th>Epoch</th>\n",
221
+ " <th>Training Loss</th>\n",
222
+ " <th>Validation Loss</th>\n",
223
+ " </tr>\n",
224
+ " </thead>\n",
225
+ " <tbody>\n",
226
+ " </tbody>\n",
227
+ "</table><p>"
228
+ ],
229
+ "text/plain": [
230
+ "<IPython.core.display.HTML object>"
231
+ ]
232
+ },
233
+ "metadata": {},
234
+ "output_type": "display_data"
235
+ },
236
+ {
237
+ "name": "stderr",
238
+ "output_type": "stream",
239
+ "text": [
240
+ "\n",
241
+ "KeyboardInterrupt\n",
242
+ "\n"
243
+ ]
244
+ }
245
+ ],
246
+ "source": [
247
+ "trainer.train()"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": null,
253
+ "id": "2f919628",
254
+ "metadata": {},
255
+ "outputs": [],
256
+ "source": [
257
+ "trainer.push_to_hub()"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": null,
263
+ "id": "6448feed",
264
+ "metadata": {},
265
+ "outputs": [],
266
+ "source": []
267
+ }
268
+ ],
269
+ "metadata": {
270
+ "kernelspec": {
271
+ "display_name": "Python 3 (ipykernel)",
272
+ "language": "python",
273
+ "name": "python3"
274
+ },
275
+ "language_info": {
276
+ "codemirror_mode": {
277
+ "name": "ipython",
278
+ "version": 3
279
+ },
280
+ "file_extension": ".py",
281
+ "mimetype": "text/x-python",
282
+ "name": "python",
283
+ "nbconvert_exporter": "python",
284
+ "pygments_lexer": "ipython3",
285
+ "version": "3.9.13"
286
+ }
287
+ },
288
+ "nbformat": 4,
289
+ "nbformat_minor": 5
290
+ }
RewardModel.ipynb CHANGED
@@ -2,10 +2,19 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 26,
6
  "id": "90683dd2",
7
  "metadata": {},
8
- "outputs": [],
 
 
 
 
 
 
 
 
 
9
  "source": [
10
  "import torch\n",
11
  "\n",
@@ -21,7 +30,7 @@
21
  },
22
  {
23
  "cell_type": "code",
24
- "execution_count": 27,
25
  "id": "24fe6f33",
26
  "metadata": {},
27
  "outputs": [
@@ -44,7 +53,7 @@
44
  "})"
45
  ]
46
  },
47
- "execution_count": 27,
48
  "metadata": {},
49
  "output_type": "execute_result"
50
  }
@@ -56,7 +65,7 @@
56
  },
57
  {
58
  "cell_type": "code",
59
- "execution_count": 28,
60
  "id": "e68286f0",
61
  "metadata": {},
62
  "outputs": [
@@ -66,7 +75,7 @@
66
  "'I rented I AM CURIOUS-YELLOW from my video store because of all the controversy that surrounded it when it was first released in 1967. I also heard that at first it was seized by U.S. customs if it ever tried to enter this country, therefore being a fan of films considered \"controversial\" I really had to see this for myself.<br /><br />The plot is centered around a young Swedish drama student named Lena who wants to learn everything she can about life. In particular she wants to focus her attentions to making some sort of documentary on what the average Swede thought about certain political issues such as the Vietnam War and race issues in the United States. In between asking politicians and ordinary denizens of Stockholm about their opinions on politics, she has sex with her drama teacher, classmates, and married men.<br /><br />What kills me about I AM CURIOUS-YELLOW is that 40 years ago, this was considered pornographic. Really, the sex and nudity scenes are few and far between, even then it\\'s not shot like some cheaply made porno. While my countrymen mind find it shocking, in reality sex and nudity are a major staple in Swedish cinema. Even Ingmar Bergman, arguably their answer to good old boy John Ford, had sex scenes in his films.<br /><br />I do commend the filmmakers for the fact that any sex shown in the film is shown for artistic purposes rather than just to shock people and make money to be shown in pornographic theaters in America. I AM CURIOUS-YELLOW is a good film for anyone wanting to study the meat and potatoes (no pun intended) of Swedish cinema. But really, this film doesn\\'t have much of a plot.'"
67
  ]
68
  },
69
- "execution_count": 28,
70
  "metadata": {},
71
  "output_type": "execute_result"
72
  }
@@ -77,7 +86,7 @@
77
  },
78
  {
79
  "cell_type": "code",
80
- "execution_count": 29,
81
  "id": "2a8de66d",
82
  "metadata": {},
83
  "outputs": [
@@ -122,7 +131,7 @@
122
  },
123
  {
124
  "cell_type": "code",
125
- "execution_count": 31,
126
  "id": "7c25e889",
127
  "metadata": {},
128
  "outputs": [],
@@ -140,7 +149,7 @@
140
  },
141
  {
142
  "cell_type": "code",
143
- "execution_count": 32,
144
  "id": "4423925c",
145
  "metadata": {},
146
  "outputs": [],
@@ -155,7 +164,7 @@
155
  },
156
  {
157
  "cell_type": "code",
158
- "execution_count": 33,
159
  "id": "f8b93ddf",
160
  "metadata": {},
161
  "outputs": [],
@@ -165,10 +174,22 @@
165
  },
166
  {
167
  "cell_type": "code",
168
- "execution_count": 34,
169
  "id": "3e7756b8",
170
  "metadata": {},
171
- "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
172
  "source": [
173
  "trainer = Trainer(model=model, tokenizer=tokenizer,\n",
174
  " data_collator=data_collator,\n",
@@ -228,30 +249,10 @@
228
  },
229
  {
230
  "cell_type": "code",
231
- "execution_count": 36,
232
  "id": "2f919628",
233
  "metadata": {},
234
- "outputs": [
235
- {
236
- "ename": "ValueError",
237
- "evalue": "Token is required (write-access action) but no token found. You need to provide a token or be logged in to Hugging Face with `huggingface-cli login` or `huggingface_hub.login`. See https://huggingface.co/settings/tokens.",
238
- "output_type": "error",
239
- "traceback": [
240
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
241
- "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
242
- "Input \u001b[0;32mIn [36]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtrainer\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpush_to_hub\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
243
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/transformers/trainer.py:3861\u001b[0m, in \u001b[0;36mTrainer.push_to_hub\u001b[0;34m(self, commit_message, blocking, **kwargs)\u001b[0m\n\u001b[1;32m 3859\u001b[0m \u001b[38;5;66;03m# In case the user calls this method with args.push_to_hub = False\u001b[39;00m\n\u001b[1;32m 3860\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhub_model_id \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m-> 3861\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minit_hf_repo\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3863\u001b[0m \u001b[38;5;66;03m# Needs to be executed on all processes for TPU training, but will only save on the processed determined by\u001b[39;00m\n\u001b[1;32m 3864\u001b[0m \u001b[38;5;66;03m# self.args.should_save.\u001b[39;00m\n\u001b[1;32m 3865\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msave_model(_internal_call\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
244
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/transformers/trainer.py:3694\u001b[0m, in \u001b[0;36mTrainer.init_hf_repo\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 3691\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 3692\u001b[0m repo_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs\u001b[38;5;241m.\u001b[39mhub_model_id\n\u001b[0;32m-> 3694\u001b[0m repo_url \u001b[38;5;241m=\u001b[39m \u001b[43mcreate_repo\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrepo_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhub_token\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprivate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhub_private_repo\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexist_ok\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 3695\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhub_model_id \u001b[38;5;241m=\u001b[39m repo_url\u001b[38;5;241m.\u001b[39mrepo_id\n\u001b[1;32m 3696\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpush_in_progress \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n",
245
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 116\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
246
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/hf_api.py:3336\u001b[0m, in \u001b[0;36mHfApi.create_repo\u001b[0;34m(self, repo_id, token, private, repo_type, exist_ok, space_sdk, space_hardware, space_storage, space_sleep_time, space_secrets, space_variables)\u001b[0m\n\u001b[1;32m 3332\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_lfsmultipartthresh\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m 3333\u001b[0m \u001b[38;5;66;03m# Testing purposes only.\u001b[39;00m\n\u001b[1;32m 3334\u001b[0m \u001b[38;5;66;03m# See https://github.com/huggingface/huggingface_hub/pull/733/files#r820604472\u001b[39;00m\n\u001b[1;32m 3335\u001b[0m json[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlfsmultipartthresh\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_lfsmultipartthresh \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m-> 3336\u001b[0m headers \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_build_hf_headers\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mis_write_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 3338\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m 3339\u001b[0m r \u001b[38;5;241m=\u001b[39m get_session()\u001b[38;5;241m.\u001b[39mpost(path, headers\u001b[38;5;241m=\u001b[39mheaders, json\u001b[38;5;241m=\u001b[39mjson)\n",
247
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/hf_api.py:8405\u001b[0m, in \u001b[0;36mHfApi._build_hf_headers\u001b[0;34m(self, token, is_write_action, library_name, library_version, user_agent)\u001b[0m\n\u001b[1;32m 8402\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m token \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 8403\u001b[0m \u001b[38;5;66;03m# Cannot do `token = token or self.token` as token can be `False`.\u001b[39;00m\n\u001b[1;32m 8404\u001b[0m token \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtoken\n\u001b[0;32m-> 8405\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mbuild_hf_headers\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 8406\u001b[0m \u001b[43m \u001b[49m\u001b[43mtoken\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtoken\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8407\u001b[0m \u001b[43m \u001b[49m\u001b[43mis_write_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mis_write_action\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8408\u001b[0m \u001b[43m \u001b[49m\u001b[43mlibrary_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlibrary_name\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlibrary_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8409\u001b[0m \u001b[43m \u001b[49m\u001b[43mlibrary_version\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlibrary_version\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlibrary_version\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8410\u001b[0m \u001b[43m \u001b[49m\u001b[43muser_agent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muser_agent\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43muser_agent\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 8411\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
248
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py:118\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[1;32m 116\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
249
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/utils/_headers.py:122\u001b[0m, in \u001b[0;36mbuild_hf_headers\u001b[0;34m(token, is_write_action, library_name, library_version, user_agent)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;66;03m# Get auth token to send\u001b[39;00m\n\u001b[1;32m 121\u001b[0m token_to_send \u001b[38;5;241m=\u001b[39m get_token_to_send(token)\n\u001b[0;32m--> 122\u001b[0m \u001b[43m_validate_token_to_send\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtoken_to_send\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mis_write_action\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mis_write_action\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 124\u001b[0m \u001b[38;5;66;03m# Combine headers\u001b[39;00m\n\u001b[1;32m 125\u001b[0m headers \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 126\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muser-agent\u001b[39m\u001b[38;5;124m\"\u001b[39m: _http_user_agent(\n\u001b[1;32m 127\u001b[0m library_name\u001b[38;5;241m=\u001b[39mlibrary_name,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 130\u001b[0m )\n\u001b[1;32m 131\u001b[0m }\n",
250
- "File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/huggingface_hub/utils/_headers.py:172\u001b[0m, in \u001b[0;36m_validate_token_to_send\u001b[0;34m(token, is_write_action)\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_write_action:\n\u001b[1;32m 171\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m token \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 172\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 173\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mToken is required (write-access action) but no token found. You need\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 174\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m to provide a token or be logged in to Hugging Face with\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 175\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m `huggingface-cli login` or `huggingface_hub.login`. See\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 176\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m https://huggingface.co/settings/tokens.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 177\u001b[0m )\n\u001b[1;32m 178\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m token\u001b[38;5;241m.\u001b[39mstartswith(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapi_org\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[1;32m 179\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 180\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mYou must use your personal account token for write-access methods. To\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 181\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m generate a write-access token, go to\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 182\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m https://huggingface.co/settings/tokens\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 183\u001b[0m )\n",
251
- "\u001b[0;31mValueError\u001b[0m: Token is required (write-access action) but no token found. You need to provide a token or be logged in to Hugging Face with `huggingface-cli login` or `huggingface_hub.login`. See https://huggingface.co/settings/tokens."
252
- ]
253
- }
254
- ],
255
  "source": [
256
  "trainer.push_to_hub()"
257
  ]
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
  "id": "90683dd2",
7
  "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
  "source": [
19
  "import torch\n",
20
  "\n",
 
30
  },
31
  {
32
  "cell_type": "code",
33
+ "execution_count": 2,
34
  "id": "24fe6f33",
35
  "metadata": {},
36
  "outputs": [
 
53
  "})"
54
  ]
55
  },
56
+ "execution_count": 2,
57
  "metadata": {},
58
  "output_type": "execute_result"
59
  }
 
65
  },
66
  {
67
  "cell_type": "code",
68
+ "execution_count": 3,
69
  "id": "e68286f0",
70
  "metadata": {},
71
  "outputs": [
 
75
  "'I rented I AM CURIOUS-YELLOW from my video store because of all the controversy that surrounded it when it was first released in 1967. I also heard that at first it was seized by U.S. customs if it ever tried to enter this country, therefore being a fan of films considered \"controversial\" I really had to see this for myself.<br /><br />The plot is centered around a young Swedish drama student named Lena who wants to learn everything she can about life. In particular she wants to focus her attentions to making some sort of documentary on what the average Swede thought about certain political issues such as the Vietnam War and race issues in the United States. In between asking politicians and ordinary denizens of Stockholm about their opinions on politics, she has sex with her drama teacher, classmates, and married men.<br /><br />What kills me about I AM CURIOUS-YELLOW is that 40 years ago, this was considered pornographic. Really, the sex and nudity scenes are few and far between, even then it\\'s not shot like some cheaply made porno. While my countrymen mind find it shocking, in reality sex and nudity are a major staple in Swedish cinema. Even Ingmar Bergman, arguably their answer to good old boy John Ford, had sex scenes in his films.<br /><br />I do commend the filmmakers for the fact that any sex shown in the film is shown for artistic purposes rather than just to shock people and make money to be shown in pornographic theaters in America. I AM CURIOUS-YELLOW is a good film for anyone wanting to study the meat and potatoes (no pun intended) of Swedish cinema. But really, this film doesn\\'t have much of a plot.'"
76
  ]
77
  },
78
+ "execution_count": 3,
79
  "metadata": {},
80
  "output_type": "execute_result"
81
  }
 
86
  },
87
  {
88
  "cell_type": "code",
89
+ "execution_count": 4,
90
  "id": "2a8de66d",
91
  "metadata": {},
92
  "outputs": [
 
131
  },
132
  {
133
  "cell_type": "code",
134
+ "execution_count": 5,
135
  "id": "7c25e889",
136
  "metadata": {},
137
  "outputs": [],
 
149
  },
150
  {
151
  "cell_type": "code",
152
+ "execution_count": 6,
153
  "id": "4423925c",
154
  "metadata": {},
155
  "outputs": [],
 
164
  },
165
  {
166
  "cell_type": "code",
167
+ "execution_count": 7,
168
  "id": "f8b93ddf",
169
  "metadata": {},
170
  "outputs": [],
 
174
  },
175
  {
176
  "cell_type": "code",
177
+ "execution_count": 8,
178
  "id": "3e7756b8",
179
  "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "ename": "NameError",
183
+ "evalue": "name 'tokenized_ds' is not defined",
184
+ "output_type": "error",
185
+ "traceback": [
186
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
187
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
188
+ "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m trainer \u001b[38;5;241m=\u001b[39m Trainer(model\u001b[38;5;241m=\u001b[39mmodel, tokenizer\u001b[38;5;241m=\u001b[39mtokenizer,\n\u001b[1;32m 2\u001b[0m data_collator\u001b[38;5;241m=\u001b[39mdata_collator,\n\u001b[1;32m 3\u001b[0m args\u001b[38;5;241m=\u001b[39mtraining_args,\n\u001b[0;32m----> 4\u001b[0m train_dataset\u001b[38;5;241m=\u001b[39m\u001b[43mtokenized_ds\u001b[49m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtrain\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[1;32m 5\u001b[0m eval_dataset\u001b[38;5;241m=\u001b[39mtokenized_ds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtest\u001b[39m\u001b[38;5;124m\"\u001b[39m], \n\u001b[1;32m 6\u001b[0m compute_metrics\u001b[38;5;241m=\u001b[39mcompute_metrics)\n",
189
+ "\u001b[0;31mNameError\u001b[0m: name 'tokenized_ds' is not defined"
190
+ ]
191
+ }
192
+ ],
193
  "source": [
194
  "trainer = Trainer(model=model, tokenizer=tokenizer,\n",
195
  " data_collator=data_collator,\n",
 
249
  },
250
  {
251
  "cell_type": "code",
252
+ "execution_count": null,
253
  "id": "2f919628",
254
  "metadata": {},
255
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  "source": [
257
  "trainer.push_to_hub()"
258
  ]