cheaptrix commited on
Commit
edfb009
·
verified ·
1 Parent(s): b54a065

Added notebooks

Browse files
notebooks/T5_Base_Model_Interface.ipynb ADDED
@@ -0,0 +1,583 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "f2b5097c-3928-435d-8a86-a9f0116f9441",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from transformers import AutoTokenizer\n",
11
+ "\n",
12
+ "checkpoint = \"google-t5/t5-small\"\n",
13
+ "tokenizer = AutoTokenizer.from_pretrained(checkpoint)"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "id": "3a43b482-4b73-4d88-8197-9e63b7029d17",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "prefix = \"summarize: \"\n",
24
+ "\n",
25
+ "\n",
26
+ "def preprocess_function(examples):\n",
27
+ " inputs = [prefix + doc for doc in examples[\"text\"]]\n",
28
+ " model_inputs = tokenizer(inputs, max_length=1024, truncation=True)\n",
29
+ "\n",
30
+ " labels = tokenizer(text_target=examples[\"summary\"], max_length=128, truncation=True)\n",
31
+ "\n",
32
+ " model_inputs[\"labels\"] = labels[\"input_ids\"]\n",
33
+ " return model_inputs"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 3,
39
+ "id": "0baf8721-cc3c-47f9-a79c-def8397f548a",
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "name": "stderr",
44
+ "output_type": "stream",
45
+ "text": [
46
+ "2024-04-10 19:08:16.517364: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
47
+ "2024-04-10 19:08:16.557667: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
48
+ "2024-04-10 19:08:16.557712: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
49
+ "2024-04-10 19:08:16.557734: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
50
+ "2024-04-10 19:08:16.565003: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
51
+ "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
52
+ "2024-04-10 19:08:17.697728: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
53
+ ]
54
+ }
55
+ ],
56
+ "source": [
57
+ "from transformers import DataCollatorForSeq2Seq\n",
58
+ "\n",
59
+ "data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=checkpoint)"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 4,
65
+ "id": "8de1fe91-7871-4e61-b8f4-392a60b92d1e",
66
+ "metadata": {},
67
+ "outputs": [],
68
+ "source": [
69
+ "def compute_metrics(eval_pred):\n",
70
+ " predictions, labels = eval_pred\n",
71
+ " decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=True)\n",
72
+ " labels = np.where(labels != -100, labels, tokenizer.pad_token_id)\n",
73
+ " decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)\n",
74
+ "\n",
75
+ " result = rouge.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)\n",
76
+ "\n",
77
+ " prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in predictions]\n",
78
+ " result[\"gen_len\"] = np.mean(prediction_lens)\n",
79
+ "\n",
80
+ " return {k: round(v, 4) for k, v in result.items()}"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": 5,
86
+ "id": "b9e50d2c-84b5-4f34-b8c0-667fe835f767",
87
+ "metadata": {},
88
+ "outputs": [],
89
+ "source": [
90
+ "import json\n",
91
+ "\n",
92
+ "cleaned_test_data = []\n",
93
+ "# Opening JSON file\n",
94
+ "with open(\"cleaned_bill_sum_test_data.json\") as json_file:\n",
95
+ " cleaned_test_data = json.load(json_file)"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": 6,
101
+ "id": "ca7908ff-e08e-4f9a-8407-006c634732c7",
102
+ "metadata": {},
103
+ "outputs": [],
104
+ "source": [
105
+ "from transformers import AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer\n",
106
+ "\n",
107
+ "model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 7,
113
+ "id": "fc7e7286-c80d-4f6e-9e27-a867df58a447",
114
+ "metadata": {},
115
+ "outputs": [],
116
+ "source": [
117
+ "from transformers import pipeline\n",
118
+ "\n",
119
+ "summarizer = pipeline(\"summarization\", model=model, tokenizer=tokenizer)"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 8,
125
+ "id": "f40cba73-72b1-4a81-a33d-b29e7d99b899",
126
+ "metadata": {},
127
+ "outputs": [
128
+ {
129
+ "name": "stderr",
130
+ "output_type": "stream",
131
+ "text": [
132
+ "Token indices sequence length is longer than the specified maximum sequence length for this model (548 > 512). Running this sequence through the model will result in indexing errors\n"
133
+ ]
134
+ }
135
+ ],
136
+ "source": [
137
+ "generated_summaries = []\n",
138
+ "for i in range(len(cleaned_test_data)):\n",
139
+ " summary = summarizer(cleaned_test_data[i]['text'])\n",
140
+ " generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : cleaned_test_data[i]['summary']})"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 9,
146
+ "id": "6988fdaa-d0a7-4ead-9e6c-efe0faed0d41",
147
+ "metadata": {},
148
+ "outputs": [
149
+ {
150
+ "data": {
151
+ "text/plain": [
152
+ "{'generated': 'ACCEPT resolution 2023-01-25 Introduced in Senate Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution or the ACCEPT Resolution This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency . this file contains bill summaries for federal legislation .',\n",
153
+ " 'summary': 'Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution or the ACCEPT Resolution This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.'}"
154
+ ]
155
+ },
156
+ "execution_count": 9,
157
+ "metadata": {},
158
+ "output_type": "execute_result"
159
+ }
160
+ ],
161
+ "source": [
162
+ "generated_summaries[0]"
163
+ ]
164
+ },
165
+ {
166
+ "cell_type": "code",
167
+ "execution_count": 10,
168
+ "id": "550e0419-e591-4b93-a98a-6b9a93771ccf",
169
+ "metadata": {},
170
+ "outputs": [
171
+ {
172
+ "data": {
173
+ "text/plain": [
174
+ "{'generated': '2023-07-25 Introduced in Senate This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran . the resolution condemns (1) the brutal beating and death of Mahsa Amini; (2) the violent suppression by the Iranian regime of women and women participating in the current demonstrations .',\n",
175
+ " 'summary': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime. The resolution condemns (1) the brutal beating and death of Mahsa Amini; and (2) the violent suppression by the Iranian regime of women and men participating in the current demonstrations, including children, and calls for transparent accountability for all killings of protesters by Iranian security forces. Finally, the resolution encourages continued efforts by the Biden Administration to respond to the protests, including the recent sanctioning of the Iranian morality police.'}"
176
+ ]
177
+ },
178
+ "execution_count": 10,
179
+ "metadata": {},
180
+ "output_type": "execute_result"
181
+ }
182
+ ],
183
+ "source": [
184
+ "generated_summaries[1]"
185
+ ]
186
+ },
187
+ {
188
+ "cell_type": "code",
189
+ "execution_count": 11,
190
+ "id": "5b4ae304-3d18-43bb-af21-8e7a10055ace",
191
+ "metadata": {},
192
+ "outputs": [
193
+ {
194
+ "data": {
195
+ "text/plain": [
196
+ "{'generated': 'a concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on religious freedom day, January 16, 2023 . the resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship .',\n",
197
+ " 'summary': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.'}"
198
+ ]
199
+ },
200
+ "execution_count": 11,
201
+ "metadata": {},
202
+ "output_type": "execute_result"
203
+ }
204
+ ],
205
+ "source": [
206
+ "generated_summaries[2]"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": 12,
212
+ "id": "6fe7ec86-c00a-4035-b333-984a1d0d3758",
213
+ "metadata": {},
214
+ "outputs": [
215
+ {
216
+ "data": {
217
+ "text/plain": [
218
+ "{'generated': '2023-02-16 Introduced in Senate This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs .',\n",
219
+ " 'summary': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'}"
220
+ ]
221
+ },
222
+ "execution_count": 12,
223
+ "metadata": {},
224
+ "output_type": "execute_result"
225
+ }
226
+ ],
227
+ "source": [
228
+ "generated_summaries[3]"
229
+ ]
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "execution_count": 13,
234
+ "id": "547ae1b9-a596-4ae0-aa4f-0f9a93fdc4f7",
235
+ "metadata": {},
236
+ "outputs": [
237
+ {
238
+ "data": {
239
+ "text/plain": [
240
+ "{'generated': '2023-03-09 Introduced in Senate This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station . this file contains bill summaries for federal legislation .',\n",
241
+ " 'summary': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance of sound recordings.'}"
242
+ ]
243
+ },
244
+ "execution_count": 13,
245
+ "metadata": {},
246
+ "output_type": "execute_result"
247
+ }
248
+ ],
249
+ "source": [
250
+ "generated_summaries[4]"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "execution_count": 14,
256
+ "id": "5eb82a5e-8f1a-46a0-a928-e9a19918b397",
257
+ "metadata": {},
258
+ "outputs": [
259
+ {
260
+ "data": {
261
+ "text/plain": [
262
+ "{'generated': '2023-03-09 Introduced in Senate This concurrent resolution recognizes \"Abortion Provider Appreciation Day\" this file contains bill summaries for federal legislation . a bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law .',\n",
263
+ " 'summary': 'This concurrent resolution recognizes Abortion Provider Appreciation Day.'}"
264
+ ]
265
+ },
266
+ "execution_count": 14,
267
+ "metadata": {},
268
+ "output_type": "execute_result"
269
+ }
270
+ ],
271
+ "source": [
272
+ "generated_summaries[5]"
273
+ ]
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": 15,
278
+ "id": "497ceac3-d31f-40ae-b1a6-03ef91a74902",
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "data": {
283
+ "text/plain": [
284
+ "{'generated': \"2023-11-02 Passed Senate This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza . it calls for his immediate release and the release of all other Russian opposition leaders .\",\n",
285
+ " 'summary': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders. It also calls for the release of all political prisoners in Russia and in Belarus, as well as for the release of Ukrainian citizens held by Russia, and calls on the President and leaders of the free world to work tirelessly for the release of political prisoners in Russia.\"}"
286
+ ]
287
+ },
288
+ "execution_count": 15,
289
+ "metadata": {},
290
+ "output_type": "execute_result"
291
+ }
292
+ ],
293
+ "source": [
294
+ "generated_summaries[6]"
295
+ ]
296
+ },
297
+ {
298
+ "cell_type": "code",
299
+ "execution_count": 16,
300
+ "id": "8dacc198-616c-4e4a-8feb-2946cd79e83e",
301
+ "metadata": {},
302
+ "outputs": [
303
+ {
304
+ "data": {
305
+ "text/plain": [
306
+ "{'generated': '2023-03-23 Introduced in Senate This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the united states . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs .',\n",
307
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.'}"
308
+ ]
309
+ },
310
+ "execution_count": 16,
311
+ "metadata": {},
312
+ "output_type": "execute_result"
313
+ }
314
+ ],
315
+ "source": [
316
+ "generated_summaries[7]"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "code",
321
+ "execution_count": 17,
322
+ "id": "9840e4e9-6c45-4a4f-bea5-7905c8564ad5",
323
+ "metadata": {},
324
+ "outputs": [
325
+ {
326
+ "data": {
327
+ "text/plain": [
328
+ "{'generated': '2023-04-27 Introduced in Senate This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency . it demands the president use existing authorities and emergency powers to mitigate and address its consequences and causes .',\n",
329
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.'}"
330
+ ]
331
+ },
332
+ "execution_count": 17,
333
+ "metadata": {},
334
+ "output_type": "execute_result"
335
+ }
336
+ ],
337
+ "source": [
338
+ "generated_summaries[8]"
339
+ ]
340
+ },
341
+ {
342
+ "cell_type": "code",
343
+ "execution_count": 18,
344
+ "id": "9274312e-db9a-4a69-98c0-026c8571eb01",
345
+ "metadata": {},
346
+ "outputs": [
347
+ {
348
+ "data": {
349
+ "text/plain": [
350
+ "{'generated': 'a bill summary describes the most significant provisions of a piece of legislation . the document is not subject to copyright protection and is in the public domain . it is authored by the Congressional Research Service .',\n",
351
+ " 'summary': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\"}"
352
+ ]
353
+ },
354
+ "execution_count": 18,
355
+ "metadata": {},
356
+ "output_type": "execute_result"
357
+ }
358
+ ],
359
+ "source": [
360
+ "generated_summaries[9]"
361
+ ]
362
+ },
363
+ {
364
+ "cell_type": "code",
365
+ "execution_count": 19,
366
+ "id": "dcb8951d-2d21-4578-aecb-f363904a0504",
367
+ "metadata": {},
368
+ "outputs": [
369
+ {
370
+ "data": {
371
+ "text/plain": [
372
+ "{'generated': '2023-05-31 Introduced in Senate This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs .',\n",
373
+ " 'summary': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.'}"
374
+ ]
375
+ },
376
+ "execution_count": 19,
377
+ "metadata": {},
378
+ "output_type": "execute_result"
379
+ }
380
+ ],
381
+ "source": [
382
+ "generated_summaries[10]"
383
+ ]
384
+ },
385
+ {
386
+ "cell_type": "code",
387
+ "execution_count": 20,
388
+ "id": "dd26c5d5-d6df-4213-b0ef-de281a97a1c9",
389
+ "metadata": {},
390
+ "outputs": [
391
+ {
392
+ "data": {
393
+ "text/plain": [
394
+ "{'generated': '2023-07-18 Introduced in Senate This concurrent resolution calls on the media to voluntarily adopt certain practices . it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public murders .',\n",
395
+ " 'summary': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public murders (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public murders.'}"
396
+ ]
397
+ },
398
+ "execution_count": 20,
399
+ "metadata": {},
400
+ "output_type": "execute_result"
401
+ }
402
+ ],
403
+ "source": [
404
+ "generated_summaries[11]"
405
+ ]
406
+ },
407
+ {
408
+ "cell_type": "code",
409
+ "execution_count": 21,
410
+ "id": "06dc9580-d980-4901-9aab-ae125b01689a",
411
+ "metadata": {},
412
+ "outputs": [
413
+ {
414
+ "data": {
415
+ "text/plain": [
416
+ "{'generated': '2023-07-27 Introduced in Senate This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery . it urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation .',\n",
417
+ " 'summary': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.'}"
418
+ ]
419
+ },
420
+ "execution_count": 21,
421
+ "metadata": {},
422
+ "output_type": "execute_result"
423
+ }
424
+ ],
425
+ "source": [
426
+ "generated_summaries[12]"
427
+ ]
428
+ },
429
+ {
430
+ "cell_type": "code",
431
+ "execution_count": 22,
432
+ "id": "6fd5488c-9ab3-4009-aacd-1414b78ce86c",
433
+ "metadata": {},
434
+ "outputs": [
435
+ {
436
+ "data": {
437
+ "text/plain": [
438
+ "{'generated': '2023-10-04 Introduced in Senate This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men . a bill summary describes the most significant provisions of a piece of legislation .',\n",
439
+ " 'summary': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\"}"
440
+ ]
441
+ },
442
+ "execution_count": 22,
443
+ "metadata": {},
444
+ "output_type": "execute_result"
445
+ }
446
+ ],
447
+ "source": [
448
+ "generated_summaries[13]"
449
+ ]
450
+ },
451
+ {
452
+ "cell_type": "code",
453
+ "execution_count": 23,
454
+ "id": "0761573c-56f5-486d-a1fd-049cac959071",
455
+ "metadata": {},
456
+ "outputs": [
457
+ {
458
+ "data": {
459
+ "text/plain": [
460
+ "{'generated': '2023-10-26 Introduced in Senate This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs .',\n",
461
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.'}"
462
+ ]
463
+ },
464
+ "execution_count": 23,
465
+ "metadata": {},
466
+ "output_type": "execute_result"
467
+ }
468
+ ],
469
+ "source": [
470
+ "generated_summaries[14]"
471
+ ]
472
+ },
473
+ {
474
+ "cell_type": "code",
475
+ "execution_count": 24,
476
+ "id": "713ea198-a3e6-46b1-b8e1-dd823ea0e04f",
477
+ "metadata": {},
478
+ "outputs": [
479
+ {
480
+ "data": {
481
+ "text/plain": [
482
+ "{'generated': '2024-02-13 Introduced in Senate This concurrent resolution provides for a correction in the official title of H.R. 815 . a bill summary describes the most significant provisions of a piece of legislation .',\n",
483
+ " 'summary': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).'}"
484
+ ]
485
+ },
486
+ "execution_count": 24,
487
+ "metadata": {},
488
+ "output_type": "execute_result"
489
+ }
490
+ ],
491
+ "source": [
492
+ "generated_summaries[15]"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "markdown",
497
+ "id": "68c08713-89d9-4611-8cf5-9c86bed5fc29",
498
+ "metadata": {},
499
+ "source": [
500
+ "# ROUGE EVALUATION"
501
+ ]
502
+ },
503
+ {
504
+ "cell_type": "code",
505
+ "execution_count": 26,
506
+ "id": "e869ae4a-6126-4256-98b4-4c36556e4cec",
507
+ "metadata": {},
508
+ "outputs": [],
509
+ "source": [
510
+ "def ROUGE_evaluate(data_set : list):\n",
511
+ " date = data_set\n",
512
+ " for i in range(len(generated_summaries)):\n",
513
+ " rouge = evaluate.load('rouge')\n",
514
+ " predictions = [generated_summaries[i]['generated']]\n",
515
+ " references = [generated_summaries[i]['summary']]\n",
516
+ " results = rouge.compute(predictions=predictions, references=references)\n",
517
+ " print(results)"
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 27,
523
+ "id": "9d9df0d5-8436-44e2-8be8-01ba1f699436",
524
+ "metadata": {},
525
+ "outputs": [
526
+ {
527
+ "name": "stdout",
528
+ "output_type": "stream",
529
+ "text": [
530
+ "{'rouge1': 0.7538461538461538, 'rouge2': 0.71875, 'rougeL': 0.7230769230769232, 'rougeLsum': 0.7230769230769232}\n",
531
+ "{'rouge1': 0.5325443786982248, 'rouge2': 0.4790419161676647, 'rougeL': 0.5207100591715977, 'rougeLsum': 0.5207100591715977}\n",
532
+ "{'rouge1': 0.7338129496402878, 'rouge2': 0.7153284671532847, 'rougeL': 0.7194244604316548, 'rougeLsum': 0.7194244604316548}\n",
533
+ "{'rouge1': 0.5319148936170212, 'rouge2': 0.41304347826086957, 'rougeL': 0.5106382978723404, 'rougeLsum': 0.5106382978723404}\n",
534
+ "{'rouge1': 0.6808510638297872, 'rouge2': 0.6521739130434783, 'rougeL': 0.6808510638297872, 'rougeLsum': 0.6808510638297872}\n",
535
+ "{'rouge1': 0.2909090909090909, 'rouge2': 0.2641509433962264, 'rougeL': 0.2909090909090909, 'rougeLsum': 0.2909090909090909}\n",
536
+ "{'rouge1': 0.5499999999999999, 'rouge2': 0.5084745762711864, 'rougeL': 0.5333333333333333, 'rougeLsum': 0.5333333333333333}\n",
537
+ "{'rouge1': 0.6067415730337079, 'rouge2': 0.5747126436781609, 'rougeL': 0.6067415730337079, 'rougeLsum': 0.6067415730337079}\n",
538
+ "{'rouge1': 0.7804878048780488, 'rouge2': 0.725, 'rougeL': 0.7804878048780488, 'rougeLsum': 0.7804878048780488}\n",
539
+ "{'rouge1': 0.2222222222222222, 'rouge2': 0.022727272727272724, 'rougeL': 0.17777777777777778, 'rougeLsum': 0.17777777777777778}\n",
540
+ "{'rouge1': 0.6133333333333333, 'rouge2': 0.6027397260273972, 'rougeL': 0.6133333333333333, 'rougeLsum': 0.6133333333333333}\n",
541
+ "{'rouge1': 0.6837606837606838, 'rouge2': 0.6434782608695652, 'rougeL': 0.6666666666666667, 'rougeLsum': 0.6666666666666667}\n",
542
+ "{'rouge1': 0.8141592920353982, 'rouge2': 0.7747747747747747, 'rougeL': 0.8141592920353982, 'rougeLsum': 0.8141592920353982}\n",
543
+ "{'rouge1': 0.5151515151515151, 'rouge2': 0.46875, 'rougeL': 0.5151515151515151, 'rougeLsum': 0.5151515151515151}\n",
544
+ "{'rouge1': 0.5822784810126582, 'rouge2': 0.4675324675324675, 'rougeL': 0.5569620253164557, 'rougeLsum': 0.5569620253164557}\n",
545
+ "{'rouge1': 0.46875, 'rouge2': 0.2903225806451613, 'rougeL': 0.40625, 'rougeLsum': 0.40625}\n"
546
+ ]
547
+ }
548
+ ],
549
+ "source": [
550
+ "ROUGE_evaluate(generated_summaries)"
551
+ ]
552
+ },
553
+ {
554
+ "cell_type": "code",
555
+ "execution_count": null,
556
+ "id": "f0fff4ba-a967-4fac-88da-88d238967680",
557
+ "metadata": {},
558
+ "outputs": [],
559
+ "source": []
560
+ }
561
+ ],
562
+ "metadata": {
563
+ "kernelspec": {
564
+ "display_name": "Python 3 (ipykernel)",
565
+ "language": "python",
566
+ "name": "python3"
567
+ },
568
+ "language_info": {
569
+ "codemirror_mode": {
570
+ "name": "ipython",
571
+ "version": 3
572
+ },
573
+ "file_extension": ".py",
574
+ "mimetype": "text/x-python",
575
+ "name": "python",
576
+ "nbconvert_exporter": "python",
577
+ "pygments_lexer": "ipython3",
578
+ "version": "3.11.7"
579
+ }
580
+ },
581
+ "nbformat": 4,
582
+ "nbformat_minor": 5
583
+ }
notebooks/T5_California_Bill_Finetune.ipynb ADDED
@@ -0,0 +1,968 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "695a0d97-6b1d-4448-b16c-3ba95bb60c30",
6
+ "metadata": {},
7
+ "source": [
8
+ "# If these install, restart the kernal so it has access to the recently installed files"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "id": "22de09b1-3c40-4195-8b5a-926d5391313f",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "!pip3 install --user transformers datasets evaluate rouge_score\n",
19
+ "!pip3 install --user datasets\n",
20
+ "!pip install --user transformers[torch]\n",
21
+ "!pip install --user accelerate -U\n",
22
+ "!pip install --user wandb"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "markdown",
27
+ "id": "e1687d09-6b14-47fb-9819-dbed0d8ae3b3",
28
+ "metadata": {},
29
+ "source": [
30
+ "# Logging into huggingface hub"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 1,
36
+ "id": "f2f10d5e-9655-4554-abb0-511044640854",
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "application/vnd.jupyter.widget-view+json": {
42
+ "model_id": "85b2b1cf7e174dc4b50a3ff3a768b282",
43
+ "version_major": 2,
44
+ "version_minor": 0
45
+ },
46
+ "text/plain": [
47
+ "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
48
+ ]
49
+ },
50
+ "metadata": {},
51
+ "output_type": "display_data"
52
+ }
53
+ ],
54
+ "source": [
55
+ "from huggingface_hub import notebook_login\n",
56
+ "\n",
57
+ "notebook_login()"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "markdown",
62
+ "id": "05b9e8c7-b52d-4a1f-8464-fb5f7e78e579",
63
+ "metadata": {},
64
+ "source": [
65
+ "# Naming the WANDB project and notebook"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 2,
71
+ "id": "6b4bad30-76c7-49dc-b563-a27ed9465eee",
72
+ "metadata": {},
73
+ "outputs": [
74
+ {
75
+ "name": "stderr",
76
+ "output_type": "stream",
77
+ "text": [
78
+ "\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m WANDB_NOTEBOOK_NAME should be a path to a notebook file, couldn't find ./TermProject.\n",
79
+ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mtah6k\u001b[0m (\u001b[33mcheaptrix\u001b[0m). Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
80
+ ]
81
+ },
82
+ {
83
+ "data": {
84
+ "text/html": [
85
+ "wandb version 0.16.6 is available! To upgrade, please run:\n",
86
+ " $ pip install wandb --upgrade"
87
+ ],
88
+ "text/plain": [
89
+ "<IPython.core.display.HTML object>"
90
+ ]
91
+ },
92
+ "metadata": {},
93
+ "output_type": "display_data"
94
+ },
95
+ {
96
+ "data": {
97
+ "text/html": [
98
+ "Tracking run with wandb version 0.16.2"
99
+ ],
100
+ "text/plain": [
101
+ "<IPython.core.display.HTML object>"
102
+ ]
103
+ },
104
+ "metadata": {},
105
+ "output_type": "display_data"
106
+ },
107
+ {
108
+ "data": {
109
+ "text/html": [
110
+ "Run data is saved locally in <code>/scratch/user/u.th161689/AI_NLP/TermProject/wandb/run-20240403_223123-2h8q76y0</code>"
111
+ ],
112
+ "text/plain": [
113
+ "<IPython.core.display.HTML object>"
114
+ ]
115
+ },
116
+ "metadata": {},
117
+ "output_type": "display_data"
118
+ },
119
+ {
120
+ "data": {
121
+ "text/html": [
122
+ "Syncing run <strong><a href='https://wandb.ai/cheaptrix/California_bills_summary/runs/2h8q76y0' target=\"_blank\">swift-planet-1</a></strong> to <a href='https://wandb.ai/cheaptrix/California_bills_summary' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
123
+ ],
124
+ "text/plain": [
125
+ "<IPython.core.display.HTML object>"
126
+ ]
127
+ },
128
+ "metadata": {},
129
+ "output_type": "display_data"
130
+ },
131
+ {
132
+ "data": {
133
+ "text/html": [
134
+ " View project at <a href='https://wandb.ai/cheaptrix/California_bills_summary' target=\"_blank\">https://wandb.ai/cheaptrix/California_bills_summary</a>"
135
+ ],
136
+ "text/plain": [
137
+ "<IPython.core.display.HTML object>"
138
+ ]
139
+ },
140
+ "metadata": {},
141
+ "output_type": "display_data"
142
+ },
143
+ {
144
+ "data": {
145
+ "text/html": [
146
+ " View run at <a href='https://wandb.ai/cheaptrix/California_bills_summary/runs/2h8q76y0' target=\"_blank\">https://wandb.ai/cheaptrix/California_bills_summary/runs/2h8q76y0</a>"
147
+ ],
148
+ "text/plain": [
149
+ "<IPython.core.display.HTML object>"
150
+ ]
151
+ },
152
+ "metadata": {},
153
+ "output_type": "display_data"
154
+ },
155
+ {
156
+ "data": {
157
+ "text/html": [
158
+ "<button onClick=\"this.nextSibling.style.display='block';this.style.display='none';\">Display W&B run</button><iframe src='https://wandb.ai/cheaptrix/California_bills_summary/runs/2h8q76y0?jupyter=true' style='border:none;width:100%;height:420px;display:none;'></iframe>"
159
+ ],
160
+ "text/plain": [
161
+ "<wandb.sdk.wandb_run.Run at 0x14c5f8617710>"
162
+ ]
163
+ },
164
+ "execution_count": 2,
165
+ "metadata": {},
166
+ "output_type": "execute_result"
167
+ }
168
+ ],
169
+ "source": [
170
+ "# Must set the global variable WANDB_NOTEBOOK_NAME to the name of the notebook\n",
171
+ "import os\n",
172
+ "import wandb\n",
173
+ "# Name is found through the os incase the name changes\n",
174
+ "# WANDB_NOTEBOOK_NAME = os.path.basename(os.getcwd())\n",
175
+ "notebook_name = str(os.path.basename(os.getcwd()))\n",
176
+ "os.environ[\"WANDB_NOTEBOOK_NAME\"] = \"./\" + notebook_name\n",
177
+ "os.environ[\"WANDB_PROJECT\"] = \"California_bills_summary\"\n",
178
+ "wandb.init(project='California_bills_summary') "
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "markdown",
183
+ "id": "69fbba70-2fb2-47c9-abc9-1824a3ab10d7",
184
+ "metadata": {},
185
+ "source": [
186
+ "# Importing and loading the California Bills dataset"
187
+ ]
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ "execution_count": 3,
192
+ "id": "fd3b62f1-5bd2-44ff-87f3-1d48ccb74459",
193
+ "metadata": {},
194
+ "outputs": [],
195
+ "source": [
196
+ "from datasets import load_dataset\n",
197
+ "\n",
198
+ "billsum = load_dataset(\"billsum\", split=\"ca_test\")"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "markdown",
203
+ "id": "2c87b4f7-bdbd-4869-8975-609373000ab0",
204
+ "metadata": {},
205
+ "source": [
206
+ "# Splitting the data to training and testing split"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": 4,
212
+ "id": "9f08c14e-820e-497d-a979-6332bce67bc1",
213
+ "metadata": {},
214
+ "outputs": [],
215
+ "source": [
216
+ "billsum = billsum.train_test_split(test_size=0.2)"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "markdown",
221
+ "id": "9949be74-ed88-49a8-8465-8290af7abe6f",
222
+ "metadata": {},
223
+ "source": [
224
+ "# Example of data within the training set"
225
+ ]
226
+ },
227
+ {
228
+ "cell_type": "code",
229
+ "execution_count": 5,
230
+ "id": "2f7551a5-631d-4de3-afb7-99d923d18ccd",
231
+ "metadata": {},
232
+ "outputs": [
233
+ {
234
+ "data": {
235
+ "text/plain": [
236
+ "{'text': \"The people of the State of California do enact as follows:\\n\\n\\nSECTION 1.\\nThe Legislature finds and declares as follows:\\n(a) On February 27, 2014, the President of the United States launched the My Brother’s Keeper initiative to address persistent opportunity gaps faced by boys and young men of color and to ensure that all young people can reach their full potential.\\n(b) The My Brother’s Keeper Task Force recognizes that challenges facing boys and young men of color affect others as well and that it is important to break down barriers wherever they exist and to identify means of creating ladders of opportunity for all.\\n(c) The My Brother’s Keeper Task Force was established to develop a coordinated federal effort to significantly improve the expected life outcomes for boys and young men of color, including Black Americans, Hispanic Americans, and Native Americans, and to improve their contributions to the nation’s prosperity, so that all youth have an equal opportunity at achieving the American dream.\\n(d) The My Brother’s Keeper Task Force noted that significant diversity exists within and among boys and men of color as a segment of the population. Differences of language status, income, disability, sexual orientation, and many other factors influence the identity and experience of these young people, just as with any other population.\\n(e) My Brother’s Keeper is focused on the following milestones: (1) getting a healthy start and entering school ready to learn; (2) reading at grade level by third grade; (3) graduating from high school ready for college and career; (4) completing postsecondary education or training; (5) successfully entering the workforce; and (6) keeping kids on track and giving them second chances.\\n(f) The My Brother’s Keeper Task Force Report to the President (May 2014) cites numerous areas in which boys and men of color consistently experience disproportionately negative outcomes. These areas include living in poverty, living without a male parent in the household, high school dropout rates, unemployment, death by homicide, and imprisonment.\\n(g) The My Brother’s Keeper Task Force has identified initial recommendations and areas of opportunity at each of these key milestones or “focus areas.” The task force has also identified several cross-cutting areas of opportunity that span all focus areas.\\n(h) The recommendations in the My Brother’s Keeper Task Force Report to the President inform and influence California policy and California’s compliance with those recommendations makes the state more competitive for federal funding and strengthens its economic competitiveness.\\n(i) Our state’s future prosperity and health depend on all Californians having a fair chance to thrive and succeed. One of the best investments we can make is to be certain we do everything possible to help young people become healthy, productive adults. As California becomes more diverse, we must nurture and harness the talents, skills, and hopes of young people of color — boys and young men in particular.\\n(j) The Department of Finance projects California’s population of boys and men of color will increasingly represent a growing percentage of the state's male population, reaching close to 80 percent for boys and men of color compared to 20 percent for non-Hispanic white males by 2050.\\n(k) The Assembly Select Committee on the Status of Boys and Men of Color in California has recognized that boys and young men of color are in jeopardy, and this poses a serious threat to California’s economic strength and competitiveness.\\n(l) The Assembly Select Committee on the Status of Boys and Men of Color’s policy framework emphasizes the following issues: (1) health and safety; (2) education; (3) juvenile justice; (4) employment and wealth; and (5) youth development. Related issues that have been recommended for expansion of the committee’s work include higher education, immigration, and housing.\\n(m) Community and youth leaders from across the state have taken a significant interest in partnering with government and systems leaders through the Alliance for Boys and Men of Color in order to improve the health and success of our state’s young people of color.\\nSEC. 2.\\nChapter 3.4 (commencing with Section 8265) is added to Division 1 of Title 2 of the Government Code, to read:\\nCHAPTER 3.4. Interagency Task Force on the Status of Boys and Men of Color\\n8265.\\n(a) (1) There is in state government the Interagency Task Force on the Status of Boys and Men of Color, which shall serve as a support mechanism for department, agency, and systems leaders by taking coordinated action in meeting the myriad of challenges facing boys and men of color, and assisting the respective departments and agencies in more successfully improving life outcomes for this population.\\n(2) It is the intent of the Legislature that the task force include participation from a core set of department, agency, and systems leaders with discretion and responsibility for policy areas of primary importance to the fulfillment of the Final Report and Policy Platform for State Action (2012–18) of the Assembly Select Committee on the Status of Boys and Men in California.\\n(b) The task force shall be comprised of the following 20 members:\\n(1) One Member of the Senate, appointed by the Senate Committee on Rules, and one Member of the Assembly, appointed by the Speaker of the Assembly, as ex officio, nonvoting members, and to the extent that participation is not incompatible with their position as Members of the Legislature.\\n(2) The Superintendent of Public Instruction, or his or her designee.\\n(3) The President of the University of California, or his or her designee.\\n(4) The Chancellor of the California State University, or his or her designee.\\n(5) The Chancellor of the California Community Colleges, or his or her designee.\\n(6) The Secretary of California Health and Human Services, or his or her designee.\\n(7) The State Public Health Officer, or his or her designee.\\n(8) The Deputy Director of the Office of Health Equity, or his or her designee.\\n(9) The Secretary of Business, Consumer Services, and Housing, or his or her designee.\\n(10) The Secretary of Labor and Workforce Development, or his or her designee.\\n(11) The Director of Employment Development, or his or her designee.\\n(12) The Executive Director of the California Workforce Investment Board, or his or her designee.\\n(13) The Chair of the California Workforce Investment Board, or his or her designee.\\n(14) The Secretary of Transportation, or his or her designee.\\n(15) The Director of Finance, or his or her designee.\\n(16) The Attorney General, or his or her designee.\\n(17) The Secretary of the Department of Corrections and Rehabilitation, or his or her designee.\\n(18) The Chair of the Board of State and Community Corrections, or his or her designee.\\n(19) The Chief Justice of California, or his or her designee.\\n(c) The task force shall elect one of its members to serve as chair of the task force. Desirable qualifications for the position of chair shall include, but not be limited to, all of the following:\\n(1) He or she should possess a broad and deep understanding of the issues facing boys and men of color.\\n(2) He or she should be a political appointee with a senior leadership role either leading a department or agency or managing a significant and pertinent body of work.\\n(3) He or she should have a demonstrated strong and positive working relationship with the members of the Legislature and the Governor.\\n(d) All members of the task force shall hold office until the appointment of their successors.\\n8266.\\nMeetings of the task force shall be subject to the Bagley-Keene Open Meetings Act (Article 9 (commencing with Section 11120) of Chapter 1 of Part 1 of Division 3).\\n8267.\\nThe task force shall have the powers and authority necessary to carry out the duties imposed upon it by this chapter, including, but not limited to, all of the following:\\n(a) To employ any administrative, technical, or other personnel necessary for the performance of its powers and duties.\\n(b) To hold hearings, make and sign any agreements, and to do or perform any acts that may be necessary, desirable, or proper to carry out the purposes of this chapter.\\n(c) To cooperate with, and secure the cooperation of, any department, division, board, bureau, commission, or other agency of the state to facilitate the task force properly to carry out its powers and duties.\\n(d) To appoint advisers or advisory committees from time to time when the task force determines that the experience or expertise of the advisers or advisory committees is needed for projects of the task force. Section 11009 shall apply to these advisers or advisory committees.\\n(e) To accept any federal funds granted, by act of Congress or by executive order, for all or any of the purposes of this chapter.\\n(f) To accept any gifts, donations, grants, or bequests for all or any of the purposes of this chapter.\\n8268.\\n(a) Within six months after the effective date of this chapter, the task force shall complete all of the following requirements:\\n(1) Assess existing department and agency programs that align with the priorities outlined in the May 2014 My Brother’s Keeper Task Force Report to the President. Based on this assessment, the task force shall identify state opportunities to partner and coordinate with the work of the federal My Brother’s Keeper Task Force.\\n(2) Assess the Governor’s Budget to identify those areas in which the budget priorities are in alignment with the objectives of the task force.\\n(3) Review the action plan of the Final Report and Policy Platform for State Action (2012–18) of the Assembly Select Committee on the Status of Boys and Men of Color in California, and identify ambitious state goals for boys and men of color, as well as barriers to achieving desired results.\\n(b) Upon completion of the requirements in subdivision (a), the long-term, ongoing responsibilities of the task force shall include all of the following:\\n(1) Assessing state policies, regulations, and programs with respect to boys and men of color, and the development of proven and promising strategies to enhance positive outcomes and eliminate or mitigate negative outcomes.\\n(2) Preparing population and agency-specific data on boys and men of color in California. The task force shall aggregate the data and make it publicly available in a manner that does not reveal personally identifiable information or otherwise conflict with federal or state privacy laws.\\n(3) Serving as a liaison to departments and agencies by ensuring engagement and partnership with other public, nonprofit, and philanthropic entities among the various member agencies and with the task force as a whole, and recommend ways to strengthen partnerships with external leaders advancing strategies relevant to boys and men of color.\\n(c) The first meeting of the task force shall be convened on or before January 31, 2016. Subsequently, the task force shall convene on no less than a quarterly basis to assess progress on its ongoing responsibilities pursuant to subdivision (b), and to provide support and ensure coordination across agencies.\\n(d) (1) Notwithstanding Section 10231.5, the task force shall prepare and submit to the Legislature an annual report on department and agency findings pursuant to this section. The task force shall also report these findings at the Assembly Select Committee on the Status of Boys and Men of Color in California’s annual hearing on the status of advancing the committee priorities and policies.\\n(2) A report submitted pursuant to this subdivision shall be submitted in compliance with Section 9795.\\n8269.\\nWith respect to its duties under Section 8268, the task force shall be an advisory body only, and there shall be no right or obligation on the part of the state, or the parties meeting and conferring, to implement the findings of the task force without further legislation that specifically authorizes that the evaluations, determinations, and findings of the task force be implemented.\\n8269.5\\nThe Boys and Men of Color Task Force Fund is hereby created as a fund in the State Treasury to carry out this chapter in support of the task force, upon appropriation by the Legislature. Subject to the approval of the Department of Finance, all moneys collected or received by the task force from gifts, bequests, or donations shall be deposited in the State Treasury to the credit of the Boys and Men of Color Task Force Fund in accordance with the terms of the gift or donation from which the moneys are derived and in accordance with Sections 8647, 11005, 11005.1, and 16302 of the Government Code.\\n8269.7.\\nThis chapter shall remain in effect only until January 1, 2026, and as of that date is repealed.\",\n",
237
+ " 'summary': 'The California Constitution prohibits a person from being deprived of life, liberty, or property without due process of law, or from being denied equal protection of the laws. The United States Constitution prohibits a state from denying to any person within its jurisdiction the equal protection of the laws. Existing law establishes various advisory boards and commissions in state government with specified duties and responsibilities.\\nThe federal My Brother’s Keeper Initiative, launched by the President of the United States in February 2014, required the establishment of the My Brother’s Keeper Task Force, an interagency effort to improve the expected educational and life outcomes for and address the persistent opportunity gaps faced by boys and young men of color in the United States.\\nThis bill would establish until January 1, 2026, the Interagency Task Force on the Status of Boys and Men of Color, a multiagency advisory body that would serve as a support mechanism for department agency and systems leaders by taking coordinated action in meeting the myriad of challenges facing boys and men of color in California, and assisting the respective departments and agencies in more successfully improving life outcomes for this population. The membership of the task force would include members of the Legislature, as well as representatives of specified agencies, departments, and private entities. The bill would set forth the initial and ongoing responsibilities of the task force, including, among others, an assessment of state program alignment with the objectives of the My Brother’s Keeper program, review the action plan of a specified final report of the Assembly Select Committee on the Status of Boys and Men of Color in California, and an assessment of the development of strategies to enhance positive outcomes and eliminate or mitigate negative outcomes for boys and men of color in the state. The bill would establish the Boys and Men of Color Task Force Fund, which would be subject to appropriation by the Legislature, to carry out the bill’s requirements in support of the task force, upon appropriation by the Legislature. The bill would authorize the task force to accept federal funds, gifts, donations, grants, or bequests for all or any of its purposes.',\n",
238
+ " 'title': 'An act to add and repeal Chapter 3.4 (commencing with Section 8265) to Division 1 of Title 2 of the Government Code, relating to state government.'}"
239
+ ]
240
+ },
241
+ "execution_count": 5,
242
+ "metadata": {},
243
+ "output_type": "execute_result"
244
+ }
245
+ ],
246
+ "source": [
247
+ "billsum[\"train\"][0]"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "markdown",
252
+ "id": "7c2e2c67-3d0b-4d4b-b3b6-e6d9afb60c8a",
253
+ "metadata": {},
254
+ "source": [
255
+ "# Load T5 tokenizer to process text and summary"
256
+ ]
257
+ },
258
+ {
259
+ "cell_type": "code",
260
+ "execution_count": 6,
261
+ "id": "b3d4454e-e7f3-4020-9ecc-4c692c6da5c6",
262
+ "metadata": {},
263
+ "outputs": [],
264
+ "source": [
265
+ "from transformers import AutoTokenizer\n",
266
+ "\n",
267
+ "checkpoint = \"google-t5/t5-small\"\n",
268
+ "tokenizer = AutoTokenizer.from_pretrained(checkpoint)"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "id": "15e4537b-4a72-434a-8af7-1cef702581d0",
274
+ "metadata": {},
275
+ "source": [
276
+ "# Perprocessing Function"
277
+ ]
278
+ },
279
+ {
280
+ "cell_type": "code",
281
+ "execution_count": 7,
282
+ "id": "2feec165-87ed-4258-a332-14c3b7dd9867",
283
+ "metadata": {},
284
+ "outputs": [],
285
+ "source": [
286
+ "prefix = \"summarize: \"\n",
287
+ "\n",
288
+ "\n",
289
+ "def preprocess_function(examples):\n",
290
+ " inputs = [prefix + doc for doc in examples[\"text\"]]\n",
291
+ " model_inputs = tokenizer(inputs, max_length=1024, truncation=True)\n",
292
+ "\n",
293
+ " labels = tokenizer(text_target=examples[\"summary\"], max_length=128, truncation=True)\n",
294
+ "\n",
295
+ " model_inputs[\"labels\"] = labels[\"input_ids\"]\n",
296
+ " return model_inputs"
297
+ ]
298
+ },
299
+ {
300
+ "cell_type": "markdown",
301
+ "id": "814f0888-e5c0-4841-9084-ed4f6762ecdd",
302
+ "metadata": {},
303
+ "source": [
304
+ "# Tokenize the dataset using the map function"
305
+ ]
306
+ },
307
+ {
308
+ "cell_type": "code",
309
+ "execution_count": 8,
310
+ "id": "65c755b9-33ae-4d95-b0d2-b7b7950f4f71",
311
+ "metadata": {},
312
+ "outputs": [
313
+ {
314
+ "data": {
315
+ "application/vnd.jupyter.widget-view+json": {
316
+ "model_id": "24949b7ce3e54b5689d7d42a928d1d49",
317
+ "version_major": 2,
318
+ "version_minor": 0
319
+ },
320
+ "text/plain": [
321
+ "Map: 0%| | 0/989 [00:00<?, ? examples/s]"
322
+ ]
323
+ },
324
+ "metadata": {},
325
+ "output_type": "display_data"
326
+ },
327
+ {
328
+ "data": {
329
+ "application/vnd.jupyter.widget-view+json": {
330
+ "model_id": "8d68949efc8c4ef68bbbffeaac9f1aae",
331
+ "version_major": 2,
332
+ "version_minor": 0
333
+ },
334
+ "text/plain": [
335
+ "Map: 0%| | 0/248 [00:00<?, ? examples/s]"
336
+ ]
337
+ },
338
+ "metadata": {},
339
+ "output_type": "display_data"
340
+ }
341
+ ],
342
+ "source": [
343
+ "tokenized_billsum = billsum.map(preprocess_function, batched=True)"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "markdown",
348
+ "id": "294ec0e7-5120-4c13-9517-6e4407dd12e7",
349
+ "metadata": {},
350
+ "source": [
351
+ "# Creating a batch of examples using DataCollatorForSeq2Seq with dynamic padding"
352
+ ]
353
+ },
354
+ {
355
+ "cell_type": "code",
356
+ "execution_count": 9,
357
+ "id": "a1e9d07d-7cbf-46c2-87c6-9ebc97fcbfcf",
358
+ "metadata": {},
359
+ "outputs": [
360
+ {
361
+ "name": "stderr",
362
+ "output_type": "stream",
363
+ "text": [
364
+ "2024-04-03 22:31:45.588933: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
365
+ "2024-04-03 22:31:45.622854: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
366
+ "2024-04-03 22:31:45.622885: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
367
+ "2024-04-03 22:31:45.622911: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
368
+ "2024-04-03 22:31:45.629431: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
369
+ "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
370
+ "2024-04-03 22:31:46.665693: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
371
+ ]
372
+ }
373
+ ],
374
+ "source": [
375
+ "from transformers import DataCollatorForSeq2Seq\n",
376
+ "\n",
377
+ "data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=checkpoint)"
378
+ ]
379
+ },
380
+ {
381
+ "cell_type": "markdown",
382
+ "id": "bd435fc8-af8b-419b-b41b-384f6b412119",
383
+ "metadata": {},
384
+ "source": [
385
+ "# Importing the evaluator"
386
+ ]
387
+ },
388
+ {
389
+ "cell_type": "code",
390
+ "execution_count": 10,
391
+ "id": "bc7159a1-3997-47bd-8d17-48c2e09f7ace",
392
+ "metadata": {},
393
+ "outputs": [],
394
+ "source": [
395
+ "import evaluate\n",
396
+ "\n",
397
+ "rouge = evaluate.load(\"rouge\")"
398
+ ]
399
+ },
400
+ {
401
+ "cell_type": "markdown",
402
+ "id": "11f1979d-91e3-414f-b76b-36034e97b8b0",
403
+ "metadata": {},
404
+ "source": [
405
+ "# Function that passes predictions and labels to compute to calculate the Rouge metric."
406
+ ]
407
+ },
408
+ {
409
+ "cell_type": "code",
410
+ "execution_count": 11,
411
+ "id": "e301045f-eb8d-4c2d-b2f5-59acf2f053b0",
412
+ "metadata": {},
413
+ "outputs": [],
414
+ "source": [
415
+ "def compute_metrics(eval_pred):\n",
416
+ " predictions, labels = eval_pred\n",
417
+ " decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=True)\n",
418
+ " labels = np.where(labels != -100, labels, tokenizer.pad_token_id)\n",
419
+ " decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)\n",
420
+ "\n",
421
+ " result = rouge.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)\n",
422
+ "\n",
423
+ " prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in predictions]\n",
424
+ " result[\"gen_len\"] = np.mean(prediction_lens)\n",
425
+ "\n",
426
+ " return {k: round(v, 4) for k, v in result.items()}"
427
+ ]
428
+ },
429
+ {
430
+ "cell_type": "markdown",
431
+ "id": "e3833f68-20da-4343-88c6-4b5c144bfb7c",
432
+ "metadata": {},
433
+ "source": [
434
+ "# Training - Loading T5 with AutoModelForSeq2SeqLM"
435
+ ]
436
+ },
437
+ {
438
+ "cell_type": "code",
439
+ "execution_count": 12,
440
+ "id": "8a9100fb-4ebe-469d-a1a3-b0a00c54528a",
441
+ "metadata": {},
442
+ "outputs": [],
443
+ "source": [
444
+ "from transformers import AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer\n",
445
+ "\n",
446
+ "model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)"
447
+ ]
448
+ },
449
+ {
450
+ "cell_type": "markdown",
451
+ "id": "9722c5f5-a9ed-44d1-b677-9fe558890218",
452
+ "metadata": {},
453
+ "source": [
454
+ "# Defining the training hyperparameters"
455
+ ]
456
+ },
457
+ {
458
+ "cell_type": "code",
459
+ "execution_count": 13,
460
+ "id": "e9d5eb20-6e52-44c7-aa09-5ad6c09576d9",
461
+ "metadata": {},
462
+ "outputs": [],
463
+ "source": [
464
+ "training_args = Seq2SeqTrainingArguments(\n",
465
+ " output_dir=\"California_bills_summary\",\n",
466
+ " evaluation_strategy=\"epoch\",\n",
467
+ " learning_rate=2e-5,\n",
468
+ " per_device_train_batch_size=16,\n",
469
+ " per_device_eval_batch_size=16,\n",
470
+ " weight_decay=0.01,\n",
471
+ " save_total_limit=3,\n",
472
+ " num_train_epochs=4,\n",
473
+ " predict_with_generate=True,\n",
474
+ " fp16=True,\n",
475
+ " push_to_hub=True,\n",
476
+ ")"
477
+ ]
478
+ },
479
+ {
480
+ "cell_type": "markdown",
481
+ "id": "aa5635ee-8d6a-45ce-8976-90df52eacd8a",
482
+ "metadata": {},
483
+ "source": [
484
+ "# Passing the arguments, model, dataset, tokenizer, data collator, and compute_metrics function to Seq2SeqTrainer for training"
485
+ ]
486
+ },
487
+ {
488
+ "cell_type": "code",
489
+ "execution_count": 14,
490
+ "id": "3476e539-1f86-41b2-beec-f9441406a692",
491
+ "metadata": {},
492
+ "outputs": [
493
+ {
494
+ "name": "stderr",
495
+ "output_type": "stream",
496
+ "text": [
497
+ "/home/u.th161689/.local/lib/python3.11/site-packages/accelerate/accelerator.py:432: FutureWarning: Passing the following arguments to `Accelerator` is deprecated and will be removed in version 1.0 of Accelerate: dict_keys(['dispatch_batches', 'split_batches']). Please pass an `accelerate.DataLoaderConfiguration` instead: \n",
498
+ "dataloader_config = DataLoaderConfiguration(dispatch_batches=None, split_batches=False)\n",
499
+ " warnings.warn(\n",
500
+ "Detected kernel version 4.18.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.\n"
501
+ ]
502
+ }
503
+ ],
504
+ "source": [
505
+ "trainer = Seq2SeqTrainer(\n",
506
+ " model=model,\n",
507
+ " args=training_args,\n",
508
+ " train_dataset=tokenized_billsum[\"train\"],\n",
509
+ " eval_dataset=tokenized_billsum[\"test\"],\n",
510
+ " tokenizer=tokenizer,\n",
511
+ " data_collator=data_collator,\n",
512
+ " compute_metrics=compute_metrics,\n",
513
+ ")"
514
+ ]
515
+ },
516
+ {
517
+ "cell_type": "markdown",
518
+ "id": "91c564a2-6a8c-4073-ac83-aa45b2ae28fa",
519
+ "metadata": {},
520
+ "source": [
521
+ "# Fine-tuning the model"
522
+ ]
523
+ },
524
+ {
525
+ "cell_type": "code",
526
+ "execution_count": 15,
527
+ "id": "d3f06124-0e43-4cf6-9af8-af0b42fa1b78",
528
+ "metadata": {},
529
+ "outputs": [
530
+ {
531
+ "name": "stderr",
532
+ "output_type": "stream",
533
+ "text": [
534
+ "You're using a T5TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n"
535
+ ]
536
+ },
537
+ {
538
+ "data": {
539
+ "text/html": [
540
+ "\n",
541
+ " <div>\n",
542
+ " \n",
543
+ " <progress value='248' max='248' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
544
+ " [248/248 03:49, Epoch 4/4]\n",
545
+ " </div>\n",
546
+ " <table border=\"1\" class=\"dataframe\">\n",
547
+ " <thead>\n",
548
+ " <tr style=\"text-align: left;\">\n",
549
+ " <th>Epoch</th>\n",
550
+ " <th>Training Loss</th>\n",
551
+ " <th>Validation Loss</th>\n",
552
+ " <th>Rouge1</th>\n",
553
+ " <th>Rouge2</th>\n",
554
+ " <th>Rougel</th>\n",
555
+ " <th>Rougelsum</th>\n",
556
+ " <th>Gen Len</th>\n",
557
+ " </tr>\n",
558
+ " </thead>\n",
559
+ " <tbody>\n",
560
+ " <tr>\n",
561
+ " <td>1</td>\n",
562
+ " <td>No log</td>\n",
563
+ " <td>2.797509</td>\n",
564
+ " <td>0.125500</td>\n",
565
+ " <td>0.036400</td>\n",
566
+ " <td>0.106700</td>\n",
567
+ " <td>0.106400</td>\n",
568
+ " <td>19.000000</td>\n",
569
+ " </tr>\n",
570
+ " <tr>\n",
571
+ " <td>2</td>\n",
572
+ " <td>No log</td>\n",
573
+ " <td>2.585288</td>\n",
574
+ " <td>0.135400</td>\n",
575
+ " <td>0.046000</td>\n",
576
+ " <td>0.112500</td>\n",
577
+ " <td>0.112200</td>\n",
578
+ " <td>19.000000</td>\n",
579
+ " </tr>\n",
580
+ " <tr>\n",
581
+ " <td>3</td>\n",
582
+ " <td>No log</td>\n",
583
+ " <td>2.522834</td>\n",
584
+ " <td>0.139200</td>\n",
585
+ " <td>0.049100</td>\n",
586
+ " <td>0.114500</td>\n",
587
+ " <td>0.114200</td>\n",
588
+ " <td>19.000000</td>\n",
589
+ " </tr>\n",
590
+ " <tr>\n",
591
+ " <td>4</td>\n",
592
+ " <td>No log</td>\n",
593
+ " <td>2.506120</td>\n",
594
+ " <td>0.141300</td>\n",
595
+ " <td>0.050300</td>\n",
596
+ " <td>0.116300</td>\n",
597
+ " <td>0.116100</td>\n",
598
+ " <td>19.000000</td>\n",
599
+ " </tr>\n",
600
+ " </tbody>\n",
601
+ "</table><p>"
602
+ ],
603
+ "text/plain": [
604
+ "<IPython.core.display.HTML object>"
605
+ ]
606
+ },
607
+ "metadata": {},
608
+ "output_type": "display_data"
609
+ },
610
+ {
611
+ "name": "stderr",
612
+ "output_type": "stream",
613
+ "text": [
614
+ "/opt/conda/lib/python3.11/site-packages/transformers/generation/utils.py:1355: UserWarning: Using the model-agnostic default `max_length` (=20) to control the generation length. We recommend setting `max_new_tokens` to control the maximum length of the generation.\n",
615
+ " warnings.warn(\n"
616
+ ]
617
+ },
618
+ {
619
+ "data": {
620
+ "text/plain": [
621
+ "TrainOutput(global_step=248, training_loss=3.0278184952274447, metrics={'train_runtime': 230.4959, 'train_samples_per_second': 17.163, 'train_steps_per_second': 1.076, 'total_flos': 1070824333246464.0, 'train_loss': 3.0278184952274447, 'epoch': 4.0})"
622
+ ]
623
+ },
624
+ "execution_count": 15,
625
+ "metadata": {},
626
+ "output_type": "execute_result"
627
+ }
628
+ ],
629
+ "source": [
630
+ "# Training needs numpy\n",
631
+ "import numpy as np\n",
632
+ "\n",
633
+ "# Fine-tuning the model\n",
634
+ "trainer.train()"
635
+ ]
636
+ },
637
+ {
638
+ "cell_type": "markdown",
639
+ "id": "166d4903-8809-4a77-9f43-45316cbccc91",
640
+ "metadata": {},
641
+ "source": [
642
+ "# Interface"
643
+ ]
644
+ },
645
+ {
646
+ "cell_type": "code",
647
+ "execution_count": 16,
648
+ "id": "4b5fd53a-df64-4273-bc9a-b0e02c212f0b",
649
+ "metadata": {},
650
+ "outputs": [],
651
+ "source": [
652
+ "text = \"summarize: The Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. It's the most aggressive action on tackling the climate crisis in American history, which will lift up American workers and create good-paying, union jobs across the country. It'll lower the deficit and ask the ultra-wealthy and corporations to pay their fair share. And no one making under $400,000 per year will pay a penny more in taxes.\""
653
+ ]
654
+ },
655
+ {
656
+ "cell_type": "markdown",
657
+ "id": "a0635a21-fde7-4d8e-92f0-9058131afd85",
658
+ "metadata": {},
659
+ "source": [
660
+ "# SAVING THE MODEL"
661
+ ]
662
+ },
663
+ {
664
+ "cell_type": "code",
665
+ "execution_count": 17,
666
+ "id": "afe34cd8-eccb-4cea-abfb-7775173be6b9",
667
+ "metadata": {},
668
+ "outputs": [
669
+ {
670
+ "data": {
671
+ "application/vnd.jupyter.widget-view+json": {
672
+ "model_id": "7afa4227cddf46b580032efb5050b6f2",
673
+ "version_major": 2,
674
+ "version_minor": 0
675
+ },
676
+ "text/plain": [
677
+ "Upload 3 LFS files: 0%| | 0/3 [00:00<?, ?it/s]"
678
+ ]
679
+ },
680
+ "metadata": {},
681
+ "output_type": "display_data"
682
+ },
683
+ {
684
+ "data": {
685
+ "application/vnd.jupyter.widget-view+json": {
686
+ "model_id": "c95787eebc7b42e8851e256c1b23e57e",
687
+ "version_major": 2,
688
+ "version_minor": 0
689
+ },
690
+ "text/plain": [
691
+ "events.out.tfevents.1712201512.fc100.155086.0: 0%| | 0.00/7.81k [00:00<?, ?B/s]"
692
+ ]
693
+ },
694
+ "metadata": {},
695
+ "output_type": "display_data"
696
+ },
697
+ {
698
+ "data": {
699
+ "application/vnd.jupyter.widget-view+json": {
700
+ "model_id": "84de531b675141bc8b471214b9a308c1",
701
+ "version_major": 2,
702
+ "version_minor": 0
703
+ },
704
+ "text/plain": [
705
+ "model.safetensors: 0%| | 0.00/242M [00:00<?, ?B/s]"
706
+ ]
707
+ },
708
+ "metadata": {},
709
+ "output_type": "display_data"
710
+ },
711
+ {
712
+ "data": {
713
+ "application/vnd.jupyter.widget-view+json": {
714
+ "model_id": "5d8b263ec643440fbddf787a0bab59a5",
715
+ "version_major": 2,
716
+ "version_minor": 0
717
+ },
718
+ "text/plain": [
719
+ "training_args.bin: 0%| | 0.00/4.86k [00:00<?, ?B/s]"
720
+ ]
721
+ },
722
+ "metadata": {},
723
+ "output_type": "display_data"
724
+ }
725
+ ],
726
+ "source": [
727
+ "trainer.save_model(\"./California_bills_summary\")"
728
+ ]
729
+ },
730
+ {
731
+ "cell_type": "markdown",
732
+ "id": "a14d26cd-ac89-4e11-a884-0550f8ff39c6",
733
+ "metadata": {},
734
+ "source": [
735
+ "# PUSHING MODEL TO PERSONAL HUGGINFACE HUB"
736
+ ]
737
+ },
738
+ {
739
+ "cell_type": "code",
740
+ "execution_count": 18,
741
+ "id": "90908ffc-9dac-451c-a0ff-edaae4312aed",
742
+ "metadata": {},
743
+ "outputs": [
744
+ {
745
+ "data": {
746
+ "text/plain": [
747
+ "CommitInfo(commit_url='https://huggingface.co/cheaptrix/California_bills_summary/commit/5a2db3aecf4f224ab11b75fc9c3dedbc4fa0a570', commit_message='cheaptrix/California_bills_summary', commit_description='', oid='5a2db3aecf4f224ab11b75fc9c3dedbc4fa0a570', pr_url=None, pr_revision=None, pr_num=None)"
748
+ ]
749
+ },
750
+ "execution_count": 18,
751
+ "metadata": {},
752
+ "output_type": "execute_result"
753
+ }
754
+ ],
755
+ "source": [
756
+ "trainer.push_to_hub(\"cheaptrix/California_bills_summary\")"
757
+ ]
758
+ },
759
+ {
760
+ "cell_type": "markdown",
761
+ "id": "484d784c-2700-4e2e-8c09-99293468487d",
762
+ "metadata": {},
763
+ "source": [
764
+ "# Creating a pipeline with the transformers module"
765
+ ]
766
+ },
767
+ {
768
+ "cell_type": "code",
769
+ "execution_count": 19,
770
+ "id": "7298e9e4-4a53-4494-8f8a-0a69dbb55d52",
771
+ "metadata": {},
772
+ "outputs": [
773
+ {
774
+ "data": {
775
+ "application/vnd.jupyter.widget-view+json": {
776
+ "model_id": "ade2d9311d3249fcb6e33fa5da4a6fa4",
777
+ "version_major": 2,
778
+ "version_minor": 0
779
+ },
780
+ "text/plain": [
781
+ "config.json: 0%| | 0.00/1.51k [00:00<?, ?B/s]"
782
+ ]
783
+ },
784
+ "metadata": {},
785
+ "output_type": "display_data"
786
+ },
787
+ {
788
+ "data": {
789
+ "application/vnd.jupyter.widget-view+json": {
790
+ "model_id": "3d89a35f912c441fa40514f6966d87af",
791
+ "version_major": 2,
792
+ "version_minor": 0
793
+ },
794
+ "text/plain": [
795
+ "model.safetensors: 0%| | 0.00/242M [00:00<?, ?B/s]"
796
+ ]
797
+ },
798
+ "metadata": {},
799
+ "output_type": "display_data"
800
+ },
801
+ {
802
+ "data": {
803
+ "application/vnd.jupyter.widget-view+json": {
804
+ "model_id": "7e37b930e95c4f6e8dbf65dd78dc7360",
805
+ "version_major": 2,
806
+ "version_minor": 0
807
+ },
808
+ "text/plain": [
809
+ "generation_config.json: 0%| | 0.00/112 [00:00<?, ?B/s]"
810
+ ]
811
+ },
812
+ "metadata": {},
813
+ "output_type": "display_data"
814
+ },
815
+ {
816
+ "data": {
817
+ "application/vnd.jupyter.widget-view+json": {
818
+ "model_id": "c63f4905c41041038fac2b6f0860655f",
819
+ "version_major": 2,
820
+ "version_minor": 0
821
+ },
822
+ "text/plain": [
823
+ "tokenizer_config.json: 0%| | 0.00/20.7k [00:00<?, ?B/s]"
824
+ ]
825
+ },
826
+ "metadata": {},
827
+ "output_type": "display_data"
828
+ },
829
+ {
830
+ "data": {
831
+ "application/vnd.jupyter.widget-view+json": {
832
+ "model_id": "beaf7c005393433f8987a5d8a612c2a3",
833
+ "version_major": 2,
834
+ "version_minor": 0
835
+ },
836
+ "text/plain": [
837
+ "tokenizer.json: 0%| | 0.00/2.42M [00:00<?, ?B/s]"
838
+ ]
839
+ },
840
+ "metadata": {},
841
+ "output_type": "display_data"
842
+ },
843
+ {
844
+ "data": {
845
+ "application/vnd.jupyter.widget-view+json": {
846
+ "model_id": "96071911ee5f42978d9d2164510bba13",
847
+ "version_major": 2,
848
+ "version_minor": 0
849
+ },
850
+ "text/plain": [
851
+ "special_tokens_map.json: 0%| | 0.00/2.54k [00:00<?, ?B/s]"
852
+ ]
853
+ },
854
+ "metadata": {},
855
+ "output_type": "display_data"
856
+ },
857
+ {
858
+ "name": "stderr",
859
+ "output_type": "stream",
860
+ "text": [
861
+ "Your max_length is set to 200, but your input_length is only 103. Since this is a summarization task, where outputs shorter than the input are typically wanted, you might consider decreasing max_length manually, e.g. summarizer('...', max_length=51)\n"
862
+ ]
863
+ },
864
+ {
865
+ "data": {
866
+ "text/plain": [
867
+ "[{'summary_text': \"the Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs . it's the most aggressive action on tackling the climate crisis in American history . no one making under $400,000 per year will pay a penny more in taxes .\"}]"
868
+ ]
869
+ },
870
+ "execution_count": 19,
871
+ "metadata": {},
872
+ "output_type": "execute_result"
873
+ }
874
+ ],
875
+ "source": [
876
+ "from transformers import pipeline\n",
877
+ "\n",
878
+ "summarizer = pipeline(\"summarization\", model=\"cheaptrix/California_bills_summary\")\n",
879
+ "summarizer(text)\n",
880
+ "# [{\"summary_text\": \"The Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. It's the most aggressive action on tackling the climate crisis in American history, which will lift up American workers and create good-paying, union jobs across the country.\"}]"
881
+ ]
882
+ },
883
+ {
884
+ "cell_type": "markdown",
885
+ "id": "08a1e990-420c-4c2b-becf-69d096865a10",
886
+ "metadata": {},
887
+ "source": [
888
+ "# Manaul pipeline"
889
+ ]
890
+ },
891
+ {
892
+ "cell_type": "code",
893
+ "execution_count": 20,
894
+ "id": "6d46a243-bfbc-4304-ae5b-db48c045e517",
895
+ "metadata": {},
896
+ "outputs": [],
897
+ "source": [
898
+ "from transformers import AutoTokenizer\n",
899
+ "\n",
900
+ "tokenizer = AutoTokenizer.from_pretrained(\"cheaptrix/California_bills_summary\")\n",
901
+ "inputs = tokenizer(text, return_tensors=\"pt\").input_ids"
902
+ ]
903
+ },
904
+ {
905
+ "cell_type": "code",
906
+ "execution_count": 21,
907
+ "id": "ff9ffe5e-24a8-4baa-abd9-b72dbf4ecc93",
908
+ "metadata": {},
909
+ "outputs": [],
910
+ "source": [
911
+ "from transformers import AutoModelForSeq2SeqLM\n",
912
+ "\n",
913
+ "model = AutoModelForSeq2SeqLM.from_pretrained(\"cheaptrix/California_bills_summary\")\n",
914
+ "outputs = model.generate(inputs, max_new_tokens=100, do_sample=False)"
915
+ ]
916
+ },
917
+ {
918
+ "cell_type": "code",
919
+ "execution_count": 22,
920
+ "id": "24aa0a58-781f-4883-90e2-8a7818192fab",
921
+ "metadata": {},
922
+ "outputs": [
923
+ {
924
+ "data": {
925
+ "text/plain": [
926
+ "\"the Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. it's the most aggressive action on tackling the climate crisis in American history. it'll ask the ultra-wealthy and corporations to pay their fair share.\""
927
+ ]
928
+ },
929
+ "execution_count": 22,
930
+ "metadata": {},
931
+ "output_type": "execute_result"
932
+ }
933
+ ],
934
+ "source": [
935
+ "tokenizer.decode(outputs[0], skip_special_tokens=True)"
936
+ ]
937
+ },
938
+ {
939
+ "cell_type": "code",
940
+ "execution_count": null,
941
+ "id": "3320e679-fd4d-4d23-ab05-5184b579af21",
942
+ "metadata": {},
943
+ "outputs": [],
944
+ "source": []
945
+ }
946
+ ],
947
+ "metadata": {
948
+ "kernelspec": {
949
+ "display_name": "Python 3 (ipykernel)",
950
+ "language": "python",
951
+ "name": "python3"
952
+ },
953
+ "language_info": {
954
+ "codemirror_mode": {
955
+ "name": "ipython",
956
+ "version": 3
957
+ },
958
+ "file_extension": ".py",
959
+ "mimetype": "text/x-python",
960
+ "name": "python",
961
+ "nbconvert_exporter": "python",
962
+ "pygments_lexer": "ipython3",
963
+ "version": "3.11.7"
964
+ }
965
+ },
966
+ "nbformat": 4,
967
+ "nbformat_minor": 5
968
+ }
notebooks/T5_California_Model_Interface.ipynb ADDED
@@ -0,0 +1,505 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "89751719-bb82-42ef-b49e-182e81b0c478",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "2024-04-10 19:08:20.316186: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
14
+ "2024-04-10 19:08:20.355370: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
15
+ "2024-04-10 19:08:20.355415: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
16
+ "2024-04-10 19:08:20.355437: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
17
+ "2024-04-10 19:08:20.362726: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
18
+ "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
19
+ "2024-04-10 19:08:21.512078: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
20
+ ]
21
+ }
22
+ ],
23
+ "source": [
24
+ "from transformers import pipeline\n",
25
+ "\n",
26
+ "summarizer = pipeline(\"summarization\", model=\"cheaptrix/California_bills_summary\")"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": 2,
32
+ "id": "883134f1-934d-422f-a64a-0a37073542c0",
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "import json\n",
37
+ "\n",
38
+ "cleaned_test_data = []\n",
39
+ "# Opening JSON file\n",
40
+ "with open(\"cleaned_bill_sum_test_data.json\") as json_file:\n",
41
+ " cleaned_test_data = json.load(json_file)"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 3,
47
+ "id": "c7f5e7f6-ac9f-4ba7-acbf-1ba7d031ef81",
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "name": "stderr",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "Token indices sequence length is longer than the specified maximum sequence length for this model (548 > 512). Running this sequence through the model will result in indexing errors\n"
55
+ ]
56
+ }
57
+ ],
58
+ "source": [
59
+ "generated_summaries = []\n",
60
+ "for i in range(len(cleaned_test_data)):\n",
61
+ " summary = summarizer(cleaned_test_data[i]['text'])\n",
62
+ " generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : cleaned_test_data[i]['summary']})"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 4,
68
+ "id": "cca1a292-1ab5-452f-b998-d404bfc633d8",
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "data": {
73
+ "text/plain": [
74
+ "{'generated': 'ACCEPT Resolution 2023-01-25 Introduced in Senate Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution . This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol .',\n",
75
+ " 'summary': 'Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution or the ACCEPT Resolution This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.'}"
76
+ ]
77
+ },
78
+ "execution_count": 4,
79
+ "metadata": {},
80
+ "output_type": "execute_result"
81
+ }
82
+ ],
83
+ "source": [
84
+ "generated_summaries[0]"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": 5,
90
+ "id": "22b594f4-b8a1-4296-bd19-31e799a368e7",
91
+ "metadata": {},
92
+ "outputs": [
93
+ {
94
+ "data": {
95
+ "text/plain": [
96
+ "{'generated': '2023-01-26 Introduced in Senate This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime. The resolution condemns (1) the brutal beating and death of Mahsa Amini; and (2) the violent suppression by the Iran regime of women . and men participating in . the current demonstrations, including children, and calls for transparency .',\n",
97
+ " 'summary': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime. The resolution condemns (1) the brutal beating and death of Mahsa Amini; and (2) the violent suppression by the Iranian regime of women and men participating in the current demonstrations, including children, and calls for transparent accountability for all killings of protesters by Iranian security forces. Finally, the resolution encourages continued efforts by the Biden Administration to respond to the protests, including the recent sanctioning of the Iranian morality police.'}"
98
+ ]
99
+ },
100
+ "execution_count": 5,
101
+ "metadata": {},
102
+ "output_type": "execute_result"
103
+ }
104
+ ],
105
+ "source": [
106
+ "generated_summaries[1]"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": 6,
112
+ "id": "7f0a025a-290f-4811-b504-793e2e0dbde2",
113
+ "metadata": {},
114
+ "outputs": [
115
+ {
116
+ "data": {
117
+ "text/plain": [
118
+ "{'generated': '2023-02-01 Introduced in Senate This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right that is essential to a free society and protected',\n",
119
+ " 'summary': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.'}"
120
+ ]
121
+ },
122
+ "execution_count": 6,
123
+ "metadata": {},
124
+ "output_type": "execute_result"
125
+ }
126
+ ],
127
+ "source": [
128
+ "generated_summaries[2]"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": 7,
134
+ "id": "e0b81c81-b0ba-4285-988a-ce9b070e215c",
135
+ "metadata": {},
136
+ "outputs": [
137
+ {
138
+ "data": {
139
+ "text/plain": [
140
+ "{'generated': '2023-02-16 Introduced in Senate This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight. this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs.',\n",
141
+ " 'summary': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'}"
142
+ ]
143
+ },
144
+ "execution_count": 7,
145
+ "metadata": {},
146
+ "output_type": "execute_result"
147
+ }
148
+ ],
149
+ "source": [
150
+ "generated_summaries[3]"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": 8,
156
+ "id": "8da96ded-73dd-474f-8c2b-b684f1aa825c",
157
+ "metadata": {},
158
+ "outputs": [
159
+ {
160
+ "data": {
161
+ "text/plain": [
162
+ "{'generated': '2023-03-09 Introduced in Senate This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs.',\n",
163
+ " 'summary': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance of sound recordings.'}"
164
+ ]
165
+ },
166
+ "execution_count": 8,
167
+ "metadata": {},
168
+ "output_type": "execute_result"
169
+ }
170
+ ],
171
+ "source": [
172
+ "generated_summaries[4]"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 9,
178
+ "id": "6d51741f-fb47-48d2-a387-ef87577817df",
179
+ "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "data": {
183
+ "text/plain": [
184
+ "{'generated': '2023-03-09 Introduced in Senate This concurrent resolution recognizes Abortion Provider Appreciation Day. Text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation.',\n",
185
+ " 'summary': 'This concurrent resolution recognizes Abortion Provider Appreciation Day.'}"
186
+ ]
187
+ },
188
+ "execution_count": 9,
189
+ "metadata": {},
190
+ "output_type": "execute_result"
191
+ }
192
+ ],
193
+ "source": [
194
+ "generated_summaries[5]"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": 10,
200
+ "id": "a69ce9c9-f18f-4aed-80f2-53fd81311555",
201
+ "metadata": {},
202
+ "outputs": [
203
+ {
204
+ "data": {
205
+ "text/plain": [
206
+ "{'generated': \"2023-11-02 Passed Senate This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza . it calls for his immediate release and the release of all other Russian opposition leaders . It also calls on the President and leaders of the free world to work tirelessly for the released of political prisoners in Russia .\",\n",
207
+ " 'summary': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders. It also calls for the release of all political prisoners in Russia and in Belarus, as well as for the release of Ukrainian citizens held by Russia, and calls on the President and leaders of the free world to work tirelessly for the release of political prisoners in Russia.\"}"
208
+ ]
209
+ },
210
+ "execution_count": 10,
211
+ "metadata": {},
212
+ "output_type": "execute_result"
213
+ }
214
+ ],
215
+ "source": [
216
+ "generated_summaries[6]"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "execution_count": 11,
222
+ "id": "14a0bc12-abe5-4dca-b97c-13577cf63ee5",
223
+ "metadata": {},
224
+ "outputs": [
225
+ {
226
+ "data": {
227
+ "text/plain": [
228
+ "{'generated': '2023-03-23 Introduced in Senate This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted . this file contains bill summaries for federal legislation and details the effects the legislative text may have on current law and federal programs.',\n",
229
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.'}"
230
+ ]
231
+ },
232
+ "execution_count": 11,
233
+ "metadata": {},
234
+ "output_type": "execute_result"
235
+ }
236
+ ],
237
+ "source": [
238
+ "generated_summaries[7]"
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "code",
243
+ "execution_count": 12,
244
+ "id": "7d4415fe-7d50-4c12-9039-c338651f8972",
245
+ "metadata": {},
246
+ "outputs": [
247
+ {
248
+ "data": {
249
+ "text/plain": [
250
+ "{'generated': '2023-04-27 Introduced in Senate This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency . a bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs.',\n",
251
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.'}"
252
+ ]
253
+ },
254
+ "execution_count": 12,
255
+ "metadata": {},
256
+ "output_type": "execute_result"
257
+ }
258
+ ],
259
+ "source": [
260
+ "generated_summaries[8]"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": 13,
266
+ "id": "ff9959f8-4c7a-4af3-8e3e-83cfde0f227a",
267
+ "metadata": {},
268
+ "outputs": [
269
+ {
270
+ "data": {
271
+ "text/plain": [
272
+ "{'generated': \"this concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation.\",\n",
273
+ " 'summary': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\"}"
274
+ ]
275
+ },
276
+ "execution_count": 13,
277
+ "metadata": {},
278
+ "output_type": "execute_result"
279
+ }
280
+ ],
281
+ "source": [
282
+ "generated_summaries[9]"
283
+ ]
284
+ },
285
+ {
286
+ "cell_type": "code",
287
+ "execution_count": 14,
288
+ "id": "54e8d283-2011-4f9a-b20e-70c90cff42be",
289
+ "metadata": {},
290
+ "outputs": [
291
+ {
292
+ "data": {
293
+ "text/plain": [
294
+ "{'generated': '2023-05-31 Introduced in Senate This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity. Text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file contains bill summaries for federal legislation .',\n",
295
+ " 'summary': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.'}"
296
+ ]
297
+ },
298
+ "execution_count": 14,
299
+ "metadata": {},
300
+ "output_type": "execute_result"
301
+ }
302
+ ],
303
+ "source": [
304
+ "generated_summaries[10]"
305
+ ]
306
+ },
307
+ {
308
+ "cell_type": "code",
309
+ "execution_count": 15,
310
+ "id": "cd4a017c-69d3-4891-b011-bdd19ca4a742",
311
+ "metadata": {},
312
+ "outputs": [
313
+ {
314
+ "data": {
315
+ "text/plain": [
316
+ "{'generated': '2023-07-18 Introduced in Senate This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders . Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public killings; and (3) prioritizes the victims of, and heroism in the response to, mass public killers.',\n",
317
+ " 'summary': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public murders (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public murders.'}"
318
+ ]
319
+ },
320
+ "execution_count": 15,
321
+ "metadata": {},
322
+ "output_type": "execute_result"
323
+ }
324
+ ],
325
+ "source": [
326
+ "generated_summaries[11]"
327
+ ]
328
+ },
329
+ {
330
+ "cell_type": "code",
331
+ "execution_count": 16,
332
+ "id": "e2a659be-e404-447e-8a35-5dbd365e4faf",
333
+ "metadata": {},
334
+ "outputs": [
335
+ {
336
+ "data": {
337
+ "text/plain": [
338
+ "{'generated': '2023-07-27 Introduced in Senate This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.',\n",
339
+ " 'summary': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.'}"
340
+ ]
341
+ },
342
+ "execution_count": 16,
343
+ "metadata": {},
344
+ "output_type": "execute_result"
345
+ }
346
+ ],
347
+ "source": [
348
+ "generated_summaries[12]"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 17,
354
+ "id": "d859483d-a664-4eb4-8910-8c590461d48e",
355
+ "metadata": {},
356
+ "outputs": [
357
+ {
358
+ "data": {
359
+ "text/plain": [
360
+ "{'generated': \"2023-10-04 Introduced in Senate This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file contains bill summaries for federal legislation.\",\n",
361
+ " 'summary': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\"}"
362
+ ]
363
+ },
364
+ "execution_count": 17,
365
+ "metadata": {},
366
+ "output_type": "execute_result"
367
+ }
368
+ ],
369
+ "source": [
370
+ "generated_summaries[13]"
371
+ ]
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "execution_count": 18,
376
+ "id": "c66b1673-d087-4b52-88d4-ef5990ecbd90",
377
+ "metadata": {},
378
+ "outputs": [
379
+ {
380
+ "data": {
381
+ "text/plain": [
382
+ "{'generated': '2023-10-26 Introduced in Senate This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country. Text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.',\n",
383
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.'}"
384
+ ]
385
+ },
386
+ "execution_count": 18,
387
+ "metadata": {},
388
+ "output_type": "execute_result"
389
+ }
390
+ ],
391
+ "source": [
392
+ "generated_summaries[14]"
393
+ ]
394
+ },
395
+ {
396
+ "cell_type": "code",
397
+ "execution_count": 19,
398
+ "id": "205ff67d-894d-40f4-814c-d9f2d3eea1d0",
399
+ "metadata": {},
400
+ "outputs": [
401
+ {
402
+ "data": {
403
+ "text/plain": [
404
+ "{'generated': '2024-02-13 Introduced in Senate This concurrent resolution provides for a correction in the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes). text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.',\n",
405
+ " 'summary': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).'}"
406
+ ]
407
+ },
408
+ "execution_count": 19,
409
+ "metadata": {},
410
+ "output_type": "execute_result"
411
+ }
412
+ ],
413
+ "source": [
414
+ "generated_summaries[15]"
415
+ ]
416
+ },
417
+ {
418
+ "cell_type": "markdown",
419
+ "id": "68c08713-89d9-4611-8cf5-9c86bed5fc29",
420
+ "metadata": {},
421
+ "source": [
422
+ "# ROUGE EVALUATION"
423
+ ]
424
+ },
425
+ {
426
+ "cell_type": "code",
427
+ "execution_count": 21,
428
+ "id": "e869ae4a-6126-4256-98b4-4c36556e4cec",
429
+ "metadata": {},
430
+ "outputs": [],
431
+ "source": [
432
+ "def ROUGE_evaluate(data_set : list):\n",
433
+ " date = data_set\n",
434
+ " for i in range(len(generated_summaries)):\n",
435
+ " rouge = evaluate.load('rouge')\n",
436
+ " predictions = [generated_summaries[i]['generated']]\n",
437
+ " references = [generated_summaries[i]['summary']]\n",
438
+ " results = rouge.compute(predictions=predictions, references=references)\n",
439
+ " print(results)"
440
+ ]
441
+ },
442
+ {
443
+ "cell_type": "code",
444
+ "execution_count": 22,
445
+ "id": "9d9df0d5-8436-44e2-8be8-01ba1f699436",
446
+ "metadata": {},
447
+ "outputs": [
448
+ {
449
+ "name": "stdout",
450
+ "output_type": "stream",
451
+ "text": [
452
+ "{'rouge1': 0.9420289855072463, 'rouge2': 0.9264705882352942, 'rougeL': 0.9130434782608696, 'rougeLsum': 0.9130434782608696}\n",
453
+ "{'rouge1': 0.7884615384615385, 'rouge2': 0.7766990291262137, 'rougeL': 0.7884615384615385, 'rougeLsum': 0.7884615384615385}\n",
454
+ "{'rouge1': 0.8715083798882681, 'rouge2': 0.847457627118644, 'rougeL': 0.8603351955307262, 'rougeLsum': 0.8603351955307262}\n",
455
+ "{'rouge1': 0.7563025210084033, 'rouge2': 0.7521367521367521, 'rougeL': 0.7563025210084033, 'rougeLsum': 0.7563025210084033}\n",
456
+ "{'rouge1': 0.689655172413793, 'rouge2': 0.6491228070175438, 'rougeL': 0.6724137931034483, 'rougeLsum': 0.6724137931034483}\n",
457
+ "{'rouge1': 0.2807017543859649, 'rouge2': 0.2545454545454546, 'rougeL': 0.2807017543859649, 'rougeLsum': 0.2807017543859649}\n",
458
+ "{'rouge1': 0.7552447552447552, 'rouge2': 0.723404255319149, 'rougeL': 0.7552447552447552, 'rougeLsum': 0.7552447552447552}\n",
459
+ "{'rouge1': 0.7010309278350516, 'rouge2': 0.6947368421052631, 'rougeL': 0.7010309278350516, 'rougeLsum': 0.7010309278350516}\n",
460
+ "{'rouge1': 0.6964285714285715, 'rouge2': 0.6909090909090909, 'rougeL': 0.6964285714285715, 'rougeLsum': 0.6964285714285715}\n",
461
+ "{'rouge1': 0.7786259541984732, 'rouge2': 0.7441860465116279, 'rougeL': 0.7480916030534351, 'rougeLsum': 0.7480916030534351}\n",
462
+ "{'rouge1': 0.6216216216216216, 'rouge2': 0.6111111111111112, 'rougeL': 0.6216216216216216, 'rougeLsum': 0.6216216216216216}\n",
463
+ "{'rouge1': 0.8888888888888888, 'rouge2': 0.8732394366197183, 'rougeL': 0.8888888888888888, 'rougeLsum': 0.8888888888888888}\n",
464
+ "{'rouge1': 0.953125, 'rouge2': 0.9523809523809523, 'rougeL': 0.953125, 'rougeLsum': 0.953125}\n",
465
+ "{'rouge1': 0.688888888888889, 'rouge2': 0.6818181818181819, 'rougeL': 0.688888888888889, 'rougeLsum': 0.688888888888889}\n",
466
+ "{'rouge1': 0.6458333333333334, 'rouge2': 0.6382978723404256, 'rougeL': 0.6458333333333334, 'rougeLsum': 0.6458333333333334}\n",
467
+ "{'rouge1': 0.6105263157894737, 'rouge2': 0.5376344086021505, 'rougeL': 0.5894736842105264, 'rougeLsum': 0.5894736842105264}\n"
468
+ ]
469
+ }
470
+ ],
471
+ "source": [
472
+ "ROUGE_evaluate(generated_summaries)"
473
+ ]
474
+ },
475
+ {
476
+ "cell_type": "code",
477
+ "execution_count": null,
478
+ "id": "5bc51dd7-c5de-495e-b286-f723d545ed35",
479
+ "metadata": {},
480
+ "outputs": [],
481
+ "source": []
482
+ }
483
+ ],
484
+ "metadata": {
485
+ "kernelspec": {
486
+ "display_name": "Python 3 (ipykernel)",
487
+ "language": "python",
488
+ "name": "python3"
489
+ },
490
+ "language_info": {
491
+ "codemirror_mode": {
492
+ "name": "ipython",
493
+ "version": 3
494
+ },
495
+ "file_extension": ".py",
496
+ "mimetype": "text/x-python",
497
+ "name": "python",
498
+ "nbconvert_exporter": "python",
499
+ "pygments_lexer": "ipython3",
500
+ "version": "3.11.7"
501
+ }
502
+ },
503
+ "nbformat": 4,
504
+ "nbformat_minor": 5
505
+ }
notebooks/T5_Congres_Bill_Model_Interface.ipynb ADDED
@@ -0,0 +1,610 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "89751719-bb82-42ef-b49e-182e81b0c478",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "2024-04-10 19:08:23.066747: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
14
+ "2024-04-10 19:08:23.106579: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
15
+ "2024-04-10 19:08:23.106623: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
16
+ "2024-04-10 19:08:23.106650: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
17
+ "2024-04-10 19:08:23.113912: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
18
+ "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
19
+ "2024-04-10 19:08:24.171199: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
20
+ ]
21
+ }
22
+ ],
23
+ "source": [
24
+ "from transformers import pipeline\n",
25
+ "\n",
26
+ "summarizer = pipeline(\"summarization\", model=\"cheaptrix/congress_bill_sumamry_model\")"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "code",
31
+ "execution_count": 2,
32
+ "id": "883134f1-934d-422f-a64a-0a37073542c0",
33
+ "metadata": {},
34
+ "outputs": [],
35
+ "source": [
36
+ "import json\n",
37
+ "\n",
38
+ "cleaned_test_data = []\n",
39
+ "# Opening JSON file\n",
40
+ "with open(\"cleaned_bill_sum_test_data.json\") as json_file:\n",
41
+ " cleaned_test_data = json.load(json_file)"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 3,
47
+ "id": "c7f5e7f6-ac9f-4ba7-acbf-1ba7d031ef81",
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "name": "stderr",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "Token indices sequence length is longer than the specified maximum sequence length for this model (548 > 512). Running this sequence through the model will result in indexing errors\n"
55
+ ]
56
+ }
57
+ ],
58
+ "source": [
59
+ "generated_summaries = []\n",
60
+ "for i in range(len(cleaned_test_data)):\n",
61
+ " summary = summarizer(cleaned_test_data[i]['text'])\n",
62
+ " generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : cleaned_test_data[i]['summary']})"
63
+ ]
64
+ },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": 4,
68
+ "id": "cca1a292-1ab5-452f-b998-d404bfc633d8",
69
+ "metadata": {},
70
+ "outputs": [
71
+ {
72
+ "data": {
73
+ "text/plain": [
74
+ "{'generated': 'This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.',\n",
75
+ " 'summary': 'Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution or the ACCEPT Resolution This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.'}"
76
+ ]
77
+ },
78
+ "execution_count": 4,
79
+ "metadata": {},
80
+ "output_type": "execute_result"
81
+ }
82
+ ],
83
+ "source": [
84
+ "generated_summaries[0]"
85
+ ]
86
+ },
87
+ {
88
+ "cell_type": "code",
89
+ "execution_count": 5,
90
+ "id": "22b594f4-b8a1-4296-bd19-31e799a368e7",
91
+ "metadata": {},
92
+ "outputs": [
93
+ {
94
+ "data": {
95
+ "text/plain": [
96
+ "{'generated': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime.',\n",
97
+ " 'summary': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime. The resolution condemns (1) the brutal beating and death of Mahsa Amini; and (2) the violent suppression by the Iranian regime of women and men participating in the current demonstrations, including children, and calls for transparent accountability for all killings of protesters by Iranian security forces. Finally, the resolution encourages continued efforts by the Biden Administration to respond to the protests, including the recent sanctioning of the Iranian morality police.'}"
98
+ ]
99
+ },
100
+ "execution_count": 5,
101
+ "metadata": {},
102
+ "output_type": "execute_result"
103
+ }
104
+ ],
105
+ "source": [
106
+ "generated_summaries[1]"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": 6,
112
+ "id": "7f0a025a-290f-4811-b504-793e2e0dbde2",
113
+ "metadata": {},
114
+ "outputs": [
115
+ {
116
+ "data": {
117
+ "text/plain": [
118
+ "{'generated': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.',\n",
119
+ " 'summary': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.'}"
120
+ ]
121
+ },
122
+ "execution_count": 6,
123
+ "metadata": {},
124
+ "output_type": "execute_result"
125
+ }
126
+ ],
127
+ "source": [
128
+ "generated_summaries[2]"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": 7,
134
+ "id": "e0b81c81-b0ba-4285-988a-ce9b070e215c",
135
+ "metadata": {},
136
+ "outputs": [
137
+ {
138
+ "data": {
139
+ "text/plain": [
140
+ "{'generated': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.',\n",
141
+ " 'summary': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'}"
142
+ ]
143
+ },
144
+ "execution_count": 7,
145
+ "metadata": {},
146
+ "output_type": "execute_result"
147
+ }
148
+ ],
149
+ "source": [
150
+ "generated_summaries[3]"
151
+ ]
152
+ },
153
+ {
154
+ "cell_type": "code",
155
+ "execution_count": 8,
156
+ "id": "8da96ded-73dd-474f-8c2b-b684f1aa825c",
157
+ "metadata": {},
158
+ "outputs": [
159
+ {
160
+ "data": {
161
+ "text/plain": [
162
+ "{'generated': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance.',\n",
163
+ " 'summary': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance of sound recordings.'}"
164
+ ]
165
+ },
166
+ "execution_count": 8,
167
+ "metadata": {},
168
+ "output_type": "execute_result"
169
+ }
170
+ ],
171
+ "source": [
172
+ "generated_summaries[4]"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 9,
178
+ "id": "6d51741f-fb47-48d2-a387-ef87577817df",
179
+ "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "data": {
183
+ "text/plain": [
184
+ "{'generated': 'This concurrent resolution recognizes Abortion Provider Appreciation Day. Text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.',\n",
185
+ " 'summary': 'This concurrent resolution recognizes Abortion Provider Appreciation Day.'}"
186
+ ]
187
+ },
188
+ "execution_count": 9,
189
+ "metadata": {},
190
+ "output_type": "execute_result"
191
+ }
192
+ ],
193
+ "source": [
194
+ "generated_summaries[5]"
195
+ ]
196
+ },
197
+ {
198
+ "cell_type": "code",
199
+ "execution_count": 10,
200
+ "id": "a69ce9c9-f18f-4aed-80f2-53fd81311555",
201
+ "metadata": {},
202
+ "outputs": [
203
+ {
204
+ "data": {
205
+ "text/plain": [
206
+ "{'generated': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders.\",\n",
207
+ " 'summary': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders. It also calls for the release of all political prisoners in Russia and in Belarus, as well as for the release of Ukrainian citizens held by Russia, and calls on the President and leaders of the free world to work tirelessly for the release of political prisoners in Russia.\"}"
208
+ ]
209
+ },
210
+ "execution_count": 10,
211
+ "metadata": {},
212
+ "output_type": "execute_result"
213
+ }
214
+ ],
215
+ "source": [
216
+ "generated_summaries[6]"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "execution_count": 11,
222
+ "id": "14a0bc12-abe5-4dca-b97c-13577cf63ee5",
223
+ "metadata": {},
224
+ "outputs": [
225
+ {
226
+ "data": {
227
+ "text/plain": [
228
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.',\n",
229
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.'}"
230
+ ]
231
+ },
232
+ "execution_count": 11,
233
+ "metadata": {},
234
+ "output_type": "execute_result"
235
+ }
236
+ ],
237
+ "source": [
238
+ "generated_summaries[7]"
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "code",
243
+ "execution_count": 12,
244
+ "id": "7d4415fe-7d50-4c12-9039-c338651f8972",
245
+ "metadata": {},
246
+ "outputs": [
247
+ {
248
+ "data": {
249
+ "text/plain": [
250
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.',\n",
251
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.'}"
252
+ ]
253
+ },
254
+ "execution_count": 12,
255
+ "metadata": {},
256
+ "output_type": "execute_result"
257
+ }
258
+ ],
259
+ "source": [
260
+ "generated_summaries[8]"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": 13,
266
+ "id": "ff9959f8-4c7a-4af3-8e3e-83cfde0f227a",
267
+ "metadata": {},
268
+ "outputs": [
269
+ {
270
+ "data": {
271
+ "text/plain": [
272
+ "{'generated': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\",\n",
273
+ " 'summary': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\"}"
274
+ ]
275
+ },
276
+ "execution_count": 13,
277
+ "metadata": {},
278
+ "output_type": "execute_result"
279
+ }
280
+ ],
281
+ "source": [
282
+ "generated_summaries[9]"
283
+ ]
284
+ },
285
+ {
286
+ "cell_type": "code",
287
+ "execution_count": 14,
288
+ "id": "54e8d283-2011-4f9a-b20e-70c90cff42be",
289
+ "metadata": {},
290
+ "outputs": [
291
+ {
292
+ "data": {
293
+ "text/plain": [
294
+ "{'generated': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.',\n",
295
+ " 'summary': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.'}"
296
+ ]
297
+ },
298
+ "execution_count": 14,
299
+ "metadata": {},
300
+ "output_type": "execute_result"
301
+ }
302
+ ],
303
+ "source": [
304
+ "generated_summaries[10]"
305
+ ]
306
+ },
307
+ {
308
+ "cell_type": "code",
309
+ "execution_count": 15,
310
+ "id": "cd4a017c-69d3-4891-b011-bdd19ca4a742",
311
+ "metadata": {},
312
+ "outputs": [
313
+ {
314
+ "data": {
315
+ "text/plain": [
316
+ "{'generated': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public killings (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public killers.',\n",
317
+ " 'summary': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public murders (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public murders.'}"
318
+ ]
319
+ },
320
+ "execution_count": 15,
321
+ "metadata": {},
322
+ "output_type": "execute_result"
323
+ }
324
+ ],
325
+ "source": [
326
+ "generated_summaries[11]"
327
+ ]
328
+ },
329
+ {
330
+ "cell_type": "code",
331
+ "execution_count": 16,
332
+ "id": "e2a659be-e404-447e-8a35-5dbd365e4faf",
333
+ "metadata": {},
334
+ "outputs": [
335
+ {
336
+ "data": {
337
+ "text/plain": [
338
+ "{'generated': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.',\n",
339
+ " 'summary': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.'}"
340
+ ]
341
+ },
342
+ "execution_count": 16,
343
+ "metadata": {},
344
+ "output_type": "execute_result"
345
+ }
346
+ ],
347
+ "source": [
348
+ "generated_summaries[12]"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 17,
354
+ "id": "d859483d-a664-4eb4-8910-8c590461d48e",
355
+ "metadata": {},
356
+ "outputs": [
357
+ {
358
+ "data": {
359
+ "text/plain": [
360
+ "{'generated': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\",\n",
361
+ " 'summary': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\"}"
362
+ ]
363
+ },
364
+ "execution_count": 17,
365
+ "metadata": {},
366
+ "output_type": "execute_result"
367
+ }
368
+ ],
369
+ "source": [
370
+ "generated_summaries[13]"
371
+ ]
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "execution_count": 18,
376
+ "id": "c66b1673-d087-4b52-88d4-ef5990ecbd90",
377
+ "metadata": {},
378
+ "outputs": [
379
+ {
380
+ "data": {
381
+ "text/plain": [
382
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.',\n",
383
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.'}"
384
+ ]
385
+ },
386
+ "execution_count": 18,
387
+ "metadata": {},
388
+ "output_type": "execute_result"
389
+ }
390
+ ],
391
+ "source": [
392
+ "generated_summaries[14]"
393
+ ]
394
+ },
395
+ {
396
+ "cell_type": "code",
397
+ "execution_count": 19,
398
+ "id": "205ff67d-894d-40f4-814c-d9f2d3eea1d0",
399
+ "metadata": {},
400
+ "outputs": [
401
+ {
402
+ "data": {
403
+ "text/plain": [
404
+ "{'generated': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).',\n",
405
+ " 'summary': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).'}"
406
+ ]
407
+ },
408
+ "execution_count": 19,
409
+ "metadata": {},
410
+ "output_type": "execute_result"
411
+ }
412
+ ],
413
+ "source": [
414
+ "generated_summaries[15]"
415
+ ]
416
+ },
417
+ {
418
+ "cell_type": "markdown",
419
+ "id": "0e3e9588-d3f3-4c0f-a86b-eb0e40d47079",
420
+ "metadata": {},
421
+ "source": [
422
+ "# NEW DATA"
423
+ ]
424
+ },
425
+ {
426
+ "cell_type": "code",
427
+ "execution_count": 38,
428
+ "id": "3a6116df-634c-4cdc-8e17-e17519f06aa7",
429
+ "metadata": {},
430
+ "outputs": [],
431
+ "source": [
432
+ "new_cleaned_test_data = []\n",
433
+ "# Opening JSON file\n",
434
+ "with open(\"new_cleaned_bill_sum_test_data.json\") as json_file:\n",
435
+ " new_cleaned_test_data = json.load(json_file)\n",
436
+ "\n",
437
+ "new_generated_summaries = []\n",
438
+ "for i in range(len(new_cleaned_test_data)):\n",
439
+ " summary = summarizer(new_cleaned_test_data[i]['text'])\n",
440
+ " new_generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : new_cleaned_test_data[i]['summary']})"
441
+ ]
442
+ },
443
+ {
444
+ "cell_type": "code",
445
+ "execution_count": 43,
446
+ "id": "4351fd53-9f09-4794-b34c-092732d27ff1",
447
+ "metadata": {},
448
+ "outputs": [
449
+ {
450
+ "data": {
451
+ "text/plain": [
452
+ "{'generated': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payments rates for certain widely available clinical diagnostic lab tests to be based on a statistical sampling of private sector rates.',\n",
453
+ " 'summary': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates.'}"
454
+ ]
455
+ },
456
+ "execution_count": 43,
457
+ "metadata": {},
458
+ "output_type": "execute_result"
459
+ }
460
+ ],
461
+ "source": [
462
+ "new_generated_summaries[0]"
463
+ ]
464
+ },
465
+ {
466
+ "cell_type": "code",
467
+ "execution_count": 44,
468
+ "id": "f8f57bd4-5082-4c0a-a61b-523814f60db6",
469
+ "metadata": {},
470
+ "outputs": [
471
+ {
472
+ "data": {
473
+ "text/plain": [
474
+ "{'generated': 'Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emission from the sector by 2040.',\n",
475
+ " 'summary': 'Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools.'}"
476
+ ]
477
+ },
478
+ "execution_count": 44,
479
+ "metadata": {},
480
+ "output_type": "execute_result"
481
+ }
482
+ ],
483
+ "source": [
484
+ "new_generated_summaries[1]"
485
+ ]
486
+ },
487
+ {
488
+ "cell_type": "markdown",
489
+ "id": "68c08713-89d9-4611-8cf5-9c86bed5fc29",
490
+ "metadata": {},
491
+ "source": [
492
+ "# ROUGE EVALUATION"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "code",
497
+ "execution_count": 46,
498
+ "id": "e869ae4a-6126-4256-98b4-4c36556e4cec",
499
+ "metadata": {},
500
+ "outputs": [],
501
+ "source": [
502
+ "def ROUGE_evaluate(data_set : list):\n",
503
+ " data = data_set\n",
504
+ " for i in range(len(data)):\n",
505
+ " rouge = evaluate.load('rouge')\n",
506
+ " predictions = [data[i]['generated']]\n",
507
+ " references = [data[i]['summary']]\n",
508
+ " results = rouge.compute(predictions=predictions, references=references)\n",
509
+ " print(results)"
510
+ ]
511
+ },
512
+ {
513
+ "cell_type": "markdown",
514
+ "id": "2e4c2db3-ee0c-4eb8-894a-c5a2b859bc79",
515
+ "metadata": {},
516
+ "source": [
517
+ "# Test Data"
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 35,
523
+ "id": "9d9df0d5-8436-44e2-8be8-01ba1f699436",
524
+ "metadata": {},
525
+ "outputs": [
526
+ {
527
+ "name": "stdout",
528
+ "output_type": "stream",
529
+ "text": [
530
+ "{'rouge1': 0.864406779661017, 'rouge2': 0.8620689655172413, 'rougeL': 0.864406779661017, 'rougeLsum': 0.864406779661017}\n",
531
+ "{'rouge1': 0.5783132530120482, 'rouge2': 0.5731707317073171, 'rougeL': 0.5783132530120482, 'rougeLsum': 0.5783132530120482}\n",
532
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
533
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
534
+ "{'rouge1': 0.968421052631579, 'rouge2': 0.967741935483871, 'rougeL': 0.968421052631579, 'rougeLsum': 0.968421052631579}\n",
535
+ "{'rouge1': 0.3636363636363636, 'rouge2': 0.33333333333333337, 'rougeL': 0.3636363636363636, 'rougeLsum': 0.3636363636363636}\n",
536
+ "{'rouge1': 0.5739130434782609, 'rouge2': 0.5663716814159292, 'rougeL': 0.5739130434782609, 'rougeLsum': 0.5739130434782609}\n",
537
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
538
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
539
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
540
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
541
+ "{'rouge1': 0.9722222222222222, 'rouge2': 0.9577464788732394, 'rougeL': 0.9722222222222222, 'rougeLsum': 0.9722222222222222}\n",
542
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
543
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
544
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n",
545
+ "{'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}\n"
546
+ ]
547
+ }
548
+ ],
549
+ "source": [
550
+ "ROUGE_evaluate(generated_summaries)"
551
+ ]
552
+ },
553
+ {
554
+ "cell_type": "markdown",
555
+ "id": "d7680e59-cdf0-419a-b9ef-5516e12cff8b",
556
+ "metadata": {},
557
+ "source": [
558
+ "# New Data"
559
+ ]
560
+ },
561
+ {
562
+ "cell_type": "code",
563
+ "execution_count": 47,
564
+ "id": "342d6f20-3992-4a4e-b68b-0c67b80674af",
565
+ "metadata": {},
566
+ "outputs": [
567
+ {
568
+ "name": "stdout",
569
+ "output_type": "stream",
570
+ "text": [
571
+ "{'rouge1': 0.9545454545454546, 'rouge2': 0.9069767441860465, 'rougeL': 0.9545454545454546, 'rougeLsum': 0.9545454545454546}\n",
572
+ "{'rouge1': 0.35877862595419846, 'rouge2': 0.34615384615384615, 'rougeL': 0.35877862595419846, 'rougeLsum': 0.35877862595419846}\n"
573
+ ]
574
+ }
575
+ ],
576
+ "source": [
577
+ "ROUGE_evaluate(new_generated_summaries)"
578
+ ]
579
+ },
580
+ {
581
+ "cell_type": "code",
582
+ "execution_count": null,
583
+ "id": "6eeab333-c8b8-42f2-9e4d-74705a6aa518",
584
+ "metadata": {},
585
+ "outputs": [],
586
+ "source": []
587
+ }
588
+ ],
589
+ "metadata": {
590
+ "kernelspec": {
591
+ "display_name": "Python 3 (ipykernel)",
592
+ "language": "python",
593
+ "name": "python3"
594
+ },
595
+ "language_info": {
596
+ "codemirror_mode": {
597
+ "name": "ipython",
598
+ "version": 3
599
+ },
600
+ "file_extension": ".py",
601
+ "mimetype": "text/x-python",
602
+ "name": "python",
603
+ "nbconvert_exporter": "python",
604
+ "pygments_lexer": "ipython3",
605
+ "version": "3.11.7"
606
+ }
607
+ },
608
+ "nbformat": 4,
609
+ "nbformat_minor": 5
610
+ }
notebooks/TermProject.ipynb ADDED
@@ -0,0 +1,1378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "695a0d97-6b1d-4448-b16c-3ba95bb60c30",
6
+ "metadata": {
7
+ "jp-MarkdownHeadingCollapsed": true
8
+ },
9
+ "source": [
10
+ "# If these install, restart the kernal so it has access to the recently installed files"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": null,
16
+ "id": "22de09b1-3c40-4195-8b5a-926d5391313f",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "!pip3 install --user transformers datasets evaluate rouge_score\n",
21
+ "!pip3 install --user datasets\n",
22
+ "!pip install --user transformers[torch]\n",
23
+ "!pip install --user accelerate -U\n",
24
+ "!pip install --user wandb"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "markdown",
29
+ "id": "e1687d09-6b14-47fb-9819-dbed0d8ae3b3",
30
+ "metadata": {},
31
+ "source": [
32
+ "# Logging into huggingface hub"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 1,
38
+ "id": "f2f10d5e-9655-4554-abb0-511044640854",
39
+ "metadata": {},
40
+ "outputs": [
41
+ {
42
+ "data": {
43
+ "application/vnd.jupyter.widget-view+json": {
44
+ "model_id": "bc57319ea4544e0cbe8fd4f2c10ee2e9",
45
+ "version_major": 2,
46
+ "version_minor": 0
47
+ },
48
+ "text/plain": [
49
+ "VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
50
+ ]
51
+ },
52
+ "metadata": {},
53
+ "output_type": "display_data"
54
+ }
55
+ ],
56
+ "source": [
57
+ "from huggingface_hub import notebook_login\n",
58
+ "\n",
59
+ "notebook_login()"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "markdown",
64
+ "id": "05b9e8c7-b52d-4a1f-8464-fb5f7e78e579",
65
+ "metadata": {},
66
+ "source": [
67
+ "# Naming the WANDB project and notebook"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": 2,
73
+ "id": "6b4bad30-76c7-49dc-b563-a27ed9465eee",
74
+ "metadata": {},
75
+ "outputs": [
76
+ {
77
+ "name": "stderr",
78
+ "output_type": "stream",
79
+ "text": [
80
+ "\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m WANDB_NOTEBOOK_NAME should be a path to a notebook file, couldn't find ./TermProject.\n",
81
+ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mtah6k\u001b[0m (\u001b[33mcheaptrix\u001b[0m). Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
82
+ ]
83
+ },
84
+ {
85
+ "data": {
86
+ "text/html": [
87
+ "Tracking run with wandb version 0.16.6"
88
+ ],
89
+ "text/plain": [
90
+ "<IPython.core.display.HTML object>"
91
+ ]
92
+ },
93
+ "metadata": {},
94
+ "output_type": "display_data"
95
+ },
96
+ {
97
+ "data": {
98
+ "text/html": [
99
+ "Run data is saved locally in <code>/scratch/user/u.th161689/AI_NLP/TermProject/wandb/run-20240412_232000-ls1byqtm</code>"
100
+ ],
101
+ "text/plain": [
102
+ "<IPython.core.display.HTML object>"
103
+ ]
104
+ },
105
+ "metadata": {},
106
+ "output_type": "display_data"
107
+ },
108
+ {
109
+ "data": {
110
+ "text/html": [
111
+ "Syncing run <strong><a href='https://wandb.ai/cheaptrix/congress_bill_sumamry_model/runs/ls1byqtm' target=\"_blank\">youthful-fire-1</a></strong> to <a href='https://wandb.ai/cheaptrix/congress_bill_sumamry_model' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
112
+ ],
113
+ "text/plain": [
114
+ "<IPython.core.display.HTML object>"
115
+ ]
116
+ },
117
+ "metadata": {},
118
+ "output_type": "display_data"
119
+ },
120
+ {
121
+ "data": {
122
+ "text/html": [
123
+ " View project at <a href='https://wandb.ai/cheaptrix/congress_bill_sumamry_model' target=\"_blank\">https://wandb.ai/cheaptrix/congress_bill_sumamry_model</a>"
124
+ ],
125
+ "text/plain": [
126
+ "<IPython.core.display.HTML object>"
127
+ ]
128
+ },
129
+ "metadata": {},
130
+ "output_type": "display_data"
131
+ },
132
+ {
133
+ "data": {
134
+ "text/html": [
135
+ " View run at <a href='https://wandb.ai/cheaptrix/congress_bill_sumamry_model/runs/ls1byqtm' target=\"_blank\">https://wandb.ai/cheaptrix/congress_bill_sumamry_model/runs/ls1byqtm</a>"
136
+ ],
137
+ "text/plain": [
138
+ "<IPython.core.display.HTML object>"
139
+ ]
140
+ },
141
+ "metadata": {},
142
+ "output_type": "display_data"
143
+ },
144
+ {
145
+ "data": {
146
+ "text/html": [
147
+ "<button onClick=\"this.nextSibling.style.display='block';this.style.display='none';\">Display W&B run</button><iframe src='https://wandb.ai/cheaptrix/congress_bill_sumamry_model/runs/ls1byqtm?jupyter=true' style='border:none;width:100%;height:420px;display:none;'></iframe>"
148
+ ],
149
+ "text/plain": [
150
+ "<wandb.sdk.wandb_run.Run at 0x14deaee5bb90>"
151
+ ]
152
+ },
153
+ "execution_count": 2,
154
+ "metadata": {},
155
+ "output_type": "execute_result"
156
+ }
157
+ ],
158
+ "source": [
159
+ "# Must set the global variable WANDB_NOTEBOOK_NAME to the name of the notebook\n",
160
+ "import os\n",
161
+ "import wandb\n",
162
+ "# Name is found through the os incase the name changes\n",
163
+ "# WANDB_NOTEBOOK_NAME = os.path.basename(os.getcwd())\n",
164
+ "notebook_name = str(os.path.basename(os.getcwd()))\n",
165
+ "os.environ[\"WANDB_NOTEBOOK_NAME\"] = \"./\" + notebook_name\n",
166
+ "os.environ[\"WANDB_PROJECT\"] = \"congress_bill_summary_model\"\n",
167
+ "wandb.init(project='congress_bill_sumamry_model') "
168
+ ]
169
+ },
170
+ {
171
+ "cell_type": "markdown",
172
+ "id": "69fbba70-2fb2-47c9-abc9-1824a3ab10d7",
173
+ "metadata": {},
174
+ "source": [
175
+ "# Importing and loading the Congressional Bills dataset"
176
+ ]
177
+ },
178
+ {
179
+ "cell_type": "code",
180
+ "execution_count": 3,
181
+ "id": "fd3b62f1-5bd2-44ff-87f3-1d48ccb74459",
182
+ "metadata": {},
183
+ "outputs": [],
184
+ "source": [
185
+ "import datasets\n",
186
+ "from datasets import load_dataset\n",
187
+ "import pandas as pd\n",
188
+ "from datasets import Dataset\n",
189
+ "import json\n",
190
+ "\n",
191
+ "# Opening JSON file\n",
192
+ "with open(\"cleaned_bill_sum_data.json\") as json_file:\n",
193
+ " cleaned_data = json.load(json_file)\n",
194
+ "data = pd.DataFrame.from_dict(cleaned_data)\n",
195
+ "dataset = Dataset.from_pandas(pd.DataFrame(data=data))"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "markdown",
200
+ "id": "2c87b4f7-bdbd-4869-8975-609373000ab0",
201
+ "metadata": {},
202
+ "source": [
203
+ "# Splitting the data to training and testing split"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 4,
209
+ "id": "9f08c14e-820e-497d-a979-6332bce67bc1",
210
+ "metadata": {},
211
+ "outputs": [],
212
+ "source": [
213
+ "billsum = dataset.train_test_split(test_size=0.2)"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "markdown",
218
+ "id": "9949be74-ed88-49a8-8465-8290af7abe6f",
219
+ "metadata": {},
220
+ "source": [
221
+ "# Example of data within the training set"
222
+ ]
223
+ },
224
+ {
225
+ "cell_type": "code",
226
+ "execution_count": 5,
227
+ "id": "2f7551a5-631d-4de3-afb7-99d923d18ccd",
228
+ "metadata": {},
229
+ "outputs": [
230
+ {
231
+ "data": {
232
+ "text/plain": [
233
+ "{'summary': '(This measure has not been amended since it was introduced. The summary of that version is repeated here.) Declares that when the House adjourns on any legislative day from Friday, July 15, 2016, through Friday, September 2, 2016, it stand adjourned until 2 p.m. on Tuesday, September 6, 2016.',\n",
234
+ " 'text': 'A concurrent resolution providing for an adjournment of the House of Representatives. 2016-07-14 Passed Senate without amendment (This measure has not been amended since it was introduced. The summary of that version is repeated here.) Declares that when the House adjourns on any legislative day from Friday, July 15, 2016, through Friday, September 2, 2016, it stand adjourned until 2 p.m. on Tuesday, September 6, 2016. 2016-07-14 Introduced in Senate Declares that when the House adjourns on any legislative day from Friday, July 15, 2016, through Friday, September 2, 2016, it stand adjourned until 2 p.m. on Tuesday, September 6, 2016. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
235
+ " 'title': 'A concurrent resolution providing for an adjournment of the House of Representatives.'}"
236
+ ]
237
+ },
238
+ "execution_count": 5,
239
+ "metadata": {},
240
+ "output_type": "execute_result"
241
+ }
242
+ ],
243
+ "source": [
244
+ "billsum[\"train\"][0]"
245
+ ]
246
+ },
247
+ {
248
+ "cell_type": "markdown",
249
+ "id": "7c2e2c67-3d0b-4d4b-b3b6-e6d9afb60c8a",
250
+ "metadata": {},
251
+ "source": [
252
+ "# Load T5 tokenizer to process text and summary"
253
+ ]
254
+ },
255
+ {
256
+ "cell_type": "code",
257
+ "execution_count": 6,
258
+ "id": "b3d4454e-e7f3-4020-9ecc-4c692c6da5c6",
259
+ "metadata": {},
260
+ "outputs": [],
261
+ "source": [
262
+ "from transformers import AutoTokenizer\n",
263
+ "\n",
264
+ "checkpoint = \"google-t5/t5-small\"\n",
265
+ "tokenizer = AutoTokenizer.from_pretrained(checkpoint)"
266
+ ]
267
+ },
268
+ {
269
+ "cell_type": "markdown",
270
+ "id": "15e4537b-4a72-434a-8af7-1cef702581d0",
271
+ "metadata": {},
272
+ "source": [
273
+ "# Perprocessing Function"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 7,
279
+ "id": "2feec165-87ed-4258-a332-14c3b7dd9867",
280
+ "metadata": {},
281
+ "outputs": [],
282
+ "source": [
283
+ "prefix = \"summarize: \"\n",
284
+ "\n",
285
+ "\n",
286
+ "def preprocess_function(examples):\n",
287
+ " inputs = [prefix + doc for doc in examples[\"text\"]]\n",
288
+ " model_inputs = tokenizer(inputs, max_length=1024, truncation=True)\n",
289
+ "\n",
290
+ " labels = tokenizer(text_target=examples[\"summary\"], max_length=128, truncation=True)\n",
291
+ "\n",
292
+ " model_inputs[\"labels\"] = labels[\"input_ids\"]\n",
293
+ " return model_inputs"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "markdown",
298
+ "id": "814f0888-e5c0-4841-9084-ed4f6762ecdd",
299
+ "metadata": {},
300
+ "source": [
301
+ "# Tokenize the dataset using the map function"
302
+ ]
303
+ },
304
+ {
305
+ "cell_type": "code",
306
+ "execution_count": 8,
307
+ "id": "65c755b9-33ae-4d95-b0d2-b7b7950f4f71",
308
+ "metadata": {},
309
+ "outputs": [
310
+ {
311
+ "data": {
312
+ "application/vnd.jupyter.widget-view+json": {
313
+ "model_id": "23e819666e29433196ea0a7457855dbf",
314
+ "version_major": 2,
315
+ "version_minor": 0
316
+ },
317
+ "text/plain": [
318
+ "Map: 0%| | 0/212 [00:00<?, ? examples/s]"
319
+ ]
320
+ },
321
+ "metadata": {},
322
+ "output_type": "display_data"
323
+ },
324
+ {
325
+ "data": {
326
+ "application/vnd.jupyter.widget-view+json": {
327
+ "model_id": "64e22b879f724c4cbe294ac1418910ef",
328
+ "version_major": 2,
329
+ "version_minor": 0
330
+ },
331
+ "text/plain": [
332
+ "Map: 0%| | 0/53 [00:00<?, ? examples/s]"
333
+ ]
334
+ },
335
+ "metadata": {},
336
+ "output_type": "display_data"
337
+ }
338
+ ],
339
+ "source": [
340
+ "tokenized_billsum = billsum.map(preprocess_function, batched=True)"
341
+ ]
342
+ },
343
+ {
344
+ "cell_type": "markdown",
345
+ "id": "294ec0e7-5120-4c13-9517-6e4407dd12e7",
346
+ "metadata": {},
347
+ "source": [
348
+ "# Creating a batch of examples using DataCollatorForSeq2Seq with dynamic padding"
349
+ ]
350
+ },
351
+ {
352
+ "cell_type": "code",
353
+ "execution_count": 9,
354
+ "id": "a1e9d07d-7cbf-46c2-87c6-9ebc97fcbfcf",
355
+ "metadata": {},
356
+ "outputs": [
357
+ {
358
+ "name": "stderr",
359
+ "output_type": "stream",
360
+ "text": [
361
+ "2024-04-12 23:20:17.382485: I tensorflow/core/util/port.cc:111] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
362
+ "2024-04-12 23:20:17.422130: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
363
+ "2024-04-12 23:20:17.422161: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
364
+ "2024-04-12 23:20:17.422185: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
365
+ "2024-04-12 23:20:17.429463: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
366
+ "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
367
+ "2024-04-12 23:20:18.470755: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
368
+ ]
369
+ }
370
+ ],
371
+ "source": [
372
+ "from transformers import DataCollatorForSeq2Seq\n",
373
+ "\n",
374
+ "data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=checkpoint)"
375
+ ]
376
+ },
377
+ {
378
+ "cell_type": "markdown",
379
+ "id": "bd435fc8-af8b-419b-b41b-384f6b412119",
380
+ "metadata": {},
381
+ "source": [
382
+ "# Importing the evaluator"
383
+ ]
384
+ },
385
+ {
386
+ "cell_type": "code",
387
+ "execution_count": 10,
388
+ "id": "bc7159a1-3997-47bd-8d17-48c2e09f7ace",
389
+ "metadata": {},
390
+ "outputs": [],
391
+ "source": [
392
+ "import evaluate\n",
393
+ "\n",
394
+ "rouge = evaluate.load(\"rouge\")"
395
+ ]
396
+ },
397
+ {
398
+ "cell_type": "markdown",
399
+ "id": "11f1979d-91e3-414f-b76b-36034e97b8b0",
400
+ "metadata": {},
401
+ "source": [
402
+ "# Function that passes predictions and labels to compute to calculate the Rouge metric."
403
+ ]
404
+ },
405
+ {
406
+ "cell_type": "code",
407
+ "execution_count": 11,
408
+ "id": "e301045f-eb8d-4c2d-b2f5-59acf2f053b0",
409
+ "metadata": {},
410
+ "outputs": [],
411
+ "source": [
412
+ "def compute_metrics(eval_pred):\n",
413
+ " predictions, labels = eval_pred\n",
414
+ " decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=True)\n",
415
+ " labels = np.where(labels != -100, labels, tokenizer.pad_token_id)\n",
416
+ " decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)\n",
417
+ "\n",
418
+ " result = rouge.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)\n",
419
+ "\n",
420
+ " prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in predictions]\n",
421
+ " result[\"gen_len\"] = np.mean(prediction_lens)\n",
422
+ "\n",
423
+ " return {k: round(v, 4) for k, v in result.items()}"
424
+ ]
425
+ },
426
+ {
427
+ "cell_type": "markdown",
428
+ "id": "e3833f68-20da-4343-88c6-4b5c144bfb7c",
429
+ "metadata": {},
430
+ "source": [
431
+ "# Training - Loading T5 with AutoModelForSeq2SeqLM"
432
+ ]
433
+ },
434
+ {
435
+ "cell_type": "code",
436
+ "execution_count": 12,
437
+ "id": "8a9100fb-4ebe-469d-a1a3-b0a00c54528a",
438
+ "metadata": {},
439
+ "outputs": [],
440
+ "source": [
441
+ "from transformers import AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer\n",
442
+ "\n",
443
+ "model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)"
444
+ ]
445
+ },
446
+ {
447
+ "cell_type": "markdown",
448
+ "id": "9722c5f5-a9ed-44d1-b677-9fe558890218",
449
+ "metadata": {},
450
+ "source": [
451
+ "# Defining the training hyperparameters"
452
+ ]
453
+ },
454
+ {
455
+ "cell_type": "code",
456
+ "execution_count": 13,
457
+ "id": "e9d5eb20-6e52-44c7-aa09-5ad6c09576d9",
458
+ "metadata": {},
459
+ "outputs": [],
460
+ "source": [
461
+ "# ORIGINAL\n",
462
+ "# training_args = Seq2SeqTrainingArguments(\n",
463
+ "# output_dir=\"my_awesome_billsum_model\",\n",
464
+ "# evaluation_strategy=\"epoch\",\n",
465
+ "# learning_rate=2e-5,\n",
466
+ "# per_device_train_batch_size=16,\n",
467
+ "# per_device_eval_batch_size=16,\n",
468
+ "# weight_decay=0.01,\n",
469
+ "# save_total_limit=3,\n",
470
+ "# num_train_epochs=4,\n",
471
+ "# predict_with_generate=True,\n",
472
+ "# fp16=True,\n",
473
+ "# push_to_hub=True,\n",
474
+ "# )\n",
475
+ "\n",
476
+ "training_args = Seq2SeqTrainingArguments(\n",
477
+ " output_dir=\"congress_bill_summary_model\",\n",
478
+ " evaluation_strategy=\"epoch\",\n",
479
+ " learning_rate=2e-4,\n",
480
+ " per_device_train_batch_size=16,\n",
481
+ " per_device_eval_batch_size=16,\n",
482
+ " weight_decay=0.01,\n",
483
+ " save_total_limit=3,\n",
484
+ " num_train_epochs=4,\n",
485
+ " predict_with_generate=True,\n",
486
+ " fp16=True,\n",
487
+ " push_to_hub=True,\n",
488
+ ")"
489
+ ]
490
+ },
491
+ {
492
+ "cell_type": "markdown",
493
+ "id": "aa5635ee-8d6a-45ce-8976-90df52eacd8a",
494
+ "metadata": {},
495
+ "source": [
496
+ "# Passing the arguments, model, dataset, tokenizer, data collator, and compute_metrics function to Seq2SeqTrainer for training"
497
+ ]
498
+ },
499
+ {
500
+ "cell_type": "code",
501
+ "execution_count": 14,
502
+ "id": "3476e539-1f86-41b2-beec-f9441406a692",
503
+ "metadata": {},
504
+ "outputs": [
505
+ {
506
+ "name": "stderr",
507
+ "output_type": "stream",
508
+ "text": [
509
+ "/home/u.th161689/.local/lib/python3.11/site-packages/accelerate/accelerator.py:436: FutureWarning: Passing the following arguments to `Accelerator` is deprecated and will be removed in version 1.0 of Accelerate: dict_keys(['dispatch_batches', 'split_batches']). Please pass an `accelerate.DataLoaderConfiguration` instead: \n",
510
+ "dataloader_config = DataLoaderConfiguration(dispatch_batches=None, split_batches=False)\n",
511
+ " warnings.warn(\n",
512
+ "Detected kernel version 4.18.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.\n"
513
+ ]
514
+ }
515
+ ],
516
+ "source": [
517
+ "trainer = Seq2SeqTrainer(\n",
518
+ " model=model,\n",
519
+ " args=training_args,\n",
520
+ " train_dataset=tokenized_billsum[\"train\"],\n",
521
+ " eval_dataset=tokenized_billsum[\"test\"],\n",
522
+ " tokenizer=tokenizer,\n",
523
+ " data_collator=data_collator,\n",
524
+ " compute_metrics=compute_metrics,\n",
525
+ ")"
526
+ ]
527
+ },
528
+ {
529
+ "cell_type": "markdown",
530
+ "id": "91c564a2-6a8c-4073-ac83-aa45b2ae28fa",
531
+ "metadata": {},
532
+ "source": [
533
+ "# Fine-tuning the model"
534
+ ]
535
+ },
536
+ {
537
+ "cell_type": "code",
538
+ "execution_count": 15,
539
+ "id": "d3f06124-0e43-4cf6-9af8-af0b42fa1b78",
540
+ "metadata": {},
541
+ "outputs": [
542
+ {
543
+ "name": "stderr",
544
+ "output_type": "stream",
545
+ "text": [
546
+ "You're using a T5TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n"
547
+ ]
548
+ },
549
+ {
550
+ "data": {
551
+ "text/html": [
552
+ "\n",
553
+ " <div>\n",
554
+ " \n",
555
+ " <progress value='56' max='56' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
556
+ " [56/56 00:38, Epoch 4/4]\n",
557
+ " </div>\n",
558
+ " <table border=\"1\" class=\"dataframe\">\n",
559
+ " <thead>\n",
560
+ " <tr style=\"text-align: left;\">\n",
561
+ " <th>Epoch</th>\n",
562
+ " <th>Training Loss</th>\n",
563
+ " <th>Validation Loss</th>\n",
564
+ " <th>Rouge1</th>\n",
565
+ " <th>Rouge2</th>\n",
566
+ " <th>Rougel</th>\n",
567
+ " <th>Rougelsum</th>\n",
568
+ " <th>Gen Len</th>\n",
569
+ " </tr>\n",
570
+ " </thead>\n",
571
+ " <tbody>\n",
572
+ " <tr>\n",
573
+ " <td>1</td>\n",
574
+ " <td>No log</td>\n",
575
+ " <td>0.108650</td>\n",
576
+ " <td>0.443800</td>\n",
577
+ " <td>0.427400</td>\n",
578
+ " <td>0.442700</td>\n",
579
+ " <td>0.442200</td>\n",
580
+ " <td>19.000000</td>\n",
581
+ " </tr>\n",
582
+ " <tr>\n",
583
+ " <td>2</td>\n",
584
+ " <td>No log</td>\n",
585
+ " <td>0.060382</td>\n",
586
+ " <td>0.455200</td>\n",
587
+ " <td>0.439900</td>\n",
588
+ " <td>0.455100</td>\n",
589
+ " <td>0.454600</td>\n",
590
+ " <td>19.000000</td>\n",
591
+ " </tr>\n",
592
+ " <tr>\n",
593
+ " <td>3</td>\n",
594
+ " <td>No log</td>\n",
595
+ " <td>0.053176</td>\n",
596
+ " <td>0.461700</td>\n",
597
+ " <td>0.448200</td>\n",
598
+ " <td>0.462300</td>\n",
599
+ " <td>0.462000</td>\n",
600
+ " <td>19.000000</td>\n",
601
+ " </tr>\n",
602
+ " <tr>\n",
603
+ " <td>4</td>\n",
604
+ " <td>No log</td>\n",
605
+ " <td>0.049938</td>\n",
606
+ " <td>0.463300</td>\n",
607
+ " <td>0.449800</td>\n",
608
+ " <td>0.463500</td>\n",
609
+ " <td>0.463100</td>\n",
610
+ " <td>19.000000</td>\n",
611
+ " </tr>\n",
612
+ " </tbody>\n",
613
+ "</table><p>"
614
+ ],
615
+ "text/plain": [
616
+ "<IPython.core.display.HTML object>"
617
+ ]
618
+ },
619
+ "metadata": {},
620
+ "output_type": "display_data"
621
+ },
622
+ {
623
+ "name": "stderr",
624
+ "output_type": "stream",
625
+ "text": [
626
+ "/opt/conda/lib/python3.11/site-packages/transformers/generation/utils.py:1355: UserWarning: Using the model-agnostic default `max_length` (=20) to control the generation length. We recommend setting `max_new_tokens` to control the maximum length of the generation.\n",
627
+ " warnings.warn(\n"
628
+ ]
629
+ },
630
+ {
631
+ "data": {
632
+ "text/plain": [
633
+ "TrainOutput(global_step=56, training_loss=0.17396153722490584, metrics={'train_runtime': 39.9457, 'train_samples_per_second': 21.229, 'train_steps_per_second': 1.402, 'total_flos': 177655146872832.0, 'train_loss': 0.17396153722490584, 'epoch': 4.0})"
634
+ ]
635
+ },
636
+ "execution_count": 15,
637
+ "metadata": {},
638
+ "output_type": "execute_result"
639
+ }
640
+ ],
641
+ "source": [
642
+ "# Training needs numpy\n",
643
+ "import numpy as np\n",
644
+ "\n",
645
+ "# Fine-tuning the model\n",
646
+ "trainer.train()"
647
+ ]
648
+ },
649
+ {
650
+ "cell_type": "markdown",
651
+ "id": "b1e694f0-394b-4a68-8183-59fdf76d30a3",
652
+ "metadata": {},
653
+ "source": [
654
+ "# Saving the Model"
655
+ ]
656
+ },
657
+ {
658
+ "cell_type": "code",
659
+ "execution_count": 16,
660
+ "id": "b4d1a48a-55cb-4456-aa3f-861e86645cae",
661
+ "metadata": {},
662
+ "outputs": [
663
+ {
664
+ "data": {
665
+ "application/vnd.jupyter.widget-view+json": {
666
+ "model_id": "2483f039d1834b40a8f0904f0207907e",
667
+ "version_major": 2,
668
+ "version_minor": 0
669
+ },
670
+ "text/plain": [
671
+ "model.safetensors: 0%| | 0.00/242M [00:00<?, ?B/s]"
672
+ ]
673
+ },
674
+ "metadata": {},
675
+ "output_type": "display_data"
676
+ },
677
+ {
678
+ "data": {
679
+ "application/vnd.jupyter.widget-view+json": {
680
+ "model_id": "64cf8e2edd09426d84c75d1bdbaeacee",
681
+ "version_major": 2,
682
+ "version_minor": 0
683
+ },
684
+ "text/plain": [
685
+ "events.out.tfevents.1712982022.fc003.3364345.0: 0%| | 0.00/7.79k [00:00<?, ?B/s]"
686
+ ]
687
+ },
688
+ "metadata": {},
689
+ "output_type": "display_data"
690
+ },
691
+ {
692
+ "data": {
693
+ "application/vnd.jupyter.widget-view+json": {
694
+ "model_id": "c7cfea8e6b0a44e49a7158d0a81edcab",
695
+ "version_major": 2,
696
+ "version_minor": 0
697
+ },
698
+ "text/plain": [
699
+ "training_args.bin: 0%| | 0.00/4.86k [00:00<?, ?B/s]"
700
+ ]
701
+ },
702
+ "metadata": {},
703
+ "output_type": "display_data"
704
+ },
705
+ {
706
+ "data": {
707
+ "application/vnd.jupyter.widget-view+json": {
708
+ "model_id": "4c29d1060f564100a4f3021ff3fc30ca",
709
+ "version_major": 2,
710
+ "version_minor": 0
711
+ },
712
+ "text/plain": [
713
+ "events.out.tfevents.1712981439.fc003.3322740.0: 0%| | 0.00/7.79k [00:00<?, ?B/s]"
714
+ ]
715
+ },
716
+ "metadata": {},
717
+ "output_type": "display_data"
718
+ },
719
+ {
720
+ "data": {
721
+ "application/vnd.jupyter.widget-view+json": {
722
+ "model_id": "59c0974429b74163a23bc5750116c026",
723
+ "version_major": 2,
724
+ "version_minor": 0
725
+ },
726
+ "text/plain": [
727
+ "Upload 4 LFS files: 0%| | 0/4 [00:00<?, ?it/s]"
728
+ ]
729
+ },
730
+ "metadata": {},
731
+ "output_type": "display_data"
732
+ }
733
+ ],
734
+ "source": [
735
+ "trainer.save_model(\"./congress_bill_summary_model\")"
736
+ ]
737
+ },
738
+ {
739
+ "cell_type": "markdown",
740
+ "id": "3a93edb3-cc87-43fa-86af-7d77c66ddaae",
741
+ "metadata": {},
742
+ "source": [
743
+ "# Pushing Model to Personal HuggingFace Hub"
744
+ ]
745
+ },
746
+ {
747
+ "cell_type": "code",
748
+ "execution_count": 17,
749
+ "id": "19fb405b-5413-4bfa-a365-66e8729a1559",
750
+ "metadata": {},
751
+ "outputs": [
752
+ {
753
+ "data": {
754
+ "text/plain": [
755
+ "CommitInfo(commit_url='https://huggingface.co/cheaptrix/congress_bill_summary_model/commit/dcdfc898778d0665ae87f330cd063a2a27fee3f4', commit_message='cheaptrix/congress_bill_summary_model', commit_description='', oid='dcdfc898778d0665ae87f330cd063a2a27fee3f4', pr_url=None, pr_revision=None, pr_num=None)"
756
+ ]
757
+ },
758
+ "execution_count": 17,
759
+ "metadata": {},
760
+ "output_type": "execute_result"
761
+ }
762
+ ],
763
+ "source": [
764
+ "trainer.push_to_hub(\"cheaptrix/congress_bill_summary_model\")"
765
+ ]
766
+ },
767
+ {
768
+ "cell_type": "markdown",
769
+ "id": "166d4903-8809-4a77-9f43-45316cbccc91",
770
+ "metadata": {},
771
+ "source": [
772
+ "# Interface"
773
+ ]
774
+ },
775
+ {
776
+ "cell_type": "code",
777
+ "execution_count": 18,
778
+ "id": "c960268a-411e-4abc-8f95-f88cf5b11055",
779
+ "metadata": {},
780
+ "outputs": [],
781
+ "source": [
782
+ "cleaned_test_data = []\n",
783
+ "# Opening JSON file\n",
784
+ "with open(\"cleaned_bill_sum_test_data.json\") as json_file:\n",
785
+ " cleaned_test_data = json.load(json_file)"
786
+ ]
787
+ },
788
+ {
789
+ "cell_type": "markdown",
790
+ "id": "484d784c-2700-4e2e-8c09-99293468487d",
791
+ "metadata": {},
792
+ "source": [
793
+ "# Creating a pipeline with the transformers module"
794
+ ]
795
+ },
796
+ {
797
+ "cell_type": "code",
798
+ "execution_count": 19,
799
+ "id": "7298e9e4-4a53-4494-8f8a-0a69dbb55d52",
800
+ "metadata": {},
801
+ "outputs": [
802
+ {
803
+ "data": {
804
+ "application/vnd.jupyter.widget-view+json": {
805
+ "model_id": "e989111988064fa799f348449f05235f",
806
+ "version_major": 2,
807
+ "version_minor": 0
808
+ },
809
+ "text/plain": [
810
+ "model.safetensors: 0%| | 0.00/242M [00:00<?, ?B/s]"
811
+ ]
812
+ },
813
+ "metadata": {},
814
+ "output_type": "display_data"
815
+ }
816
+ ],
817
+ "source": [
818
+ "from transformers import pipeline\n",
819
+ "\n",
820
+ "summarizer = pipeline(\"summarization\", model=\"cheaptrix/congress_bill_summary_model\")"
821
+ ]
822
+ },
823
+ {
824
+ "cell_type": "code",
825
+ "execution_count": 20,
826
+ "id": "fbde06cc-a162-437e-bda4-89f5de65c808",
827
+ "metadata": {},
828
+ "outputs": [
829
+ {
830
+ "data": {
831
+ "text/plain": [
832
+ "'A concurrent resolution establishing deadlines for the Joint Committee of Congress on the Library to approve or deny the statue of the Reverend William Franklin \"Billy\" Graham, Jr., for placement in the National Statuary Hall. 2023-02-16 Introduced in Senate This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.'"
833
+ ]
834
+ },
835
+ "execution_count": 20,
836
+ "metadata": {},
837
+ "output_type": "execute_result"
838
+ }
839
+ ],
840
+ "source": [
841
+ "text = cleaned_test_data[3]['text']\n",
842
+ "text"
843
+ ]
844
+ },
845
+ {
846
+ "cell_type": "code",
847
+ "execution_count": 21,
848
+ "id": "72b8b7cb-f4cd-4282-9343-d8ec1be2d0d5",
849
+ "metadata": {},
850
+ "outputs": [
851
+ {
852
+ "data": {
853
+ "text/plain": [
854
+ "[{'summary_text': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'}]"
855
+ ]
856
+ },
857
+ "execution_count": 21,
858
+ "metadata": {},
859
+ "output_type": "execute_result"
860
+ }
861
+ ],
862
+ "source": [
863
+ "summarizer(text)"
864
+ ]
865
+ },
866
+ {
867
+ "cell_type": "code",
868
+ "execution_count": 22,
869
+ "id": "f3744109-c882-454a-9ecb-ff9fc7468e0a",
870
+ "metadata": {},
871
+ "outputs": [
872
+ {
873
+ "data": {
874
+ "text/plain": [
875
+ "'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'"
876
+ ]
877
+ },
878
+ "execution_count": 22,
879
+ "metadata": {},
880
+ "output_type": "execute_result"
881
+ }
882
+ ],
883
+ "source": [
884
+ "cleaned_test_data[3]['summary']"
885
+ ]
886
+ },
887
+ {
888
+ "cell_type": "code",
889
+ "execution_count": 23,
890
+ "id": "c1b02b6c-5d8d-421e-9225-17802b183304",
891
+ "metadata": {},
892
+ "outputs": [
893
+ {
894
+ "name": "stderr",
895
+ "output_type": "stream",
896
+ "text": [
897
+ "Token indices sequence length is longer than the specified maximum sequence length for this model (548 > 512). Running this sequence through the model will result in indexing errors\n"
898
+ ]
899
+ }
900
+ ],
901
+ "source": [
902
+ "generated_summaries = []\n",
903
+ "for i in range(len(cleaned_test_data)):\n",
904
+ " summary = summarizer(cleaned_test_data[i]['text'])\n",
905
+ " generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : cleaned_test_data[i]['summary']})"
906
+ ]
907
+ },
908
+ {
909
+ "cell_type": "code",
910
+ "execution_count": 24,
911
+ "id": "1791b057-3684-4e51-8d4e-3649a7811f20",
912
+ "metadata": {},
913
+ "outputs": [
914
+ {
915
+ "data": {
916
+ "text/plain": [
917
+ "{'generated': 'This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.',\n",
918
+ " 'summary': 'Adopting Cryptocurrency in Congress as an Exchange of Payment for Transactions Resolution or the ACCEPT Resolution This resolution requires the Architect of the Capitol, the Secretary of the Senate, and the Chief Administrative Officer of the House of Representatives to encourage Capitol gift shops to accept cryptocurrency and to enter into contracts with vendors that accept cryptocurrency to provide food service and vending machines in the Capitol.'}"
919
+ ]
920
+ },
921
+ "execution_count": 24,
922
+ "metadata": {},
923
+ "output_type": "execute_result"
924
+ }
925
+ ],
926
+ "source": [
927
+ "generated_summaries[0]"
928
+ ]
929
+ },
930
+ {
931
+ "cell_type": "code",
932
+ "execution_count": 25,
933
+ "id": "ecc976d1-27f0-4094-94a2-ac1d025b9595",
934
+ "metadata": {},
935
+ "outputs": [
936
+ {
937
+ "data": {
938
+ "text/plain": [
939
+ "{'generated': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime.',\n",
940
+ " 'summary': 'This concurrent resolution commends the bravery, courage, and resolve of the women and men of Iran who are (1) participating in the current protests to defend their fundamental human rights, and (2) risking their safety to speak out against the human rights abuses committed by the Iranian regime. The resolution condemns (1) the brutal beating and death of Mahsa Amini; and (2) the violent suppression by the Iranian regime of women and men participating in the current demonstrations, including children, and calls for transparent accountability for all killings of protesters by Iranian security forces. Finally, the resolution encourages continued efforts by the Biden Administration to respond to the protests, including the recent sanctioning of the Iranian morality police.'}"
941
+ ]
942
+ },
943
+ "execution_count": 25,
944
+ "metadata": {},
945
+ "output_type": "execute_result"
946
+ }
947
+ ],
948
+ "source": [
949
+ "generated_summaries[1]"
950
+ ]
951
+ },
952
+ {
953
+ "cell_type": "code",
954
+ "execution_count": 26,
955
+ "id": "f3739cf1-846a-4f1e-acac-be1f629001da",
956
+ "metadata": {},
957
+ "outputs": [
958
+ {
959
+ "data": {
960
+ "text/plain": [
961
+ "{'generated': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.',\n",
962
+ " 'summary': 'This concurrent resolution calls for honoring the 237th anniversary of the enactment of the Virginia Statute for Religious Freedom on Religious Freedom Day, January 16, 2023. The resolution affirms that religious freedom includes the right of individuals of any faith and individuals of no faith to live, work, associate, and worship in accordance with their beliefs; all people of the United States can be unified in supporting religious freedom because it is a fundamental human right; and the American people will remain forever unshackled in matters of faith.'}"
963
+ ]
964
+ },
965
+ "execution_count": 26,
966
+ "metadata": {},
967
+ "output_type": "execute_result"
968
+ }
969
+ ],
970
+ "source": [
971
+ "generated_summaries[2]"
972
+ ]
973
+ },
974
+ {
975
+ "cell_type": "code",
976
+ "execution_count": 27,
977
+ "id": "ad90c77a-bc5c-48e9-a22d-9f7f95a34625",
978
+ "metadata": {},
979
+ "outputs": [
980
+ {
981
+ "data": {
982
+ "text/plain": [
983
+ "{'generated': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.',\n",
984
+ " 'summary': 'This concurrent resolution requires the Joint Committee on the Library to approve or deny the statue of Rev. Billy Graham for placement in the National Statuary Hall within 30 days after North Carolina submits specific information about the statute, including its dimensions and final weight.'}"
985
+ ]
986
+ },
987
+ "execution_count": 27,
988
+ "metadata": {},
989
+ "output_type": "execute_result"
990
+ }
991
+ ],
992
+ "source": [
993
+ "generated_summaries[3]"
994
+ ]
995
+ },
996
+ {
997
+ "cell_type": "code",
998
+ "execution_count": 28,
999
+ "id": "e15cdcb1-10e4-4a0b-8921-b9f56bfb63de",
1000
+ "metadata": {},
1001
+ "outputs": [
1002
+ {
1003
+ "data": {
1004
+ "text/plain": [
1005
+ "{'generated': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance .',\n",
1006
+ " 'summary': 'This concurrent resolution declares that Congress should not impose any new performance fee, tax, royalty, or other charge relating to the public performance of sound recordings on a local radio station for broadcasting sound recordings over the air or on any business for such public performance of sound recordings.'}"
1007
+ ]
1008
+ },
1009
+ "execution_count": 28,
1010
+ "metadata": {},
1011
+ "output_type": "execute_result"
1012
+ }
1013
+ ],
1014
+ "source": [
1015
+ "generated_summaries[4]"
1016
+ ]
1017
+ },
1018
+ {
1019
+ "cell_type": "code",
1020
+ "execution_count": 29,
1021
+ "id": "fa5ad2a1-5dae-44c6-b442-d632d37dd0e0",
1022
+ "metadata": {},
1023
+ "outputs": [
1024
+ {
1025
+ "data": {
1026
+ "text/plain": [
1027
+ "{'generated': 'This concurrent resolution recognizes Abortion Provider Appreciation Day. Text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.',\n",
1028
+ " 'summary': 'This concurrent resolution recognizes Abortion Provider Appreciation Day.'}"
1029
+ ]
1030
+ },
1031
+ "execution_count": 29,
1032
+ "metadata": {},
1033
+ "output_type": "execute_result"
1034
+ }
1035
+ ],
1036
+ "source": [
1037
+ "generated_summaries[5]"
1038
+ ]
1039
+ },
1040
+ {
1041
+ "cell_type": "code",
1042
+ "execution_count": 30,
1043
+ "id": "7ac4cad6-e406-4160-a1c4-dede5d30db1a",
1044
+ "metadata": {},
1045
+ "outputs": [
1046
+ {
1047
+ "data": {
1048
+ "text/plain": [
1049
+ "{'generated': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders.\",\n",
1050
+ " 'summary': \"This concurrent resolution condemns Russia's unjust and arbitrary detention of Russian democratic opposition leader Vladimir Kara-Murza and calls for his immediate release and the release of all other Russian opposition leaders. It also calls for the release of all political prisoners in Russia and in Belarus, as well as for the release of Ukrainian citizens held by Russia, and calls on the President and leaders of the free world to work tirelessly for the release of political prisoners in Russia.\"}"
1051
+ ]
1052
+ },
1053
+ "execution_count": 30,
1054
+ "metadata": {},
1055
+ "output_type": "execute_result"
1056
+ }
1057
+ ],
1058
+ "source": [
1059
+ "generated_summaries[6]"
1060
+ ]
1061
+ },
1062
+ {
1063
+ "cell_type": "code",
1064
+ "execution_count": 31,
1065
+ "id": "5f197b89-be47-48bd-a1ab-926e95294392",
1066
+ "metadata": {},
1067
+ "outputs": [
1068
+ {
1069
+ "data": {
1070
+ "text/plain": [
1071
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.',\n",
1072
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that tax-exempt fraternal benefit societies provide critical benefits to the people and communities of the United States and their work should continue to be promoted.'}"
1073
+ ]
1074
+ },
1075
+ "execution_count": 31,
1076
+ "metadata": {},
1077
+ "output_type": "execute_result"
1078
+ }
1079
+ ],
1080
+ "source": [
1081
+ "generated_summaries[7]"
1082
+ ]
1083
+ },
1084
+ {
1085
+ "cell_type": "code",
1086
+ "execution_count": 32,
1087
+ "id": "6f6e69b9-8e2e-4daf-9809-40bb835456fa",
1088
+ "metadata": {},
1089
+ "outputs": [
1090
+ {
1091
+ "data": {
1092
+ "text/plain": [
1093
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.',\n",
1094
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that climate change caused by human activities constitutes a climate emergency, which demands the President use existing authorities and emergency powers to mitigate and prepare for the consequences of the emergency.'}"
1095
+ ]
1096
+ },
1097
+ "execution_count": 32,
1098
+ "metadata": {},
1099
+ "output_type": "execute_result"
1100
+ }
1101
+ ],
1102
+ "source": [
1103
+ "generated_summaries[8]"
1104
+ ]
1105
+ },
1106
+ {
1107
+ "cell_type": "code",
1108
+ "execution_count": 33,
1109
+ "id": "6400f171-c491-406f-85a6-aab41d159e59",
1110
+ "metadata": {},
1111
+ "outputs": [
1112
+ {
1113
+ "data": {
1114
+ "text/plain": [
1115
+ "{'generated': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\",\n",
1116
+ " 'summary': \"Fiscal State of the Nation Resolution This concurrent resolution requires the congressional budget committees to conduct an annual joint hearing to receive a presentation from the Comptroller General regarding (1) the Government Accountability Office's audit of the financial statement of the executive branch, and (2) the financial position and condition of the federal government.\"}"
1117
+ ]
1118
+ },
1119
+ "execution_count": 33,
1120
+ "metadata": {},
1121
+ "output_type": "execute_result"
1122
+ }
1123
+ ],
1124
+ "source": [
1125
+ "generated_summaries[9]"
1126
+ ]
1127
+ },
1128
+ {
1129
+ "cell_type": "code",
1130
+ "execution_count": 34,
1131
+ "id": "912101c6-66fb-4250-9320-1885e64f61c2",
1132
+ "metadata": {},
1133
+ "outputs": [
1134
+ {
1135
+ "data": {
1136
+ "text/plain": [
1137
+ "{'generated': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.',\n",
1138
+ " 'summary': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.'}"
1139
+ ]
1140
+ },
1141
+ "execution_count": 34,
1142
+ "metadata": {},
1143
+ "output_type": "execute_result"
1144
+ }
1145
+ ],
1146
+ "source": [
1147
+ "generated_summaries[10]"
1148
+ ]
1149
+ },
1150
+ {
1151
+ "cell_type": "code",
1152
+ "execution_count": 35,
1153
+ "id": "31a9a3d8-0ecd-47d2-95d3-855490f824cc",
1154
+ "metadata": {},
1155
+ "outputs": [
1156
+ {
1157
+ "data": {
1158
+ "text/plain": [
1159
+ "{'generated': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public killings (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public killers.',\n",
1160
+ " 'summary': 'This concurrent resolution calls on the media to voluntarily adopt certain practices to prevent further harm from its coverage of mass public murders. Specifically, it calls for coverage that (1) denies murderers a public platform; (2) minimizes the potential for media reporting to increase the likelihood of future mass public murders (i.e., the media contagion effect); and (3) prioritizes the victims of, and heroism in the response to, mass public murders.'}"
1161
+ ]
1162
+ },
1163
+ "execution_count": 35,
1164
+ "metadata": {},
1165
+ "output_type": "execute_result"
1166
+ }
1167
+ ],
1168
+ "source": [
1169
+ "generated_summaries[11]"
1170
+ ]
1171
+ },
1172
+ {
1173
+ "cell_type": "code",
1174
+ "execution_count": 36,
1175
+ "id": "ece694d3-1870-4f9a-902d-346b97e54f8d",
1176
+ "metadata": {},
1177
+ "outputs": [
1178
+ {
1179
+ "data": {
1180
+ "text/plain": [
1181
+ "{'generated': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation',\n",
1182
+ " 'summary': 'This concurrent resolution affirms, more than 400 years after the arrival of the first slave ship, that the United States owes a debt of remembrance to those who lived through slavery or other historical injustices against people of color, as well as to their descendants. It also urges the establishment of a U.S. Commission on Truth, Racial Healing, and Transformation.'}"
1183
+ ]
1184
+ },
1185
+ "execution_count": 36,
1186
+ "metadata": {},
1187
+ "output_type": "execute_result"
1188
+ }
1189
+ ],
1190
+ "source": [
1191
+ "generated_summaries[12]"
1192
+ ]
1193
+ },
1194
+ {
1195
+ "cell_type": "code",
1196
+ "execution_count": 37,
1197
+ "id": "346509c4-c31e-4e6e-a5df-b3b470a3dc8a",
1198
+ "metadata": {},
1199
+ "outputs": [
1200
+ {
1201
+ "data": {
1202
+ "text/plain": [
1203
+ "{'generated': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\",\n",
1204
+ " 'summary': \"This concurrent resolution recognizes the disparity between wages paid to Latina women in comparison to men and reaffirms Congress's support for ensuring equal pay and closing the gender wage gap.\"}"
1205
+ ]
1206
+ },
1207
+ "execution_count": 37,
1208
+ "metadata": {},
1209
+ "output_type": "execute_result"
1210
+ }
1211
+ ],
1212
+ "source": [
1213
+ "generated_summaries[13]"
1214
+ ]
1215
+ },
1216
+ {
1217
+ "cell_type": "code",
1218
+ "execution_count": 38,
1219
+ "id": "3c2d0904-4b8c-45ab-99dd-f661e55438b5",
1220
+ "metadata": {},
1221
+ "outputs": [
1222
+ {
1223
+ "data": {
1224
+ "text/plain": [
1225
+ "{'generated': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.',\n",
1226
+ " 'summary': 'This concurrent resolution expresses the sense of Congress that a carbon tax would be detrimental to families and businesses and would severely harm the economic and national security of the country.'}"
1227
+ ]
1228
+ },
1229
+ "execution_count": 38,
1230
+ "metadata": {},
1231
+ "output_type": "execute_result"
1232
+ }
1233
+ ],
1234
+ "source": [
1235
+ "generated_summaries[14]"
1236
+ ]
1237
+ },
1238
+ {
1239
+ "cell_type": "code",
1240
+ "execution_count": 39,
1241
+ "id": "23e3e126-ae9f-4e5e-94ed-9ab55b9b4dec",
1242
+ "metadata": {},
1243
+ "outputs": [
1244
+ {
1245
+ "data": {
1246
+ "text/plain": [
1247
+ "{'generated': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).',\n",
1248
+ " 'summary': 'This concurrent resolution makes a correction to the official title of H.R. 815 (Making emergency supplemental appropriations for the fiscal year ending September 30, 2024, and for other purposes).'}"
1249
+ ]
1250
+ },
1251
+ "execution_count": 39,
1252
+ "metadata": {},
1253
+ "output_type": "execute_result"
1254
+ }
1255
+ ],
1256
+ "source": [
1257
+ "generated_summaries[15]"
1258
+ ]
1259
+ },
1260
+ {
1261
+ "cell_type": "code",
1262
+ "execution_count": 40,
1263
+ "id": "f3c08476-c1d6-4fd3-9bb1-1590d4e1ec65",
1264
+ "metadata": {},
1265
+ "outputs": [],
1266
+ "source": [
1267
+ "new_cleaned_test_data = []\n",
1268
+ "# Opening JSON file\n",
1269
+ "with open(\"new_cleaned_bill_sum_test_data.json\") as json_file:\n",
1270
+ " new_cleaned_test_data = json.load(json_file)"
1271
+ ]
1272
+ },
1273
+ {
1274
+ "cell_type": "code",
1275
+ "execution_count": 41,
1276
+ "id": "324fa648-056b-4a5d-8990-48fb75ea032b",
1277
+ "metadata": {},
1278
+ "outputs": [
1279
+ {
1280
+ "data": {
1281
+ "text/plain": [
1282
+ "[{'summary': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates.',\n",
1283
+ " 'text': 'Saving Access to Laboratory Services Act 2023-03-28 Introduced in Senate Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
1284
+ " 'title': 'Saving Access to Laboratory Services Act'},\n",
1285
+ " {'summary': 'Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools.',\n",
1286
+ " 'text': 'Agriculture Resilience Act of 2023 2023-03-28 Introduced in Senate Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
1287
+ " 'title': 'Agriculture Resilience Act of 2023'}]"
1288
+ ]
1289
+ },
1290
+ "execution_count": 41,
1291
+ "metadata": {},
1292
+ "output_type": "execute_result"
1293
+ }
1294
+ ],
1295
+ "source": [
1296
+ "new_cleaned_test_data"
1297
+ ]
1298
+ },
1299
+ {
1300
+ "cell_type": "code",
1301
+ "execution_count": 42,
1302
+ "id": "996ad83e-6b0c-4819-b44f-ed91d4d32c7e",
1303
+ "metadata": {},
1304
+ "outputs": [],
1305
+ "source": [
1306
+ "new_generated_summaries = []\n",
1307
+ "for i in range(len(new_cleaned_test_data)):\n",
1308
+ " summary = summarizer(new_cleaned_test_data[i]['text'])\n",
1309
+ " new_generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : new_cleaned_test_data[i]['summary']})"
1310
+ ]
1311
+ },
1312
+ {
1313
+ "cell_type": "code",
1314
+ "execution_count": 43,
1315
+ "id": "4351fd53-9f09-4794-b34c-092732d27ff1",
1316
+ "metadata": {},
1317
+ "outputs": [
1318
+ {
1319
+ "data": {
1320
+ "text/plain": [
1321
+ "{'generated': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payments rates for certain widely available clinical diagnostic lab tests to be based on a statistical sampling of private sector rates.',\n",
1322
+ " 'summary': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates.'}"
1323
+ ]
1324
+ },
1325
+ "execution_count": 43,
1326
+ "metadata": {},
1327
+ "output_type": "execute_result"
1328
+ }
1329
+ ],
1330
+ "source": [
1331
+ "new_generated_summaries[0]"
1332
+ ]
1333
+ },
1334
+ {
1335
+ "cell_type": "code",
1336
+ "execution_count": 44,
1337
+ "id": "f8f57bd4-5082-4c0a-a61b-523814f60db6",
1338
+ "metadata": {},
1339
+ "outputs": [
1340
+ {
1341
+ "data": {
1342
+ "text/plain": [
1343
+ "{'generated': 'USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the Bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector.',\n",
1344
+ " 'summary': 'Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools.'}"
1345
+ ]
1346
+ },
1347
+ "execution_count": 44,
1348
+ "metadata": {},
1349
+ "output_type": "execute_result"
1350
+ }
1351
+ ],
1352
+ "source": [
1353
+ "new_generated_summaries[1]"
1354
+ ]
1355
+ }
1356
+ ],
1357
+ "metadata": {
1358
+ "kernelspec": {
1359
+ "display_name": "Python 3 (ipykernel)",
1360
+ "language": "python",
1361
+ "name": "python3"
1362
+ },
1363
+ "language_info": {
1364
+ "codemirror_mode": {
1365
+ "name": "ipython",
1366
+ "version": 3
1367
+ },
1368
+ "file_extension": ".py",
1369
+ "mimetype": "text/x-python",
1370
+ "name": "python",
1371
+ "nbconvert_exporter": "python",
1372
+ "pygments_lexer": "ipython3",
1373
+ "version": "3.11.7"
1374
+ }
1375
+ },
1376
+ "nbformat": 4,
1377
+ "nbformat_minor": 5
1378
+ }
notebooks/data_cleaning.ipynb ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "bab83122-6939-4366-8a44-17cf9d96621e",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import xml.etree.ElementTree as ET\n",
11
+ "import re\n",
12
+ "import os\n",
13
+ "import json"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 2,
19
+ "id": "29e40ec8-5ed8-458f-b071-07c4a1d88ffb",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "cleaned_data = []\n",
24
+ "cleaned_test_data = []"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "markdown",
29
+ "id": "2c03b036-edc1-4e40-9f43-36a5ccbcc787",
30
+ "metadata": {},
31
+ "source": [
32
+ "# FUNCTION TO CLEAN DATA FILES IN SPECIFIC DIRECTORIES"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 3,
38
+ "id": "44c5a2ac-3e10-439d-8c0c-65bff7ce4c9f",
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "def clean_data(summary_path : str, bill_path : str):\n",
43
+ " sums_path = summary_path\n",
44
+ " bills_path = bill_path\n",
45
+ " \n",
46
+ " # GETTING A LIST OF THE FILE NAMES FOR THE SUMMARY DATA FILES\n",
47
+ " sums_dir_list = []\n",
48
+ " for x in os.listdir(sums_path):\n",
49
+ " if x.endswith(\".xml\"):\n",
50
+ " sums_dir_list.append(x)\n",
51
+ " sums_dir_list = sorted(sums_dir_list)\n",
52
+ "\n",
53
+ " # GETTING A LIST OF THE FILE NAMES FOR THE BILL DATA FILES\n",
54
+ " bills_dir_list = []\n",
55
+ " for x in os.listdir(bills_path):\n",
56
+ " if x.endswith(\".xml\"):\n",
57
+ " bills_dir_list.append(x)\n",
58
+ " bills_dir_list = sorted(bills_dir_list)\n",
59
+ " \n",
60
+ " for i in range(len(sums_dir_list)):\n",
61
+ " # SUMMARY\n",
62
+ " summary_texts = []\n",
63
+ " sum_path = sums_path + sums_dir_list[i]\n",
64
+ " tree_sum = ET.parse(sum_path)\n",
65
+ " root_sum = tree_sum.getroot()\n",
66
+ " for description in root_sum.iter('summary-text'):\n",
67
+ " temp = description.text\n",
68
+ " temp = re.sub('<[^>]+>', '', temp)\n",
69
+ " temp = re.sub('\\s+', ' ', temp)\n",
70
+ " temp = re.sub('^[\\s]+', '', temp)\n",
71
+ " temp = re.sub('[\\s]+$', '', temp)\n",
72
+ " summary_texts.append(str(temp))\n",
73
+ " summary = summary_texts[0]\n",
74
+ " \n",
75
+ " # TITLE\n",
76
+ " title = \"\"\n",
77
+ " for title in root_sum.iter(\"title\"):\n",
78
+ " title = title.text\n",
79
+ " \n",
80
+ " # BILL\n",
81
+ " bill_path = bills_path + bills_dir_list[i]\n",
82
+ " tree_bill = ET.parse(sum_path)\n",
83
+ " root_bill = tree_bill.getroot()\n",
84
+ " bill = \"\"\n",
85
+ " for child in root_bill.iter():\n",
86
+ " temp = child.text\n",
87
+ " bill = bill + temp + \" \"\n",
88
+ " bill = re.sub('<[^>]+>', '', bill)\n",
89
+ " bill = re.sub('\\s+', ' ', bill)\n",
90
+ " bill = re.sub('^[\\s]+', '', bill)\n",
91
+ " bill = re.sub('[\\s]+$', '', bill)\n",
92
+ " \n",
93
+ " # MERGE TO LIST OF DICTIONARIES\n",
94
+ " cleaned_data.append({\"summary\" : summary, \"text\" : bill, \"title\" : title})"
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "markdown",
99
+ "id": "d70c8e1a-39e5-46af-a72d-5f979272c70f",
100
+ "metadata": {},
101
+ "source": [
102
+ "# CALLING CLEAN DATA FUNCTION ON ALL DATA FOLDERS"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "id": "7524db26-7e8e-4bd7-ac0a-36223d51abb5",
109
+ "metadata": {},
110
+ "outputs": [],
111
+ "source": [
112
+ "clean_data(\"./data/sums/117/\", \"./data/bills/117\")"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": null,
118
+ "id": "f6afd2a1-88a9-4fc0-892c-0c928a1a65af",
119
+ "metadata": {},
120
+ "outputs": [],
121
+ "source": [
122
+ "clean_data(\"./data/sums/116/\", \"./data/bills/116\")"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": null,
128
+ "id": "23a9ff4b-bf53-4e62-a356-909b464687bb",
129
+ "metadata": {},
130
+ "outputs": [],
131
+ "source": [
132
+ "clean_data(\"./data/sums/115/\", \"./data/bills/115\")"
133
+ ]
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "execution_count": null,
138
+ "id": "501757e3-ae60-494e-a9dc-f9eeee1b997f",
139
+ "metadata": {},
140
+ "outputs": [],
141
+ "source": [
142
+ "clean_data(\"./data/sums/114/\", \"./data/bills/114\")"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": null,
148
+ "id": "ca133591-0acc-427a-9c5d-dd8e8a530828",
149
+ "metadata": {},
150
+ "outputs": [],
151
+ "source": [
152
+ "clean_data(\"./data/sums/113/\", \"./data/bills/113\")"
153
+ ]
154
+ },
155
+ {
156
+ "cell_type": "markdown",
157
+ "id": "95a2be9e-5bc6-47f8-8183-c415c8f2a5d8",
158
+ "metadata": {},
159
+ "source": [
160
+ "# CHECKING FOR CORRECT LENGTH AND SPOT CHECKING DATA"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": null,
166
+ "id": "7db890e9-86bc-49bf-a278-f6d13277f6fb",
167
+ "metadata": {},
168
+ "outputs": [],
169
+ "source": [
170
+ "len(cleaned_data)"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": null,
176
+ "id": "5119d34d-fc3a-49a6-ac1a-ac2f293a6829",
177
+ "metadata": {},
178
+ "outputs": [],
179
+ "source": [
180
+ "cleaned_data[19]"
181
+ ]
182
+ },
183
+ {
184
+ "cell_type": "markdown",
185
+ "id": "a8fe2092-2bed-4f50-bf80-934cdb4b7cac",
186
+ "metadata": {},
187
+ "source": [
188
+ "# SAVING CLEANED DATA AS JSON FILE TO TRANSFER TO TEMU"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": null,
194
+ "id": "12605fea-ea7a-43d4-9ed0-92bd7192d879",
195
+ "metadata": {},
196
+ "outputs": [],
197
+ "source": [
198
+ "# Convert and write JSON object to file\n",
199
+ "with open(\"cleaned_bill_sum_data.json\", \"w\") as outfile: \n",
200
+ " json.dump(cleaned_data, outfile)"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "markdown",
205
+ "id": "1770d5e7-0970-44c2-8472-1494fc6c8d9d",
206
+ "metadata": {},
207
+ "source": [
208
+ "# IMPORTING CLEANED DATA JSON FILE TO A LIST OF DICTIONARIES"
209
+ ]
210
+ },
211
+ {
212
+ "cell_type": "code",
213
+ "execution_count": null,
214
+ "id": "7f890296-f09d-4590-a8d8-1489b07a1a34",
215
+ "metadata": {},
216
+ "outputs": [],
217
+ "source": [
218
+ "# Opening JSON file\n",
219
+ "with open(\"cleaned_bill_sum_data.json\") as json_file:\n",
220
+ " cleaned_data = json.load(json_file)"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "code",
225
+ "execution_count": null,
226
+ "id": "2d561958-5795-446d-9104-57012635db0b",
227
+ "metadata": {},
228
+ "outputs": [],
229
+ "source": [
230
+ "# import datasets\n",
231
+ "# from datasets import load_dataset\n",
232
+ "# import pandas as pd\n",
233
+ "# from datasets import Dataset"
234
+ ]
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "execution_count": null,
239
+ "id": "c3eaa971-2f84-4962-912b-b0cee8147ae3",
240
+ "metadata": {},
241
+ "outputs": [],
242
+ "source": [
243
+ "# data = pd.DataFrame.from_dict(cleaned_data)"
244
+ ]
245
+ },
246
+ {
247
+ "cell_type": "code",
248
+ "execution_count": null,
249
+ "id": "8397087c-9a2a-4fa1-8d79-7915b8c2d13b",
250
+ "metadata": {},
251
+ "outputs": [],
252
+ "source": [
253
+ "# dataset = Dataset.from_pandas(pd.DataFrame(data=data))"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "execution_count": null,
259
+ "id": "91e76f1d-2602-4270-84e5-7663446c79b2",
260
+ "metadata": {},
261
+ "outputs": [],
262
+ "source": [
263
+ "# billsum = dataset.train_test_split(test_size=0.2)"
264
+ ]
265
+ },
266
+ {
267
+ "cell_type": "markdown",
268
+ "id": "a2e80fe5-56fa-4803-9657-76e42cd9eeab",
269
+ "metadata": {},
270
+ "source": [
271
+ "# FUNCTION TO CLEAN THE TEST DATA"
272
+ ]
273
+ },
274
+ {
275
+ "cell_type": "code",
276
+ "execution_count": null,
277
+ "id": "1bb9a98f-913e-42d2-8bac-a8504f8d2013",
278
+ "metadata": {},
279
+ "outputs": [],
280
+ "source": [
281
+ "def clean_test_data(summary_path : str, bill_path : str):\n",
282
+ " sums_path = summary_path\n",
283
+ " bills_path = bill_path\n",
284
+ " \n",
285
+ " # GETTING A LIST OF THE FILE NAMES FOR THE SUMMARY DATA FILES\n",
286
+ " sums_dir_list = []\n",
287
+ " for x in os.listdir(sums_path):\n",
288
+ " if x.endswith(\".xml\"):\n",
289
+ " sums_dir_list.append(x)\n",
290
+ " sums_dir_list = sorted(sums_dir_list)\n",
291
+ "\n",
292
+ " # GETTING A LIST OF THE FILE NAMES FOR THE BILL DATA FILES\n",
293
+ " bills_dir_list = []\n",
294
+ " for x in os.listdir(bills_path):\n",
295
+ " if x.endswith(\".xml\"):\n",
296
+ " bills_dir_list.append(x)\n",
297
+ " bills_dir_list = sorted(bills_dir_list)\n",
298
+ " \n",
299
+ " for i in range(len(sums_dir_list)):\n",
300
+ " # SUMMARY\n",
301
+ " summary_texts = []\n",
302
+ " sum_path = sums_path + sums_dir_list[i]\n",
303
+ " tree_sum = ET.parse(sum_path)\n",
304
+ " root_sum = tree_sum.getroot()\n",
305
+ " for description in root_sum.iter('summary-text'):\n",
306
+ " temp = description.text\n",
307
+ " temp = re.sub('<[^>]+>', '', temp)\n",
308
+ " temp = re.sub('\\s+', ' ', temp)\n",
309
+ " temp = re.sub('^[\\s]+', '', temp)\n",
310
+ " temp = re.sub('[\\s]+$', '', temp)\n",
311
+ " summary_texts.append(str(temp))\n",
312
+ " summary = summary_texts[0]\n",
313
+ " \n",
314
+ " # TITLE\n",
315
+ " title = \"\"\n",
316
+ " for title in root_sum.iter(\"title\"):\n",
317
+ " title = title.text\n",
318
+ " \n",
319
+ " # BILL\n",
320
+ " bill_path = bills_path + bills_dir_list[i]\n",
321
+ " tree_bill = ET.parse(sum_path)\n",
322
+ " root_bill = tree_bill.getroot()\n",
323
+ " bill = \"\"\n",
324
+ " for child in root_bill.iter():\n",
325
+ " temp = child.text\n",
326
+ " bill = bill + temp + \" \"\n",
327
+ " bill = re.sub('<[^>]+>', '', bill)\n",
328
+ " bill = re.sub('\\s+', ' ', bill)\n",
329
+ " bill = re.sub('^[\\s]+', '', bill)\n",
330
+ " bill = re.sub('[\\s]+$', '', bill)\n",
331
+ " \n",
332
+ " # MERGE TO LIST OF DICTIONARIES\n",
333
+ " cleaned_test_data.append({\"summary\" : summary, \"text\" : bill, \"title\" : title})"
334
+ ]
335
+ },
336
+ {
337
+ "cell_type": "markdown",
338
+ "id": "fe641226-2779-4de1-8066-1b65abde1a21",
339
+ "metadata": {},
340
+ "source": [
341
+ "# CALLING FUNCTION TO CLEAN THE TEST DATA"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "code",
346
+ "execution_count": null,
347
+ "id": "342881ed-cd6d-4be0-9e1e-ca402d9b57af",
348
+ "metadata": {},
349
+ "outputs": [],
350
+ "source": [
351
+ "clean_test_data(\"./data/test/sums/\", \"./data/test/bills/\")"
352
+ ]
353
+ },
354
+ {
355
+ "cell_type": "markdown",
356
+ "id": "f276dd3a-76f0-4e19-a9d3-59ea94fae58a",
357
+ "metadata": {},
358
+ "source": [
359
+ "# SHOWING A SAMPLE OF THE TEST DATA"
360
+ ]
361
+ },
362
+ {
363
+ "cell_type": "code",
364
+ "execution_count": null,
365
+ "id": "ded519a6-dcd8-4399-b415-384cd609bdf0",
366
+ "metadata": {},
367
+ "outputs": [],
368
+ "source": [
369
+ "cleaned_test_data[11]"
370
+ ]
371
+ },
372
+ {
373
+ "cell_type": "markdown",
374
+ "id": "f3d07f33-bd77-43dc-9ea6-20a1eb1d4314",
375
+ "metadata": {},
376
+ "source": [
377
+ "# SAVING CLEANED TEST DATA TO JSON"
378
+ ]
379
+ },
380
+ {
381
+ "cell_type": "code",
382
+ "execution_count": null,
383
+ "id": "1fc0a1c7-47a6-4b06-a47f-de77c7cc41df",
384
+ "metadata": {},
385
+ "outputs": [],
386
+ "source": [
387
+ "# Convert and write JSON object to file\n",
388
+ "with open(\"cleaned_bill_sum_test_data.json\", \"w\") as outfile: \n",
389
+ " json.dump(cleaned_test_data, outfile)"
390
+ ]
391
+ },
392
+ {
393
+ "cell_type": "markdown",
394
+ "id": "8ed577e6-e553-4ad8-8ddc-5ec3acb7f982",
395
+ "metadata": {},
396
+ "source": [
397
+ "# LOADING CLEANED TEST DATA"
398
+ ]
399
+ },
400
+ {
401
+ "cell_type": "code",
402
+ "execution_count": null,
403
+ "id": "254f3c2b-4d95-4c0e-8487-43cd2ea0f4be",
404
+ "metadata": {},
405
+ "outputs": [],
406
+ "source": [
407
+ "# Opening JSON file\n",
408
+ "with open(\"cleaned_bill_sum_test_data.json\") as json_file:\n",
409
+ " cleaned_test_data = json.load(json_file)"
410
+ ]
411
+ },
412
+ {
413
+ "cell_type": "code",
414
+ "execution_count": null,
415
+ "id": "34054ada-c930-478d-866b-d1a6bc1ed241",
416
+ "metadata": {},
417
+ "outputs": [],
418
+ "source": []
419
+ },
420
+ {
421
+ "cell_type": "markdown",
422
+ "id": "926c806f-a3c4-4c86-a655-949e9c33da8f",
423
+ "metadata": {},
424
+ "source": [
425
+ "# SINGLE FILE CLEANING"
426
+ ]
427
+ },
428
+ {
429
+ "cell_type": "code",
430
+ "execution_count": 4,
431
+ "id": "a7205466-3b57-4f31-a61e-00023e23db2e",
432
+ "metadata": {},
433
+ "outputs": [],
434
+ "source": [
435
+ "new_cleaned_test_data = []"
436
+ ]
437
+ },
438
+ {
439
+ "cell_type": "code",
440
+ "execution_count": 5,
441
+ "id": "e28bcda9-0dc5-46ba-ac90-05096e32b331",
442
+ "metadata": {},
443
+ "outputs": [],
444
+ "source": [
445
+ "def single_file_cleaning(summary : str, bill : str):\n",
446
+ " sum_path = summary\n",
447
+ " bill_path = bill\n",
448
+ " \n",
449
+ " # SUMMARY\n",
450
+ " summary_texts = []\n",
451
+ " # sum_path = sums_path + sums_dir_list[i]\n",
452
+ " tree_sum = ET.parse(sum_path)\n",
453
+ " root_sum = tree_sum.getroot()\n",
454
+ " for description in root_sum.iter('summary-text'):\n",
455
+ " temp = description.text\n",
456
+ " temp = re.sub('<[^>]+>', '', temp)\n",
457
+ " temp = re.sub('\\s+', ' ', temp)\n",
458
+ " temp = re.sub('^[\\s]+', '', temp)\n",
459
+ " temp = re.sub('[\\s]+$', '', temp)\n",
460
+ " summary_texts.append(str(temp))\n",
461
+ " summary = summary_texts[0]\n",
462
+ " \n",
463
+ " # TITLE\n",
464
+ " title = \"\"\n",
465
+ " for title in root_sum.iter(\"title\"):\n",
466
+ " title = title.text\n",
467
+ " \n",
468
+ " # BILL\n",
469
+ " # bill_path = bills_path + bills_dir_list[i]\n",
470
+ " tree_bill = ET.parse(sum_path)\n",
471
+ " root_bill = tree_bill.getroot()\n",
472
+ " bill = \"\"\n",
473
+ " for child in root_bill.iter():\n",
474
+ " temp = child.text\n",
475
+ " bill = bill + temp + \" \"\n",
476
+ " bill = re.sub('<[^>]+>', '', bill)\n",
477
+ " bill = re.sub('\\s+', ' ', bill)\n",
478
+ " bill = re.sub('^[\\s]+', '', bill)\n",
479
+ " bill = re.sub('[\\s]+$', '', bill)\n",
480
+ " \n",
481
+ " # MERGE TO LIST OF DICTIONARIES\n",
482
+ " new_cleaned_test_data.append({\"summary\" : summary, \"text\" : bill, \"title\" : title})"
483
+ ]
484
+ },
485
+ {
486
+ "cell_type": "code",
487
+ "execution_count": 6,
488
+ "id": "ccfd78ec-3d57-4459-badb-824ca3092c4c",
489
+ "metadata": {},
490
+ "outputs": [],
491
+ "source": [
492
+ "single_file_cleaning(\"./BILLSUM-118s1000.xml\", \"./BILLS-118s1000is.xml\")"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "code",
497
+ "execution_count": 7,
498
+ "id": "3ef2cd68-7f37-4025-bf06-821c49c18932",
499
+ "metadata": {},
500
+ "outputs": [
501
+ {
502
+ "data": {
503
+ "text/plain": [
504
+ "[{'summary': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates.',\n",
505
+ " 'text': 'Saving Access to Laboratory Services Act 2023-03-28 Introduced in Senate Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
506
+ " 'title': 'Saving Access to Laboratory Services Act'}]"
507
+ ]
508
+ },
509
+ "execution_count": 7,
510
+ "metadata": {},
511
+ "output_type": "execute_result"
512
+ }
513
+ ],
514
+ "source": [
515
+ "new_cleaned_test_data"
516
+ ]
517
+ },
518
+ {
519
+ "cell_type": "code",
520
+ "execution_count": 8,
521
+ "id": "510b26bf-afff-44b8-ba3e-516445d98379",
522
+ "metadata": {},
523
+ "outputs": [],
524
+ "source": [
525
+ "single_file_cleaning(\"./BILLSUM-118s1016.xml\", \"./BILLS-118s1016is.xml\")"
526
+ ]
527
+ },
528
+ {
529
+ "cell_type": "code",
530
+ "execution_count": 9,
531
+ "id": "1d5ceac2-0fa7-4ddf-b8d5-888ffd51b754",
532
+ "metadata": {},
533
+ "outputs": [
534
+ {
535
+ "data": {
536
+ "text/plain": [
537
+ "[{'summary': 'Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates.',\n",
538
+ " 'text': 'Saving Access to Laboratory Services Act 2023-03-28 Introduced in Senate Saving Access to Laboratory Services Act This bill modifies provisions relating to Medicare payment rates for clinical diagnostic laboratory services, including by requiring payment rates for certain widely available clinical diagnostic laboratory tests to be based on a statistical sampling of private sector rates. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
539
+ " 'title': 'Saving Access to Laboratory Services Act'},\n",
540
+ " {'summary': 'Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools.',\n",
541
+ " 'text': 'Agriculture Resilience Act of 2023 2023-03-28 Introduced in Senate Agriculture Resilience Act of 2023 This bill establishes, expands, and revises multiple programs and activities of the Department of Agriculture (USDA) primarily to reduce carbon emissions from the agriculture sector. Specifically, USDA must finalize and implement a plan to achieve net-zero emissions from the sector by 2040. USDA must periodically review and revise the plan, as necessary, and annually report on its implementation. Additionally, the bill expands the scope of various USDA research, extension, and education programs; conservation programs; and livestock programs to incorporate climate change adaptation and mitigation. Expanded activities include efforts to improve soil health and preserve farmland and grassland. Further, the bill changes programs that support renewable energy in rural areas to address carbon emissions in the agriculture sector. Among these changes, the bill provides statutory authority for the AgSTAR program for reducing methane emissions from livestock waste and requires the program to be moved from the Environmental Protection Agency to USDA. The bill also addresses food waste, for example, by (1) standardizing the voluntary labels used by food producers to indicate the date by which food should be used or discarded, and (2) making composting activities eligible for support through USDA conservation programs. Moreover, the bill establishes grants to reduce and prevent food waste in landfills and in schools. text/xml EN Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain. Congressional Research Service, Library of Congress This file contains bill summaries for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is \"to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives\". For more information, refer to the User Guide that accompanies this file.',\n",
542
+ " 'title': 'Agriculture Resilience Act of 2023'}]"
543
+ ]
544
+ },
545
+ "execution_count": 9,
546
+ "metadata": {},
547
+ "output_type": "execute_result"
548
+ }
549
+ ],
550
+ "source": [
551
+ "new_cleaned_test_data"
552
+ ]
553
+ },
554
+ {
555
+ "cell_type": "code",
556
+ "execution_count": 10,
557
+ "id": "0d1ce846-892c-4856-b45f-aeaa4d2cbc33",
558
+ "metadata": {},
559
+ "outputs": [],
560
+ "source": [
561
+ "# Convert and write JSON object to file\n",
562
+ "with open(\"new_cleaned_bill_sum_test_data.json\", \"w\") as outfile: \n",
563
+ " json.dump(new_cleaned_test_data, outfile)"
564
+ ]
565
+ },
566
+ {
567
+ "cell_type": "code",
568
+ "execution_count": null,
569
+ "id": "0f8c6a5f-2c4d-4f99-ab42-e258ac13701b",
570
+ "metadata": {},
571
+ "outputs": [],
572
+ "source": []
573
+ }
574
+ ],
575
+ "metadata": {
576
+ "kernelspec": {
577
+ "display_name": "Python 3 (ipykernel)",
578
+ "language": "python",
579
+ "name": "python3"
580
+ },
581
+ "language_info": {
582
+ "codemirror_mode": {
583
+ "name": "ipython",
584
+ "version": 3
585
+ },
586
+ "file_extension": ".py",
587
+ "mimetype": "text/x-python",
588
+ "name": "python",
589
+ "nbconvert_exporter": "python",
590
+ "pygments_lexer": "ipython3",
591
+ "version": "3.11.7"
592
+ }
593
+ },
594
+ "nbformat": 4,
595
+ "nbformat_minor": 5
596
+ }