MVesalA commited on
Commit
b1d68c7
·
verified ·
1 Parent(s): 992d157

Delete util.ipynb

Browse files
Files changed (1) hide show
  1. util.ipynb +0 -475
util.ipynb DELETED
@@ -1,475 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "BI5kXWukdii1",
6
- "metadata": {
7
- "id": "BI5kXWukdii1"
8
- },
9
- "source": [
10
- "**github_Link**:https://github.com/mohammadVesall/Summarize/blob/main/Summarizer.ipynb"
11
- ]
12
- },
13
- {
14
- "cell_type": "code",
15
- "execution_count": 1,
16
- "id": "ec592020-dff5-4077-902d-7e852a6793f5",
17
- "metadata": {
18
- "id": "ec592020-dff5-4077-902d-7e852a6793f5"
19
- },
20
- "outputs": [],
21
- "source": [
22
- "import warnings\n",
23
- "import torch\n",
24
- "import gradio\n",
25
- "from transformers import pipeline\n",
26
- "from bs4 import BeautifulSoup\n",
27
- "import requests"
28
- ]
29
- },
30
- {
31
- "cell_type": "markdown",
32
- "id": "T_D-esc6FIsI",
33
- "metadata": {
34
- "id": "T_D-esc6FIsI"
35
- },
36
- "source": [
37
- "# **1.display the orginal text by link**\n",
38
- "\n"
39
- ]
40
- },
41
- {
42
- "cell_type": "code",
43
- "execution_count": 2,
44
- "id": "cc02cb9c-daf7-4b94-8770-ea9ff4037203",
45
- "metadata": {
46
- "id": "cc02cb9c-daf7-4b94-8770-ea9ff4037203"
47
- },
48
- "outputs": [],
49
- "source": [
50
- "summarizer = pipeline(\"summarization\", model=\"stevhliu/my_awesome_billsum_model\")"
51
- ]
52
- },
53
- {
54
- "cell_type": "code",
55
- "execution_count": 3,
56
- "id": "0aa4d56f-864c-41e0-932a-d804e95dfbc1",
57
- "metadata": {
58
- "id": "0aa4d56f-864c-41e0-932a-d804e95dfbc1"
59
- },
60
- "outputs": [],
61
- "source": [
62
- "url = \"https://medium.com/analytics-vidhya/openai-gpt-3-language-models-are-few-shot-learners-82531b3d3122\""
63
- ]
64
- },
65
- {
66
- "cell_type": "code",
67
- "execution_count": 4,
68
- "id": "47a7e4aa-27cd-474c-8444-4b68052b6ea9",
69
- "metadata": {
70
- "id": "47a7e4aa-27cd-474c-8444-4b68052b6ea9"
71
- },
72
- "outputs": [],
73
- "source": [
74
- "r = requests.get(url)"
75
- ]
76
- },
77
- {
78
- "cell_type": "code",
79
- "execution_count": 5,
80
- "id": "c83bff7e-340e-4bc3-af2b-35ec85c5ce14",
81
- "metadata": {
82
- "id": "c83bff7e-340e-4bc3-af2b-35ec85c5ce14"
83
- },
84
- "outputs": [],
85
- "source": [
86
- "soup = BeautifulSoup(r.text, 'html.parser')\n",
87
- "results = soup.find_all(['hl', 'p'])\n",
88
- "text = [result.text for result in results]\n",
89
- "Article = ''.join(text)"
90
- ]
91
- },
92
- {
93
- "cell_type": "code",
94
- "execution_count": 6,
95
- "id": "c1c2cc22-752d-42c7-a228-affe13e043a6",
96
- "metadata": {
97
- "id": "c1c2cc22-752d-42c7-a228-affe13e043a6",
98
- "outputId": "fac83567-3eea-4408-88b5-63a11dbd4f65"
99
- },
100
- "outputs": [
101
- {
102
- "data": {
103
- "text/plain": [
104
- "'Sign upSign inSign upSign inSoheil TehranipourFollowAnalytics Vidhya--4ListenShareOpenAI recently published a paper describing GPT-3, a deep-learning model for Natural Language Processing, with 175 Billion parameters(!!!), 100x more than the previous version, GPT-2. The model is pre-trained on nearly half a trillion words and achieves SOTA performance on several NLP benchmarks without fine-tuning.Based on its paper, GPT-3 is an autoregressive language model as opposed to a denoising autoencoder like BERT. I decided to write about some of the comparative differences between those two architectures of language models. The paper is an investigation into what you can do with giant language models. Now this language model is an order of magnitude larger than anyone has ever built a language model.OpenAI’s researchers: “In this work we do not fine-tune GPT-3 because our focus is on task-agnostic performance,”So, they seem appropriate for natural language generation. One of the things I want to explore here, is mainly an academic endeavor. The commercial utility which is something that can help us in industry is not possible with GPT-3 (at least not possible right not) which is only in reach for the very top tech companies like Microsoft,Google or OpenAI.you could learn a complex hierarchy of relationships directly between the tokens it was no longer this sequential representation where you only knew what happened at one time step backwards it was a real paradigm shift and straight away these language processing models produce SOTA results across the board.Generally speaking, there are two architectural patterns that we see with these transformers’ architectures.2. The other type of model is what’s called a denoising autoencoder like BERT and RoBERTa and XLNET and what these do is you feed in an input sentence and then you typically add some noise to it and then you say what you expect. in the photo below, you can check the size of parameters for each NLP effort before GPT-3.Now, it’s time to check some famous terms.The OpenAI researchers state that larger models make increasingly efficient use of in-context information. As can be seen in the plot below, the steeper “in-context learning curves” for large models show improved ability to learn from contextual information.I read somewhere that the whole story of GPT-3 costs “nearly $12 million dollars.” I know that it’s not even a penny for Elon Musk but for using GPT-3 in action for practical uses, this is not what the companies like. Also, One hypothesis is that GPT-3 has so many parameters (half the number of tokens trained on) that it is starting to act like a memory network.As you should know, GPT-2 GPT-2 (a successor to GPT), was trained simply to predict the next word in 40GB of Internet text. GPT-2 is a large transformer-based language model with 1.5 billion parameters, trained on a dataset of 8 million web pages. GPT-2 is trained with a simple objective: predict the next word, given all of the previous words within some text. The diversity of the dataset causes this simple goal to contain naturally occurring demonstrations of many tasks across diverse domains. GPT-2 is a direct scale-up of GPT, with more than 10X the parameters and trained on more than 10X the amount of data. (Based on OpenAI)But, GPT-3 is upgraded with 175 billion parameters, it tailors and escalates the GPT-2 architecture, it also involves adjusted initialization, pre-normalization, and changeable tokenization. It reflects substantial performance on various NLP tasks and benchmarks in three distinct shots, i.e. zero-shot, one-shot and some-shot environments.So, these things seem to be appropriate for things like question answering when you need to point to spans in your input sequence for example if you’re doing in-span question answering the auto-regressive models are quite attractive because you can just keep generating data forever.For training, the researchers have used a combination of model parallelism within each matrix multiply and model parallelism. More information about the training corpus is listed below:GPT-3 was trained on V100 GPU on the part of a high-bandwidth cluster provided by Microsoft. Evaluation of GPT-3 is done under 3 conditions:The results show that GPT-3 showed strong performance with translation, question-answering, and cloze tasks, as well as with unscrambling words and performing 3-digit arithmetic. The researchers claim that GPT-3 can even generate news articles in which human evaluators have difficulty distinguishing from articles written by humans.GPT-3 is an incredibly large model, and one cannot expect to build something like this without fancy computational resources. However, the researchers assure that these models can be efficient once trained, where even a full GPT-3 model generating 74 pages of content from a trained model can cost only a few cents in energy costs.As with GPT-2, OpenAI has not released the trained model or the code, although there is a GitHub repository containing some of the test datasets as well as a collection of text samples generated by the model.OpenAI has recently unveiled the latest epitome of its eye-catching text generator, GPT-3 that has 175 billion parameters. GPT-3 can execute an amazing bandwidth of natural language processing tasks, even without requiring fine-tuning for a specific task. It is capable of performing machine translation, question-answering, reading conceptual tasks, scripting poems, and elementary math.Public domain.----4Analytics VidhyaPh.D. Candidate, Passionate about data science to improve the world./ Linkedin: https://www.linkedin.com/in/soheiltehrani/HelpStatusAboutCareersPressBlogPrivacyTermsText to speechTeams'"
105
- ]
106
- },
107
- "execution_count": 6,
108
- "metadata": {},
109
- "output_type": "execute_result"
110
- }
111
- ],
112
- "source": [
113
- "Article"
114
- ]
115
- },
116
- {
117
- "cell_type": "markdown",
118
- "id": "1MLobC5mGFrX",
119
- "metadata": {
120
- "id": "1MLobC5mGFrX"
121
- },
122
- "source": [
123
- "# **2.Separate into different parts**"
124
- ]
125
- },
126
- {
127
- "cell_type": "code",
128
- "execution_count": 7,
129
- "id": "fe88051f-e2ab-4c65-9b70-539e934f24c0",
130
- "metadata": {
131
- "id": "fe88051f-e2ab-4c65-9b70-539e934f24c0"
132
- },
133
- "outputs": [],
134
- "source": [
135
- "max_chunk = 500"
136
- ]
137
- },
138
- {
139
- "cell_type": "code",
140
- "execution_count": 8,
141
- "id": "6eb89890-c213-4438-9d05-492c1870cf64",
142
- "metadata": {
143
- "id": "6eb89890-c213-4438-9d05-492c1870cf64"
144
- },
145
- "outputs": [],
146
- "source": [
147
- "Article = Article.replace('.', '')\n",
148
- "Article = Article.replace('?', '')\n",
149
- "Article = Article.replace('!', '')"
150
- ]
151
- },
152
- {
153
- "cell_type": "code",
154
- "execution_count": 9,
155
- "id": "d50737d5-387d-4aa3-ad4a-b6db0bcbf9a6",
156
- "metadata": {
157
- "id": "d50737d5-387d-4aa3-ad4a-b6db0bcbf9a6",
158
- "outputId": "f1d102d3-64d0-4406-e910-cef82d902f4f"
159
- },
160
- "outputs": [
161
- {
162
- "name": "stdout",
163
- "output_type": "stream",
164
- "text": [
165
- "0\n"
166
- ]
167
- }
168
- ],
169
- "source": [
170
- "sentences = Article.split(' ')\n",
171
- "current_chunk = 0\n",
172
- "chunks = []\n",
173
- "for sentence in sentences:\n",
174
- " if len(chunks) == current_chunk + 1:\n",
175
- " if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:\n",
176
- " chunks[current_chunk].extend(sentence.split(' '))\n",
177
- " else:\n",
178
- " current_chunk += 1\n",
179
- " chunks.append(sentence.split(' '))\n",
180
- " else:\n",
181
- " print(current_chunk)\n",
182
- " chunks.append(sentence.split(' '))\n",
183
- "\n",
184
- "for chunk_id in range(len(chunks)):\n",
185
- " chunks[chunk_id] = ' '.join(chunks[chunk_id])"
186
- ]
187
- },
188
- {
189
- "cell_type": "code",
190
- "execution_count": 10,
191
- "id": "23c0caae-1ce3-42d4-8914-35f15a15c572",
192
- "metadata": {
193
- "id": "23c0caae-1ce3-42d4-8914-35f15a15c572",
194
- "outputId": "c1297323-60c5-408d-e89a-93d4d9a1e9b1"
195
- },
196
- "outputs": [
197
- {
198
- "data": {
199
- "text/plain": [
200
- "2"
201
- ]
202
- },
203
- "execution_count": 10,
204
- "metadata": {},
205
- "output_type": "execute_result"
206
- }
207
- ],
208
- "source": [
209
- "len(chunks)"
210
- ]
211
- },
212
- {
213
- "cell_type": "code",
214
- "execution_count": 11,
215
- "id": "109eae32-d1fe-4257-a820-7841e5d6e08b",
216
- "metadata": {
217
- "id": "109eae32-d1fe-4257-a820-7841e5d6e08b",
218
- "outputId": "7fde050f-defe-43ef-fda5-1b7c991b8c00"
219
- },
220
- "outputs": [
221
- {
222
- "data": {
223
- "text/plain": [
224
- "'Sign upSign inSign upSign inSoheil TehranipourFollowAnalytics Vidhya--4ListenShareOpenAI recently published a paper describing GPT-3, a deep-learning model for Natural Language Processing, with 175 Billion parameters(), 100x more than the previous version, GPT-2 The model is pre-trained on nearly half a trillion words and achieves SOTA performance on several NLP benchmarks without fine-tuningBased on its paper, GPT-3 is an autoregressive language model as opposed to a denoising autoencoder like BERT I decided to write about some of the comparative differences between those two architectures of language models The paper is an investigation into what you can do with giant language models Now this language model is an order of magnitude larger than anyone has ever built a language modelOpenAI’s researchers: “In this work we do not fine-tune GPT-3 because our focus is on task-agnostic performance,”So, they seem appropriate for natural language generation One of the things I want to explore here, is mainly an academic endeavor The commercial utility which is something that can help us in industry is not possible with GPT-3 (at least not possible right not) which is only in reach for the very top tech companies like Microsoft,Google or OpenAIyou could learn a complex hierarchy of relationships directly between the tokens it was no longer this sequential representation where you only knew what happened at one time step backwards it was a real paradigm shift and straight away these language processing models produce SOTA results across the boardGenerally speaking, there are two architectural patterns that we see with these transformers’ architectures2 The other type of model is what’s called a denoising autoencoder like BERT and RoBERTa and XLNET and what these do is you feed in an input sentence and then you typically add some noise to it and then you say what you expect in the photo below, you can check the size of parameters for each NLP effort before GPT-3Now, it’s time to check some famous termsThe OpenAI researchers state that larger models make increasingly efficient use of in-context information As can be seen in the plot below, the steeper “in-context learning curves” for large models show improved ability to learn from contextual informationI read somewhere that the whole story of GPT-3 costs “nearly $12 million dollars” I know that it’s not even a penny for Elon Musk but for using GPT-3 in action for practical uses, this is not what the companies like Also, One hypothesis is that GPT-3 has so many parameters (half the number of tokens trained on) that it is starting to act like a memory networkAs you should know, GPT-2 GPT-2 (a successor to GPT), was trained simply to predict the next word in 40GB of Internet text GPT-2 is a large transformer-based language model with 15 billion parameters, trained on a dataset of 8 million web pages GPT-2 is trained with a simple objective: predict the next word, given all of the previous words within some text The diversity of the dataset causes this simple goal to contain naturally occurring'"
225
- ]
226
- },
227
- "execution_count": 11,
228
- "metadata": {},
229
- "output_type": "execute_result"
230
- }
231
- ],
232
- "source": [
233
- "chunks[0]"
234
- ]
235
- },
236
- {
237
- "cell_type": "markdown",
238
- "id": "FPjsoPy7G01E",
239
- "metadata": {
240
- "id": "FPjsoPy7G01E"
241
- },
242
- "source": [
243
- "# **3.Summarizing each part**"
244
- ]
245
- },
246
- {
247
- "cell_type": "code",
248
- "execution_count": 12,
249
- "id": "c9655275-9311-4ec8-8942-f77e415c5e55",
250
- "metadata": {
251
- "id": "c9655275-9311-4ec8-8942-f77e415c5e55",
252
- "outputId": "16e9c2b6-0cff-4560-92af-352afaf0cec5"
253
- },
254
- "outputs": [
255
- {
256
- "name": "stderr",
257
- "output_type": "stream",
258
- "text": [
259
- "Token indices sequence length is longer than the specified maximum sequence length for this model (700 > 512). Running this sequence through the model will result in indexing errors\n"
260
- ]
261
- }
262
- ],
263
- "source": [
264
- "res = summarizer(chunks, max_length=50, min_length=30, do_sample=False)"
265
- ]
266
- },
267
- {
268
- "cell_type": "code",
269
- "execution_count": 13,
270
- "id": "c3377904-21e7-4778-b70b-a3222d55446f",
271
- "metadata": {
272
- "id": "c3377904-21e7-4778-b70b-a3222d55446f",
273
- "outputId": "15d5c0a2-0e15-4259-e5d2-e760d67f0861"
274
- },
275
- "outputs": [
276
- {
277
- "data": {
278
- "text/plain": [
279
- "2"
280
- ]
281
- },
282
- "execution_count": 13,
283
- "metadata": {},
284
- "output_type": "execute_result"
285
- }
286
- ],
287
- "source": [
288
- "len(res)"
289
- ]
290
- },
291
- {
292
- "cell_type": "code",
293
- "execution_count": 14,
294
- "id": "352e1671-dd89-4545-9a4f-a9eebc7763ce",
295
- "metadata": {
296
- "id": "352e1671-dd89-4545-9a4f-a9eebc7763ce",
297
- "outputId": "5011c45c-3efb-4574-f2a4-f8e3f7f87a56"
298
- },
299
- "outputs": [
300
- {
301
- "data": {
302
- "text/plain": [
303
- "{'summary_text': 'GPT-3 is a direct scale-up of GPT, with 175 billion parameters and trained on more than 10X the amount of data (Based on OpenAI) It reflects substantial performance on various NLP tasks and benchmarks'}"
304
- ]
305
- },
306
- "execution_count": 14,
307
- "metadata": {},
308
- "output_type": "execute_result"
309
- }
310
- ],
311
- "source": [
312
- "res[1]"
313
- ]
314
- },
315
- {
316
- "cell_type": "code",
317
- "execution_count": 15,
318
- "id": "6557cefe-aba0-43d8-a6a4-88b0aaeadfe7",
319
- "metadata": {
320
- "id": "6557cefe-aba0-43d8-a6a4-88b0aaeadfe7",
321
- "outputId": "9abfd595-131b-43ae-e45b-ec90a7eed89b"
322
- },
323
- "outputs": [
324
- {
325
- "name": "stdout",
326
- "output_type": "stream",
327
- "text": [
328
- "{'summary_text': 'GPT-3 is a deep-learning model for Natural Language Processing, with 175 Billion parameters(), 100x more than the previous version, GPT-2 The model is pre-trained on nearly half a trillion words and'}\n",
329
- "{'summary_text': 'GPT-3 is a direct scale-up of GPT, with 175 billion parameters and trained on more than 10X the amount of data (Based on OpenAI) It reflects substantial performance on various NLP tasks and benchmarks'}\n"
330
- ]
331
- }
332
- ],
333
- "source": [
334
- "for i in range(len(res)):\n",
335
- " print(res[i])"
336
- ]
337
- },
338
- {
339
- "cell_type": "markdown",
340
- "id": "LI7KM9pLHSja",
341
- "metadata": {
342
- "id": "LI7KM9pLHSja"
343
- },
344
- "source": [
345
- "# *** Display in app**"
346
- ]
347
- },
348
- {
349
- "cell_type": "code",
350
- "execution_count": 16,
351
- "id": "2140e706-db66-410c-8181-9d595bc6a953",
352
- "metadata": {
353
- "id": "2140e706-db66-410c-8181-9d595bc6a953"
354
- },
355
- "outputs": [],
356
- "source": [
357
- "def SUMMARIZE(Url):\n",
358
- " Url = \"https://medium.com/analytics-vidhya/openai-gpt-3-language-models-are-few-shot-learners-82531b3d3122\"\n",
359
- " summarizer = pipeline(\"summarization\", model=\"stevhliu/my_awesome_billsum_model\")\n",
360
- " r = requests.get(Url)\n",
361
- " soup = BeautifulSoup(r.text, 'html.parser')\n",
362
- " results = soup.find_all(['hl', 'p'])\n",
363
- " text = [result.text for result in results]\n",
364
- " Article = ''.join(text)\n",
365
- " sentences = Article.split(' ')\n",
366
- " current_chunk = 0\n",
367
- " chunks = []\n",
368
- " for sentence in sentences:\n",
369
- " if len(chunks) == current_chunk + 1:\n",
370
- " if len(chunks[current_chunk]) + len(sentence.split(' ')) <= max_chunk:\n",
371
- " chunks[current_chunk].extend(sentence.split(' '))\n",
372
- " else:\n",
373
- " current_chunk += 1\n",
374
- " chunks.append(sentence.split(' '))\n",
375
- " else:\n",
376
- " #print(current_chunk)\n",
377
- " chunks.append(sentence.split(' '))\n",
378
- "\n",
379
- " for chunk_id in range(len(chunks)):\n",
380
- " chunks[chunk_id] = ' '.join(chunks[chunk_id])\n",
381
- " res = summarizer(chunks, max_length=120, min_length=30, do_sample=False)\n",
382
- " for i in range(len(res)):\n",
383
- " return res[i].values()"
384
- ]
385
- },
386
- {
387
- "cell_type": "markdown",
388
- "id": "OzG5meMJH5EL",
389
- "metadata": {
390
- "id": "OzG5meMJH5EL"
391
- },
392
- "source": [
393
- "**get the link, show the suumarized text**"
394
- ]
395
- },
396
- {
397
- "cell_type": "code",
398
- "execution_count": 17,
399
- "id": "68c7ff4a-d685-406b-a5a5-cb2dd5834f6f",
400
- "metadata": {
401
- "id": "68c7ff4a-d685-406b-a5a5-cb2dd5834f6f",
402
- "outputId": "ebb84c02-0da2-4103-8763-e77160825cbf"
403
- },
404
- "outputs": [
405
- {
406
- "name": "stdout",
407
- "output_type": "stream",
408
- "text": [
409
- "Running on local URL: http://127.0.0.1:7864\n",
410
- "\n",
411
- "Could not create share link. Please check your internet connection or our status page: https://status.gradio.app.\n"
412
- ]
413
- },
414
- {
415
- "data": {
416
- "text/html": [
417
- "<div><iframe src=\"http://127.0.0.1:7864/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
418
- ],
419
- "text/plain": [
420
- "<IPython.core.display.HTML object>"
421
- ]
422
- },
423
- "metadata": {},
424
- "output_type": "display_data"
425
- },
426
- {
427
- "data": {
428
- "text/plain": []
429
- },
430
- "execution_count": 17,
431
- "metadata": {},
432
- "output_type": "execute_result"
433
- }
434
- ],
435
- "source": [
436
- "interface = gradio.Interface(fn=SUMMARIZE,\n",
437
- " inputs=gradio.TextArea(lines=2, value=\"https://medium.com/analytics-vidhya/openai-gpt-3-language-models-are-few-shot-learners-82531b3d3122\"),\n",
438
- " outputs=gradio.TextArea())\n",
439
- "interface.launch(share=True)"
440
- ]
441
- },
442
- {
443
- "cell_type": "code",
444
- "execution_count": null,
445
- "id": "1d068ac5-d649-4f57-b2aa-2130b1a2dade",
446
- "metadata": {},
447
- "outputs": [],
448
- "source": []
449
- }
450
- ],
451
- "metadata": {
452
- "colab": {
453
- "provenance": []
454
- },
455
- "kernelspec": {
456
- "display_name": "Python 3 (ipykernel)",
457
- "language": "python",
458
- "name": "python3"
459
- },
460
- "language_info": {
461
- "codemirror_mode": {
462
- "name": "ipython",
463
- "version": 3
464
- },
465
- "file_extension": ".py",
466
- "mimetype": "text/x-python",
467
- "name": "python",
468
- "nbconvert_exporter": "python",
469
- "pygments_lexer": "ipython3",
470
- "version": "3.11.4"
471
- }
472
- },
473
- "nbformat": 4,
474
- "nbformat_minor": 5
475
- }