Was following your project on youtube and came across an issue with the syntax of the SGD function.
So when I call the import statement like this, then instantiate the SGD function, it's fine in the ide. However, when I have everything else running with it in the training file, I get the syntax issues. Maybe it has something to do with tensorflow library?
from tensorflow.keras.optimizers import SGD
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
Here is the code. Also, this is my fist github post, sorry if I did anything wrong with how I approached this. Let me know if there is a convention for this type of stuff. Thanks!
import random
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation, Dropout
from tensorflow.keras.optimizers import SGD
for intent in intents['intents']:
for pattern in intent['patterns']:
word_list = nltk.word_tokenize(pattern)
words.extend(word_list)
documents.append((word_list, intent['tag']))
if intent['tag'] not in classes:
classes.append(intent['tag'])
words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letters]
words = sorted(set(words))
for document in documents:
bag = []
word_patterns = document[0]
word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns]
for word in words:
bag.appends(1) if word in word_patterns else bag.append(0)
Was following your project on youtube and came across an issue with the syntax of the SGD function. So when I call the import statement like this, then instantiate the SGD function, it's fine in the ide. However, when I have everything else running with it in the training file, I get the syntax issues. Maybe it has something to do with tensorflow library?
from tensorflow.keras.optimizers import SGD sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
Here is the code. Also, this is my fist github post, sorry if I did anything wrong with how I approached this. Let me know if there is a convention for this type of stuff. Thanks!
import random import json import pickle import numpy as np
import nltk from nltk.stem import WordNetLemmatizer
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Activation, Dropout from tensorflow.keras.optimizers import SGD
lemmatizer = WordNetLemmatizer()
intents = json.loads(open('intents.json').read())
words = [] classes = [] documents = [] ignore_letters = ['?','!','.','.',',']
for intent in intents['intents']: for pattern in intent['patterns']: word_list = nltk.word_tokenize(pattern) words.extend(word_list) documents.append((word_list, intent['tag'])) if intent['tag'] not in classes: classes.append(intent['tag'])
words = [lemmatizer.lemmatize(word) for word in words if word not in ignore_letters] words = sorted(set(words))
classes = sorted(set(classes))
pickle.dump(words, open('words.pkl'), 'wb') pickle.dump(words, open('words.pkl'), 'wb')
training = [] output_empty = [0] * len(classes)
for document in documents: bag = [] word_patterns = document[0] word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns] for word in words: bag.appends(1) if word in word_patterns else bag.append(0)
random.shuffle(training) training = np.array(training)
train_x = list(training[:, 0]) train_y = list(training[:, 1])
model = Sequential() model.add(Dense(128, input_shape =(len(train_x[0]),),activation = 'relu')) model.add(Dropout()) model.add(Dense(64, activation='relu')) model.add(Dropout(0.5)) model.add(Dense(len(train_y[0]), activation = 'softmax')
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss = 'categorical_crossentrop', optimizer = sgd)