Skip to content

Commit b90c7ad

Browse files
authored
Exercise solutions (rasbt#237)
1 parent 06921f3 commit b90c7ad

File tree

6 files changed

+1427
-18
lines changed

6 files changed

+1427
-18
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Configs and keys
2-
ch07/01_main-chapter-code/instruction-data-with-response-standalone.json
32
ch07/01_main-chapter-code/gpt2-medium355M-sft-standalone.pth
43
ch07/02_dataset-utilities/config.json
54
ch07/03_model-evaluation/config.json
@@ -68,6 +67,9 @@ ch06/03_bonus_imdb-classification/test.csv
6867
ch06/03_bonus_imdb-classification/train.csv
6968
ch06/03_bonus_imdb-classification/validation.csv
7069

70+
ch07/01_main-chapter-code/instruction-data-with-response-standalone.json
71+
ch07/01_main-chapter-code/instruction-data-with-response-baseline.json
72+
ch07/01_main-chapter-code/instruction-data-with-response-mask-instructions.json
7173
ch07/02_dataset-utilities/instruction-examples-modified.json
7274

7375
# Temporary OS-related files

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Alternatively, you can view this and other files on GitHub at [https://github.co
5656
| Ch 4: Implementing a GPT Model from Scratch | - [ch04.ipynb](ch04/01_main-chapter-code/ch04.ipynb)<br/>- [gpt.py](ch04/01_main-chapter-code/gpt.py) (summary)<br/>- [exercise-solutions.ipynb](ch04/01_main-chapter-code/exercise-solutions.ipynb) | [./ch04](./ch04) |
5757
| Ch 5: Pretraining on Unlabeled Data | - [ch05.ipynb](ch05/01_main-chapter-code/ch05.ipynb)<br/>- [gpt_train.py](ch05/01_main-chapter-code/gpt_train.py) (summary) <br/>- [gpt_generate.py](ch05/01_main-chapter-code/gpt_generate.py) (summary) <br/>- [exercise-solutions.ipynb](ch05/01_main-chapter-code/exercise-solutions.ipynb) | [./ch05](./ch05) |
5858
| Ch 6: Finetuning for Text Classification | - [ch06.ipynb](ch06/01_main-chapter-code/ch06.ipynb) <br/>- [gpt_class_finetune.py](ch06/01_main-chapter-code/gpt_class_finetune.py) <br/>- [exercise-solutions.ipynb](ch06/01_main-chapter-code/exercise-solutions.ipynb) | [./ch06](./ch06) |
59-
| Ch 7: Finetuning to Follow Instructions | - [ch07.ipynb](ch07/01_main-chapter-code/ch07.ipynb) | [./ch07](./ch07) |
59+
| Ch 7: Finetuning to Follow Instructions | - [ch07.ipynb](ch07/01_main-chapter-code/ch07.ipynb)<br/>- [gpt_instruction_finetuning.py](ch07/01_main-chapter-code/gpt_instruction_finetuning.py)<br/>- [ollama_evaluate.py](ch07/01_main-chapter-code/ollama_evaluate.py)<br/>- [exercise-solutions.ipynb](ch07/01_main-chapter-code/exercise-solutions.ipynb) | [./ch07](./ch07) |
6060
| Appendix A: Introduction to PyTorch | - [code-part1.ipynb](appendix-A/01_main-chapter-code/code-part1.ipynb)<br/>- [code-part2.ipynb](appendix-A/01_main-chapter-code/code-part2.ipynb)<br/>- [DDP-script.py](appendix-A/01_main-chapter-code/DDP-script.py)<br/>- [exercise-solutions.ipynb](appendix-A/01_main-chapter-code/exercise-solutions.ipynb) | [./appendix-A](./appendix-A) |
6161
| Appendix B: References and Further Reading | No code | - |
6262
| Appendix C: Exercise Solutions | No code | - |

ch07/01_main-chapter-code/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
### Main Chapter Code
44

55
- [ch07.ipynb](ch07.ipynb) contains all the code as it appears in the chapter
6-
- [previous_chapters.py](previous_chapters.py) is a Python module that contains the GPT model we coded and trained in previous chapters, alongside many utility functions, which we reuse in this chapter
6+
- [previous_chapters.py](previous_chapters.py) is a Python module that contains the GPT model we coded and trained in previous chapters, alongside many utility functions, which we reuse in this chapter
77
- [gpt_download.py](gpt_download.py) contains the utility functions for downloading the pretrained GPT model weights
8+
- [exercise-solutions.ipynb](exercise-solutions.ipynb) contains the exercise solutions for this chapter
9+
810

911
### Optional Code
1012

11-
- [load-finetuned-model.ipynb](load-finetuned-model.ipynb) is a standalone Jupyter notebook to load the instruction finetuned model we created in this chapter
13+
- [load-finetuned-model.ipynb](load-finetuned-model.ipynb) is a standalone Jupyter notebook to load the instruction finetuned model we created in this chapter
1214

1315
- [gpt_instruction_finetuning.py](gpt_instruction_finetuning.py) is a standalone Python script to instruction finetune the model as described in the main chapter (think of it as a chapter summary focused on the finetuning parts)
1416

@@ -71,3 +73,4 @@ Number of scores: 110 of 110
7173
Average score: 51.75
7274
```
7375

76+
- [exercise_experiments.py](exercise_experiments.py) is an optional scropt that implements the exercise solutions; for more details see [exercise-solutions.ipynb](exercise-solutions.ipynb)

0 commit comments

Comments
 (0)