Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -47,11 +47,12 @@ emotions_target = pd.Categorical(df['emotion']).codes
|
|
47 |
emotion_classes = pd.Categorical(df['emotion']).categories
|
48 |
|
49 |
# Memory-efficient Neural Network with PyTorch
|
|
|
50 |
class MemoryEfficientNN(nn.Module):
|
51 |
def __init__(self, input_size, hidden_size, num_classes):
|
52 |
super(MemoryEfficientNN, self).__init__()
|
53 |
self.layers = nn.Sequential(
|
54 |
-
nn.
|
55 |
nn.ReLU(),
|
56 |
nn.Dropout(0.2),
|
57 |
nn.Linear(hidden_size, hidden_size),
|
@@ -61,7 +62,7 @@ class MemoryEfficientNN(nn.Module):
|
|
61 |
)
|
62 |
|
63 |
def forward(self, x):
|
64 |
-
return self.layers(x)
|
65 |
|
66 |
# Memory-efficient dataset
|
67 |
class MemoryEfficientDataset(IterableDataset):
|
@@ -282,7 +283,7 @@ def process_input(text):
|
|
282 |
|
283 |
rf_prediction = rf_model.predict(encoded_text)[0]
|
284 |
isolation_score = isolation_forest.decision_function(encoded_text)[0]
|
285 |
-
nn_prediction = model(torch.
|
286 |
|
287 |
predicted_emotion = emotion_classes[rf_prediction]
|
288 |
sentiment_score = isolation_score
|
|
|
47 |
emotion_classes = pd.Categorical(df['emotion']).categories
|
48 |
|
49 |
# Memory-efficient Neural Network with PyTorch
|
50 |
+
|
51 |
class MemoryEfficientNN(nn.Module):
|
52 |
def __init__(self, input_size, hidden_size, num_classes):
|
53 |
super(MemoryEfficientNN, self).__init__()
|
54 |
self.layers = nn.Sequential(
|
55 |
+
nn.Embedding(input_size, hidden_size),
|
56 |
nn.ReLU(),
|
57 |
nn.Dropout(0.2),
|
58 |
nn.Linear(hidden_size, hidden_size),
|
|
|
62 |
)
|
63 |
|
64 |
def forward(self, x):
|
65 |
+
return self.layers(x.long())
|
66 |
|
67 |
# Memory-efficient dataset
|
68 |
class MemoryEfficientDataset(IterableDataset):
|
|
|
283 |
|
284 |
rf_prediction = rf_model.predict(encoded_text)[0]
|
285 |
isolation_score = isolation_forest.decision_function(encoded_text)[0]
|
286 |
+
nn_prediction = model(torch.LongTensor(encoded_text.todense()).to(device)).argmax(dim=1).item()
|
287 |
|
288 |
predicted_emotion = emotion_classes[rf_prediction]
|
289 |
sentiment_score = isolation_score
|