Kernel: Python 3 (ipykernel)
Machine Learning with PyTorch and Scikit-Learn
-- Code Examples
Package version checks
Add folder to path in order to load from the check_packages.py script:
In [1]:
Check recommended package versions:
In [2]:
Out[2]:
[OK] Your Python version is 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27)
[GCC 9.3.0]
[OK] torch 1.10.0
[OK] transformers 4.9.1
Chapter 16: Transformers – Improving Natural Language Processing with Attention Mechanisms (Part 2/3)
In [2]:
Building large-scale language models by leveraging unlabeled data
Pre-training and fine-tuning transformer models
In [4]:
Out[4]:
Leveraging unlabeled data with GPT
In [5]:
Out[5]:
In [ ]:
Using GPT-2 to generate new text
In [3]:
Out[3]:
Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.
[{'generated_text': "Hey readers, today is not the last time we'll be seeing one of our favorite indie rock bands"},
{'generated_text': 'Hey readers, today is Christmas. This is not Christmas, because Christmas is so long and I hope'},
{'generated_text': "Hey readers, today is CTA Day!\n\nWe're proud to be hosting a special event"}]
In [31]:
Out[31]:
{'input_ids': tensor([[ 5756, 514, 37773, 428, 6827]]), 'attention_mask': tensor([[1, 1, 1, 1, 1]])}
In [ ]:
In [30]:
Out[30]:
torch.Size([1, 5, 768])
Bidirectional pre-training with BERT
In [7]:
Out[7]:
In [9]:
Out[9]:
In [11]:
Out[11]:
The best of both worlds: BART
In [13]:
Out[13]:
Readers may ignore the next cell.
In [2]:
Out[2]:
[NbConvertApp] WARNING | Config option `kernel_spec_manager_class` not recognized by `NbConvertApp`.
[NbConvertApp] Converting notebook ch16-part2-gpt2.ipynb to script
[NbConvertApp] Writing 2690 bytes to ch16-part2-gpt2.py
In [ ]: