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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "5a7c444a-5800-45c3-9cfa-8a73de12c8e5",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import os\n",
|
11 |
+
"\n",
|
12 |
+
"os.environ[\"HF_HOME\"] = \"/workspace/local-HF-cache/\"\n",
|
13 |
+
"os.environ[\"HF_HUB_ENABLE_HF_TRANSFER\"] = \"1\"\n"
|
14 |
+
]
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"cell_type": "code",
|
18 |
+
"execution_count": 2,
|
19 |
+
"id": "5dd927f1-1cad-43ac-ae9c-817e75048350",
|
20 |
+
"metadata": {},
|
21 |
+
"outputs": [
|
22 |
+
{
|
23 |
+
"name": "stdout",
|
24 |
+
"output_type": "stream",
|
25 |
+
"text": [
|
26 |
+
"NVIDIA GeForce RTX 4090 (compute capability 8.9) supports NVIDIA Ampere or later, enabled TF32 in PyTorch.\n"
|
27 |
+
]
|
28 |
+
}
|
29 |
+
],
|
30 |
+
"source": [
|
31 |
+
"import torch\n",
|
32 |
+
"\n",
|
33 |
+
"from textsum.utils import check_ampere_gpu\n",
|
34 |
+
"check_ampere_gpu() # automatically enables TF32 if Ampere+ available\n"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"execution_count": 3,
|
40 |
+
"id": "0c252525-7f63-4da1-8c9c-f939873cc484",
|
41 |
+
"metadata": {},
|
42 |
+
"outputs": [
|
43 |
+
{
|
44 |
+
"name": "stderr",
|
45 |
+
"output_type": "stream",
|
46 |
+
"text": [
|
47 |
+
"12/05/2024 05:46:29 INFO PyTorch version 2.4.1+cu124 available.\n"
|
48 |
+
]
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"data": {
|
52 |
+
"text/plain": [
|
53 |
+
"DatasetDict({\n",
|
54 |
+
" train: Dataset({\n",
|
55 |
+
" features: ['title', 'summary_official', 'metadata', 'source', 'summary_chunks', 'summary_generated'],\n",
|
56 |
+
" num_rows: 1315\n",
|
57 |
+
" })\n",
|
58 |
+
"})"
|
59 |
+
]
|
60 |
+
},
|
61 |
+
"execution_count": 3,
|
62 |
+
"metadata": {},
|
63 |
+
"output_type": "execute_result"
|
64 |
+
}
|
65 |
+
],
|
66 |
+
"source": [
|
67 |
+
"from datasets import load_dataset\n",
|
68 |
+
"\n",
|
69 |
+
"# Login using e.g. `huggingface-cli login` to access this dataset\n",
|
70 |
+
"ds = load_dataset(\"pszemraj/scriptbase-pegX-summaries\", \"no-text-4beams\")\n",
|
71 |
+
"ds"
|
72 |
+
]
|
73 |
+
},
|
74 |
+
{
|
75 |
+
"cell_type": "code",
|
76 |
+
"execution_count": 4,
|
77 |
+
"id": "d1be6062-f813-496d-b15f-4db98b02d66f",
|
78 |
+
"metadata": {},
|
79 |
+
"outputs": [
|
80 |
+
{
|
81 |
+
"data": {
|
82 |
+
"application/vnd.jupyter.widget-view+json": {
|
83 |
+
"model_id": "3cf7628f7d1e403d9339a1bb46a13610",
|
84 |
+
"version_major": 2,
|
85 |
+
"version_minor": 0
|
86 |
+
},
|
87 |
+
"text/plain": [
|
88 |
+
"Downloading shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
89 |
+
]
|
90 |
+
},
|
91 |
+
"metadata": {},
|
92 |
+
"output_type": "display_data"
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"name": "stderr",
|
96 |
+
"output_type": "stream",
|
97 |
+
"text": [
|
98 |
+
"12/05/2024 05:46:32 INFO We will use 90% of the memory on device 0 for storing the model, and 10% for the buffer to avoid OOM. You can set `max_memory` in to a higher value to use more memory (at your own risk).\n"
|
99 |
+
]
|
100 |
+
},
|
101 |
+
{
|
102 |
+
"data": {
|
103 |
+
"application/vnd.jupyter.widget-view+json": {
|
104 |
+
"model_id": "a2adc839e69c4c799b789ea92e6e90b9",
|
105 |
+
"version_major": 2,
|
106 |
+
"version_minor": 0
|
107 |
+
},
|
108 |
+
"text/plain": [
|
109 |
+
"Loading checkpoint shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
"metadata": {},
|
113 |
+
"output_type": "display_data"
|
114 |
+
},
|
115 |
+
{
|
116 |
+
"data": {
|
117 |
+
"application/vnd.jupyter.widget-view+json": {
|
118 |
+
"model_id": "c5776ec846244a5ab3ae53c05bb10e02",
|
119 |
+
"version_major": 2,
|
120 |
+
"version_minor": 0
|
121 |
+
},
|
122 |
+
"text/plain": [
|
123 |
+
"tokenizer_config.json: 0%| | 0.00/20.8k [00:00<?, ?B/s]"
|
124 |
+
]
|
125 |
+
},
|
126 |
+
"metadata": {},
|
127 |
+
"output_type": "display_data"
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"name": "stdout",
|
131 |
+
"output_type": "stream",
|
132 |
+
"text": [
|
133 |
+
"A computer-implemented method of generating a syntactic object involves providing input data sets containing one or more words, each associated with at least one non-adjacent second word, and creating an exocentric relationship between the words by applying neo-ian event semantics. This neo-antagonistic effect results in the generation of a syntactic object, which is then stored for future use. Additionally, a method of learning and using language involves creating a lexicon of words with at least two possible states, selecting a base state for a computational operation, and applying the computational operation to the base state to form a new output state. Furthermore, a computer-implemented method for changing workspaces involves merging two workspaces based on conditions such as an impenetrable condition, constraint on movement, or resource restriction.\n"
|
134 |
+
]
|
135 |
+
}
|
136 |
+
],
|
137 |
+
"source": [
|
138 |
+
"import torch\n",
|
139 |
+
"from transformers import pipeline\n",
|
140 |
+
"\n",
|
141 |
+
"pipe = pipeline(\n",
|
142 |
+
" \"text2text-generation\",\n",
|
143 |
+
" model=\"pszemraj/flan-t5-xl-summary-map-reduce-1024\",\n",
|
144 |
+
" device_map=\"auto\",\n",
|
145 |
+
")\n",
|
146 |
+
"\n",
|
147 |
+
"# examples\n",
|
148 |
+
"text = \"\"\"\"Sangers on a Train\" is a 1950 film about a train driver, Guy Haines, who discovers his wife, Miriam, has been murdered in Metcalf, Washington, DC. The film delves into the relationship between Guy and Anne Burton, focusing on Guy's desire for Anne to marry him.\n",
|
149 |
+
"\"Screentalk\" is a comedy about Anne Burton and her husband, Guy Haines, who are investigating the murder of their daughter, Miriam. The plot revolves around Anne's relationship with Bruno, who has been arrested for his wife's murder. In the second set, Guy and Anne meet at a tennis court in Washington, DC, where they plan to play against each other. Hennessy and Hammond investigate the crime scene, leading to Guy's arrest.\n",
|
150 |
+
"\"The Announcer's Boom Forest Hills\" is a tennis game between Guy Haines and Bruno Antony, with the score six-five. In the second set, Haines leads three games to four, but his opponent, Bernard Reynolds, attacks him in the third set. Meanwhile, Anne Hennessy and Barbara Hammond are preparing for dinner at the amusement park, where Guy has been waiting for hours. A police car arrives, followed by a taxi. The boatman and detectives follow Guy through the queue, leading to the conclusion that Guy was the man responsible for the accident.\"\"\"\n",
|
151 |
+
"\n",
|
152 |
+
"text = \"\"\"A computer implemented method of generating a syntactic object. The method includes the steps of providing a plurality of input data sets, each input data set comprising one or more words, wherein each word is associated with at least one non-adjacent second word; creating an exocentric relationship between the first and second words by applying a neo-ian event semantics to the input data in such a way that the neo-antagonistic effect results in the generation of the syntactic object; and storing the generated syntactic object for future use.\n",
|
153 |
+
" A method of learning and using language is disclosed. The method includes the steps of creating a lexicon of words, wherein each word in the lexicon has at least two possible states, selecting a set of one or more of the possible states of the lexicon to be used as a base state for a subsequent computational operation, and applying the computational operation to the base state to form a new output state.\n",
|
154 |
+
" A computer implemented method for changing a first workspace to a second workspace. The method includes the steps of creating a new workspace by merging the first workspace with the second workspace, wherein the merging is based on at least one of: an impenetrable condition; a constraint on movement; and a resource restriction.\n",
|
155 |
+
" The brain is constantly loosing neurons because you doesn't want all the junk around.\"\"\"\n",
|
156 |
+
"\n",
|
157 |
+
"# generate\n",
|
158 |
+
"if torch.cuda.is_available():\n",
|
159 |
+
" torch.cuda.empty_cache()\n",
|
160 |
+
"with torch.autocast('cuda', dtype=torch.bfloat16):\n",
|
161 |
+
" res = pipe(\n",
|
162 |
+
" text,\n",
|
163 |
+
" max_new_tokens=512, # increase up to 1024 if needed\n",
|
164 |
+
" num_beams=4,\n",
|
165 |
+
" early_stopping=True,\n",
|
166 |
+
" truncation=True,\n",
|
167 |
+
")\n",
|
168 |
+
"print(res[0][\"generated_text\"])\n"
|
169 |
+
]
|
170 |
+
},
|
171 |
+
{
|
172 |
+
"cell_type": "code",
|
173 |
+
"execution_count": 7,
|
174 |
+
"id": "93b0fda6-6478-4cfe-8ddc-acddb59edb1a",
|
175 |
+
"metadata": {},
|
176 |
+
"outputs": [],
|
177 |
+
"source": [
|
178 |
+
"pipe.model = torch.compile(pipe.model)"
|
179 |
+
]
|
180 |
+
},
|
181 |
+
{
|
182 |
+
"cell_type": "code",
|
183 |
+
"execution_count": null,
|
184 |
+
"id": "adf7599a-f52f-4519-b86b-b1079521b1ac",
|
185 |
+
"metadata": {},
|
186 |
+
"outputs": [
|
187 |
+
{
|
188 |
+
"data": {
|
189 |
+
"application/vnd.jupyter.widget-view+json": {
|
190 |
+
"model_id": "7a0bf9e015fd4072b0a1b38380bf47ce",
|
191 |
+
"version_major": 2,
|
192 |
+
"version_minor": 0
|
193 |
+
},
|
194 |
+
"text/plain": [
|
195 |
+
"Map: 0%| | 0/1315 [00:00<?, ? examples/s]"
|
196 |
+
]
|
197 |
+
},
|
198 |
+
"metadata": {},
|
199 |
+
"output_type": "display_data"
|
200 |
+
}
|
201 |
+
],
|
202 |
+
"source": [
|
203 |
+
"def reduce_summary(example):\n",
|
204 |
+
" if torch.cuda.is_available():\n",
|
205 |
+
" torch.cuda.empty_cache()\n",
|
206 |
+
" with torch.autocast('cuda', dtype=torch.bfloat16, enabled=False):\n",
|
207 |
+
" res = pipe(\n",
|
208 |
+
" example['summary_chunks'],\n",
|
209 |
+
" max_new_tokens=512, # increase up to 1024 if needed\n",
|
210 |
+
" num_beams=4,\n",
|
211 |
+
" early_stopping=True,\n",
|
212 |
+
" truncation=True,\n",
|
213 |
+
" )\n",
|
214 |
+
" return {\"summary_reduced_flanT5xl\": res[0][\"generated_text\"]}\n",
|
215 |
+
"\n",
|
216 |
+
"ds = ds.map(reduce_summary, batched=False)\n",
|
217 |
+
"ds"
|
218 |
+
]
|
219 |
+
},
|
220 |
+
{
|
221 |
+
"cell_type": "code",
|
222 |
+
"execution_count": null,
|
223 |
+
"id": "2788312f-804b-4a7e-b2b0-b7e20fac024d",
|
224 |
+
"metadata": {},
|
225 |
+
"outputs": [],
|
226 |
+
"source": [
|
227 |
+
"# ds.push_to_hub(\"pszemraj/scriptbase-pegX-summaries\", config_name=\"no-text-4beams-flanXL\", \n",
|
228 |
+
"# commit_description='generate with pszemraj/flan-t5-xl-summary-map-reduce-1024')"
|
229 |
+
]
|
230 |
+
}
|
231 |
+
],
|
232 |
+
"metadata": {
|
233 |
+
"kernelspec": {
|
234 |
+
"display_name": "Python 3 (ipykernel)",
|
235 |
+
"language": "python",
|
236 |
+
"name": "python3"
|
237 |
+
},
|
238 |
+
"language_info": {
|
239 |
+
"codemirror_mode": {
|
240 |
+
"name": "ipython",
|
241 |
+
"version": 3
|
242 |
+
},
|
243 |
+
"file_extension": ".py",
|
244 |
+
"mimetype": "text/x-python",
|
245 |
+
"name": "python",
|
246 |
+
"nbconvert_exporter": "python",
|
247 |
+
"pygments_lexer": "ipython3",
|
248 |
+
"version": "3.11.11"
|
249 |
+
}
|
250 |
+
},
|
251 |
+
"nbformat": 4,
|
252 |
+
"nbformat_minor": 5
|
253 |
+
}
|