app update
Browse files
app.py
CHANGED
|
@@ -22,50 +22,6 @@ dropout = 0.0
|
|
| 22 |
|
| 23 |
torch.manual_seed(1337)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
# with open('input.txt', 'r', encoding='utf-8') as f:
|
| 27 |
-
# text = f.read()
|
| 28 |
-
|
| 29 |
-
# # here are all the unique characters that occur in this text
|
| 30 |
-
# chars = sorted(list(set(text)))
|
| 31 |
-
# vocab_size = len(chars)
|
| 32 |
-
# # create a mapping from characters to integers
|
| 33 |
-
# stoi = { ch:i for i,ch in enumerate(chars) }
|
| 34 |
-
# itos = { i:ch for i,ch in enumerate(chars) }
|
| 35 |
-
# encode = lambda s: [stoi[c] for c in s] # encoder: take a string, output a list of integers
|
| 36 |
-
# decode = lambda l: ''.join([itos[i] for i in l]) # decoder: take a list of integers, output a string
|
| 37 |
-
|
| 38 |
-
# # Train and test splits
|
| 39 |
-
# data = torch.tensor(encode(text), dtype=torch.long)
|
| 40 |
-
# n = int(0.9*len(data)) # first 90% will be train, rest val
|
| 41 |
-
# train_data = data[:n]
|
| 42 |
-
# val_data = data[n:]
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
# # data loading
|
| 46 |
-
# def get_batch(split):
|
| 47 |
-
# # generate a small batch of data of inputs x and targets y
|
| 48 |
-
# data = train_data if split == 'train' else val_data
|
| 49 |
-
# ix = torch.randint(len(data) - block_size, (batch_size,))
|
| 50 |
-
# x = torch.stack([data[i:i+block_size] for i in ix])
|
| 51 |
-
# y = torch.stack([data[i+1:i+block_size+1] for i in ix])
|
| 52 |
-
# x, y = x.to(device), y.to(device)
|
| 53 |
-
# return x, y
|
| 54 |
-
|
| 55 |
-
# @torch.no_grad()
|
| 56 |
-
# def estimate_loss():
|
| 57 |
-
# out = {}
|
| 58 |
-
# model.eval()
|
| 59 |
-
# for split in ['train', 'val']:
|
| 60 |
-
# losses = torch.zeros(eval_iters)
|
| 61 |
-
# for k in range(eval_iters):
|
| 62 |
-
# X, Y = get_batch(split)
|
| 63 |
-
# logits, loss = model(X, Y)
|
| 64 |
-
# losses[k] = loss.item()
|
| 65 |
-
# out[split] = losses.mean()
|
| 66 |
-
# model.train()
|
| 67 |
-
# return out
|
| 68 |
-
|
| 69 |
class Head(nn.Module):
|
| 70 |
""" one head of self-attention """
|
| 71 |
|
|
@@ -138,7 +94,6 @@ class Block(nn.Module):
|
|
| 138 |
x = x + self.ffwd(self.ln2(x))
|
| 139 |
return x
|
| 140 |
|
| 141 |
-
# super simple bigram model
|
| 142 |
# super simple bigram model
|
| 143 |
class BigramLanguageModel(nn.Module):
|
| 144 |
def __init__(self, dataset_text, n_embd):
|
|
@@ -256,13 +211,16 @@ def generate_wikipedia_outputs(prompt=None, max_new_tokens=2000):
|
|
| 256 |
|
| 257 |
|
| 258 |
title = "Nano GPT"
|
| 259 |
-
|
|
|
|
| 260 |
|
| 261 |
shakespeare_interface = gr.Interface(generate_shakespeare_outputs,
|
| 262 |
inputs=[gr.Textbox(label="Enter any prompt ", type="text", value="Once upon a time,"),
|
| 263 |
gr.Slider(minimum=100, maximum=5000, step=100, value=2000, label="Max new tokens")],
|
| 264 |
outputs=gr.Textbox(label="Output generated", type="text"), description=description)
|
| 265 |
|
|
|
|
|
|
|
| 266 |
wiki_interface = gr.Interface(generate_wikipedia_outputs,
|
| 267 |
inputs=[gr.Textbox(label="Enter any prompt ", type="text", value="James Bond"),
|
| 268 |
gr.Slider(minimum=100, maximum=5000, step=100, value=2000, label="Max new tokens")],
|
|
|
|
| 22 |
|
| 23 |
torch.manual_seed(1337)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
class Head(nn.Module):
|
| 26 |
""" one head of self-attention """
|
| 27 |
|
|
|
|
| 94 |
x = x + self.ffwd(self.ln2(x))
|
| 95 |
return x
|
| 96 |
|
|
|
|
| 97 |
# super simple bigram model
|
| 98 |
class BigramLanguageModel(nn.Module):
|
| 99 |
def __init__(self, dataset_text, n_embd):
|
|
|
|
| 211 |
|
| 212 |
|
| 213 |
title = "Nano GPT"
|
| 214 |
+
|
| 215 |
+
description1 = "Nano GPT trained on Shakespeare dataset. It is trained on a very small amount of data to understand how GPT's are trained and built. The implementation can be found <a href='https://github.com/karpathy/nanoGPT'>here.</a>"
|
| 216 |
|
| 217 |
shakespeare_interface = gr.Interface(generate_shakespeare_outputs,
|
| 218 |
inputs=[gr.Textbox(label="Enter any prompt ", type="text", value="Once upon a time,"),
|
| 219 |
gr.Slider(minimum=100, maximum=5000, step=100, value=2000, label="Max new tokens")],
|
| 220 |
outputs=gr.Textbox(label="Output generated", type="text"), description=description)
|
| 221 |
|
| 222 |
+
description2 = "Nano GPT trained on Wikipedia dataset. It is trained on a very small amount of data to understand how GPT's are trained and built. The implementation can be found <a href='https://github.com/karpathy/nanoGPT'>here.</a>"
|
| 223 |
+
|
| 224 |
wiki_interface = gr.Interface(generate_wikipedia_outputs,
|
| 225 |
inputs=[gr.Textbox(label="Enter any prompt ", type="text", value="James Bond"),
|
| 226 |
gr.Slider(minimum=100, maximum=5000, step=100, value=2000, label="Max new tokens")],
|