Path: blob/main/a5/mingpt-demo/play_char.ipynb
1003 views
Kernel: Python 3
Train a character-level GPT on some text data
The inputs here are simple text files, which we chop up to individual characters and then train GPT on. So you could say this is a char-transformer instead of a char-rnn. Doesn't quite roll off the tongue as well. In this example we will feed it some Shakespeare, which we'll get it to predict character-level.
In [1]:
In [2]:
In [3]:
In [4]:
In [5]:
In [6]:
Out[6]:
data has 1115394 characters, 65 unique.
In [7]:
Out[7]:
08/24/2020 22:59:58 - INFO - mingpt.model - number of parameters: 2.535219e+07
In [8]:
Out[8]:
0%| | 0/2179 [00:00<?, ?it/s]/apcv/shared/conda-envs/apcv-6244e1d-566/lib/python3.8/site-packages/torch/nn/parallel/_functions.py:61: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.
warnings.warn('Was asked to gather along dimension 0, but all '
epoch 1 iter 2178: train loss 0.33318. lr 3.000169e-04: 100%|██████████| 2179/2179 [09:22<00:00, 3.88it/s]
epoch 2 iter 2178: train loss 0.17447. lr 6.000000e-05: 100%|██████████| 2179/2179 [08:45<00:00, 4.15it/s]
In [10]:
Out[10]:
O God, O God! that e'er this tongue of mine,
That laid the sentence of dread banishment
On yon proud man, should take it off again
With words of sooth! O that I were as great
As is my grief, or lesser than my name!
Or that I could forget
With Richmond, I'll tell you what I am,
The Lord Aumerle, .
CLAUDIO:
The prenzie Angelo!
ISABELLA:
O, 'tis the cunning livery of hell,
The damned'st body to invest and cover
In prenzie guards! Dost thou think, Claudio?
If I would yield him my virginity,
Thou mightst be freed.
CLAUDIO:
O heavens! it cannot be.
ISABELLA:
Yes, he would give't thee, from this rank offence,
So to offend him still. This night's the time
That I should do what I abhor to name,
Or else thou diest to-morrow.
CLAUDIO:
Thou shalt not do't.
ISABELLA:
O, were it but my life,
I'ld throw it down for your deliverance
As frankly as a pin.
CLAUDIO:
Thanks, dear Isabel.
ISABELLA:
Be ready, Claudio, for your death tomorrow.
CLAUDIO:
Yes. Has he affections
That profit us.
DUKE VINCENTIO:
By the world they see the word in 's doom.
ANGELO:
Thou art the like, thus hate the course in heaven.
What foul hath bled the wheel or at wild,
And wash him fresh again with true-love tears.
Ah, thou, the model where old Troy did stand,
Thou map of honour, thou King Richard's tomb,
And not King Richard; thou most beauteous inn,
Why should hard-favour'd grief be lodged in thee,
When triumph is become an alehouse guest?
KING RICHARD II:
Join not with grief, fair woman, do not so,
To make my end too sudden: learn, good soul,
To think our former state a happy dream;
From which awaked, the truth of what we are
Shows us but this: I am sworn brother, sweet,
To grim Necessity, and he and I
Will keep a league till death. Hie thee to France
And cloister thee in some religious house:
Our holy lives must win a new world's crown,
Which our profane hours here have stricken down.
QUEEN:
What, is my Richard both in shape and mind
Transform'd and weaken'd? hath Bolingbroke deposed
Thine intellect? hath h
In [ ]: