Sephfox commited on
Commit
5d1ef69
·
verified ·
1 Parent(s): a7b534c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -67,7 +67,7 @@ class MemoryEfficientNN(nn.Module):
67
  class MemoryEfficientDataset(IterableDataset):
68
  def __init__(self, X, y, batch_size):
69
  self.X = X
70
- self.y = y
71
  self.batch_size = batch_size
72
 
73
  def __iter__(self):
@@ -76,6 +76,12 @@ class MemoryEfficientDataset(IterableDataset):
76
  y_batch = self.y[i:i+self.batch_size]
77
  yield torch.FloatTensor(X_batch), torch.LongTensor(y_batch)
78
 
 
 
 
 
 
 
79
  # Train Memory-Efficient Neural Network
80
  X_train, X_test, y_train, y_test = train_test_split(contexts_encoded, emotions_target, test_size=0.2, random_state=42)
81
  input_size = X_train.shape[1]
 
67
  class MemoryEfficientDataset(IterableDataset):
68
  def __init__(self, X, y, batch_size):
69
  self.X = X
70
+ self.y = y.astype(int) # Convert labels to integers
71
  self.batch_size = batch_size
72
 
73
  def __iter__(self):
 
76
  y_batch = self.y[i:i+self.batch_size]
77
  yield torch.FloatTensor(X_batch), torch.LongTensor(y_batch)
78
 
79
+ def __iter__(self):
80
+ for i in range(0, len(self.y), self.batch_size):
81
+ X_batch = self.X[i:i+self.batch_size].toarray()
82
+ y_batch = self.y[i:i+self.batch_size]
83
+ yield torch.FloatTensor(X_batch), torch.LongTensor(y_batch)
84
+
85
  # Train Memory-Efficient Neural Network
86
  X_train, X_test, y_train, y_test = train_test_split(contexts_encoded, emotions_target, test_size=0.2, random_state=42)
87
  input_size = X_train.shape[1]