当前位置:   article > 正文

学习人工智能-3条Python命令,从零开始搭建GPT,minGPT by Andrej karpathy_搭建自己的mingpt

搭建自己的mingpt

 github链接:GitHub - karpathy/minGPT: A minimal PyTorch re-implementation of the OpenAI GPT (Generative Pretrained Transformer) training

搬运到CSDN资源链接:从零创建一个最简单的GPT,minGPTbyAndrejkarpathy资源-CSDN文库

1,安装Python环境 和以下包

pip install torch numpy transformers datasets tiktoken wandb tqdm

2,准备训练数据-莎士比亚

如果你不是深度学习领域的专业人士,只是想感受一下它的魔力并初步尝试,那么最快速的入门方式就是在莎士比亚的作品上训练一个字符级别的GPT模型。首先,我们需要将其下载为一个单独(1MB)的文件,并将原始文本转换为一串大的整数流。

python data/shakespeare_char/prepare.py

3,开始训练并生成结果:

3a,开始训练并生成结果 by CPU


python train.py config/train_shakespeare_char.py --device=cpu --compile=False --eval_iters=20 --log_interval=1 --block_size=64 --batch_size=12 --n_layer=4 --n_head=4 --n_embd=128 --max_iters=2000 --lr_decay_iters=2000 --dropout=0.0

生成结果 by CPU

python sample.py --out_dir=out-shakespeare-char --device=cpu

结果大概长这样:

GLEORKEN VINGHARD III:
Whell's the couse, the came light gacks,
And the for mought you in Aut fries the not high shee
bot thou the sought bechive in that to doth groan you,
No relving thee post mose the wear
```

3b, 开始训练并生成结果 by GPU

python train.py config/train_shakespeare_char.py

生成结果 by GPU


$ python sample.py --out_dir=out-shakespeare-char
 

结果大概长这样:

ANGELO:
And cowards it be strawn to my bed,
And thrust the gates of my threats,
Because he that ale away, and hang'd
An one with him.

DUKE VINCENTIO:
I thank your eyes against it.

DUKE VINCENTIO:
Then will answer him to save the malm:
And what have you tyrannous shall do this?

DUKE VINCENTIO:
If you have done evils of all disposition
To end his power, the day of thrust for a common men
That I leave, to fight with over-liking
Hasting in a roseman.


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/882131
推荐阅读
相关标签
  

闽ICP备14008679号