Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Abstractive.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"code","source":"!pip install transformers==4.15.0\n\nimport torch\nfrom transformers import PegasusForConditionalGeneration, PegasusTokenizer\n\n# Load pre-trained PEGASUS model and tokenizer\nmodel_name = 'google/pegasus-large'\ntokenizer = PegasusTokenizer.from_pretrained(model_name)\nmodel = PegasusForConditionalGeneration.from_pretrained(model_name)\n\n# Define input text\ninput_text = \"Climate change is a major threat to the planet, with rising temperatures and sea levels causing widespread damage to ecosystems and human societies. Scientists and policymakers around the world are working to address the issue through a variety of measures, including reducing greenhouse gas emissions and investing in renewable energy.\"\n\n# Tokenize input text\ninputs = tokenizer([input_text], max_length=1024, truncation=True, return_tensors='pt')\n\n# Generate summary\nsummary_ids = model.generate(inputs['input_ids'], max_length=50, min_length=10, length_penalty=2.0)\nsummary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\n\nprint(\"Input text:\", input_text)\nprint(\"Generated summary:\", summary)\n","metadata":{"cell_id":"5a59d94e29254b0198a759c3c9a02930","source_hash":"c4a40bd2","execution_start":1680394143015,"execution_millis":6178,"deepnote_to_be_reexecuted":false,"deepnote_cell_type":"code"},"outputs":[{"name":"stdout","text":"Requirement already satisfied: transformers==4.15.0 in /root/venv/lib/python3.9/site-packages (4.15.0)\nRequirement already satisfied: filelock in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers==4.15.0) (3.8.0)\nRequirement already satisfied: tqdm>=4.27 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers==4.15.0) (4.64.1)\nRequirement already satisfied: numpy>=1.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers==4.15.0) (1.23.4)\nRequirement already satisfied: pyyaml>=5.1 in /root/venv/lib/python3.9/site-packages (from transformers==4.15.0) (6.0)\nRequirement already satisfied: packaging>=20.0 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from transformers==4.15.0) (21.3)\nRequirement already satisfied: requests in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers==4.15.0) (2.28.1)\nRequirement already satisfied: regex!=2019.12.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers==4.15.0) (2022.9.13)\nRequirement already satisfied: sacremoses in /root/venv/lib/python3.9/site-packages (from transformers==4.15.0) (0.0.53)\nRequirement already satisfied: huggingface-hub<1.0,>=0.1.0 in /root/venv/lib/python3.9/site-packages (from transformers==4.15.0) (0.13.3)\nRequirement already satisfied: tokenizers<0.11,>=0.10.1 in /root/venv/lib/python3.9/site-packages (from transformers==4.15.0) (0.10.3)\nRequirement already satisfied: typing-extensions>=3.7.4.3 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from huggingface-hub<1.0,>=0.1.0->transformers==4.15.0) (4.4.0)\nRequirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from packaging>=20.0->transformers==4.15.0) (3.0.9)\nRequirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests->transformers==4.15.0) (2022.9.24)\nRequirement already satisfied: idna<4,>=2.5 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests->transformers==4.15.0) (3.4)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests->transformers==4.15.0) (1.26.12)\nRequirement already satisfied: charset-normalizer<3,>=2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests->transformers==4.15.0) (2.1.1)\nRequirement already satisfied: click in /shared-libs/python3.9/py/lib/python3.9/site-packages (from sacremoses->transformers==4.15.0) (8.1.3)\nRequirement already satisfied: six in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from sacremoses->transformers==4.15.0) (1.16.0)\nRequirement already satisfied: joblib in /shared-libs/python3.9/py/lib/python3.9/site-packages (from sacremoses->transformers==4.15.0) (1.2.0)\n\u001b[33mWARNING: You are using pip version 22.0.4; however, version 23.0.1 is available.\nYou should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.\u001b[0m\u001b[33m\n\u001b[0m/shared-libs/python3.9/py/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n from .autonotebook import tqdm as notebook_tqdm\n","output_type":"stream"},{"output_type":"error","ename":"KernelInterrupted","evalue":"Execution interrupted by the Jupyter kernel.","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKernelInterrupted\u001b[0m: Execution interrupted by the Jupyter kernel."]}],"execution_count":1},{"cell_type":"markdown","source":"<a style='text-decoration:none;line-height:16px;display:flex;color:#5B5B62;padding:10px;justify-content:end;' href='https://deepnote.com?utm_source=created-in-deepnote-cell&projectId=4d0f828c-1acf-4255-9513-84f75676e692' target=\"_blank\">\n<img alt='Created in deepnote.com' style='display:inline;max-height:16px;margin:0px;margin-right:7.5px;' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iODBweCIgaGVpZ2h0PSI4MHB4IiB2aWV3Qm94PSIwIDAgODAgODAiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogU2tldGNoIDU0LjEgKDc2NDkwKSAtIGh0dHBzOi8vc2tldGNoYXBwLmNvbSAtLT4KICAgIDx0aXRsZT5Hcm91cCAzPC90aXRsZT4KICAgIDxkZXNjPkNyZWF0ZWQgd2l0aCBTa2V0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Ny43MzA0NDA1IEwyNy4xMTQ1MzcsMC4yNTcxMTE0MzYgQzYyLjM3MTUxMjMsLTEuOTkwNzE3MDEgODAsMTAuNTAwMzkyNyA4MCwzNy43MzA0NDA1IEM4MCw2NC45NjA0ODgyIDY0Ljc3NjUwMzgsNzkuMDUwMzQxNCAzNC4zMjk1MTEzLDgwIEM0Ny4wNTUzNDg5LDc3LjU2NzA4MDggNTMuNDE4MjY3Nyw3MC4zMTM2MTAzIDUzLjQxODI2NzcsNTguMjM5NTg4NSBDNTMuNDE4MjY3Nyw0MC4xMjg1NTU3IDM2LjMwMzk1NDQsMzcuNzMwNDQwNSAyNS4yMjc0MTcsMzcuNzMwNDQwNSBDMTcuODQzMDU4NiwzNy43MzA0NDA1IDkuNDMzOTE5NjYsMzcuNzMwNDQwNSAwLDM3LjczMDQ0MDUgWiIgaWQ9IlBhdGgtMTkiIGZpbGw9IiMzNzkzRUYiPjwvcGF0aD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+' > </img>\nCreated in <span style='font-weight:600;margin-left:4px;'>Deepnote</span></a>","metadata":{"created_in_deepnote_cell":true,"deepnote_cell_type":"markdown"}}],"nbformat":4,"nbformat_minor":0,"metadata":{"deepnote":{},"orig_nbformat":2,"deepnote_notebook_id":"3465a23de2e6438d96b697eb4068c117","deepnote_execution_queue":[]}}
22 changes: 22 additions & 0 deletions Abstractive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
!pip install transformers==4.15.0

import torch
from transformers import PegasusForConditionalGeneration, PegasusTokenizer

# Load pre-trained PEGASUS model and tokenizer
model_name = 'google/pegasus-large'
tokenizer = PegasusTokenizer.from_pretrained(model_name)
model = PegasusForConditionalGeneration.from_pretrained(model_name)

# Define input text
input_text = "Climate change is a major threat to the planet, with rising temperatures and sea levels causing widespread damage to ecosystems and human societies. Scientists and policymakers around the world are working to address the issue through a variety of measures, including reducing greenhouse gas emissions and investing in renewable energy."

# Tokenize input text
inputs = tokenizer([input_text], max_length=1024, truncation=True, return_tensors='pt')

# Generate summary
summary_ids = model.generate(inputs['input_ids'], max_length=50, min_length=10, length_penalty=2.0)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)

print("Input text:", input_text)
print("Generated summary:", summary)
Loading