JaminOne commited on
Commit
7000ec4
1 Parent(s): a523a0a
Files changed (1) hide show
  1. hugging_face_shared.ipynb +572 -0
hugging_face_shared.ipynb ADDED
@@ -0,0 +1,572 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "## Use it locally"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "metadata": {},
15
+ "outputs": [
16
+ {
17
+ "name": "stderr",
18
+ "output_type": "stream",
19
+ "text": [
20
+ "/Users/jamin/.pyenv/versions/3.8.13/envs/bert_nlp/lib/python3.8/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",
21
+ " from .autonotebook import tqdm as notebook_tqdm\n",
22
+ "Downloading (…)okenizer_config.json: 1.30kB [00:00, 1.73MB/s]\n",
23
+ "Downloading (…)olve/main/vocab.json: 798kB [00:00, 1.11MB/s]\n",
24
+ "Downloading (…)olve/main/merges.txt: 456kB [00:00, 920kB/s] \n",
25
+ "Downloading (…)/main/tokenizer.json: 1.36MB [00:01, 1.31MB/s]\n",
26
+ "Downloading (…)cial_tokens_map.json: 100%|██████████| 239/239 [00:00<00:00, 91.2kB/s]\n",
27
+ "Downloading (…)lve/main/config.json: 1.88kB [00:00, 3.10MB/s]\n",
28
+ "Downloading pytorch_model.bin: 100%|██████████| 499M/499M [00:17<00:00, 28.4MB/s] \n"
29
+ ]
30
+ }
31
+ ],
32
+ "source": [
33
+ "from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
34
+ "\n",
35
+ "tokenizer = AutoTokenizer.from_pretrained(\"cardiffnlp/tweet-topic-21-multi\")\n",
36
+ "\n",
37
+ "model = AutoModelForSequenceClassification.from_pretrained(\"cardiffnlp/tweet-topic-21-multi\")"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 5,
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "name": "stdout",
47
+ "output_type": "stream",
48
+ "text": [
49
+ "news_&_social_concern\n",
50
+ "sports\n"
51
+ ]
52
+ }
53
+ ],
54
+ "source": [
55
+ "from transformers import AutoModelForSequenceClassification, TFAutoModelForSequenceClassification\n",
56
+ "from transformers import AutoTokenizer\n",
57
+ "import numpy as np\n",
58
+ "from scipy.special import expit\n",
59
+ "\n",
60
+ "class_mapping = model.config.id2label\n",
61
+ "\n",
62
+ "text = \"It is great to see athletes promoting awareness for climate change.\"\n",
63
+ "tokens = tokenizer(text, return_tensors='pt')\n",
64
+ "output = model(**tokens)\n",
65
+ "\n",
66
+ "scores = output[0][0].detach().numpy()\n",
67
+ "scores = expit(scores)\n",
68
+ "predictions = (scores >= 0.5) * 1\n",
69
+ "\n",
70
+ "# Map to classes\n",
71
+ "for i in range(len(predictions)):\n",
72
+ " if predictions[i]:\n",
73
+ " print(class_mapping[i])"
74
+ ]
75
+ },
76
+ {
77
+ "attachments": {},
78
+ "cell_type": "markdown",
79
+ "metadata": {},
80
+ "source": [
81
+ "## API"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": 8,
87
+ "metadata": {},
88
+ "outputs": [
89
+ {
90
+ "name": "stdout",
91
+ "output_type": "stream",
92
+ "text": [
93
+ "[[{'label': 'diaries_&_daily_life', 'score': 0.752070963382721}, {'label': 'relationships', 'score': 0.6936709880828857}, {'label': 'family', 'score': 0.10573585331439972}, {'label': 'celebrity_&_pop_culture', 'score': 0.06716123223304749}, {'label': 'other_hobbies', 'score': 0.04402140900492668}, {'label': 'film_tv_&_video', 'score': 0.029309650883078575}, {'label': 'sports', 'score': 0.026606008410453796}, {'label': 'arts_&_culture', 'score': 0.017974767833948135}, {'label': 'news_&_social_concern', 'score': 0.017801295965909958}, {'label': 'music', 'score': 0.015016891993582249}, {'label': 'gaming', 'score': 0.009747783653438091}, {'label': 'fashion_&_style', 'score': 0.0088553661480546}, {'label': 'business_&_entrepreneurs', 'score': 0.008412620052695274}, {'label': 'fitness_&_health', 'score': 0.008045237511396408}, {'label': 'youth_&_student_life', 'score': 0.006527383346110582}, {'label': 'science_&_technology', 'score': 0.006279776804149151}, {'label': 'learning_&_educational', 'score': 0.005272668786346912}, {'label': 'travel_&_adventure', 'score': 0.00523344473913312}, {'label': 'food_&_dining', 'score': 0.0045149847865104675}]]\n"
94
+ ]
95
+ }
96
+ ],
97
+ "source": [
98
+ "import requests\n",
99
+ "\n",
100
+ "API_TOKEN = \"YOUR_API_TOKEN\"\n",
101
+ "\n",
102
+ "API_URL = \"https://api-inference.huggingface.co/models/cardiffnlp/tweet-topic-21-multi\"\n",
103
+ "headers = {\"Authorization\": f\"Bearer {API_TOKEN}\"}\n",
104
+ "\n",
105
+ "def query(payload):\n",
106
+ "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
107
+ "\treturn response.json()\n",
108
+ "\t\n",
109
+ "output = query({\n",
110
+ "\t\"inputs\": \"I like you. I love you\",\n",
111
+ "})\n",
112
+ "print(output)"
113
+ ]
114
+ },
115
+ {
116
+ "attachments": {},
117
+ "cell_type": "markdown",
118
+ "metadata": {},
119
+ "source": [
120
+ "## Train Our Own Model and Upload to Hugging Face"
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": 2,
126
+ "metadata": {},
127
+ "outputs": [
128
+ {
129
+ "name": "stderr",
130
+ "output_type": "stream",
131
+ "text": [
132
+ "Found cached dataset yelp_review_full (/Users/jamin/.cache/huggingface/datasets/yelp_review_full/yelp_review_full/1.0.0/e8e18e19d7be9e75642fc66b198abadb116f73599ec89a69ba5dd8d1e57ba0bf)\n"
133
+ ]
134
+ },
135
+ {
136
+ "data": {
137
+ "application/vnd.jupyter.widget-view+json": {
138
+ "model_id": "8207b9c42a2e4b3eb0e8cd59a27fc67b",
139
+ "version_major": 2,
140
+ "version_minor": 0
141
+ },
142
+ "text/plain": [
143
+ " 0%| | 0/2 [00:00<?, ?it/s]"
144
+ ]
145
+ },
146
+ "metadata": {},
147
+ "output_type": "display_data"
148
+ },
149
+ {
150
+ "data": {
151
+ "text/plain": [
152
+ "{'label': 0,\n",
153
+ " 'text': 'My expectations for McDonalds are t rarely high. But for one to still fail so spectacularly...that takes something special!\\\\nThe cashier took my friends\\'s order, then promptly ignored me. I had to force myself in front of a cashier who opened his register to wait on the person BEHIND me. I waited over five minutes for a gigantic order that included precisely one kid\\'s meal. After watching two people who ordered after me be handed their food, I asked where mine was. The manager started yelling at the cashiers for \\\\\"serving off their orders\\\\\" when they didn\\'t have their food. But neither cashier was anywhere near those controls, and the manager was the one serving food to customers and clearing the boards.\\\\nThe manager was rude when giving me my order. She didn\\'t make sure that I had everything ON MY RECEIPT, and never even had the decency to apologize that I felt I was getting poor service.\\\\nI\\'ve eaten at various McDonalds restaurants for over 30 years. I\\'ve worked at more than one location. I expect bad days, bad moods, and the occasional mistake. But I have yet to have a decent experience at this store. It will remain a place I avoid unless someone in my party needs to avoid illness from low blood sugar. Perhaps I should go back to the racially biased service of Steak n Shake instead!'}"
154
+ ]
155
+ },
156
+ "execution_count": 2,
157
+ "metadata": {},
158
+ "output_type": "execute_result"
159
+ }
160
+ ],
161
+ "source": [
162
+ "from datasets import load_dataset\n",
163
+ "\n",
164
+ "dataset = load_dataset(\"yelp_review_full\")\n",
165
+ "dataset[\"train\"][100]"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 2,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "DatasetDict({\n",
177
+ " train: Dataset({\n",
178
+ " features: ['label', 'text'],\n",
179
+ " num_rows: 650000\n",
180
+ " })\n",
181
+ " test: Dataset({\n",
182
+ " features: ['label', 'text'],\n",
183
+ " num_rows: 50000\n",
184
+ " })\n",
185
+ "})"
186
+ ]
187
+ },
188
+ "execution_count": 2,
189
+ "metadata": {},
190
+ "output_type": "execute_result"
191
+ }
192
+ ],
193
+ "source": [
194
+ "dataset"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": 3,
200
+ "metadata": {},
201
+ "outputs": [
202
+ {
203
+ "name": "stderr",
204
+ "output_type": "stream",
205
+ "text": [
206
+ "Loading cached processed dataset at /Users/jamin/.cache/huggingface/datasets/yelp_review_full/yelp_review_full/1.0.0/e8e18e19d7be9e75642fc66b198abadb116f73599ec89a69ba5dd8d1e57ba0bf/cache-aad1af4c7095bfa1.arrow\n",
207
+ "Loading cached processed dataset at /Users/jamin/.cache/huggingface/datasets/yelp_review_full/yelp_review_full/1.0.0/e8e18e19d7be9e75642fc66b198abadb116f73599ec89a69ba5dd8d1e57ba0bf/cache-29f27748f0b54d01.arrow\n"
208
+ ]
209
+ }
210
+ ],
211
+ "source": [
212
+ "from transformers import AutoTokenizer\n",
213
+ "\n",
214
+ "tokenizer = AutoTokenizer.from_pretrained(\"bert-base-cased\")\n",
215
+ "\n",
216
+ "\n",
217
+ "def tokenize_function(examples):\n",
218
+ " return tokenizer(examples[\"text\"], padding=\"max_length\", truncation=True)\n",
219
+ "\n",
220
+ "\n",
221
+ "tokenized_datasets = dataset.map(tokenize_function, batched=True)"
222
+ ]
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "execution_count": 4,
227
+ "metadata": {},
228
+ "outputs": [
229
+ {
230
+ "name": "stderr",
231
+ "output_type": "stream",
232
+ "text": [
233
+ "Loading cached shuffled indices for dataset at /Users/jamin/.cache/huggingface/datasets/yelp_review_full/yelp_review_full/1.0.0/e8e18e19d7be9e75642fc66b198abadb116f73599ec89a69ba5dd8d1e57ba0bf/cache-11a7619c6a3c070f.arrow\n",
234
+ "Loading cached shuffled indices for dataset at /Users/jamin/.cache/huggingface/datasets/yelp_review_full/yelp_review_full/1.0.0/e8e18e19d7be9e75642fc66b198abadb116f73599ec89a69ba5dd8d1e57ba0bf/cache-3c5c2a245be1b332.arrow\n"
235
+ ]
236
+ }
237
+ ],
238
+ "source": [
239
+ "small_train_dataset = tokenized_datasets[\"train\"].shuffle(seed=42).select(range(1000))\n",
240
+ "small_eval_dataset = tokenized_datasets[\"test\"].shuffle(seed=42).select(range(1000))"
241
+ ]
242
+ },
243
+ {
244
+ "cell_type": "code",
245
+ "execution_count": 5,
246
+ "metadata": {},
247
+ "outputs": [
248
+ {
249
+ "name": "stderr",
250
+ "output_type": "stream",
251
+ "text": [
252
+ "Some weights of the model checkpoint at bert-base-cased were not used when initializing BertForSequenceClassification: ['cls.predictions.transform.dense.weight', 'cls.predictions.transform.dense.bias', 'cls.predictions.transform.LayerNorm.weight', 'cls.predictions.bias', 'cls.seq_relationship.bias', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.bias']\n",
253
+ "- This IS expected if you are initializing BertForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
254
+ "- This IS NOT expected if you are initializing BertForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
255
+ "Some weights of BertForSequenceClassification were not initialized from the model checkpoint at bert-base-cased and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
256
+ "You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
257
+ ]
258
+ }
259
+ ],
260
+ "source": [
261
+ "from transformers import AutoModelForSequenceClassification\n",
262
+ "\n",
263
+ "model = AutoModelForSequenceClassification.from_pretrained(\"bert-base-cased\", num_labels=5)"
264
+ ]
265
+ },
266
+ {
267
+ "cell_type": "code",
268
+ "execution_count": 14,
269
+ "metadata": {},
270
+ "outputs": [],
271
+ "source": [
272
+ "from transformers import TrainingArguments, Trainer\n",
273
+ "\n",
274
+ "training_args = TrainingArguments(output_dir=\"./output\",use_mps_device=True, push_to_hub=True)"
275
+ ]
276
+ },
277
+ {
278
+ "cell_type": "code",
279
+ "execution_count": 15,
280
+ "metadata": {},
281
+ "outputs": [],
282
+ "source": [
283
+ "import numpy as np\n",
284
+ "import evaluate\n",
285
+ "\n",
286
+ "metric = evaluate.load(\"accuracy\")"
287
+ ]
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": 16,
292
+ "metadata": {},
293
+ "outputs": [],
294
+ "source": [
295
+ "def compute_metrics(eval_pred):\n",
296
+ " logits, labels = eval_pred\n",
297
+ " predictions = np.argmax(logits, axis=-1)\n",
298
+ " return metric.compute(predictions=predictions, references=labels)"
299
+ ]
300
+ },
301
+ {
302
+ "cell_type": "code",
303
+ "execution_count": 17,
304
+ "metadata": {},
305
+ "outputs": [
306
+ {
307
+ "name": "stderr",
308
+ "output_type": "stream",
309
+ "text": [
310
+ "Cloning https://huggingface.co/JaminOne/output into local empty directory.\n"
311
+ ]
312
+ }
313
+ ],
314
+ "source": [
315
+ "trainer = Trainer(\n",
316
+ " model=model,\n",
317
+ " args=training_args,\n",
318
+ " train_dataset=small_train_dataset,\n",
319
+ " eval_dataset=small_eval_dataset,\n",
320
+ " compute_metrics=compute_metrics,\n",
321
+ ")"
322
+ ]
323
+ },
324
+ {
325
+ "cell_type": "code",
326
+ "execution_count": 18,
327
+ "metadata": {},
328
+ "outputs": [
329
+ {
330
+ "name": "stderr",
331
+ "output_type": "stream",
332
+ "text": [
333
+ "/Users/jamin/.pyenv/versions/3.8.13/envs/bert_nlp/lib/python3.8/site-packages/transformers/optimization.py:411: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning\n",
334
+ " warnings.warn(\n"
335
+ ]
336
+ },
337
+ {
338
+ "data": {
339
+ "application/vnd.jupyter.widget-view+json": {
340
+ "model_id": "182076eda0db44a0a50151543c3f910c",
341
+ "version_major": 2,
342
+ "version_minor": 0
343
+ },
344
+ "text/plain": [
345
+ " 0%| | 0/375 [00:00<?, ?it/s]"
346
+ ]
347
+ },
348
+ "metadata": {},
349
+ "output_type": "display_data"
350
+ },
351
+ {
352
+ "name": "stdout",
353
+ "output_type": "stream",
354
+ "text": [
355
+ "{'train_runtime': 520.3828, 'train_samples_per_second': 5.765, 'train_steps_per_second': 0.721, 'train_loss': 0.5104451090494792, 'epoch': 3.0}\n"
356
+ ]
357
+ },
358
+ {
359
+ "data": {
360
+ "text/plain": [
361
+ "TrainOutput(global_step=375, training_loss=0.5104451090494792, metrics={'train_runtime': 520.3828, 'train_samples_per_second': 5.765, 'train_steps_per_second': 0.721, 'train_loss': 0.5104451090494792, 'epoch': 3.0})"
362
+ ]
363
+ },
364
+ "execution_count": 18,
365
+ "metadata": {},
366
+ "output_type": "execute_result"
367
+ }
368
+ ],
369
+ "source": [
370
+ "trainer.train()"
371
+ ]
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "execution_count": 19,
376
+ "metadata": {},
377
+ "outputs": [
378
+ {
379
+ "data": {
380
+ "application/vnd.jupyter.widget-view+json": {
381
+ "model_id": "eb1761c75ce04a00a35c888c03a3edb1",
382
+ "version_major": 2,
383
+ "version_minor": 0
384
+ },
385
+ "text/plain": [
386
+ " 0%| | 0/125 [00:00<?, ?it/s]"
387
+ ]
388
+ },
389
+ "metadata": {},
390
+ "output_type": "display_data"
391
+ },
392
+ {
393
+ "data": {
394
+ "text/plain": [
395
+ "{'eval_loss': 1.4900177717208862,\n",
396
+ " 'eval_accuracy': 0.575,\n",
397
+ " 'eval_runtime': 50.098,\n",
398
+ " 'eval_samples_per_second': 19.961,\n",
399
+ " 'eval_steps_per_second': 2.495,\n",
400
+ " 'epoch': 3.0}"
401
+ ]
402
+ },
403
+ "execution_count": 19,
404
+ "metadata": {},
405
+ "output_type": "execute_result"
406
+ }
407
+ ],
408
+ "source": [
409
+ "trainer.evaluate()"
410
+ ]
411
+ },
412
+ {
413
+ "cell_type": "code",
414
+ "execution_count": 20,
415
+ "metadata": {},
416
+ "outputs": [
417
+ {
418
+ "data": {
419
+ "application/vnd.jupyter.widget-view+json": {
420
+ "model_id": "8307540768794d629ab41e2c9c4c4528",
421
+ "version_major": 2,
422
+ "version_minor": 0
423
+ },
424
+ "text/plain": [
425
+ "Upload file pytorch_model.bin: 0%| | 1.00/413M [00:00<?, ?B/s]"
426
+ ]
427
+ },
428
+ "metadata": {},
429
+ "output_type": "display_data"
430
+ },
431
+ {
432
+ "data": {
433
+ "application/vnd.jupyter.widget-view+json": {
434
+ "model_id": "31b0d6fbe6f9448c84cf5bcd6fde8fda",
435
+ "version_major": 2,
436
+ "version_minor": 0
437
+ },
438
+ "text/plain": [
439
+ "Upload file runs/Jun26_16-16-56_Jamins-MBP.local/events.out.tfevents.1687753086.Jamins-MBP.local.99394.2: 0%…"
440
+ ]
441
+ },
442
+ "metadata": {},
443
+ "output_type": "display_data"
444
+ },
445
+ {
446
+ "data": {
447
+ "application/vnd.jupyter.widget-view+json": {
448
+ "model_id": "9ba96571a2d24847a45211701e0c90ea",
449
+ "version_major": 2,
450
+ "version_minor": 0
451
+ },
452
+ "text/plain": [
453
+ "Upload file runs/Jun26_16-16-56_Jamins-MBP.local/events.out.tfevents.1687753661.Jamins-MBP.local.99394.3: 0%…"
454
+ ]
455
+ },
456
+ "metadata": {},
457
+ "output_type": "display_data"
458
+ },
459
+ {
460
+ "data": {
461
+ "application/vnd.jupyter.widget-view+json": {
462
+ "model_id": "070b216d93864e3e9bb360c437c8edf3",
463
+ "version_major": 2,
464
+ "version_minor": 0
465
+ },
466
+ "text/plain": [
467
+ "Upload file training_args.bin: 0%| | 1.00/3.81k [00:00<?, ?B/s]"
468
+ ]
469
+ },
470
+ "metadata": {},
471
+ "output_type": "display_data"
472
+ },
473
+ {
474
+ "name": "stderr",
475
+ "output_type": "stream",
476
+ "text": [
477
+ "To https://huggingface.co/JaminOne/output\n",
478
+ " 22a0170..12eaa4e main -> main\n",
479
+ "\n",
480
+ "To https://huggingface.co/JaminOne/output\n",
481
+ " 12eaa4e..0bf2de2 main -> main\n",
482
+ "\n"
483
+ ]
484
+ },
485
+ {
486
+ "data": {
487
+ "text/plain": [
488
+ "'https://huggingface.co/JaminOne/output/commit/12eaa4e4155940088dea9098d47075d967361ea8'"
489
+ ]
490
+ },
491
+ "execution_count": 20,
492
+ "metadata": {},
493
+ "output_type": "execute_result"
494
+ }
495
+ ],
496
+ "source": [
497
+ "trainer.push_to_hub()"
498
+ ]
499
+ },
500
+ {
501
+ "cell_type": "code",
502
+ "execution_count": 24,
503
+ "metadata": {},
504
+ "outputs": [
505
+ {
506
+ "data": {
507
+ "text/plain": [
508
+ "CommitInfo(commit_url='https://huggingface.co/JaminOne/output/commit/ed14549910b3b5016f6f6a2b92c0abc7179420fd', commit_message='Upload tokenizer', commit_description='', oid='ed14549910b3b5016f6f6a2b92c0abc7179420fd', pr_url=None, pr_revision=None, pr_num=None)"
509
+ ]
510
+ },
511
+ "execution_count": 24,
512
+ "metadata": {},
513
+ "output_type": "execute_result"
514
+ }
515
+ ],
516
+ "source": [
517
+ "tokenizer.push_to_hub(\"output\")"
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 26,
523
+ "metadata": {},
524
+ "outputs": [
525
+ {
526
+ "name": "stdout",
527
+ "output_type": "stream",
528
+ "text": [
529
+ "[[{'label': 'LABEL_4', 'score': 0.9605125784873962}, {'label': 'LABEL_3', 'score': 0.028813829645514488}, {'label': 'LABEL_0', 'score': 0.005277871619910002}, {'label': 'LABEL_1', 'score': 0.003208584152162075}, {'label': 'LABEL_2', 'score': 0.002187149366363883}]]\n"
530
+ ]
531
+ }
532
+ ],
533
+ "source": [
534
+ "import requests\n",
535
+ "\n",
536
+ "API_URL = \"https://api-inference.huggingface.co/models/JaminOne/output\"\n",
537
+ "headers = {\"Authorization\": \"Bearer YOUR_API_TOKEN\"}\n",
538
+ "\n",
539
+ "def query(payload):\n",
540
+ "\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
541
+ "\treturn response.json()\n",
542
+ "\t\n",
543
+ "output = query({\n",
544
+ "\t\"inputs\": \"I like you. I love you\",\n",
545
+ "})\n",
546
+ "print(output)"
547
+ ]
548
+ }
549
+ ],
550
+ "metadata": {
551
+ "kernelspec": {
552
+ "display_name": "bert_nlp",
553
+ "language": "python",
554
+ "name": "python3"
555
+ },
556
+ "language_info": {
557
+ "codemirror_mode": {
558
+ "name": "ipython",
559
+ "version": 3
560
+ },
561
+ "file_extension": ".py",
562
+ "mimetype": "text/x-python",
563
+ "name": "python",
564
+ "nbconvert_exporter": "python",
565
+ "pygments_lexer": "ipython3",
566
+ "version": "3.8.13"
567
+ },
568
+ "orig_nbformat": 4
569
+ },
570
+ "nbformat": 4,
571
+ "nbformat_minor": 2
572
+ }