{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 23644, "status": "ok", "timestamp": 1669576254858, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "1jUAOZGjfYt8", "outputId": "11f8fd4f-1229-4ce4-96cf-6662f2c706b1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: datasets in /home/user/.local/lib/python3.10/site-packages (2.6.1)\n", "Requirement already satisfied: transformers in /home/user/.local/lib/python3.10/site-packages (4.20.0)\n", "Requirement already satisfied: rouge-score in /home/user/.local/lib/python3.10/site-packages (0.1.2)\n", "Requirement already satisfied: nltk in /home/user/.local/lib/python3.10/site-packages (3.7)\n", "Requirement already satisfied: requests>=2.19.0 in /usr/lib/python3/dist-packages (from datasets) (2.25.1)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/lib/python3/dist-packages (from datasets) (5.4.1)\n", "Requirement already satisfied: dill<0.3.6 in /home/user/.local/lib/python3.10/site-packages (from datasets) (0.3.5.1)\n", "Requirement already satisfied: numpy>=1.17 in /home/user/.local/lib/python3.10/site-packages (from datasets) (1.23.3)\n", "Requirement already satisfied: xxhash in /home/user/.local/lib/python3.10/site-packages (from datasets) (3.1.0)\n", "Requirement already satisfied: pandas in /home/user/.local/lib/python3.10/site-packages (from datasets) (1.5.0)\n", "Requirement already satisfied: aiohttp in /home/user/.local/lib/python3.10/site-packages (from datasets) (3.8.3)\n", "Requirement already satisfied: responses<0.19 in /home/user/.local/lib/python3.10/site-packages (from datasets) (0.18.0)\n", "Requirement already satisfied: pyarrow>=6.0.0 in /home/user/.local/lib/python3.10/site-packages (from datasets) (10.0.0)\n", "Requirement already satisfied: multiprocess in /home/user/.local/lib/python3.10/site-packages (from datasets) (0.70.13)\n", "Requirement already satisfied: fsspec[http]>=2021.11.1 in /home/user/.local/lib/python3.10/site-packages (from datasets) (2022.10.0)\n", "Requirement already satisfied: packaging in /home/user/.local/lib/python3.10/site-packages (from datasets) (21.3)\n", "Requirement already satisfied: tqdm>=4.62.1 in /home/user/.local/lib/python3.10/site-packages (from datasets) (4.64.1)\n", "Requirement already satisfied: huggingface-hub<1.0.0,>=0.2.0 in /home/user/.local/lib/python3.10/site-packages (from datasets) (0.10.1)\n", "Requirement already satisfied: tokenizers!=0.11.3,<0.13,>=0.11.1 in /home/user/.local/lib/python3.10/site-packages (from transformers) (0.12.1)\n", "Requirement already satisfied: filelock in /usr/lib/python3/dist-packages (from transformers) (3.6.0)\n", "Requirement already satisfied: regex!=2019.12.17 in /home/user/.local/lib/python3.10/site-packages (from transformers) (2022.9.13)\n", "Requirement already satisfied: six>=1.14.0 in /usr/lib/python3/dist-packages (from rouge-score) (1.16.0)\n", "Requirement already satisfied: absl-py in /home/user/.local/lib/python3.10/site-packages (from rouge-score) (1.2.0)\n", "Requirement already satisfied: joblib in /home/user/.local/lib/python3.10/site-packages (from nltk) (1.2.0)\n", "Requirement already satisfied: click in /usr/lib/python3/dist-packages (from nltk) (8.0.3)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (6.0.2)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (1.2.0)\n", "Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (2.1.1)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (1.3.1)\n", "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (4.0.2)\n", "Requirement already satisfied: attrs>=17.3.0 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (22.1.0)\n", "Requirement already satisfied: yarl<2.0,>=1.0 in /home/user/.local/lib/python3.10/site-packages (from aiohttp->datasets) (1.8.1)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/user/.local/lib/python3.10/site-packages (from huggingface-hub<1.0.0,>=0.2.0->datasets) (4.4.0)\n", "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/lib/python3/dist-packages (from packaging->datasets) (2.4.7)\n", "Requirement already satisfied: urllib3>=1.25.10 in /usr/lib/python3/dist-packages (from responses<0.19->datasets) (1.26.5)\n", "Requirement already satisfied: python-dateutil>=2.8.1 in /home/user/.local/lib/python3.10/site-packages (from pandas->datasets) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/lib/python3/dist-packages (from pandas->datasets) (2022.1)\n", "Requirement already satisfied: idna>=2.0 in /usr/lib/python3/dist-packages (from yarl<2.0,>=1.0->aiohttp->datasets) (3.3)\n" ] } ], "source": [ "! pip install datasets transformers rouge-score nltk" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 331, "referenced_widgets": [ "c38b3a29bdb24edf9f9ffc2a1d7ea136", "bd4317d0cace4fa8a9d4e6f55643457f", "1458810480da42cc81793be5af19d9fd", "8a1d2e60bee942129dad6a705ed03aa5", "a6f0d0297c6347c9a271bf33c27d3e8e", "80ed1d76abc34b0a9d95d937eae6b626", "3b9d888697984453978d8b82e167a7cd", "5468607c66ac4a5d893b66de7803a1da", "ec07fb7fa6754fe3ad81d7e8a128fac3", "bd84f71efa3942b69c337203376d6f9d", "50339a3619674663958b9cacc42224b0", "8916adf78ef54b1b80e04a3a4f9bdf8c", "a6bd07e3118f42e79e1b3d7675dd28e3", "14946c0a0b124448aec12ab62adecee9", "c7630aea76ff4160a20578c22f8e97e8", "75149305e7614e0b84cbebb12fc7340b", "f3fd3ead9fb44d0d9616d89b1992c7ba" ] }, "executionInfo": { "elapsed": 333, "status": "ok", "timestamp": 1669576266320, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "6IuXlV3Ffanz", "outputId": "bb952e77-9ef9-482e-c532-502b9b20462c" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Login successful\n", "Your token has been saved to /home/user/.huggingface/token\n", "\u001b[1m\u001b[31mAuthenticated through git-credential store but this isn't the helper defined on your machine.\n", "You might have to re-authenticate when pushing to the Hugging Face Hub. Run the following command in your terminal in case you want to set this credential helper as the default\n", "\n", "git config --global credential.helper store\u001b[0m\n" ] } ], "source": [ "from huggingface_hub import notebook_login\n", "\n", "notebook_login()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "!git config --global credential.helper store\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 1875, "status": "ok", "timestamp": 1669576287294, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "zA3LmEG9fu80", "outputId": "f9583b3c-db03-41e0-b153-b912a0020595" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;31mE: \u001b[0mCould not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)\u001b[0m\r\n", "\u001b[1;31mE: \u001b[0mUnable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?\u001b[0m\r\n" ] } ], "source": [ "!apt install git-lfs" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 2483, "status": "ok", "timestamp": 1669576292029, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "50K-4gBfgGRh", "outputId": "cf0ee968-30ef-44cc-e00c-1401fd6efe09" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4.20.0\n" ] } ], "source": [ "import transformers\n", "\n", "print(transformers.__version__)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "executionInfo": { "elapsed": 358, "status": "ok", "timestamp": 1669576294061, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "ymFBPi-XgJ0_" }, "outputs": [], "source": [ "model_checkpoint = 'facebook/bart-large-cnn'" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 712, "referenced_widgets": [ "d2e8b31a5ff34826a0a9add966b3a612", "522be447cd3a49e5abc09c438405dd2c", "179dd0a736aa470a993585febe5c1462", "4e3e2875eb2b47abbdfd0994a1a1ab77", "56ac28edb6ca4415ba964f42d4d27bed", "83d334d4b71e4c07a1fc3dac8115f948", "c1aa4ce82ce44a6fbe342d6f9d27ace3", "6ff11cd026154544bee3ea10ceff2c2d", "3aef5fca9d01411dbf02c42bb9edd293", "fa597dbb89aa4f5fac6cc6e0a9859d59", "867595abfc9c4dd28a19346afb584534" ] }, "executionInfo": { "elapsed": 2879, "status": "ok", "timestamp": 1669576300418, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "57B0I_4zguys", "outputId": "0945df5a-9aee-4441-b006-55d10db99374" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_47026/939338506.py:3: FutureWarning: load_metric is deprecated and will be removed in the next major version of datasets. Use 'evaluate.load' instead, from the new library 🤗 Evaluate: https://huggingface.co/docs/evaluate\n", " load_metric('rouge')\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c802d13e0abb4a44a77e3cb10af6651e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading builder script: 0%| | 0.00/2.16k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "Metric(name: \"rouge\", features: {'predictions': Value(dtype='string', id='sequence'), 'references': Value(dtype='string', id='sequence')}, usage: \"\"\"\n", "Calculates average rouge scores for a list of hypotheses and references\n", "Args:\n", " predictions: list of predictions to score. Each prediction\n", " should be a string with tokens separated by spaces.\n", " references: list of reference for each prediction. Each\n", " reference should be a string with tokens separated by spaces.\n", " rouge_types: A list of rouge types to calculate.\n", " Valid names:\n", " `\"rouge{n}\"` (e.g. `\"rouge1\"`, `\"rouge2\"`) where: {n} is the n-gram based scoring,\n", " `\"rougeL\"`: Longest common subsequence based scoring.\n", " `\"rougeLSum\"`: rougeLsum splits text using `\"\n", "\"`.\n", " See details in https://github.com/huggingface/datasets/issues/617\n", " use_stemmer: Bool indicating whether Porter stemmer should be used to strip word suffixes.\n", " use_aggregator: Return aggregates if this is set to True\n", "Returns:\n", " rouge1: rouge_1 (precision, recall, f1),\n", " rouge2: rouge_2 (precision, recall, f1),\n", " rougeL: rouge_l (precision, recall, f1),\n", " rougeLsum: rouge_lsum (precision, recall, f1)\n", "Examples:\n", "\n", " >>> rouge = datasets.load_metric('rouge')\n", " >>> predictions = [\"hello there\", \"general kenobi\"]\n", " >>> references = [\"hello there\", \"general kenobi\"]\n", " >>> results = rouge.compute(predictions=predictions, references=references)\n", " >>> print(list(results.keys()))\n", " ['rouge1', 'rouge2', 'rougeL', 'rougeLsum']\n", " >>> print(results[\"rouge1\"])\n", " AggregateScore(low=Score(precision=1.0, recall=1.0, fmeasure=1.0), mid=Score(precision=1.0, recall=1.0, fmeasure=1.0), high=Score(precision=1.0, recall=1.0, fmeasure=1.0))\n", " >>> print(results[\"rouge1\"].mid.fmeasure)\n", " 1.0\n", "\"\"\", stored examples: 0)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datasets import load_dataset, load_metric\n", "\n", "load_metric('rouge')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "executionInfo": { "elapsed": 912, "status": "ok", "timestamp": 1669576305170, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "ycjFViueiC1x", "outputId": "d982e6dd-79ee-4ffb-abe7-89002fd2d7bc" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package punkt to /home/user/nltk_data...\n", "[nltk_data] Package punkt is already up-to-date!\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import nltk\n", "nltk.download('punkt')\n", " " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "executionInfo": { "elapsed": 354, "status": "ok", "timestamp": 1669576330301, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "YHBxeIxlhJ-t" }, "outputs": [], "source": [ "result = pd.read_csv('results.csv')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "executionInfo": { "elapsed": 303, "status": "ok", "timestamp": 1669576335012, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "Gq6dBpcsiAKS" }, "outputs": [], "source": [ "red_panel = pd.read_csv('red_panel.csv')\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 424 }, "executionInfo": { "elapsed": 323, "status": "ok", "timestamp": 1669576337691, "user": { "displayName": "Hayk Nersesyan", "userId": "12126341854567580260" }, "user_tz": -240 }, "id": "NaXyZezfi8jZ", "outputId": "fd7cec48-c512-45b7-f9d1-4f5face4e677" }, "outputs": [ { "data": { "text/html": [ "
\n", " | red_panel_text_box_body | \n", "Unnamed: 1 | \n", "
---|---|---|
0 | \n", "The numerical model, was able to predict a rea... | \n", "NaN | \n", "
1 | \n", "Lines with recessive ppd-H1 presented delayed ... | \n", "NaN | \n", "
2 | \n", "Tumor- but not macrophage-derived PGRN is asso... | \n", "NaN | \n", "
3 | \n", "A total of 449 BCs were analyzed.Sensitivities... | \n", "NaN | \n", "
4 | \n", "Factors for non-adherent behavior were examine... | \n", "NaN | \n", "
... | \n", "... | \n", "... | \n", "
90 | \n", "Results: The mean age of participants was 50 y... | \n", "NaN | \n", "
91 | \n", "NaN | \n", "NaN | \n", "
92 | \n", "Subjects with reduced left ventricular systoli... | \n", "NaN | \n", "
93 | \n", "Results A total of 47 722 new cases were repor... | \n", "NaN | \n", "
94 | \n", "In isolated hearts, CPT showed a biphasic effe... | \n", "NaN | \n", "
95 rows × 2 columns
\n", "\n", " | red_panel_text_box_body | \n", "
---|---|
0 | \n", "For metaphyseal fracture healing in the distal... | \n", "
1 | \n", "For breeding of high-yielding cultivars with s... | \n", "
2 | \n", "In pancreatic ductal adenocarcinoma: We show a... | \n", "
3 | \n", "For the detection of frequent Gram-negatives d... | \n", "
4 | \n", "Patients with cluster headache: Tended to hav... | \n", "
... | \n", "... | \n", "
90 | \n", "After bariatric surgery: Reduced anti-apoA-1 I... | \n", "
91 | \n", "For children/young adults with diabetes and di... | \n", "
92 | \n", "In dilated cardiomyopathy: Advanced flow imagi... | \n", "
93 | \n", "For COVID-19: Approximately 85% of the Chinese... | \n", "
94 | \n", "In the heart: CPT may affect contraction and a... | \n", "
95 rows × 1 columns
\n", "