{ "cells": [ { "cell_type": "markdown", "id": "695a0d97-6b1d-4448-b16c-3ba95bb60c30", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "# If these install, restart the kernal so it has access to the recently installed files" ] }, { "cell_type": "code", "execution_count": null, "id": "22de09b1-3c40-4195-8b5a-926d5391313f", "metadata": {}, "outputs": [], "source": [ "!pip3 install --user transformers datasets evaluate rouge_score\n", "!pip3 install --user datasets\n", "!pip install --user transformers[torch]\n", "!pip install --user accelerate -U\n", "!pip install --user wandb" ] }, { "cell_type": "markdown", "id": "e1687d09-6b14-47fb-9819-dbed0d8ae3b3", "metadata": {}, "source": [ "# Logging into huggingface hub" ] }, { "cell_type": "code", "execution_count": 1, "id": "f2f10d5e-9655-4554-abb0-511044640854", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bc57319ea4544e0cbe8fd4f2c10ee2e9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HTML(value='
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in /scratch/user/u.th161689/AI_NLP/TermProject/wandb/run-20240412_232000-ls1byqtm" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run youthful-fire-1 to Weights & Biases (docs)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/cheaptrix/congress_bill_sumamry_model" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/cheaptrix/congress_bill_sumamry_model/runs/ls1byqtm" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Must set the global variable WANDB_NOTEBOOK_NAME to the name of the notebook\n", "import os\n", "import wandb\n", "# Name is found through the os incase the name changes\n", "# WANDB_NOTEBOOK_NAME = os.path.basename(os.getcwd())\n", "notebook_name = str(os.path.basename(os.getcwd()))\n", "os.environ[\"WANDB_NOTEBOOK_NAME\"] = \"./\" + notebook_name\n", "os.environ[\"WANDB_PROJECT\"] = \"congress_bill_summary_model\"\n", "wandb.init(project='congress_bill_sumamry_model') " ] }, { "cell_type": "markdown", "id": "69fbba70-2fb2-47c9-abc9-1824a3ab10d7", "metadata": {}, "source": [ "# Importing and loading the Congressional Bills dataset" ] }, { "cell_type": "code", "execution_count": 3, "id": "fd3b62f1-5bd2-44ff-87f3-1d48ccb74459", "metadata": {}, "outputs": [], "source": [ "import datasets\n", "from datasets import load_dataset\n", "import pandas as pd\n", "from datasets import Dataset\n", "import json\n", "\n", "# Opening JSON file\n", "with open(\"cleaned_bill_sum_data.json\") as json_file:\n", " cleaned_data = json.load(json_file)\n", "data = pd.DataFrame.from_dict(cleaned_data)\n", "dataset = Dataset.from_pandas(pd.DataFrame(data=data))" ] }, { "cell_type": "markdown", "id": "2c87b4f7-bdbd-4869-8975-609373000ab0", "metadata": {}, "source": [ "# Splitting the data to training and testing split" ] }, { "cell_type": "code", "execution_count": 4, "id": "9f08c14e-820e-497d-a979-6332bce67bc1", "metadata": {}, "outputs": [], "source": [ "billsum = dataset.train_test_split(test_size=0.2)" ] }, { "cell_type": "markdown", "id": "9949be74-ed88-49a8-8465-8290af7abe6f", "metadata": {}, "source": [ "# Example of data within the training set" ] }, { "cell_type": "code", "execution_count": 5, "id": "2f7551a5-631d-4de3-afb7-99d923d18ccd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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", " 'title': 'A concurrent resolution providing for an adjournment of the House of Representatives.'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "billsum[\"train\"][0]" ] }, { "cell_type": "markdown", "id": "7c2e2c67-3d0b-4d4b-b3b6-e6d9afb60c8a", "metadata": {}, "source": [ "# Load T5 tokenizer to process text and summary" ] }, { "cell_type": "code", "execution_count": 6, "id": "b3d4454e-e7f3-4020-9ecc-4c692c6da5c6", "metadata": {}, "outputs": [], "source": [ "from transformers import AutoTokenizer\n", "\n", "checkpoint = \"google-t5/t5-small\"\n", "tokenizer = AutoTokenizer.from_pretrained(checkpoint)" ] }, { "cell_type": "markdown", "id": "15e4537b-4a72-434a-8af7-1cef702581d0", "metadata": {}, "source": [ "# Perprocessing Function" ] }, { "cell_type": "code", "execution_count": 7, "id": "2feec165-87ed-4258-a332-14c3b7dd9867", "metadata": {}, "outputs": [], "source": [ "prefix = \"summarize: \"\n", "\n", "\n", "def preprocess_function(examples):\n", " inputs = [prefix + doc for doc in examples[\"text\"]]\n", " model_inputs = tokenizer(inputs, max_length=1024, truncation=True)\n", "\n", " labels = tokenizer(text_target=examples[\"summary\"], max_length=128, truncation=True)\n", "\n", " model_inputs[\"labels\"] = labels[\"input_ids\"]\n", " return model_inputs" ] }, { "cell_type": "markdown", "id": "814f0888-e5c0-4841-9084-ed4f6762ecdd", "metadata": {}, "source": [ "# Tokenize the dataset using the map function" ] }, { "cell_type": "code", "execution_count": 8, "id": "65c755b9-33ae-4d95-b0d2-b7b7950f4f71", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "23e819666e29433196ea0a7457855dbf", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Map: 0%| | 0/212 [00:00\n", " \n", " \n", " [56/56 00:38, Epoch 4/4]\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EpochTraining LossValidation LossRouge1Rouge2RougelRougelsumGen Len
1No log0.1086500.4438000.4274000.4427000.44220019.000000
2No log0.0603820.4552000.4399000.4551000.45460019.000000
3No log0.0531760.4617000.4482000.4623000.46200019.000000
4No log0.0499380.4633000.4498000.4635000.46310019.000000

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/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", " warnings.warn(\n" ] }, { "data": { "text/plain": [ "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})" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Training needs numpy\n", "import numpy as np\n", "\n", "# Fine-tuning the model\n", "trainer.train()" ] }, { "cell_type": "markdown", "id": "b1e694f0-394b-4a68-8183-59fdf76d30a3", "metadata": {}, "source": [ "# Saving the Model" ] }, { "cell_type": "code", "execution_count": 16, "id": "b4d1a48a-55cb-4456-aa3f-861e86645cae", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2483f039d1834b40a8f0904f0207907e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "model.safetensors: 0%| | 0.00/242M [00:00 512). Running this sequence through the model will result in indexing errors\n" ] } ], "source": [ "generated_summaries = []\n", "for i in range(len(cleaned_test_data)):\n", " summary = summarizer(cleaned_test_data[i]['text'])\n", " generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : cleaned_test_data[i]['summary']})" ] }, { "cell_type": "code", "execution_count": 24, "id": "1791b057-3684-4e51-8d4e-3649a7811f20", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[0]" ] }, { "cell_type": "code", "execution_count": 25, "id": "ecc976d1-27f0-4094-94a2-ac1d025b9595", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[1]" ] }, { "cell_type": "code", "execution_count": 26, "id": "f3739cf1-846a-4f1e-acac-be1f629001da", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[2]" ] }, { "cell_type": "code", "execution_count": 27, "id": "ad90c77a-bc5c-48e9-a22d-9f7f95a34625", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[3]" ] }, { "cell_type": "code", "execution_count": 28, "id": "e15cdcb1-10e4-4a0b-8921-b9f56bfb63de", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[4]" ] }, { "cell_type": "code", "execution_count": 29, "id": "fa5ad2a1-5dae-44c6-b442-d632d37dd0e0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " 'summary': 'This concurrent resolution recognizes Abortion Provider Appreciation Day.'}" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[5]" ] }, { "cell_type": "code", "execution_count": 30, "id": "7ac4cad6-e406-4160-a1c4-dede5d30db1a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.\"}" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[6]" ] }, { "cell_type": "code", "execution_count": 31, "id": "5f197b89-be47-48bd-a1ab-926e95294392", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[7]" ] }, { "cell_type": "code", "execution_count": 32, "id": "6f6e69b9-8e2e-4daf-9809-40bb835456fa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[8]" ] }, { "cell_type": "code", "execution_count": 33, "id": "6400f171-c491-406f-85a6-aab41d159e59", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.\"}" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[9]" ] }, { "cell_type": "code", "execution_count": 34, "id": "912101c6-66fb-4250-9320-1885e64f61c2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " 'summary': 'This concurrent resolution expresses the sense that the Senate should provide its advice and consent to ratification of the Convention on Biological Diversity.'}" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[10]" ] }, { "cell_type": "code", "execution_count": 35, "id": "31a9a3d8-0ecd-47d2-95d3-855490f824cc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[11]" ] }, { "cell_type": "code", "execution_count": 36, "id": "ece694d3-1870-4f9a-902d-346b97e54f8d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[12]" ] }, { "cell_type": "code", "execution_count": 37, "id": "346509c4-c31e-4e6e-a5df-b3b470a3dc8a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.\"}" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[13]" ] }, { "cell_type": "code", "execution_count": 38, "id": "3c2d0904-4b8c-45ab-99dd-f661e55438b5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[14]" ] }, { "cell_type": "code", "execution_count": 39, "id": "23e3e126-ae9f-4e5e-94ed-9ab55b9b4dec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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).'}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "generated_summaries[15]" ] }, { "cell_type": "code", "execution_count": 40, "id": "f3c08476-c1d6-4fd3-9bb1-1590d4e1ec65", "metadata": {}, "outputs": [], "source": [ "new_cleaned_test_data = []\n", "# Opening JSON file\n", "with open(\"new_cleaned_bill_sum_test_data.json\") as json_file:\n", " new_cleaned_test_data = json.load(json_file)" ] }, { "cell_type": "code", "execution_count": 41, "id": "324fa648-056b-4a5d-8990-48fb75ea032b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'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", " '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", " 'title': 'Saving Access to Laboratory Services Act'},\n", " {'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", " '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", " 'title': 'Agriculture Resilience Act of 2023'}]" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_cleaned_test_data" ] }, { "cell_type": "code", "execution_count": 42, "id": "996ad83e-6b0c-4819-b44f-ed91d4d32c7e", "metadata": {}, "outputs": [], "source": [ "new_generated_summaries = []\n", "for i in range(len(new_cleaned_test_data)):\n", " summary = summarizer(new_cleaned_test_data[i]['text'])\n", " new_generated_summaries.append({\"generated\" : summary[0]['summary_text'], \"summary\" : new_cleaned_test_data[i]['summary']})" ] }, { "cell_type": "code", "execution_count": 43, "id": "4351fd53-9f09-4794-b34c-092732d27ff1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_generated_summaries[0]" ] }, { "cell_type": "code", "execution_count": 44, "id": "f8f57bd4-5082-4c0a-a61b-523814f60db6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'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", " '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.'}" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_generated_summaries[1]" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }