|
16 | 16 | "name": "stderr",
|
17 | 17 | "output_type": "stream",
|
18 | 18 | "text": [
|
19 |
| - "/opt/homebrew/Caskroom/miniforge/base/envs/torchtext39/lib/python3.9/site-packages/tqdm-4.64.0-py3.9.egg/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
| 19 | + "/data/home/jrcummings/miniconda/envs/torchtext/lib/python3.9/site-packages/tqdm-4.64.1-py3.9.egg/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
20 | 20 | " from .autonotebook import tqdm as notebook_tqdm\n"
|
21 | 21 | ]
|
22 | 22 | }
|
|
39 | 39 | },
|
40 | 40 | {
|
41 | 41 | "cell_type": "code",
|
42 |
| - "execution_count": 3, |
| 42 | + "execution_count": 5, |
43 | 43 | "metadata": {},
|
44 | 44 | "outputs": [
|
45 | 45 | {
|
46 | 46 | "name": "stderr",
|
47 | 47 | "output_type": "stream",
|
48 | 48 | "text": [
|
49 |
| - "/opt/homebrew/Caskroom/miniforge/base/envs/torchtext39/lib/python3.9/site-packages/transformers/models/t5/tokenization_t5.py:164: FutureWarning: This tokenizer was incorrectly instantiated with a model max length of 512 which will be corrected in Transformers v5.\n", |
| 49 | + "/data/home/jrcummings/miniconda/envs/torchtext/lib/python3.9/site-packages/transformers/models/t5/tokenization_t5.py:163: FutureWarning: This tokenizer was incorrectly instantiated with a model max length of 512 which will be corrected in Transformers v5.\n", |
50 | 50 | "For now, this behavior is kept to avoid breaking backwards compatibility when padding/encoding with `truncation is True`.\n",
|
51 | 51 | "- Be aware that you SHOULD NOT rely on t5-base automatically truncating your input to 512 when padding/encoding.\n",
|
52 | 52 | "- If you want to encode/pad to sequences longer than 512 you can either instantiate this tokenizer with `model_max_length` or pass `max_length` when encoding/padding.\n",
|
|
74 | 74 | },
|
75 | 75 | {
|
76 | 76 | "cell_type": "code",
|
77 |
| - "execution_count": 4, |
| 77 | + "execution_count": 6, |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [ |
| 80 | + { |
| 81 | + "name": "stdout", |
| 82 | + "output_type": "stream", |
| 83 | + "text": [ |
| 84 | + "['a dog is good for you. studies have shown that dog ownership is good for your overall health and well-being.']\n" |
| 85 | + ] |
| 86 | + } |
| 87 | + ], |
| 88 | + "source": [ |
| 89 | + "# Testing HuggingFace's T5 w/ Beam Search\n", |
| 90 | + "tokens = generative_hf_t5.generate(test_sequence_tk, max_len=100, pad_idx=t5.config.pad_token_id, num_beams=5, beam_size_token=t5.config.vocab_size)\n", |
| 91 | + "print(t5_tokenizer.batch_decode(tokens, skip_special_tokens=True))" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 7, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [ |
| 99 | + { |
| 100 | + "name": "stdout", |
| 101 | + "output_type": "stream", |
| 102 | + "text": [ |
| 103 | + "['a dog is good for you. studies have shown that dog ownership is good for your overall health and well-being.'] 9.786320924758911\n", |
| 104 | + "['studies have shown that owning a dog is good for you. studies have shown that owning a dog is good for you.'] 1.3000121116638184\n" |
| 105 | + ] |
| 106 | + } |
| 107 | + ], |
| 108 | + "source": [ |
| 109 | + "# Testing Decoding Speed HuggingFace's T5 w/ TorchText Beam Search vs. HuggingFace Beam Search\n", |
| 110 | + "import time\n", |
| 111 | + "\n", |
| 112 | + "start = time.time()\n", |
| 113 | + "tokens = generative_hf_t5.generate(test_sequence_tk, max_len=100, pad_idx=t5.config.pad_token_id, num_beams=5, beam_size_token=t5.config.vocab_size)\n", |
| 114 | + "end = time.time()\n", |
| 115 | + "print(t5_tokenizer.batch_decode(tokens, skip_special_tokens=True), end - start)\n", |
| 116 | + "\n", |
| 117 | + "start = time.time()\n", |
| 118 | + "tokens = t5.generate(test_sequence_tk, max_length=100, num_beams=5, do_sample=False)\n", |
| 119 | + "end = time.time()\n", |
| 120 | + "print(t5_tokenizer.batch_decode(tokens, skip_special_tokens=True), end - start)" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "code", |
| 125 | + "execution_count": 8, |
78 | 126 | "metadata": {},
|
79 | 127 | "outputs": [
|
80 | 128 | {
|
|
99 | 147 | },
|
100 | 148 | {
|
101 | 149 | "cell_type": "code",
|
102 |
| - "execution_count": 5, |
| 150 | + "execution_count": 9, |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [ |
| 153 | + { |
| 154 | + "name": "stdout", |
| 155 | + "output_type": "stream", |
| 156 | + "text": [ |
| 157 | + "['Nearly. PG&E scheduled the blackouts in response to forecasts for high winds amid dry conditions.']\n" |
| 158 | + ] |
| 159 | + } |
| 160 | + ], |
| 161 | + "source": [ |
| 162 | + "tokens = generative_hf_bart.generate(test_sequence_tk, max_len=20, pad_idx=bart.config.pad_token_id, num_beams=5, beam_size_token=bart.config.vocab_size)\n", |
| 163 | + "print(bart_tokenizer.batch_decode(tokens, skip_special_tokens=True))\n" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "code", |
| 168 | + "execution_count": 10, |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [ |
| 171 | + { |
| 172 | + "name": "stdout", |
| 173 | + "output_type": "stream", |
| 174 | + "text": [ |
| 175 | + "['PG&E scheduled the blackouts in response to forecasts for high winds amid dry conditions. The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by the shutoffs. The blackouts are expected to last through at least midday tomorrow. to be affected by the shutoffs which were expected to last through at least midday tomorrow. to be affected by the shutoffs which were expected to last through at least midday tomorrow. to be affected by the'] 58.09997892379761\n", |
| 176 | + "['PG&E scheduled the blackouts in response to forecasts for high winds amid dry conditions. The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by the shutoffs. The blackouts were expected to last through at least midday tomorrow.'] 2.456479787826538\n" |
| 177 | + ] |
| 178 | + } |
| 179 | + ], |
| 180 | + "source": [ |
| 181 | + "# Testing Decoding Speed HuggingFace's BART w/ TorchText Beam Search vs. HuggingFace Beam Search\n", |
| 182 | + "import time\n", |
| 183 | + "\n", |
| 184 | + "start = time.time()\n", |
| 185 | + "tokens = generative_hf_bart.generate(test_sequence_tk, max_len=100, pad_idx=t5.config.pad_token_id, num_beams=5, eos_score=1.0, beam_size_token=t5.config.vocab_size)\n", |
| 186 | + "end = time.time()\n", |
| 187 | + "print(bart_tokenizer.batch_decode(tokens, skip_special_tokens=True), end - start)\n", |
| 188 | + "\n", |
| 189 | + "start = time.time()\n", |
| 190 | + "tokens = bart.generate(test_sequence_tk, max_length=100, num_beams=5, do_sample=False)\n", |
| 191 | + "end = time.time()\n", |
| 192 | + "print(bart_tokenizer.batch_decode(tokens, skip_special_tokens=True), end - start)" |
| 193 | + ] |
| 194 | + }, |
| 195 | + { |
| 196 | + "cell_type": "code", |
| 197 | + "execution_count": 3, |
103 | 198 | "metadata": {},
|
104 | 199 | "outputs": [
|
105 | 200 | {
|
|
119 | 214 | "tokens = generative_hf_gpt2.generate(test_sequence_tk, max_len=20, pad_idx=gpt2.config.pad_token_id)\n",
|
120 | 215 | "print(gpt2_tokenizer.batch_decode(tokens, skip_special_tokens=True))"
|
121 | 216 | ]
|
| 217 | + }, |
| 218 | + { |
| 219 | + "cell_type": "code", |
| 220 | + "execution_count": 4, |
| 221 | + "metadata": {}, |
| 222 | + "outputs": [ |
| 223 | + { |
| 224 | + "name": "stdout", |
| 225 | + "output_type": "stream", |
| 226 | + "text": [ |
| 227 | + "['I enjoy walking with my cute dog,\" says Kelli Williams-Petersen. The dog loves it so much, that when she']\n" |
| 228 | + ] |
| 229 | + } |
| 230 | + ], |
| 231 | + "source": [ |
| 232 | + "tokens = generative_hf_gpt2.generate(test_sequence_tk, max_len=20, pad_idx=gpt2.config.pad_token_id, num_beams=5, beam_size_token=gpt2.config.vocab_size)\n", |
| 233 | + "print(gpt2_tokenizer.batch_decode(tokens, skip_special_tokens=True))" |
| 234 | + ] |
122 | 235 | }
|
123 | 236 | ],
|
124 | 237 | "metadata": {
|
125 | 238 | "kernelspec": {
|
126 |
| - "display_name": "Python 3.9.13 ('torchtext39')", |
| 239 | + "display_name": "torchtext", |
127 | 240 | "language": "python",
|
128 | 241 | "name": "python3"
|
129 | 242 | },
|
|
137 | 250 | "name": "python",
|
138 | 251 | "nbconvert_exporter": "python",
|
139 | 252 | "pygments_lexer": "ipython3",
|
140 |
| - "version": "3.9.13" |
| 253 | + "version": "3.9.15" |
141 | 254 | },
|
142 | 255 | "orig_nbformat": 4,
|
143 | 256 | "vscode": {
|
144 | 257 | "interpreter": {
|
145 |
| - "hash": "63c8862cb56f124e3ee7674b73de745eeb216416a9b24f78d1fcb7c775bff1b7" |
| 258 | + "hash": "1851d106532ddfc6fbd983b9ae95397243fcc3930d811046c990ea169e960650" |
146 | 259 | }
|
147 | 260 | }
|
148 | 261 | },
|
|
0 commit comments