-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on training loop and debuggin index issue in embeddings
- Loading branch information
Showing
8 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import torch | ||
import torch.nn as nn | ||
from torch.nn import functional as F | ||
|
||
|
||
class AttentionHead(nn.Module): | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from transformers import GPT2Tokenizer | ||
import torch | ||
from torch.utils.data import DataLoader, Dataset | ||
from gpt import default_context_window, default_batch_size | ||
|
||
|
||
class TextDataset(Dataset): | ||
def __init__(self, text, tokenizer, context_window): | ||
self.tokens = tokenizer.encode(text) | ||
self.context_window = context_window | ||
|
||
def __len__(self): | ||
return len(self.tokens) - self.context_window | ||
|
||
def __getitem__(self, index): | ||
x = self.tokens[index : index + self.context_window] | ||
y = self.tokens[index + 1 : index + self.context_window + 1] | ||
return torch.tensor(x), torch.tensor(y) | ||
|
||
|
||
def get_tokenizer(model="gpt2"): | ||
tokenizer = GPT2Tokenizer.from_pretrained(model) | ||
tokenizer.pad_token = tokenizer.eos_token | ||
return tokenizer | ||
|
||
|
||
def get_data_loader(tokenizer, data_path="data/dataset.txt"): | ||
|
||
with open(data_path, "r") as file: | ||
text = file.read() | ||
|
||
dataset = TextDataset( | ||
text=text, tokenizer=tokenizer, context_window=default_context_window | ||
) | ||
|
||
return DataLoader(dataset=dataset, batch_size=default_batch_size, shuffle=True) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Empty file.