Hi,
First of all thanks for fastai and the great online course (just went through Part I). It’s really impressive to see what you can achieve with fastai in a few lines of code
However, I am currently struggling with something that seems to me a very easy problem compared to the problems shown in the course. I wanted to start with a very simple Boolean function that my model should learn (to later on develop it to a more difficult problem): e.g. a simple XOR of two binary inputs.
My collab notebook is located here btw.: https://colab.research.google.com/drive/1rCkqVUNG7JIkkYxVpPgRAcmkc5_Jk4wF
For passing my Dataset (numpy.array, containing the input bits and the output bit) to a DataBunch , I used the “ArrayDataset” from the fastai docs:
class ArrayDataset(Dataset):
"Sample numpy array dataset"
def __init__(self, x, y):
self.x, self.y = x, y
self.c = 2 # binary label
def __len__(self):
return len(self.x)
def __getitem__(self, i):
return self.x[i], self.y[i]
# First two indices are the two inputs a and b, third index = output of funtion to learn
train_ds = ArrayDataset(training_set[:,0:2], training_set[:,2])
valid_ds = ArrayDataset(validation_set[:,0:2], validation_set[:,2])
# Define data bunch to use for learner
db = DataBunch(train_dl= DataLoader(dataset=train_ds), valid_dl=DataLoader(dataset=valid_ds))
db.batch_size=int(num_training_samples/batches)
learn = Learner(db, model, loss_func=MSELossFlat())
The model also seems to learn the model (at least sometimes) since the MSE loss function drops to 0.00… However, this is not deterministic, in the sense that when I restart the whole notebook the error sometimes gets stuck at 0.25 (I seeded the numpy RNG such that I always create the same data sets).
My questions in short:
-
What else can I configure in fastai to make the learning reproducable (always learn the same model)?
-
Also, is the code/model okay so far or did I make some fundamental mistakes, which is the reason for the strange behavior I get?
-
Is the “c=2” parameter in ArrayDataset correct. Since I defined a regression problem (rather than a classification problem, which I also could have done) I am not sure what this parameter is used for in this case
-
Is there an easier way to get my data set into the DataBunch?
Thanks for helping me,
Hannes