This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| The most atomic way to train and run inference for a GPT in pure, dependency-free Python. | |
| This file is the complete algorithm. | |
| Everything else is just efficiency. | |
| @karpathy | |
| """ | |
| import os # os.path.exists | |
| import math # math.log, math.exp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| def get_pattern(df): | |
| """ Generates the DBIR "patterns," with liberal inspiration from the getpatternlist.R: | |
| https://gist.github.com/jayjacobs/a145cb87551f551fc719 | |
| Parameters | |
| ---------- | |
| df: pd DataFrame with most VERIS encodings already built (from verispy package). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def press_statistic(y_true, y_pred, xs): | |
| """ | |
| Calculation of the `Press Statistics <https://www.otexts.org/1580>`_ | |
| """ | |
| res = y_pred - y_true | |
| hat = xs.dot(np.linalg.pinv(xs)) | |
| den = (1 - np.diagonal(hat)) | |
| sqr = np.square(res/den) | |
| return sqr.sum() |