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
# Copyright (c) Sebastian Raschka under Apache License 2.0 (see LICENSE.txt). | |
# Source for "Build a Large Language Model From Scratch" | |
# - https://www.manning.com/books/build-a-large-language-model-from-scratch | |
# Code: https://github.com/rasbt/LLMs-from-scratch | |
# This is a summary file containing the main takeaways from chapter 6. | |
import urllib.request | |
import zipfile | |
import os |
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 math | |
from functools import reduce | |
from collections import namedtuple | |
def multiply_all(numbers): | |
return reduce(int.__mul__, numbers) | |
# 1. Highly composite number consists only of the consecutive primes | |
# 2. Larger primes cannot have larger powers, since the number can always be reduced without effecting | |
# number of divisors |
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 numpy as np | |
from itertools import combinations | |
primes = [2, 2, 2, 5, 5, 7] | |
number = 1400 | |
assert np.prod(primes) == number # sanity check | |
observed_sets = set() | |
n_hips = 0 |
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 random | |
n_start_milk_choc = 2 | |
n_start_black_choc = 8 | |
n_trials = 1000000 | |
n_milk_last = 0 | |
for _ in range(n_trials): | |
prev_pulled_choc = None |
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 numpy as np | |
n_rolls = 10000000 | |
n_sides = 20 | |
min_dice_value = 8 | |
rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
print('-' * 30) |
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 numpy as np | |
n_rolls = 10000000 | |
n_sides = 20 | |
rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
print('-' * 30) | |
print('advantage of disadvantages') |
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 numpy as np | |
import tensorflow as tf | |
np.random.seed(0) | |
w1 = np.random.random((3, 3, 1, 100)) | |
w2 = np.random.random((3, 3, 1, 100)) | |
x1 = np.random.random((1, 256, 256, 1)) | |
x2 = np.random.random((1, 256, 256, 1)) |
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
from collections import namedtuple | |
def flatten_tuples(values): | |
for value in values: | |
if isinstance(value, tuple): | |
for inner_value in flatten_tuples(value): | |
yield inner_value | |
else: | |
yield value |
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
(defn replace-values | |
[array current-value new-value] | |
(assoc array (.indexOf array current-value) new-value)) | |
(defn swap-balls-in-boxes | |
[box-a box-b] | |
(let [random-ball-a (rand-nth box-a) | |
random-ball-b (rand-nth box-b)] | |
[(replace-values box-a random-ball-a random-ball-b) | |
(replace-values box-b random-ball-b random-ball-a)])) |
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 theano | |
import theano.tensor as T | |
import numpy as np | |
def asfloat(value): | |
""" Convert variable to float type configured by theano | |
floatX variable. | |
Parameters |
NewerOlder