Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +31 -0
- requirements.txt +4 -0
- smart-meeting-notes-by-llm-session7.ipynb +1415 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
7 |
+
|
8 |
+
def summarize_text(text):
|
9 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
+
summary_ids = model.generate(
|
11 |
+
inputs["input_ids"],
|
12 |
+
attention_mask=inputs["attention_mask"],
|
13 |
+
max_length=100,
|
14 |
+
min_length=20,
|
15 |
+
length_penalty=2.0,
|
16 |
+
num_beams=4,
|
17 |
+
early_stopping=True,
|
18 |
+
no_repeat_ngram_size=3
|
19 |
+
)
|
20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
21 |
+
return summary
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=summarize_text,
|
25 |
+
inputs=gr.Textbox(lines=5, label="Input Text"),
|
26 |
+
outputs=gr.Textbox(label="Summary"),
|
27 |
+
title="DistilBART Summarizer",
|
28 |
+
description="Summarize any input text using DistilBART fine-tuned model."
|
29 |
+
)
|
30 |
+
|
31 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
transformers
|
3 |
+
torch
|
4 |
+
gradio
|
smart-meeting-notes-by-llm-session7.ipynb
ADD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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
|
8 |
+
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
|
9 |
+
"execution": {
|
10 |
+
"iopub.execute_input": "2025-06-12T17:04:41.889457Z",
|
11 |
+
"iopub.status.busy": "2025-06-12T17:04:41.889269Z",
|
12 |
+
"iopub.status.idle": "2025-06-12T17:04:43.013740Z",
|
13 |
+
"shell.execute_reply": "2025-06-12T17:04:43.012978Z",
|
14 |
+
"shell.execute_reply.started": "2025-06-12T17:04:41.889440Z"
|
15 |
+
},
|
16 |
+
"trusted": true
|
17 |
+
},
|
18 |
+
"outputs": [],
|
19 |
+
"source": [
|
20 |
+
"# This Python 3 environment comes with many helpful analytics libraries installed\n",
|
21 |
+
"# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n",
|
22 |
+
"# For example, here's several helpful packages to load\n",
|
23 |
+
"\n",
|
24 |
+
"import numpy as np # linear algebra\n",
|
25 |
+
"import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
|
26 |
+
"\n",
|
27 |
+
"# Input data files are available in the read-only \"../input/\" directory\n",
|
28 |
+
"# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n",
|
29 |
+
"\n",
|
30 |
+
"import os\n",
|
31 |
+
"for dirname, _, filenames in os.walk('/kaggle/input'):\n",
|
32 |
+
" for filename in filenames:\n",
|
33 |
+
" print(os.path.join(dirname, filename))\n",
|
34 |
+
"\n",
|
35 |
+
"# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n",
|
36 |
+
"# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session"
|
37 |
+
]
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"cell_type": "code",
|
41 |
+
"execution_count": 2,
|
42 |
+
"metadata": {
|
43 |
+
"execution": {
|
44 |
+
"iopub.execute_input": "2025-06-12T17:04:43.015611Z",
|
45 |
+
"iopub.status.busy": "2025-06-12T17:04:43.015277Z",
|
46 |
+
"iopub.status.idle": "2025-06-12T17:04:47.753149Z",
|
47 |
+
"shell.execute_reply": "2025-06-12T17:04:47.752453Z",
|
48 |
+
"shell.execute_reply.started": "2025-06-12T17:04:43.015591Z"
|
49 |
+
},
|
50 |
+
"trusted": true
|
51 |
+
},
|
52 |
+
"outputs": [
|
53 |
+
{
|
54 |
+
"name": "stdout",
|
55 |
+
"output_type": "stream",
|
56 |
+
"text": [
|
57 |
+
"Requirement already satisfied: datasets in /usr/local/lib/python3.11/dist-packages (3.6.0)\n",
|
58 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from datasets) (3.18.0)\n",
|
59 |
+
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.11/dist-packages (from datasets) (1.26.4)\n",
|
60 |
+
"Requirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.11/dist-packages (from datasets) (19.0.1)\n",
|
61 |
+
"Requirement already satisfied: dill<0.3.9,>=0.3.0 in /usr/local/lib/python3.11/dist-packages (from datasets) (0.3.8)\n",
|
62 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (from datasets) (2.2.3)\n",
|
63 |
+
"Requirement already satisfied: requests>=2.32.2 in /usr/local/lib/python3.11/dist-packages (from datasets) (2.32.3)\n",
|
64 |
+
"Requirement already satisfied: tqdm>=4.66.3 in /usr/local/lib/python3.11/dist-packages (from datasets) (4.67.1)\n",
|
65 |
+
"Requirement already satisfied: xxhash in /usr/local/lib/python3.11/dist-packages (from datasets) (3.5.0)\n",
|
66 |
+
"Requirement already satisfied: multiprocess<0.70.17 in /usr/local/lib/python3.11/dist-packages (from datasets) (0.70.16)\n",
|
67 |
+
"Collecting fsspec<=2025.3.0,>=2023.1.0 (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets)\n",
|
68 |
+
" Downloading fsspec-2025.3.0-py3-none-any.whl.metadata (11 kB)\n",
|
69 |
+
"Requirement already satisfied: huggingface-hub>=0.24.0 in /usr/local/lib/python3.11/dist-packages (from datasets) (0.31.1)\n",
|
70 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from datasets) (25.0)\n",
|
71 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from datasets) (6.0.2)\n",
|
72 |
+
"Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /usr/local/lib/python3.11/dist-packages (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (3.11.18)\n",
|
73 |
+
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.24.0->datasets) (4.13.2)\n",
|
74 |
+
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.24.0->datasets) (1.1.0)\n",
|
75 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (1.3.8)\n",
|
76 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (1.2.4)\n",
|
77 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (0.1.1)\n",
|
78 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (2025.1.0)\n",
|
79 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (2022.1.0)\n",
|
80 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->datasets) (2.4.1)\n",
|
81 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (3.4.2)\n",
|
82 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (3.10)\n",
|
83 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (2.4.0)\n",
|
84 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (2025.4.26)\n",
|
85 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets) (2.9.0.post0)\n",
|
86 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets) (2025.2)\n",
|
87 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets) (2025.2)\n",
|
88 |
+
"Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (2.6.1)\n",
|
89 |
+
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.3.2)\n",
|
90 |
+
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (25.3.0)\n",
|
91 |
+
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.6.0)\n",
|
92 |
+
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (6.4.3)\n",
|
93 |
+
"Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (0.3.1)\n",
|
94 |
+
"Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets) (1.20.0)\n",
|
95 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas->datasets) (1.17.0)\n",
|
96 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.17->datasets) (2024.2.0)\n",
|
97 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.17->datasets) (2022.1.0)\n",
|
98 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy>=1.17->datasets) (1.3.0)\n",
|
99 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy>=1.17->datasets) (2024.2.0)\n",
|
100 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy>=1.17->datasets) (2024.2.0)\n",
|
101 |
+
"Downloading fsspec-2025.3.0-py3-none-any.whl (193 kB)\n",
|
102 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m193.6/193.6 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
|
103 |
+
"\u001b[?25hInstalling collected packages: fsspec\n",
|
104 |
+
" Attempting uninstall: fsspec\n",
|
105 |
+
" Found existing installation: fsspec 2025.3.2\n",
|
106 |
+
" Uninstalling fsspec-2025.3.2:\n",
|
107 |
+
" Successfully uninstalled fsspec-2025.3.2\n",
|
108 |
+
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
|
109 |
+
"cesium 0.12.4 requires numpy<3.0,>=2.0, but you have numpy 1.26.4 which is incompatible.\n",
|
110 |
+
"bigframes 1.42.0 requires rich<14,>=12.4.4, but you have rich 14.0.0 which is incompatible.\n",
|
111 |
+
"torch 2.6.0+cu124 requires nvidia-cublas-cu12==12.4.5.8; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-cublas-cu12 12.9.0.13 which is incompatible.\n",
|
112 |
+
"torch 2.6.0+cu124 requires nvidia-cudnn-cu12==9.1.0.70; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-cudnn-cu12 9.3.0.75 which is incompatible.\n",
|
113 |
+
"torch 2.6.0+cu124 requires nvidia-cufft-cu12==11.2.1.3; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-cufft-cu12 11.4.0.6 which is incompatible.\n",
|
114 |
+
"torch 2.6.0+cu124 requires nvidia-curand-cu12==10.3.5.147; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-curand-cu12 10.3.10.19 which is incompatible.\n",
|
115 |
+
"torch 2.6.0+cu124 requires nvidia-cusolver-cu12==11.6.1.9; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-cusolver-cu12 11.7.4.40 which is incompatible.\n",
|
116 |
+
"torch 2.6.0+cu124 requires nvidia-cusparse-cu12==12.3.1.170; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-cusparse-cu12 12.5.9.5 which is incompatible.\n",
|
117 |
+
"torch 2.6.0+cu124 requires nvidia-nvjitlink-cu12==12.4.127; platform_system == \"Linux\" and platform_machine == \"x86_64\", but you have nvidia-nvjitlink-cu12 12.9.41 which is incompatible.\n",
|
118 |
+
"gcsfs 2025.3.2 requires fsspec==2025.3.2, but you have fsspec 2025.3.0 which is incompatible.\u001b[0m\u001b[31m\n",
|
119 |
+
"\u001b[0mSuccessfully installed fsspec-2025.3.0\n"
|
120 |
+
]
|
121 |
+
}
|
122 |
+
],
|
123 |
+
"source": [
|
124 |
+
"!pip install datasets\n"
|
125 |
+
]
|
126 |
+
},
|
127 |
+
{
|
128 |
+
"cell_type": "code",
|
129 |
+
"execution_count": 3,
|
130 |
+
"metadata": {
|
131 |
+
"execution": {
|
132 |
+
"iopub.execute_input": "2025-06-12T17:04:47.754432Z",
|
133 |
+
"iopub.status.busy": "2025-06-12T17:04:47.754136Z",
|
134 |
+
"iopub.status.idle": "2025-06-12T17:04:51.067474Z",
|
135 |
+
"shell.execute_reply": "2025-06-12T17:04:51.066953Z",
|
136 |
+
"shell.execute_reply.started": "2025-06-12T17:04:47.754407Z"
|
137 |
+
},
|
138 |
+
"trusted": true
|
139 |
+
},
|
140 |
+
"outputs": [
|
141 |
+
{
|
142 |
+
"data": {
|
143 |
+
"application/vnd.jupyter.widget-view+json": {
|
144 |
+
"model_id": "1493ba48468f46648af0bfb811beee06",
|
145 |
+
"version_major": 2,
|
146 |
+
"version_minor": 0
|
147 |
+
},
|
148 |
+
"text/plain": [
|
149 |
+
"README.md: 0%| | 0.00/4.65k [00:00<?, ?B/s]"
|
150 |
+
]
|
151 |
+
},
|
152 |
+
"metadata": {},
|
153 |
+
"output_type": "display_data"
|
154 |
+
},
|
155 |
+
{
|
156 |
+
"data": {
|
157 |
+
"application/vnd.jupyter.widget-view+json": {
|
158 |
+
"model_id": "d146713524544f65af5a9c2c7bc33d70",
|
159 |
+
"version_major": 2,
|
160 |
+
"version_minor": 0
|
161 |
+
},
|
162 |
+
"text/plain": [
|
163 |
+
"train.csv: 0%| | 0.00/11.3M [00:00<?, ?B/s]"
|
164 |
+
]
|
165 |
+
},
|
166 |
+
"metadata": {},
|
167 |
+
"output_type": "display_data"
|
168 |
+
},
|
169 |
+
{
|
170 |
+
"data": {
|
171 |
+
"application/vnd.jupyter.widget-view+json": {
|
172 |
+
"model_id": "b83b84e119a64c14b78c97549f709b0a",
|
173 |
+
"version_major": 2,
|
174 |
+
"version_minor": 0
|
175 |
+
},
|
176 |
+
"text/plain": [
|
177 |
+
"validation.csv: 0%| | 0.00/442k [00:00<?, ?B/s]"
|
178 |
+
]
|
179 |
+
},
|
180 |
+
"metadata": {},
|
181 |
+
"output_type": "display_data"
|
182 |
+
},
|
183 |
+
{
|
184 |
+
"data": {
|
185 |
+
"application/vnd.jupyter.widget-view+json": {
|
186 |
+
"model_id": "bd01c9577b4646d1a16cc3d8f508d610",
|
187 |
+
"version_major": 2,
|
188 |
+
"version_minor": 0
|
189 |
+
},
|
190 |
+
"text/plain": [
|
191 |
+
"test.csv: 0%| | 0.00/1.35M [00:00<?, ?B/s]"
|
192 |
+
]
|
193 |
+
},
|
194 |
+
"metadata": {},
|
195 |
+
"output_type": "display_data"
|
196 |
+
},
|
197 |
+
{
|
198 |
+
"data": {
|
199 |
+
"application/vnd.jupyter.widget-view+json": {
|
200 |
+
"model_id": "e486ee8329dc4d29924e3edfb7df2479",
|
201 |
+
"version_major": 2,
|
202 |
+
"version_minor": 0
|
203 |
+
},
|
204 |
+
"text/plain": [
|
205 |
+
"Generating train split: 0%| | 0/12460 [00:00<?, ? examples/s]"
|
206 |
+
]
|
207 |
+
},
|
208 |
+
"metadata": {},
|
209 |
+
"output_type": "display_data"
|
210 |
+
},
|
211 |
+
{
|
212 |
+
"data": {
|
213 |
+
"application/vnd.jupyter.widget-view+json": {
|
214 |
+
"model_id": "366c9a3006034d439092c1a1bc12ace9",
|
215 |
+
"version_major": 2,
|
216 |
+
"version_minor": 0
|
217 |
+
},
|
218 |
+
"text/plain": [
|
219 |
+
"Generating validation split: 0%| | 0/500 [00:00<?, ? examples/s]"
|
220 |
+
]
|
221 |
+
},
|
222 |
+
"metadata": {},
|
223 |
+
"output_type": "display_data"
|
224 |
+
},
|
225 |
+
{
|
226 |
+
"data": {
|
227 |
+
"application/vnd.jupyter.widget-view+json": {
|
228 |
+
"model_id": "70d73fc03dcb446e886abfce07d50b4e",
|
229 |
+
"version_major": 2,
|
230 |
+
"version_minor": 0
|
231 |
+
},
|
232 |
+
"text/plain": [
|
233 |
+
"Generating test split: 0%| | 0/1500 [00:00<?, ? examples/s]"
|
234 |
+
]
|
235 |
+
},
|
236 |
+
"metadata": {},
|
237 |
+
"output_type": "display_data"
|
238 |
+
}
|
239 |
+
],
|
240 |
+
"source": [
|
241 |
+
"from datasets import load_dataset\n",
|
242 |
+
"ds = load_dataset(\"knkarthick/dialogsum\")\n"
|
243 |
+
]
|
244 |
+
},
|
245 |
+
{
|
246 |
+
"cell_type": "code",
|
247 |
+
"execution_count": 4,
|
248 |
+
"metadata": {
|
249 |
+
"execution": {
|
250 |
+
"iopub.execute_input": "2025-06-12T17:04:51.068492Z",
|
251 |
+
"iopub.status.busy": "2025-06-12T17:04:51.068151Z",
|
252 |
+
"iopub.status.idle": "2025-06-12T17:04:52.772955Z",
|
253 |
+
"shell.execute_reply": "2025-06-12T17:04:52.772321Z",
|
254 |
+
"shell.execute_reply.started": "2025-06-12T17:04:51.068474Z"
|
255 |
+
},
|
256 |
+
"trusted": true
|
257 |
+
},
|
258 |
+
"outputs": [
|
259 |
+
{
|
260 |
+
"data": {
|
261 |
+
"application/vnd.jupyter.widget-view+json": {
|
262 |
+
"model_id": "1814d5ef014147d0ac7e1a9b2ddc6560",
|
263 |
+
"version_major": 2,
|
264 |
+
"version_minor": 0
|
265 |
+
},
|
266 |
+
"text/plain": [
|
267 |
+
"Map: 0%| | 0/12460 [00:00<?, ? examples/s]"
|
268 |
+
]
|
269 |
+
},
|
270 |
+
"metadata": {},
|
271 |
+
"output_type": "display_data"
|
272 |
+
},
|
273 |
+
{
|
274 |
+
"data": {
|
275 |
+
"application/vnd.jupyter.widget-view+json": {
|
276 |
+
"model_id": "ea9b9978b1b24eb188251a9908682166",
|
277 |
+
"version_major": 2,
|
278 |
+
"version_minor": 0
|
279 |
+
},
|
280 |
+
"text/plain": [
|
281 |
+
"Map: 0%| | 0/500 [00:00<?, ? examples/s]"
|
282 |
+
]
|
283 |
+
},
|
284 |
+
"metadata": {},
|
285 |
+
"output_type": "display_data"
|
286 |
+
},
|
287 |
+
{
|
288 |
+
"data": {
|
289 |
+
"application/vnd.jupyter.widget-view+json": {
|
290 |
+
"model_id": "9f0ca8f8df98458381d20cd0908c507f",
|
291 |
+
"version_major": 2,
|
292 |
+
"version_minor": 0
|
293 |
+
},
|
294 |
+
"text/plain": [
|
295 |
+
"Map: 0%| | 0/1500 [00:00<?, ? examples/s]"
|
296 |
+
]
|
297 |
+
},
|
298 |
+
"metadata": {},
|
299 |
+
"output_type": "display_data"
|
300 |
+
}
|
301 |
+
],
|
302 |
+
"source": [
|
303 |
+
"import re\n",
|
304 |
+
"def clean_text(text):\n",
|
305 |
+
" text=re.sub(r'\\s+', ' ', text).strip()\n",
|
306 |
+
" return text \n",
|
307 |
+
"def preprocess(example):\n",
|
308 |
+
" example[\"dialogue\"] = clean_text(example[\"dialogue\"])\n",
|
309 |
+
" example[\"summary\"] = clean_text(example[\"summary\"])\n",
|
310 |
+
" return example\n",
|
311 |
+
"ds[\"train\"] = ds[\"train\"].map(preprocess)\n",
|
312 |
+
"ds[\"validation\"] = ds[\"validation\"].map(preprocess)\n",
|
313 |
+
"ds[\"test\"] = ds[\"test\"].map(preprocess)"
|
314 |
+
]
|
315 |
+
},
|
316 |
+
{
|
317 |
+
"cell_type": "code",
|
318 |
+
"execution_count": 5,
|
319 |
+
"metadata": {
|
320 |
+
"execution": {
|
321 |
+
"iopub.execute_input": "2025-06-12T17:04:52.774820Z",
|
322 |
+
"iopub.status.busy": "2025-06-12T17:04:52.774612Z",
|
323 |
+
"iopub.status.idle": "2025-06-12T17:05:15.376798Z",
|
324 |
+
"shell.execute_reply": "2025-06-12T17:05:15.375993Z",
|
325 |
+
"shell.execute_reply.started": "2025-06-12T17:04:52.774804Z"
|
326 |
+
},
|
327 |
+
"trusted": true
|
328 |
+
},
|
329 |
+
"outputs": [
|
330 |
+
{
|
331 |
+
"data": {
|
332 |
+
"application/vnd.jupyter.widget-view+json": {
|
333 |
+
"model_id": "c9843e22bdeb412f89c8ac4deb2fd6c6",
|
334 |
+
"version_major": 2,
|
335 |
+
"version_minor": 0
|
336 |
+
},
|
337 |
+
"text/plain": [
|
338 |
+
"tokenizer_config.json: 0%| | 0.00/26.0 [00:00<?, ?B/s]"
|
339 |
+
]
|
340 |
+
},
|
341 |
+
"metadata": {},
|
342 |
+
"output_type": "display_data"
|
343 |
+
},
|
344 |
+
{
|
345 |
+
"data": {
|
346 |
+
"application/vnd.jupyter.widget-view+json": {
|
347 |
+
"model_id": "6345b5f45bd245499f288926d631543e",
|
348 |
+
"version_major": 2,
|
349 |
+
"version_minor": 0
|
350 |
+
},
|
351 |
+
"text/plain": [
|
352 |
+
"config.json: 0%| | 0.00/1.80k [00:00<?, ?B/s]"
|
353 |
+
]
|
354 |
+
},
|
355 |
+
"metadata": {},
|
356 |
+
"output_type": "display_data"
|
357 |
+
},
|
358 |
+
{
|
359 |
+
"data": {
|
360 |
+
"application/vnd.jupyter.widget-view+json": {
|
361 |
+
"model_id": "c73e268748254c1ab6376245698e649a",
|
362 |
+
"version_major": 2,
|
363 |
+
"version_minor": 0
|
364 |
+
},
|
365 |
+
"text/plain": [
|
366 |
+
"vocab.json: 0%| | 0.00/899k [00:00<?, ?B/s]"
|
367 |
+
]
|
368 |
+
},
|
369 |
+
"metadata": {},
|
370 |
+
"output_type": "display_data"
|
371 |
+
},
|
372 |
+
{
|
373 |
+
"data": {
|
374 |
+
"application/vnd.jupyter.widget-view+json": {
|
375 |
+
"model_id": "9deb932fd0c247568e7fa87f909f1413",
|
376 |
+
"version_major": 2,
|
377 |
+
"version_minor": 0
|
378 |
+
},
|
379 |
+
"text/plain": [
|
380 |
+
"merges.txt: 0%| | 0.00/456k [00:00<?, ?B/s]"
|
381 |
+
]
|
382 |
+
},
|
383 |
+
"metadata": {},
|
384 |
+
"output_type": "display_data"
|
385 |
+
},
|
386 |
+
{
|
387 |
+
"data": {
|
388 |
+
"application/vnd.jupyter.widget-view+json": {
|
389 |
+
"model_id": "dd000a5f19dd423eb8e3ba0071ee8ed4",
|
390 |
+
"version_major": 2,
|
391 |
+
"version_minor": 0
|
392 |
+
},
|
393 |
+
"text/plain": [
|
394 |
+
"Map: 0%| | 0/12460 [00:00<?, ? examples/s]"
|
395 |
+
]
|
396 |
+
},
|
397 |
+
"metadata": {},
|
398 |
+
"output_type": "display_data"
|
399 |
+
},
|
400 |
+
{
|
401 |
+
"name": "stderr",
|
402 |
+
"output_type": "stream",
|
403 |
+
"text": [
|
404 |
+
"/usr/local/lib/python3.11/dist-packages/transformers/tokenization_utils_base.py:3980: UserWarning: `as_target_tokenizer` is deprecated and will be removed in v5 of Transformers. You can tokenize your labels by using the argument `text_target` of the regular `__call__` method (either in the same call as your input texts if you use the same keyword arguments, or in a separate call.\n",
|
405 |
+
" warnings.warn(\n"
|
406 |
+
]
|
407 |
+
},
|
408 |
+
{
|
409 |
+
"data": {
|
410 |
+
"application/vnd.jupyter.widget-view+json": {
|
411 |
+
"model_id": "b50d71bf97ae48e2b6a90a0606380024",
|
412 |
+
"version_major": 2,
|
413 |
+
"version_minor": 0
|
414 |
+
},
|
415 |
+
"text/plain": [
|
416 |
+
"Map: 0%| | 0/500 [00:00<?, ? examples/s]"
|
417 |
+
]
|
418 |
+
},
|
419 |
+
"metadata": {},
|
420 |
+
"output_type": "display_data"
|
421 |
+
},
|
422 |
+
{
|
423 |
+
"data": {
|
424 |
+
"application/vnd.jupyter.widget-view+json": {
|
425 |
+
"model_id": "c3b5f103b9644a1294886e5f32480dc3",
|
426 |
+
"version_major": 2,
|
427 |
+
"version_minor": 0
|
428 |
+
},
|
429 |
+
"text/plain": [
|
430 |
+
"Map: 0%| | 0/1500 [00:00<?, ? examples/s]"
|
431 |
+
]
|
432 |
+
},
|
433 |
+
"metadata": {},
|
434 |
+
"output_type": "display_data"
|
435 |
+
}
|
436 |
+
],
|
437 |
+
"source": [
|
438 |
+
"from transformers import AutoTokenizer\n",
|
439 |
+
"\n",
|
440 |
+
"# Load the tokenizer\n",
|
441 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
442 |
+
"\n",
|
443 |
+
"def tokenize_function(example):\n",
|
444 |
+
" inputs = tokenizer(\n",
|
445 |
+
" example[\"dialogue\"],\n",
|
446 |
+
" max_length=1024,\n",
|
447 |
+
" padding=\"max_length\",\n",
|
448 |
+
" truncation=True\n",
|
449 |
+
" )\n",
|
450 |
+
" with tokenizer.as_target_tokenizer():\n",
|
451 |
+
" labels = tokenizer(\n",
|
452 |
+
" example[\"summary\"],\n",
|
453 |
+
" max_length=128,\n",
|
454 |
+
" padding=\"max_length\",\n",
|
455 |
+
" truncation=True\n",
|
456 |
+
" )\n",
|
457 |
+
" inputs[\"labels\"] = labels[\"input_ids\"]\n",
|
458 |
+
" return inputs\n",
|
459 |
+
"tokenized_ds = ds.map(\n",
|
460 |
+
" tokenize_function,\n",
|
461 |
+
" batched=True,\n",
|
462 |
+
" remove_columns=ds[\"train\"].column_names\n",
|
463 |
+
")\n"
|
464 |
+
]
|
465 |
+
},
|
466 |
+
{
|
467 |
+
"cell_type": "code",
|
468 |
+
"execution_count": 6,
|
469 |
+
"metadata": {
|
470 |
+
"execution": {
|
471 |
+
"iopub.execute_input": "2025-06-12T17:05:15.378134Z",
|
472 |
+
"iopub.status.busy": "2025-06-12T17:05:15.377670Z",
|
473 |
+
"iopub.status.idle": "2025-06-12T17:05:15.384805Z",
|
474 |
+
"shell.execute_reply": "2025-06-12T17:05:15.384102Z",
|
475 |
+
"shell.execute_reply.started": "2025-06-12T17:05:15.378114Z"
|
476 |
+
},
|
477 |
+
"trusted": true
|
478 |
+
},
|
479 |
+
"outputs": [],
|
480 |
+
"source": [
|
481 |
+
"import torch \n",
|
482 |
+
"from torch.utils.data import DataLoader\n",
|
483 |
+
"\n",
|
484 |
+
"for split in [\"train\", \"validation\", \"test\"]:\n",
|
485 |
+
" tokenized_ds[split].set_format(type=\"torch\", columns=[\"input_ids\", \"attention_mask\", \"labels\"])\n",
|
486 |
+
"train_loader = DataLoader(tokenized_ds[\"train\"], batch_size=8, shuffle=True,num_workers=4)\n",
|
487 |
+
"val_loader = DataLoader(tokenized_ds[\"validation\"], batch_size=8,num_workers=4)\n",
|
488 |
+
"test_loader = DataLoader(tokenized_ds[\"test\"], batch_size=8,num_workers=4)\n",
|
489 |
+
"\n"
|
490 |
+
]
|
491 |
+
},
|
492 |
+
{
|
493 |
+
"cell_type": "code",
|
494 |
+
"execution_count": 7,
|
495 |
+
"metadata": {
|
496 |
+
"execution": {
|
497 |
+
"iopub.execute_input": "2025-06-12T17:05:15.385961Z",
|
498 |
+
"iopub.status.busy": "2025-06-12T17:05:15.385696Z",
|
499 |
+
"iopub.status.idle": "2025-06-12T17:05:35.597065Z",
|
500 |
+
"shell.execute_reply": "2025-06-12T17:05:35.596176Z",
|
501 |
+
"shell.execute_reply.started": "2025-06-12T17:05:15.385922Z"
|
502 |
+
},
|
503 |
+
"trusted": true
|
504 |
+
},
|
505 |
+
"outputs": [
|
506 |
+
{
|
507 |
+
"name": "stderr",
|
508 |
+
"output_type": "stream",
|
509 |
+
"text": [
|
510 |
+
"2025-06-12 17:05:18.048160: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
|
511 |
+
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
|
512 |
+
"E0000 00:00:1749747918.257111 35 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
|
513 |
+
"E0000 00:00:1749747918.316434 35 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"
|
514 |
+
]
|
515 |
+
},
|
516 |
+
{
|
517 |
+
"data": {
|
518 |
+
"application/vnd.jupyter.widget-view+json": {
|
519 |
+
"model_id": "d89f33cc54124a7e9aa9ee425c7a81ac",
|
520 |
+
"version_major": 2,
|
521 |
+
"version_minor": 0
|
522 |
+
},
|
523 |
+
"text/plain": [
|
524 |
+
"pytorch_model.bin: 0%| | 0.00/1.22G [00:00<?, ?B/s]"
|
525 |
+
]
|
526 |
+
},
|
527 |
+
"metadata": {},
|
528 |
+
"output_type": "display_data"
|
529 |
+
},
|
530 |
+
{
|
531 |
+
"data": {
|
532 |
+
"application/vnd.jupyter.widget-view+json": {
|
533 |
+
"model_id": "53e22b661e6a46029ef1f0db2b69d58d",
|
534 |
+
"version_major": 2,
|
535 |
+
"version_minor": 0
|
536 |
+
},
|
537 |
+
"text/plain": [
|
538 |
+
"model.safetensors: 0%| | 0.00/1.22G [00:00<?, ?B/s]"
|
539 |
+
]
|
540 |
+
},
|
541 |
+
"metadata": {},
|
542 |
+
"output_type": "display_data"
|
543 |
+
},
|
544 |
+
{
|
545 |
+
"name": "stdout",
|
546 |
+
"output_type": "stream",
|
547 |
+
"text": [
|
548 |
+
"Using device: cuda\n"
|
549 |
+
]
|
550 |
+
},
|
551 |
+
{
|
552 |
+
"data": {
|
553 |
+
"text/plain": [
|
554 |
+
"BartForConditionalGeneration(\n",
|
555 |
+
" (model): BartModel(\n",
|
556 |
+
" (shared): BartScaledWordEmbedding(50264, 1024, padding_idx=1)\n",
|
557 |
+
" (encoder): BartEncoder(\n",
|
558 |
+
" (embed_tokens): BartScaledWordEmbedding(50264, 1024, padding_idx=1)\n",
|
559 |
+
" (embed_positions): BartLearnedPositionalEmbedding(1026, 1024)\n",
|
560 |
+
" (layers): ModuleList(\n",
|
561 |
+
" (0-11): 12 x BartEncoderLayer(\n",
|
562 |
+
" (self_attn): BartSdpaAttention(\n",
|
563 |
+
" (k_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
564 |
+
" (v_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
565 |
+
" (q_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
566 |
+
" (out_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
567 |
+
" )\n",
|
568 |
+
" (self_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
569 |
+
" (activation_fn): GELUActivation()\n",
|
570 |
+
" (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
571 |
+
" (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
572 |
+
" (final_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
573 |
+
" )\n",
|
574 |
+
" )\n",
|
575 |
+
" (layernorm_embedding): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
576 |
+
" )\n",
|
577 |
+
" (decoder): BartDecoder(\n",
|
578 |
+
" (embed_tokens): BartScaledWordEmbedding(50264, 1024, padding_idx=1)\n",
|
579 |
+
" (embed_positions): BartLearnedPositionalEmbedding(1026, 1024)\n",
|
580 |
+
" (layers): ModuleList(\n",
|
581 |
+
" (0-5): 6 x BartDecoderLayer(\n",
|
582 |
+
" (self_attn): BartSdpaAttention(\n",
|
583 |
+
" (k_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
584 |
+
" (v_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
585 |
+
" (q_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
586 |
+
" (out_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
587 |
+
" )\n",
|
588 |
+
" (activation_fn): GELUActivation()\n",
|
589 |
+
" (self_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
590 |
+
" (encoder_attn): BartSdpaAttention(\n",
|
591 |
+
" (k_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
592 |
+
" (v_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
593 |
+
" (q_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
594 |
+
" (out_proj): Linear(in_features=1024, out_features=1024, bias=True)\n",
|
595 |
+
" )\n",
|
596 |
+
" (encoder_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
597 |
+
" (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n",
|
598 |
+
" (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n",
|
599 |
+
" (final_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
600 |
+
" )\n",
|
601 |
+
" )\n",
|
602 |
+
" (layernorm_embedding): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
|
603 |
+
" )\n",
|
604 |
+
" )\n",
|
605 |
+
" (lm_head): Linear(in_features=1024, out_features=50264, bias=False)\n",
|
606 |
+
")"
|
607 |
+
]
|
608 |
+
},
|
609 |
+
"execution_count": 7,
|
610 |
+
"metadata": {},
|
611 |
+
"output_type": "execute_result"
|
612 |
+
}
|
613 |
+
],
|
614 |
+
"source": [
|
615 |
+
"\n",
|
616 |
+
"import torch\n",
|
617 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
618 |
+
"\n",
|
619 |
+
"model_name = \"sshleifer/distilbart-cnn-12-6\"\n",
|
620 |
+
"\n",
|
621 |
+
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
|
622 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(model_name)\n",
|
623 |
+
"\n",
|
624 |
+
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
|
625 |
+
"print(f\"Using device: {device}\")\n",
|
626 |
+
"\n",
|
627 |
+
"model.to(device)\n"
|
628 |
+
]
|
629 |
+
},
|
630 |
+
{
|
631 |
+
"cell_type": "code",
|
632 |
+
"execution_count": 8,
|
633 |
+
"metadata": {
|
634 |
+
"execution": {
|
635 |
+
"iopub.execute_input": "2025-06-12T17:05:35.598725Z",
|
636 |
+
"iopub.status.busy": "2025-06-12T17:05:35.598092Z",
|
637 |
+
"iopub.status.idle": "2025-06-12T17:05:35.634550Z",
|
638 |
+
"shell.execute_reply": "2025-06-12T17:05:35.633637Z",
|
639 |
+
"shell.execute_reply.started": "2025-06-12T17:05:35.598704Z"
|
640 |
+
},
|
641 |
+
"trusted": true
|
642 |
+
},
|
643 |
+
"outputs": [],
|
644 |
+
"source": [
|
645 |
+
"from torch.optim import AdamW\n",
|
646 |
+
"from transformers import get_scheduler\n",
|
647 |
+
"\n",
|
648 |
+
"optimizer = AdamW(model.parameters(), lr=5e-5, weight_decay=0.01)\n",
|
649 |
+
"num_epochs=3\n",
|
650 |
+
"\n",
|
651 |
+
"num_training_steps = num_epochs * len(train_loader)\n",
|
652 |
+
"lr_scheduler = get_scheduler(\n",
|
653 |
+
" name=\"linear\", \n",
|
654 |
+
" optimizer=optimizer,\n",
|
655 |
+
" num_warmup_steps=0, \n",
|
656 |
+
" num_training_steps=num_training_steps,\n",
|
657 |
+
")\n"
|
658 |
+
]
|
659 |
+
},
|
660 |
+
{
|
661 |
+
"cell_type": "code",
|
662 |
+
"execution_count": 9,
|
663 |
+
"metadata": {
|
664 |
+
"execution": {
|
665 |
+
"iopub.execute_input": "2025-06-12T17:05:35.635812Z",
|
666 |
+
"iopub.status.busy": "2025-06-12T17:05:35.635590Z",
|
667 |
+
"iopub.status.idle": "2025-06-12T17:05:35.670246Z",
|
668 |
+
"shell.execute_reply": "2025-06-12T17:05:35.669407Z",
|
669 |
+
"shell.execute_reply.started": "2025-06-12T17:05:35.635795Z"
|
670 |
+
},
|
671 |
+
"trusted": true
|
672 |
+
},
|
673 |
+
"outputs": [
|
674 |
+
{
|
675 |
+
"name": "stdout",
|
676 |
+
"output_type": "stream",
|
677 |
+
"text": [
|
678 |
+
"CUDA Available: True\n",
|
679 |
+
"Device Name: Tesla T4\n",
|
680 |
+
"Model is on: cuda:0\n"
|
681 |
+
]
|
682 |
+
}
|
683 |
+
],
|
684 |
+
"source": [
|
685 |
+
"import torch\n",
|
686 |
+
"\n",
|
687 |
+
"print(\"CUDA Available:\", torch.cuda.is_available())\n",
|
688 |
+
"print(\"Device Name:\", torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"CPU only\")\n",
|
689 |
+
"print(\"Model is on:\", next(model.parameters()).device)\n"
|
690 |
+
]
|
691 |
+
},
|
692 |
+
{
|
693 |
+
"cell_type": "code",
|
694 |
+
"execution_count": 10,
|
695 |
+
"metadata": {
|
696 |
+
"execution": {
|
697 |
+
"iopub.execute_input": "2025-06-12T17:05:35.671585Z",
|
698 |
+
"iopub.status.busy": "2025-06-12T17:05:35.671257Z",
|
699 |
+
"iopub.status.idle": "2025-06-12T17:05:39.563479Z",
|
700 |
+
"shell.execute_reply": "2025-06-12T17:05:39.562626Z",
|
701 |
+
"shell.execute_reply.started": "2025-06-12T17:05:35.671526Z"
|
702 |
+
},
|
703 |
+
"trusted": true
|
704 |
+
},
|
705 |
+
"outputs": [
|
706 |
+
{
|
707 |
+
"name": "stdout",
|
708 |
+
"output_type": "stream",
|
709 |
+
"text": [
|
710 |
+
"\n",
|
711 |
+
"--- Dialogue ---\n",
|
712 |
+
"\n",
|
713 |
+
"#Person1#: Ms. Dawson, I need you to take a dictation for me.\n",
|
714 |
+
"#Person2#: Yes, sir...\n",
|
715 |
+
"#Person1#: This should go out as an intra-office memorandum to all employees by this afternoon. Are you ready?\n",
|
716 |
+
"#Person2#: Yes, sir. Go ahead.\n",
|
717 |
+
"#Person1#: Attention all staff... Effective immediately, all office communications are restricted to email correspondence and official memos. The use of Instant Message programs by employees during working hours is strictly prohibited.\n",
|
718 |
+
"#Person2#: Sir, does this apply to intra-office communications only? Or will it also restrict external communications?\n",
|
719 |
+
"#Person1#: It should apply to all communications, not only in this office between employees, but also any outside communications.\n",
|
720 |
+
"#Person2#: But sir, many employees use Instant Messaging to communicate with their clients.\n",
|
721 |
+
"#Person1#: They will just have to change their communication methods. I don't want any - one using Instant Messaging in this office. It wastes too much time! Now, please continue with the memo. Where were we?\n",
|
722 |
+
"#Person2#: This applies to internal and external communications.\n",
|
723 |
+
"#Person1#: Yes. Any employee who persists in using Instant Messaging will first receive a warning and be placed on probation. At second offense, the employee will face termination. Any questions regarding this new policy may be directed to department heads.\n",
|
724 |
+
"#Person2#: Is that all?\n",
|
725 |
+
"#Person1#: Yes. Please get this memo typed up and distributed to all employees before 4 pm.\n",
|
726 |
+
"\n",
|
727 |
+
"--- Summary ---\n",
|
728 |
+
"\n",
|
729 |
+
" The use of Instant Message programs by employees during working hours is strictly prohibited . Any employee who persists in using Instant Messaging will first receive a warning and be placed on probation . At second offense, the employee will face termination . Any questions regarding this new policy may be directed to department heads .\n"
|
730 |
+
]
|
731 |
+
}
|
732 |
+
],
|
733 |
+
"source": [
|
734 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
735 |
+
"from datasets import load_dataset\n",
|
736 |
+
"import torch\n",
|
737 |
+
"\n",
|
738 |
+
"# 1. Load dataset\n",
|
739 |
+
"ds = load_dataset(\"knkarthick/dialogsum\")\n",
|
740 |
+
"test_dialogues = ds[\"test\"][\"dialogue\"]\n",
|
741 |
+
"\n",
|
742 |
+
"# 2. Load a lightweight pretrained summarization model\n",
|
743 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
744 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
745 |
+
"\n",
|
746 |
+
"# 3. Move model to device (GPU if available)\n",
|
747 |
+
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
|
748 |
+
"model.to(device)\n",
|
749 |
+
"model.eval()\n",
|
750 |
+
"\n",
|
751 |
+
"# 4. Pick a test example to summarize\n",
|
752 |
+
"example_dialogue = test_dialogues[0]\n",
|
753 |
+
"\n",
|
754 |
+
"# 5. Tokenize and summarize\n",
|
755 |
+
"inputs = tokenizer(example_dialogue, return_tensors=\"pt\", max_length=1024, truncation=True).to(device)\n",
|
756 |
+
"summary_ids = model.generate(inputs[\"input_ids\"], max_length=128, num_beams=4, early_stopping=True)\n",
|
757 |
+
"summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\n",
|
758 |
+
"\n",
|
759 |
+
"# 6. Output\n",
|
760 |
+
"print(\"\\n--- Dialogue ---\\n\")\n",
|
761 |
+
"print(example_dialogue)\n",
|
762 |
+
"\n",
|
763 |
+
"print(\"\\n--- Summary ---\\n\")\n",
|
764 |
+
"print(summary)\n"
|
765 |
+
]
|
766 |
+
},
|
767 |
+
{
|
768 |
+
"cell_type": "code",
|
769 |
+
"execution_count": 11,
|
770 |
+
"metadata": {
|
771 |
+
"execution": {
|
772 |
+
"iopub.execute_input": "2025-06-12T17:05:39.564906Z",
|
773 |
+
"iopub.status.busy": "2025-06-12T17:05:39.564625Z",
|
774 |
+
"iopub.status.idle": "2025-06-12T17:05:43.195555Z",
|
775 |
+
"shell.execute_reply": "2025-06-12T17:05:43.194726Z",
|
776 |
+
"shell.execute_reply.started": "2025-06-12T17:05:39.564883Z"
|
777 |
+
},
|
778 |
+
"trusted": true
|
779 |
+
},
|
780 |
+
"outputs": [
|
781 |
+
{
|
782 |
+
"name": "stderr",
|
783 |
+
"output_type": "stream",
|
784 |
+
"text": [
|
785 |
+
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
786 |
+
"To disable this warning, you can either:\n",
|
787 |
+
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
788 |
+
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
789 |
+
]
|
790 |
+
},
|
791 |
+
{
|
792 |
+
"name": "stdout",
|
793 |
+
"output_type": "stream",
|
794 |
+
"text": [
|
795 |
+
"Collecting evaluate\n",
|
796 |
+
" Downloading evaluate-0.4.3-py3-none-any.whl.metadata (9.2 kB)\n",
|
797 |
+
"Requirement already satisfied: datasets>=2.0.0 in /usr/local/lib/python3.11/dist-packages (from evaluate) (3.6.0)\n",
|
798 |
+
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.11/dist-packages (from evaluate) (1.26.4)\n",
|
799 |
+
"Requirement already satisfied: dill in /usr/local/lib/python3.11/dist-packages (from evaluate) (0.3.8)\n",
|
800 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (from evaluate) (2.2.3)\n",
|
801 |
+
"Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.11/dist-packages (from evaluate) (2.32.3)\n",
|
802 |
+
"Requirement already satisfied: tqdm>=4.62.1 in /usr/local/lib/python3.11/dist-packages (from evaluate) (4.67.1)\n",
|
803 |
+
"Requirement already satisfied: xxhash in /usr/local/lib/python3.11/dist-packages (from evaluate) (3.5.0)\n",
|
804 |
+
"Requirement already satisfied: multiprocess in /usr/local/lib/python3.11/dist-packages (from evaluate) (0.70.16)\n",
|
805 |
+
"Requirement already satisfied: fsspec>=2021.05.0 in /usr/local/lib/python3.11/dist-packages (from fsspec[http]>=2021.05.0->evaluate) (2025.3.0)\n",
|
806 |
+
"Requirement already satisfied: huggingface-hub>=0.7.0 in /usr/local/lib/python3.11/dist-packages (from evaluate) (0.31.1)\n",
|
807 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from evaluate) (25.0)\n",
|
808 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from datasets>=2.0.0->evaluate) (3.18.0)\n",
|
809 |
+
"Requirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.0.0->evaluate) (19.0.1)\n",
|
810 |
+
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from datasets>=2.0.0->evaluate) (6.0.2)\n",
|
811 |
+
"Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /usr/local/lib/python3.11/dist-packages (from fsspec[http]>=2021.05.0->evaluate) (3.11.18)\n",
|
812 |
+
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.7.0->evaluate) (4.13.2)\n",
|
813 |
+
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.7.0->evaluate) (1.1.0)\n",
|
814 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (1.3.8)\n",
|
815 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (1.2.4)\n",
|
816 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (0.1.1)\n",
|
817 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (2025.1.0)\n",
|
818 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (2022.1.0)\n",
|
819 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy>=1.17->evaluate) (2.4.1)\n",
|
820 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.19.0->evaluate) (3.4.2)\n",
|
821 |
+
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.19.0->evaluate) (3.10)\n",
|
822 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.19.0->evaluate) (2.4.0)\n",
|
823 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.19.0->evaluate) (2025.4.26)\n",
|
824 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas->evaluate) (2.9.0.post0)\n",
|
825 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas->evaluate) (2025.2)\n",
|
826 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas->evaluate) (2025.2)\n",
|
827 |
+
"Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (2.6.1)\n",
|
828 |
+
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (1.3.2)\n",
|
829 |
+
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (25.3.0)\n",
|
830 |
+
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (1.6.0)\n",
|
831 |
+
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (6.4.3)\n",
|
832 |
+
"Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (0.3.1)\n",
|
833 |
+
"Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>=2021.05.0->evaluate) (1.20.0)\n",
|
834 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas->evaluate) (1.17.0)\n",
|
835 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.17->evaluate) (2024.2.0)\n",
|
836 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy>=1.17->evaluate) (2022.1.0)\n",
|
837 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy>=1.17->evaluate) (1.3.0)\n",
|
838 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy>=1.17->evaluate) (2024.2.0)\n",
|
839 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy>=1.17->evaluate) (2024.2.0)\n",
|
840 |
+
"Downloading evaluate-0.4.3-py3-none-any.whl (84 kB)\n",
|
841 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m84.0/84.0 kB\u001b[0m \u001b[31m3.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
842 |
+
"\u001b[?25hInstalling collected packages: evaluate\n",
|
843 |
+
"Successfully installed evaluate-0.4.3\n"
|
844 |
+
]
|
845 |
+
}
|
846 |
+
],
|
847 |
+
"source": [
|
848 |
+
"!pip install evaluate\n"
|
849 |
+
]
|
850 |
+
},
|
851 |
+
{
|
852 |
+
"cell_type": "code",
|
853 |
+
"execution_count": 12,
|
854 |
+
"metadata": {
|
855 |
+
"collapsed": true,
|
856 |
+
"execution": {
|
857 |
+
"iopub.execute_input": "2025-06-12T17:05:43.196795Z",
|
858 |
+
"iopub.status.busy": "2025-06-12T17:05:43.196573Z",
|
859 |
+
"iopub.status.idle": "2025-06-12T17:05:56.234877Z",
|
860 |
+
"shell.execute_reply": "2025-06-12T17:05:56.234133Z",
|
861 |
+
"shell.execute_reply.started": "2025-06-12T17:05:43.196773Z"
|
862 |
+
},
|
863 |
+
"jupyter": {
|
864 |
+
"outputs_hidden": true
|
865 |
+
},
|
866 |
+
"trusted": true
|
867 |
+
},
|
868 |
+
"outputs": [
|
869 |
+
{
|
870 |
+
"name": "stderr",
|
871 |
+
"output_type": "stream",
|
872 |
+
"text": [
|
873 |
+
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
874 |
+
"To disable this warning, you can either:\n",
|
875 |
+
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
876 |
+
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
877 |
+
]
|
878 |
+
},
|
879 |
+
{
|
880 |
+
"name": "stdout",
|
881 |
+
"output_type": "stream",
|
882 |
+
"text": [
|
883 |
+
"Collecting rouge_score\n",
|
884 |
+
" Downloading rouge_score-0.1.2.tar.gz (17 kB)\n",
|
885 |
+
" Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
886 |
+
"Requirement already satisfied: absl-py in /usr/local/lib/python3.11/dist-packages (from rouge_score) (1.4.0)\n",
|
887 |
+
"Requirement already satisfied: nltk in /usr/local/lib/python3.11/dist-packages (from rouge_score) (3.9.1)\n",
|
888 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (from rouge_score) (1.26.4)\n",
|
889 |
+
"Requirement already satisfied: six>=1.14.0 in /usr/local/lib/python3.11/dist-packages (from rouge_score) (1.17.0)\n",
|
890 |
+
"Requirement already satisfied: click in /usr/local/lib/python3.11/dist-packages (from nltk->rouge_score) (8.1.8)\n",
|
891 |
+
"Requirement already satisfied: joblib in /usr/local/lib/python3.11/dist-packages (from nltk->rouge_score) (1.5.0)\n",
|
892 |
+
"Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.11/dist-packages (from nltk->rouge_score) (2024.11.6)\n",
|
893 |
+
"Requirement already satisfied: tqdm in /usr/local/lib/python3.11/dist-packages (from nltk->rouge_score) (4.67.1)\n",
|
894 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (1.3.8)\n",
|
895 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (1.2.4)\n",
|
896 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (0.1.1)\n",
|
897 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (2025.1.0)\n",
|
898 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (2022.1.0)\n",
|
899 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy->rouge_score) (2.4.1)\n",
|
900 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy->rouge_score) (2024.2.0)\n",
|
901 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy->rouge_score) (2022.1.0)\n",
|
902 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy->rouge_score) (1.3.0)\n",
|
903 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy->rouge_score) (2024.2.0)\n",
|
904 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy->rouge_score) (2024.2.0)\n",
|
905 |
+
"Building wheels for collected packages: rouge_score\n",
|
906 |
+
" Building wheel for rouge_score (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
907 |
+
" Created wheel for rouge_score: filename=rouge_score-0.1.2-py3-none-any.whl size=24934 sha256=b66536c4a57b6d602a59f82536abf9cdb3d83ae75b752f815f298def1a2891ee\n",
|
908 |
+
" Stored in directory: /root/.cache/pip/wheels/1e/19/43/8a442dc83660ca25e163e1bd1f89919284ab0d0c1475475148\n",
|
909 |
+
"Successfully built rouge_score\n",
|
910 |
+
"Installing collected packages: rouge_score\n",
|
911 |
+
"Successfully installed rouge_score-0.1.2\n"
|
912 |
+
]
|
913 |
+
}
|
914 |
+
],
|
915 |
+
"source": [
|
916 |
+
"!pip install rouge_score"
|
917 |
+
]
|
918 |
+
},
|
919 |
+
{
|
920 |
+
"cell_type": "code",
|
921 |
+
"execution_count": 13,
|
922 |
+
"metadata": {
|
923 |
+
"execution": {
|
924 |
+
"iopub.execute_input": "2025-06-12T17:05:56.236436Z",
|
925 |
+
"iopub.status.busy": "2025-06-12T17:05:56.236159Z",
|
926 |
+
"iopub.status.idle": "2025-06-12T17:05:57.972541Z",
|
927 |
+
"shell.execute_reply": "2025-06-12T17:05:57.971744Z",
|
928 |
+
"shell.execute_reply.started": "2025-06-12T17:05:56.236413Z"
|
929 |
+
},
|
930 |
+
"trusted": true
|
931 |
+
},
|
932 |
+
"outputs": [
|
933 |
+
{
|
934 |
+
"data": {
|
935 |
+
"application/vnd.jupyter.widget-view+json": {
|
936 |
+
"model_id": "0a0de9e1e5ee4a9d9c1d705fad7fc03d",
|
937 |
+
"version_major": 2,
|
938 |
+
"version_minor": 0
|
939 |
+
},
|
940 |
+
"text/plain": [
|
941 |
+
"Downloading builder script: 0%| | 0.00/6.27k [00:00<?, ?B/s]"
|
942 |
+
]
|
943 |
+
},
|
944 |
+
"metadata": {},
|
945 |
+
"output_type": "display_data"
|
946 |
+
},
|
947 |
+
{
|
948 |
+
"name": "stdout",
|
949 |
+
"output_type": "stream",
|
950 |
+
"text": [
|
951 |
+
"{'rouge1': 0.6666666666666666, 'rouge2': 0.42105263157894735, 'rougeL': 0.6666666666666666, 'rougeLsum': 0.6666666666666666}\n"
|
952 |
+
]
|
953 |
+
}
|
954 |
+
],
|
955 |
+
"source": [
|
956 |
+
"import evaluate\n",
|
957 |
+
"\n",
|
958 |
+
"rouge = evaluate.load(\"rouge\")\n",
|
959 |
+
"\n",
|
960 |
+
"predictions = [\"The use of Instant Messaging is prohibited...\"]\n",
|
961 |
+
"references = [\"The use of Instant Messaging programs by employees during working hours is strictly prohibited...\"]\n",
|
962 |
+
"\n",
|
963 |
+
"results = rouge.compute(predictions=predictions, references=references)\n",
|
964 |
+
"print(results)\n"
|
965 |
+
]
|
966 |
+
},
|
967 |
+
{
|
968 |
+
"cell_type": "code",
|
969 |
+
"execution_count": 16,
|
970 |
+
"metadata": {
|
971 |
+
"execution": {
|
972 |
+
"iopub.execute_input": "2025-06-12T17:19:07.923722Z",
|
973 |
+
"iopub.status.busy": "2025-06-12T17:19:07.922912Z",
|
974 |
+
"iopub.status.idle": "2025-06-12T17:19:07.938514Z",
|
975 |
+
"shell.execute_reply": "2025-06-12T17:19:07.937755Z",
|
976 |
+
"shell.execute_reply.started": "2025-06-12T17:19:07.923698Z"
|
977 |
+
},
|
978 |
+
"trusted": true
|
979 |
+
},
|
980 |
+
"outputs": [
|
981 |
+
{
|
982 |
+
"data": {
|
983 |
+
"application/vnd.jupyter.widget-view+json": {
|
984 |
+
"model_id": "a89c2a8663494ab0a27750205864dc51",
|
985 |
+
"version_major": 2,
|
986 |
+
"version_minor": 0
|
987 |
+
},
|
988 |
+
"text/plain": [
|
989 |
+
"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
|
990 |
+
]
|
991 |
+
},
|
992 |
+
"metadata": {},
|
993 |
+
"output_type": "display_data"
|
994 |
+
}
|
995 |
+
],
|
996 |
+
"source": [
|
997 |
+
"from huggingface_hub import notebook_login\n",
|
998 |
+
"notebook_login()\n"
|
999 |
+
]
|
1000 |
+
},
|
1001 |
+
{
|
1002 |
+
"cell_type": "code",
|
1003 |
+
"execution_count": 19,
|
1004 |
+
"metadata": {
|
1005 |
+
"collapsed": true,
|
1006 |
+
"execution": {
|
1007 |
+
"iopub.execute_input": "2025-06-12T17:23:13.786175Z",
|
1008 |
+
"iopub.status.busy": "2025-06-12T17:23:13.785509Z",
|
1009 |
+
"iopub.status.idle": "2025-06-12T17:23:30.231846Z",
|
1010 |
+
"shell.execute_reply": "2025-06-12T17:23:30.231079Z",
|
1011 |
+
"shell.execute_reply.started": "2025-06-12T17:23:13.786150Z"
|
1012 |
+
},
|
1013 |
+
"jupyter": {
|
1014 |
+
"outputs_hidden": true
|
1015 |
+
},
|
1016 |
+
"trusted": true
|
1017 |
+
},
|
1018 |
+
"outputs": [
|
1019 |
+
{
|
1020 |
+
"name": "stderr",
|
1021 |
+
"output_type": "stream",
|
1022 |
+
"text": [
|
1023 |
+
"/usr/local/lib/python3.11/dist-packages/transformers/modeling_utils.py:3339: UserWarning: Moving the following attributes in the config to the generation config: {'max_length': 142, 'min_length': 56, 'early_stopping': True, 'num_beams': 4, 'length_penalty': 2.0, 'no_repeat_ngram_size': 3, 'forced_bos_token_id': 0}. You are seeing this warning because you've set generation parameters in the model config, as opposed to in the generation config.\n",
|
1024 |
+
" warnings.warn(\n"
|
1025 |
+
]
|
1026 |
+
},
|
1027 |
+
{
|
1028 |
+
"data": {
|
1029 |
+
"application/vnd.jupyter.widget-view+json": {
|
1030 |
+
"model_id": "ed9e01e36c42436fb8e4be77e3b51552",
|
1031 |
+
"version_major": 2,
|
1032 |
+
"version_minor": 0
|
1033 |
+
},
|
1034 |
+
"text/plain": [
|
1035 |
+
"Uploading...: 0%| | 0.00/1.22G [00:00<?, ?B/s]"
|
1036 |
+
]
|
1037 |
+
},
|
1038 |
+
"metadata": {},
|
1039 |
+
"output_type": "display_data"
|
1040 |
+
},
|
1041 |
+
{
|
1042 |
+
"name": "stderr",
|
1043 |
+
"output_type": "stream",
|
1044 |
+
"text": [
|
1045 |
+
"No files have been modified since last commit. Skipping to prevent empty commit.\n",
|
1046 |
+
"No files have been modified since last commit. Skipping to prevent empty commit.\n"
|
1047 |
+
]
|
1048 |
+
},
|
1049 |
+
{
|
1050 |
+
"data": {
|
1051 |
+
"text/plain": [
|
1052 |
+
"CommitInfo(commit_url='https://huggingface.co/zahraa12355/tiny-distilbart-dialogsum/commit/002c41446a8368246986e3bd3175e7e1f2363e59', commit_message='Upload tokenizer', commit_description='', oid='002c41446a8368246986e3bd3175e7e1f2363e59', pr_url=None, repo_url=RepoUrl('https://huggingface.co/zahraa12355/tiny-distilbart-dialogsum', endpoint='https://huggingface.co', repo_type='model', repo_id='zahraa12355/tiny-distilbart-dialogsum'), pr_revision=None, pr_num=None)"
|
1053 |
+
]
|
1054 |
+
},
|
1055 |
+
"execution_count": 19,
|
1056 |
+
"metadata": {},
|
1057 |
+
"output_type": "execute_result"
|
1058 |
+
}
|
1059 |
+
],
|
1060 |
+
"source": [
|
1061 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
1062 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1063 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1064 |
+
"repo_id = \"zahraa12355/tiny-distilbart-dialogsum\"\n",
|
1065 |
+
"model.push_to_hub(repo_id)\n",
|
1066 |
+
"tokenizer.push_to_hub(repo_id)\n"
|
1067 |
+
]
|
1068 |
+
},
|
1069 |
+
{
|
1070 |
+
"cell_type": "code",
|
1071 |
+
"execution_count": 21,
|
1072 |
+
"metadata": {
|
1073 |
+
"collapsed": true,
|
1074 |
+
"execution": {
|
1075 |
+
"iopub.execute_input": "2025-06-12T17:28:01.717930Z",
|
1076 |
+
"iopub.status.busy": "2025-06-12T17:28:01.717304Z",
|
1077 |
+
"iopub.status.idle": "2025-06-12T17:28:10.952330Z",
|
1078 |
+
"shell.execute_reply": "2025-06-12T17:28:10.951482Z",
|
1079 |
+
"shell.execute_reply.started": "2025-06-12T17:28:01.717908Z"
|
1080 |
+
},
|
1081 |
+
"jupyter": {
|
1082 |
+
"outputs_hidden": true
|
1083 |
+
},
|
1084 |
+
"trusted": true
|
1085 |
+
},
|
1086 |
+
"outputs": [
|
1087 |
+
{
|
1088 |
+
"name": "stderr",
|
1089 |
+
"output_type": "stream",
|
1090 |
+
"text": [
|
1091 |
+
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
1092 |
+
"To disable this warning, you can either:\n",
|
1093 |
+
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
1094 |
+
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
1095 |
+
]
|
1096 |
+
},
|
1097 |
+
{
|
1098 |
+
"name": "stdout",
|
1099 |
+
"output_type": "stream",
|
1100 |
+
"text": [
|
1101 |
+
"Collecting gradio\n",
|
1102 |
+
" Downloading gradio-5.33.2-py3-none-any.whl.metadata (16 kB)\n",
|
1103 |
+
"Requirement already satisfied: aiofiles<25.0,>=22.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (22.1.0)\n",
|
1104 |
+
"Requirement already satisfied: anyio<5.0,>=3.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (4.9.0)\n",
|
1105 |
+
"Collecting fastapi<1.0,>=0.115.2 (from gradio)\n",
|
1106 |
+
" Downloading fastapi-0.115.12-py3-none-any.whl.metadata (27 kB)\n",
|
1107 |
+
"Collecting ffmpy (from gradio)\n",
|
1108 |
+
" Downloading ffmpy-0.6.0-py3-none-any.whl.metadata (2.9 kB)\n",
|
1109 |
+
"Collecting gradio-client==1.10.3 (from gradio)\n",
|
1110 |
+
" Downloading gradio_client-1.10.3-py3-none-any.whl.metadata (7.1 kB)\n",
|
1111 |
+
"Collecting groovy~=0.1 (from gradio)\n",
|
1112 |
+
" Downloading groovy-0.1.2-py3-none-any.whl.metadata (6.1 kB)\n",
|
1113 |
+
"Requirement already satisfied: httpx>=0.24.1 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.28.1)\n",
|
1114 |
+
"Requirement already satisfied: huggingface-hub>=0.28.1 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.31.1)\n",
|
1115 |
+
"Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.1.6)\n",
|
1116 |
+
"Requirement already satisfied: markupsafe<4.0,>=2.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.0.2)\n",
|
1117 |
+
"Requirement already satisfied: numpy<3.0,>=1.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (1.26.4)\n",
|
1118 |
+
"Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (3.10.16)\n",
|
1119 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from gradio) (25.0)\n",
|
1120 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (2.2.3)\n",
|
1121 |
+
"Requirement already satisfied: pillow<12.0,>=8.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (11.1.0)\n",
|
1122 |
+
"Requirement already satisfied: pydantic<2.12,>=2.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (2.11.4)\n",
|
1123 |
+
"Requirement already satisfied: pydub in /usr/local/lib/python3.11/dist-packages (from gradio) (0.25.1)\n",
|
1124 |
+
"Collecting python-multipart>=0.0.18 (from gradio)\n",
|
1125 |
+
" Downloading python_multipart-0.0.20-py3-none-any.whl.metadata (1.8 kB)\n",
|
1126 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (6.0.2)\n",
|
1127 |
+
"Collecting ruff>=0.9.3 (from gradio)\n",
|
1128 |
+
" Downloading ruff-0.11.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (25 kB)\n",
|
1129 |
+
"Collecting safehttpx<0.2.0,>=0.1.6 (from gradio)\n",
|
1130 |
+
" Downloading safehttpx-0.1.6-py3-none-any.whl.metadata (4.2 kB)\n",
|
1131 |
+
"Collecting semantic-version~=2.0 (from gradio)\n",
|
1132 |
+
" Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\n",
|
1133 |
+
"Collecting starlette<1.0,>=0.40.0 (from gradio)\n",
|
1134 |
+
" Downloading starlette-0.47.0-py3-none-any.whl.metadata (6.2 kB)\n",
|
1135 |
+
"Collecting tomlkit<0.14.0,>=0.12.0 (from gradio)\n",
|
1136 |
+
" Downloading tomlkit-0.13.3-py3-none-any.whl.metadata (2.8 kB)\n",
|
1137 |
+
"Requirement already satisfied: typer<1.0,>=0.12 in /usr/local/lib/python3.11/dist-packages (from gradio) (0.15.2)\n",
|
1138 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.11/dist-packages (from gradio) (4.13.2)\n",
|
1139 |
+
"Collecting uvicorn>=0.14.0 (from gradio)\n",
|
1140 |
+
" Downloading uvicorn-0.34.3-py3-none-any.whl.metadata (6.5 kB)\n",
|
1141 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from gradio-client==1.10.3->gradio) (2025.3.0)\n",
|
1142 |
+
"Requirement already satisfied: websockets<16.0,>=10.0 in /usr/local/lib/python3.11/dist-packages (from gradio-client==1.10.3->gradio) (15.0.1)\n",
|
1143 |
+
"Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.11/dist-packages (from anyio<5.0,>=3.0->gradio) (3.10)\n",
|
1144 |
+
"Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.11/dist-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n",
|
1145 |
+
"Collecting starlette<1.0,>=0.40.0 (from gradio)\n",
|
1146 |
+
" Downloading starlette-0.46.2-py3-none-any.whl.metadata (6.2 kB)\n",
|
1147 |
+
"Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx>=0.24.1->gradio) (2025.4.26)\n",
|
1148 |
+
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx>=0.24.1->gradio) (1.0.7)\n",
|
1149 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
|
1150 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (3.18.0)\n",
|
1151 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (2.32.3)\n",
|
1152 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (4.67.1)\n",
|
1153 |
+
"Requirement already satisfied: hf-xet<2.0.0,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.28.1->gradio) (1.1.0)\n",
|
1154 |
+
"Requirement already satisfied: mkl_fft in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (1.3.8)\n",
|
1155 |
+
"Requirement already satisfied: mkl_random in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (1.2.4)\n",
|
1156 |
+
"Requirement already satisfied: mkl_umath in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (0.1.1)\n",
|
1157 |
+
"Requirement already satisfied: mkl in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2025.1.0)\n",
|
1158 |
+
"Requirement already satisfied: tbb4py in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2022.1.0)\n",
|
1159 |
+
"Requirement already satisfied: mkl-service in /usr/local/lib/python3.11/dist-packages (from numpy<3.0,>=1.0->gradio) (2.4.1)\n",
|
1160 |
+
"Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2.9.0.post0)\n",
|
1161 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2025.2)\n",
|
1162 |
+
"Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas<3.0,>=1.0->gradio) (2025.2)\n",
|
1163 |
+
"Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (0.7.0)\n",
|
1164 |
+
"Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (2.33.2)\n",
|
1165 |
+
"Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic<2.12,>=2.0->gradio) (0.4.0)\n",
|
1166 |
+
"Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (8.1.8)\n",
|
1167 |
+
"Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
|
1168 |
+
"Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.11/dist-packages (from typer<1.0,>=0.12->gradio) (14.0.0)\n",
|
1169 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.17.0)\n",
|
1170 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.11/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
|
1171 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.11/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.19.1)\n",
|
1172 |
+
"Requirement already satisfied: intel-openmp<2026,>=2024 in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.0->gradio) (2024.2.0)\n",
|
1173 |
+
"Requirement already satisfied: tbb==2022.* in /usr/local/lib/python3.11/dist-packages (from mkl->numpy<3.0,>=1.0->gradio) (2022.1.0)\n",
|
1174 |
+
"Requirement already satisfied: tcmlib==1.* in /usr/local/lib/python3.11/dist-packages (from tbb==2022.*->mkl->numpy<3.0,>=1.0->gradio) (1.3.0)\n",
|
1175 |
+
"Requirement already satisfied: intel-cmplr-lib-rt in /usr/local/lib/python3.11/dist-packages (from mkl_umath->numpy<3.0,>=1.0->gradio) (2024.2.0)\n",
|
1176 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.28.1->gradio) (3.4.2)\n",
|
1177 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->huggingface-hub>=0.28.1->gradio) (2.4.0)\n",
|
1178 |
+
"Requirement already satisfied: intel-cmplr-lib-ur==2024.2.0 in /usr/local/lib/python3.11/dist-packages (from intel-openmp<2026,>=2024->mkl->numpy<3.0,>=1.0->gradio) (2024.2.0)\n",
|
1179 |
+
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.11/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
|
1180 |
+
"Downloading gradio-5.33.2-py3-none-any.whl (54.3 MB)\n",
|
1181 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m54.3/54.3 MB\u001b[0m \u001b[31m33.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n",
|
1182 |
+
"\u001b[?25hDownloading gradio_client-1.10.3-py3-none-any.whl (323 kB)\n",
|
1183 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m323.6/323.6 kB\u001b[0m \u001b[31m24.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
1184 |
+
"\u001b[?25hDownloading fastapi-0.115.12-py3-none-any.whl (95 kB)\n",
|
1185 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m95.2/95.2 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
1186 |
+
"\u001b[?25hDownloading groovy-0.1.2-py3-none-any.whl (14 kB)\n",
|
1187 |
+
"Downloading python_multipart-0.0.20-py3-none-any.whl (24 kB)\n",
|
1188 |
+
"Downloading ruff-0.11.13-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB)\n",
|
1189 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.6/11.6 MB\u001b[0m \u001b[31m101.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m0:01\u001b[0m\n",
|
1190 |
+
"\u001b[?25hDownloading safehttpx-0.1.6-py3-none-any.whl (8.7 kB)\n",
|
1191 |
+
"Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
|
1192 |
+
"Downloading starlette-0.46.2-py3-none-any.whl (72 kB)\n",
|
1193 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m72.0/72.0 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
1194 |
+
"\u001b[?25hDownloading tomlkit-0.13.3-py3-none-any.whl (38 kB)\n",
|
1195 |
+
"Downloading uvicorn-0.34.3-py3-none-any.whl (62 kB)\n",
|
1196 |
+
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.4/62.4 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
1197 |
+
"\u001b[?25hDownloading ffmpy-0.6.0-py3-none-any.whl (5.5 kB)\n",
|
1198 |
+
"Installing collected packages: uvicorn, tomlkit, semantic-version, ruff, python-multipart, groovy, ffmpy, starlette, safehttpx, gradio-client, fastapi, gradio\n",
|
1199 |
+
"Successfully installed fastapi-0.115.12 ffmpy-0.6.0 gradio-5.33.2 gradio-client-1.10.3 groovy-0.1.2 python-multipart-0.0.20 ruff-0.11.13 safehttpx-0.1.6 semantic-version-2.10.0 starlette-0.46.2 tomlkit-0.13.3 uvicorn-0.34.3\n"
|
1200 |
+
]
|
1201 |
+
}
|
1202 |
+
],
|
1203 |
+
"source": [
|
1204 |
+
"!pip install gradio\n"
|
1205 |
+
]
|
1206 |
+
},
|
1207 |
+
{
|
1208 |
+
"cell_type": "code",
|
1209 |
+
"execution_count": 24,
|
1210 |
+
"metadata": {
|
1211 |
+
"execution": {
|
1212 |
+
"iopub.execute_input": "2025-06-12T17:41:26.920321Z",
|
1213 |
+
"iopub.status.busy": "2025-06-12T17:41:26.919582Z",
|
1214 |
+
"iopub.status.idle": "2025-06-12T17:41:29.615709Z",
|
1215 |
+
"shell.execute_reply": "2025-06-12T17:41:29.615166Z",
|
1216 |
+
"shell.execute_reply.started": "2025-06-12T17:41:26.920296Z"
|
1217 |
+
},
|
1218 |
+
"trusted": true
|
1219 |
+
},
|
1220 |
+
"outputs": [
|
1221 |
+
{
|
1222 |
+
"name": "stdout",
|
1223 |
+
"output_type": "stream",
|
1224 |
+
"text": [
|
1225 |
+
"* Running on local URL: http://127.0.0.1:7862\n",
|
1226 |
+
"It looks like you are running Gradio on a hosted Jupyter notebook, which requires `share=True`. Automatically setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
1227 |
+
"\n",
|
1228 |
+
"* Running on public URL: https://49b0cf98fc551a8610.gradio.live\n",
|
1229 |
+
"\n",
|
1230 |
+
"This share link expires in 1 week. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"
|
1231 |
+
]
|
1232 |
+
},
|
1233 |
+
{
|
1234 |
+
"data": {
|
1235 |
+
"text/html": [
|
1236 |
+
"<div><iframe src=\"https://49b0cf98fc551a8610.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
1237 |
+
],
|
1238 |
+
"text/plain": [
|
1239 |
+
"<IPython.core.display.HTML object>"
|
1240 |
+
]
|
1241 |
+
},
|
1242 |
+
"metadata": {},
|
1243 |
+
"output_type": "display_data"
|
1244 |
+
},
|
1245 |
+
{
|
1246 |
+
"data": {
|
1247 |
+
"text/plain": []
|
1248 |
+
},
|
1249 |
+
"execution_count": 24,
|
1250 |
+
"metadata": {},
|
1251 |
+
"output_type": "execute_result"
|
1252 |
+
}
|
1253 |
+
],
|
1254 |
+
"source": [
|
1255 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
1256 |
+
"import gradio as gr\n",
|
1257 |
+
"\n",
|
1258 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1259 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1260 |
+
"\n",
|
1261 |
+
"def summarize_text(text):\n",
|
1262 |
+
" inputs = tokenizer(text, return_tensors=\"pt\", max_length=1024, truncation=True)\n",
|
1263 |
+
" summary_ids = model.generate(\n",
|
1264 |
+
" inputs[\"input_ids\"],\n",
|
1265 |
+
" attention_mask=inputs[\"attention_mask\"],\n",
|
1266 |
+
" max_length=100,\n",
|
1267 |
+
" min_length=20,\n",
|
1268 |
+
" length_penalty=2.0,\n",
|
1269 |
+
" num_beams=4,\n",
|
1270 |
+
" early_stopping=True,\n",
|
1271 |
+
" no_repeat_ngram_size=3\n",
|
1272 |
+
" )\n",
|
1273 |
+
" summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\n",
|
1274 |
+
" return summary\n",
|
1275 |
+
"\n",
|
1276 |
+
"iface = gr.Interface(\n",
|
1277 |
+
" fn=summarize_text,\n",
|
1278 |
+
" inputs=gr.Textbox(lines=5, label=\"Input Text\"),\n",
|
1279 |
+
" outputs=gr.Textbox(label=\"Summary\"),\n",
|
1280 |
+
" title=\"DistilBART Summarizer\",\n",
|
1281 |
+
" description=\"Summarize any input text using DistilBART fine-tuned model.\"\n",
|
1282 |
+
")\n",
|
1283 |
+
"\n",
|
1284 |
+
"iface.launch()\n"
|
1285 |
+
]
|
1286 |
+
},
|
1287 |
+
{
|
1288 |
+
"cell_type": "code",
|
1289 |
+
"execution_count": 27,
|
1290 |
+
"metadata": {
|
1291 |
+
"execution": {
|
1292 |
+
"iopub.execute_input": "2025-06-12T17:49:48.620290Z",
|
1293 |
+
"iopub.status.busy": "2025-06-12T17:49:48.620045Z",
|
1294 |
+
"iopub.status.idle": "2025-06-12T17:49:48.625290Z",
|
1295 |
+
"shell.execute_reply": "2025-06-12T17:49:48.624563Z",
|
1296 |
+
"shell.execute_reply.started": "2025-06-12T17:49:48.620275Z"
|
1297 |
+
},
|
1298 |
+
"trusted": true
|
1299 |
+
},
|
1300 |
+
"outputs": [
|
1301 |
+
{
|
1302 |
+
"name": "stdout",
|
1303 |
+
"output_type": "stream",
|
1304 |
+
"text": [
|
1305 |
+
"requirements.txt created!\n"
|
1306 |
+
]
|
1307 |
+
}
|
1308 |
+
],
|
1309 |
+
"source": [
|
1310 |
+
"requirements = \"\"\"\n",
|
1311 |
+
"transformers\n",
|
1312 |
+
"torch\n",
|
1313 |
+
"gradio\n",
|
1314 |
+
"\"\"\"\n",
|
1315 |
+
"\n",
|
1316 |
+
"with open(\"requirements.txt\", \"w\") as f:\n",
|
1317 |
+
" f.write(requirements)\n",
|
1318 |
+
"\n",
|
1319 |
+
"print(\"requirements.txt created!\")\n"
|
1320 |
+
]
|
1321 |
+
},
|
1322 |
+
{
|
1323 |
+
"cell_type": "code",
|
1324 |
+
"execution_count": 28,
|
1325 |
+
"metadata": {
|
1326 |
+
"execution": {
|
1327 |
+
"iopub.execute_input": "2025-06-12T17:50:44.573519Z",
|
1328 |
+
"iopub.status.busy": "2025-06-12T17:50:44.572783Z",
|
1329 |
+
"iopub.status.idle": "2025-06-12T17:50:44.578702Z",
|
1330 |
+
"shell.execute_reply": "2025-06-12T17:50:44.577872Z",
|
1331 |
+
"shell.execute_reply.started": "2025-06-12T17:50:44.573494Z"
|
1332 |
+
},
|
1333 |
+
"trusted": true
|
1334 |
+
},
|
1335 |
+
"outputs": [
|
1336 |
+
{
|
1337 |
+
"name": "stdout",
|
1338 |
+
"output_type": "stream",
|
1339 |
+
"text": [
|
1340 |
+
"app.py created!\n"
|
1341 |
+
]
|
1342 |
+
}
|
1343 |
+
],
|
1344 |
+
"source": [
|
1345 |
+
"code = '''\n",
|
1346 |
+
"import gradio as gr\n",
|
1347 |
+
"from transformers import AutoTokenizer, AutoModelForSeq2SeqLM\n",
|
1348 |
+
"\n",
|
1349 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1350 |
+
"model = AutoModelForSeq2SeqLM.from_pretrained(\"sshleifer/distilbart-cnn-12-6\")\n",
|
1351 |
+
"\n",
|
1352 |
+
"def summarize_text(text):\n",
|
1353 |
+
" inputs = tokenizer(text, return_tensors=\"pt\", max_length=1024, truncation=True)\n",
|
1354 |
+
" summary_ids = model.generate(\n",
|
1355 |
+
" inputs[\"input_ids\"],\n",
|
1356 |
+
" attention_mask=inputs[\"attention_mask\"],\n",
|
1357 |
+
" max_length=100,\n",
|
1358 |
+
" min_length=20,\n",
|
1359 |
+
" length_penalty=2.0,\n",
|
1360 |
+
" num_beams=4,\n",
|
1361 |
+
" early_stopping=True,\n",
|
1362 |
+
" no_repeat_ngram_size=3\n",
|
1363 |
+
" )\n",
|
1364 |
+
" summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)\n",
|
1365 |
+
" return summary\n",
|
1366 |
+
"\n",
|
1367 |
+
"iface = gr.Interface(\n",
|
1368 |
+
" fn=summarize_text,\n",
|
1369 |
+
" inputs=gr.Textbox(lines=5, label=\"Input Text\"),\n",
|
1370 |
+
" outputs=gr.Textbox(label=\"Summary\"),\n",
|
1371 |
+
" title=\"DistilBART Summarizer\",\n",
|
1372 |
+
" description=\"Summarize any input text using DistilBART fine-tuned model.\"\n",
|
1373 |
+
")\n",
|
1374 |
+
"\n",
|
1375 |
+
"iface.launch()\n",
|
1376 |
+
"'''\n",
|
1377 |
+
"\n",
|
1378 |
+
"with open(\"app.py\", \"w\") as f:\n",
|
1379 |
+
" f.write(code)\n",
|
1380 |
+
"\n",
|
1381 |
+
"print(\"app.py created!\")\n"
|
1382 |
+
]
|
1383 |
+
}
|
1384 |
+
],
|
1385 |
+
"metadata": {
|
1386 |
+
"kaggle": {
|
1387 |
+
"accelerator": "nvidiaTeslaT4",
|
1388 |
+
"dataSources": [],
|
1389 |
+
"dockerImageVersionId": 31040,
|
1390 |
+
"isGpuEnabled": true,
|
1391 |
+
"isInternetEnabled": true,
|
1392 |
+
"language": "python",
|
1393 |
+
"sourceType": "notebook"
|
1394 |
+
},
|
1395 |
+
"kernelspec": {
|
1396 |
+
"display_name": "Python 3",
|
1397 |
+
"language": "python",
|
1398 |
+
"name": "python3"
|
1399 |
+
},
|
1400 |
+
"language_info": {
|
1401 |
+
"codemirror_mode": {
|
1402 |
+
"name": "ipython",
|
1403 |
+
"version": 3
|
1404 |
+
},
|
1405 |
+
"file_extension": ".py",
|
1406 |
+
"mimetype": "text/x-python",
|
1407 |
+
"name": "python",
|
1408 |
+
"nbconvert_exporter": "python",
|
1409 |
+
"pygments_lexer": "ipython3",
|
1410 |
+
"version": "3.11.11"
|
1411 |
+
}
|
1412 |
+
},
|
1413 |
+
"nbformat": 4,
|
1414 |
+
"nbformat_minor": 4
|
1415 |
+
}
|