Skip to content
Snippets Groups Projects
Verified Commit 64580b0e authored by Claudio Scheer's avatar Claudio Scheer
Browse files

Add data.csv and dataset loader for PyTorch

parent 8cb8571a
No related branches found
No related tags found
No related merge requests found
question,answer
how are you?,good
how are you?,sad
how are you?,upset
how old are you?,23 years old
how old are you?,9 years old
how old are you?,65 years old
\ No newline at end of file
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Dataset ## Dataset
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
This section describes the process to load the dataset used to train and test the model. This section describes the process to load the dataset used to train and test the model. The dataset I am using on this project is just as stupid as the network. The idea is just to learn more about recurrent neural networks.
%% Cell type:code id: tags:
``` python
import pandas as pd
```
%% Cell type:code id: tags:
``` python
dataset = "../../dataset/data.csv"
data = pd.read_csv(dataset, header=0)
data.head()
```
%% Output
question answer
0 how are you? good
1 how are you? sad
2 how are you? upset
3 how old are you? 23 years old
4 how old are you? 9 years old
%% Cell type:markdown id: tags:
This dataset is not large enough to justify using the PyTorch `Dataset` utility class. However, I will use it.
%% Cell type:code id: tags:
``` python
import torch
from torch.utils.data.dataset import Dataset
import pandas as pd
class StupidBotDataset(Dataset):
def __init__(self, csv_path):
self.data = pd.read_csv(csv_path, header=0)
self.questions = self.data.iloc[:, 0]
self.answers = self.data.iloc[:, 1]
self.data_len = len(self.data.index)
def __getitem__(self, index):
x = [self.questions[index]]
x = torch.Tensor(x).cuda()
y = [self.price[index]]
y = torch.Tensor(y).cuda()
# One-hot encode questions and answers.
return x, y
def __len__(self):
return self.data_len
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment