Spaces:
Runtime error
Runtime error
typesdigital
commited on
Commit
•
2a0f2b0
1
Parent(s):
fc7f7f8
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import nltk
|
3 |
import spacy
|
4 |
import tensorflow as tf
|
|
|
5 |
from tensorflow.keras.layers import Input, Dense, LSTM, Embedding, Dropout
|
6 |
from tensorflow.keras.models import Model
|
7 |
from tensorflow.keras.optimizers import Adam
|
@@ -12,6 +13,12 @@ from tensorflow.keras.preprocessing.text import Tokenizer
|
|
12 |
nlp = spacy.load('en_core_web_sm')
|
13 |
|
14 |
# Define the neural network architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
input_text = Input(shape=(None,))
|
16 |
embedding_layer = Embedding(input_dim=num_words, output_dim=embedding_dim)(input_text)
|
17 |
lstm_layer = LSTM(units=lstm_units)(embedding_layer)
|
@@ -19,10 +26,13 @@ dropout_layer = Dropout(rate=dropout_rate)(lstm_layer)
|
|
19 |
output_layer = Dense(units=num_classes, activation='softmax')(dropout_layer)
|
20 |
|
21 |
# Compile the model
|
|
|
22 |
model = Model(inputs=input_text, outputs=output_layer)
|
23 |
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=learning_rate), metrics=['accuracy'])
|
24 |
|
25 |
# Train the model
|
|
|
|
|
26 |
model.fit(x_train, y_train, validation_data=(x_test, y_test), batch_size=batch_size, epochs=num_epochs)
|
27 |
|
28 |
# Define the function for providing feedback and corrections
|
|
|
2 |
import nltk
|
3 |
import spacy
|
4 |
import tensorflow as tf
|
5 |
+
import numpy as np
|
6 |
from tensorflow.keras.layers import Input, Dense, LSTM, Embedding, Dropout
|
7 |
from tensorflow.keras.models import Model
|
8 |
from tensorflow.keras.optimizers import Adam
|
|
|
13 |
nlp = spacy.load('en_core_web_sm')
|
14 |
|
15 |
# Define the neural network architecture
|
16 |
+
num_words = 10000
|
17 |
+
embedding_dim = 128
|
18 |
+
lstm_units = 128
|
19 |
+
dropout_rate = 0.2
|
20 |
+
num_classes = 10
|
21 |
+
|
22 |
input_text = Input(shape=(None,))
|
23 |
embedding_layer = Embedding(input_dim=num_words, output_dim=embedding_dim)(input_text)
|
24 |
lstm_layer = LSTM(units=lstm_units)(embedding_layer)
|
|
|
26 |
output_layer = Dense(units=num_classes, activation='softmax')(dropout_layer)
|
27 |
|
28 |
# Compile the model
|
29 |
+
learning_rate = 0.001
|
30 |
model = Model(inputs=input_text, outputs=output_layer)
|
31 |
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=learning_rate), metrics=['accuracy'])
|
32 |
|
33 |
# Train the model
|
34 |
+
batch_size = 32
|
35 |
+
num_epochs = 10
|
36 |
model.fit(x_train, y_train, validation_data=(x_test, y_test), batch_size=batch_size, epochs=num_epochs)
|
37 |
|
38 |
# Define the function for providing feedback and corrections
|