diff --git a/Abstractive.ipynb b/Abstractive.ipynb new file mode 100644 index 0000000..459fb5a --- /dev/null +++ b/Abstractive.ipynb @@ -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":"\nCreated in deepnote.com \nCreated in Deepnote","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":[]}} \ No newline at end of file diff --git a/Abstractive.py b/Abstractive.py new file mode 100644 index 0000000..d699109 --- /dev/null +++ b/Abstractive.py @@ -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) diff --git a/Extractive Text Summarization.ipynb b/Extractive Text Summarization.ipynb new file mode 100644 index 0000000..b248d8d --- /dev/null +++ b/Extractive Text Summarization.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"code","source":"!pip install spacy==3\n!python -m spacy download en_core_web_trf\n\nimport spacy\n\n# Load the language model\nnlp = spacy.load('en_core_web_trf')\n\n# Sample text for demonstration\ntext = \"\"\"\n The rise of technology has drastically changed the way we live our lives. From smartphones to social media, technology has revolutionized the way we communicate and interact with each other. While technology has brought many benefits, it has also raised concerns about privacy and the impact on our mental health. As we continue to advance in technology, it is important to consider both the positive and negative effects on society.\" \n \"\"\"\n\n# Process the text with spaCy\ndoc = nlp(text)\n\n# Calculate sentence scores based on their similarity to the document\nsent_scores = []\nfor sent in doc.sents:\n score = 0\n for word in sent:\n score += word.similarity(doc)\n sent_scores.append((sent, score))\n\n# Sort the sentences in decreasing order of score and get the top 3\nsent_scores = sorted(sent_scores, key=lambda x: x[1], reverse=True)[:3]\n\n# Extract the top 3 sentences and join them to form a summary\nsummary = ' '.join([sent[0].text for sent in sent_scores])\n\n# Print the summary\nprint(summary)\n","metadata":{"cell_id":"b95dfabcdd7c4abd8c04b94e183a7ccd","source_hash":"49628487","execution_start":1680234176391,"execution_millis":32848,"deepnote_to_be_reexecuted":false,"deepnote_cell_type":"code"},"outputs":[{"name":"stdout","text":"Requirement already satisfied: spacy==3 in /root/venv/lib/python3.9/site-packages (3.0.0)\nRequirement already satisfied: setuptools in /root/venv/lib/python3.9/site-packages (from spacy==3) (58.1.0)\nRequirement already satisfied: tqdm<5.0.0,>=4.38.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (4.64.1)\nRequirement already satisfied: jinja2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from spacy==3) (2.11.3)\nRequirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (1.0.9)\nRequirement already satisfied: preshed<3.1.0,>=3.0.2 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (3.0.8)\nRequirement already satisfied: thinc<8.1.0,>=8.0.0 in /root/venv/lib/python3.9/site-packages (from spacy==3) (8.0.17)\nRequirement already satisfied: wasabi<1.1.0,>=0.8.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (0.10.1)\nRequirement already satisfied: packaging>=20.0 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from spacy==3) (21.3)\nRequirement already satisfied: srsly<3.0.0,>=2.4.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (2.4.5)\nRequirement already satisfied: blis<0.8.0,>=0.4.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (0.7.9)\nRequirement already satisfied: typer<0.4.0,>=0.3.0 in /root/venv/lib/python3.9/site-packages (from spacy==3) (0.3.2)\nRequirement already satisfied: numpy>=1.15.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (1.23.4)\nRequirement already satisfied: spacy-legacy<3.1.0,>=3.0.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (3.0.10)\nRequirement already satisfied: requests<3.0.0,>=2.13.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (2.28.1)\nRequirement already satisfied: pydantic<1.8.0,>=1.7.1 in /root/venv/lib/python3.9/site-packages (from spacy==3) (1.7.4)\nRequirement already satisfied: cymem<2.1.0,>=2.0.2 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (2.0.7)\nRequirement already satisfied: catalogue<2.1.0,>=2.0.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (2.0.8)\nRequirement already satisfied: pathy in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy==3) (0.6.2)\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->spacy==3) (3.0.9)\nRequirement already satisfied: charset-normalizer<3,>=2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy==3) (2.1.1)\nRequirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy==3) (2022.9.24)\nRequirement already satisfied: idna<4,>=2.5 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy==3) (3.4)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy==3) (1.26.12)\nRequirement already satisfied: click<7.2.0,>=7.1.1 in /root/venv/lib/python3.9/site-packages (from typer<0.4.0,>=0.3.0->spacy==3) (7.1.2)\nRequirement already satisfied: MarkupSafe>=0.23 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from jinja2->spacy==3) (2.0.0)\nRequirement already satisfied: smart-open<6.0.0,>=5.2.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from pathy->spacy==3) (5.2.1)\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[0m2023-03-31 03:43:02.871470: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n2023-03-31 03:43:03.071857: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n2023-03-31 03:43:03.071894: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n2023-03-31 03:43:03.107690: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n2023-03-31 03:43:04.925511: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory\n2023-03-31 03:43:04.925595: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory\n2023-03-31 03:43:04.925611: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\nCollecting en-core-web-trf==3.0.0\n Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.0.0/en_core_web_trf-3.0.0-py3-none-any.whl (459.7 MB)\n\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m459.7/459.7 MB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n\u001b[?25hRequirement already satisfied: spacy<3.1.0,>=3.0.0 in /root/venv/lib/python3.9/site-packages (from en-core-web-trf==3.0.0) (3.0.0)\nRequirement already satisfied: spacy-transformers<1.1.0,>=1.0.0rc4 in /root/venv/lib/python3.9/site-packages (from en-core-web-trf==3.0.0) (1.0.4)\nRequirement already satisfied: srsly<3.0.0,>=2.4.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.4.5)\nRequirement already satisfied: blis<0.8.0,>=0.4.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (0.7.9)\nRequirement already satisfied: numpy>=1.15.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (1.23.4)\nRequirement already satisfied: pathy in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (0.6.2)\nRequirement already satisfied: jinja2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.11.3)\nRequirement already satisfied: wasabi<1.1.0,>=0.8.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (0.10.1)\nRequirement already satisfied: packaging>=20.0 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (21.3)\nRequirement already satisfied: requests<3.0.0,>=2.13.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.28.1)\nRequirement already satisfied: tqdm<5.0.0,>=4.38.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (4.64.1)\nRequirement already satisfied: thinc<8.1.0,>=8.0.0 in /root/venv/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (8.0.17)\nRequirement already satisfied: pydantic<1.8.0,>=1.7.1 in /root/venv/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (1.7.4)\nRequirement already satisfied: typer<0.4.0,>=0.3.0 in /root/venv/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (0.3.2)\nRequirement already satisfied: cymem<2.1.0,>=2.0.2 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.0.7)\nRequirement already satisfied: spacy-legacy<3.1.0,>=3.0.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (3.0.10)\nRequirement already satisfied: catalogue<2.1.0,>=2.0.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.0.8)\nRequirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (1.0.9)\nRequirement already satisfied: setuptools in /root/venv/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (58.1.0)\nRequirement already satisfied: preshed<3.1.0,>=3.0.2 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (3.0.8)\nRequirement already satisfied: transformers<4.10.0,>=3.4.0 in /root/venv/lib/python3.9/site-packages (from spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (4.9.2)\nRequirement already satisfied: torch>=1.5.0 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (1.12.1)\nRequirement already satisfied: spacy-alignments<1.0.0,>=0.7.2 in /root/venv/lib/python3.9/site-packages (from spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (0.9.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->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (3.0.9)\nRequirement already satisfied: idna<4,>=2.5 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (3.4)\nRequirement already satisfied: charset-normalizer<3,>=2 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.1.1)\nRequirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2022.9.24)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (1.26.12)\nRequirement already satisfied: typing-extensions in /shared-libs/python3.9/py/lib/python3.9/site-packages (from torch>=1.5.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (4.4.0)\nRequirement already satisfied: tokenizers<0.11,>=0.10.1 in /root/venv/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (0.10.3)\nRequirement already satisfied: filelock in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (3.8.0)\nRequirement already satisfied: regex!=2019.12.17 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (2022.9.13)\nRequirement already satisfied: pyyaml>=5.1 in /root/venv/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (6.0)\nRequirement already satisfied: sacremoses in /root/venv/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (0.0.53)\nRequirement already satisfied: huggingface-hub==0.0.12 in /root/venv/lib/python3.9/site-packages (from transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (0.0.12)\nRequirement already satisfied: click<7.2.0,>=7.1.1 in /root/venv/lib/python3.9/site-packages (from typer<0.4.0,>=0.3.0->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (7.1.2)\nRequirement already satisfied: MarkupSafe>=0.23 in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from jinja2->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (2.0.0)\nRequirement already satisfied: smart-open<6.0.0,>=5.2.1 in /shared-libs/python3.9/py/lib/python3.9/site-packages (from pathy->spacy<3.1.0,>=3.0.0->en-core-web-trf==3.0.0) (5.2.1)\nRequirement already satisfied: joblib in /shared-libs/python3.9/py/lib/python3.9/site-packages (from sacremoses->transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (1.2.0)\nRequirement already satisfied: six in /shared-libs/python3.9/py-core/lib/python3.9/site-packages (from sacremoses->transformers<4.10.0,>=3.4.0->spacy-transformers<1.1.0,>=1.0.0rc4->en-core-web-trf==3.0.0) (1.16.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\u001b[38;5;2m✔ Download and installation successful\u001b[0m\nYou can now load the package via spacy.load('en_core_web_trf')\n/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\n2023-03-31 03:43:21.629185: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA\nTo enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n2023-03-31 03:43:21.832494: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n2023-03-31 03:43:21.832526: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n2023-03-31 03:43:21.877565: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n2023-03-31 03:43:22.964977: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory\n2023-03-31 03:43:22.965075: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory\n2023-03-31 03:43:22.965087: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.\n/shared-libs/python3.9/py/lib/python3.9/site-packages/torch/amp/autocast_mode.py:198: UserWarning: User provided device_type of 'cuda', but CUDA is not available. Disabling\n warnings.warn('User provided device_type of \\'cuda\\', but CUDA is not available. Disabling')\n\n The rise of technology has drastically changed the way we live our lives. From smartphones to social media, technology has revolutionized the way we communicate and interact with each other. While technology has brought many benefits, it has also raised concerns about privacy and the impact on our mental health.\n/tmp/ipykernel_277/3509711580.py:22: UserWarning: [W007] The model you're using has no word vectors loaded, so the result of the Token.similarity method will be based on the tagger, parser and NER, which may not give useful similarity judgements. This may happen if you're using one of the small models, e.g. `en_core_web_sm`, which don't ship with word vectors and only use context-sensitive tensors. You can always add your own word vectors, or use one of the larger models instead if available.\n score += word.similarity(doc)\n/tmp/ipykernel_277/3509711580.py:22: UserWarning: [W008] Evaluating Token.similarity based on empty vectors.\n score += word.similarity(doc)\n","output_type":"stream"}],"execution_count":1},{"cell_type":"markdown","source":"\nCreated in deepnote.com \nCreated in Deepnote","metadata":{"created_in_deepnote_cell":true,"deepnote_cell_type":"markdown"}}],"nbformat":4,"nbformat_minor":0,"metadata":{"deepnote":{},"orig_nbformat":2,"deepnote_notebook_id":"61dd012b72d64ffeaeb97616c867546c","deepnote_execution_queue":[]}} diff --git a/Extractive.py b/Extractive.py new file mode 100644 index 0000000..386b8a7 --- /dev/null +++ b/Extractive.py @@ -0,0 +1,32 @@ +!pip install spacy==3 +!python -m spacy download en_core_web_trf + +import spacy + +# Load the language model +nlp = spacy.load('en_core_web_trf') + +# Sample text for demonstration +text = """ + The rise of technology has drastically changed the way we live our lives. From smartphones to social media, technology has revolutionized the way we communicate and interact with each other. While technology has brought many benefits, it has also raised concerns about privacy and the impact on our mental health. As we continue to advance in technology, it is important to consider both the positive and negative effects on society." + """ + +# Process the text with spaCy +doc = nlp(text) + +# Calculate sentence scores based on their similarity to the document +sent_scores = [] +for sent in doc.sents: + score = 0 + for word in sent: + score += word.similarity(doc) + sent_scores.append((sent, score)) + +# Sort the sentences in decreasing order of score and get the top 3 +sent_scores = sorted(sent_scores, key=lambda x: x[1], reverse=True)[:3] + +# Extract the top 3 sentences and join them to form a summary +summary = ' '.join([sent[0].text for sent in sent_scores]) + +# Print the summary +print(summary)