So I’ve been messing around with basic neural network stuff using python and I’ve managed to train my network using an ordered set of movie reviews using the imdb API through tensorflow’s keras platform, but when it comes to adding new custom movie reviews, for example, if I wrote a movie review that I wanted to add to the dataset, I’m doing this:
model = keras.models.load_model(“model.h5”) #loading the .h5 model file from my local files#
with open(“test.txt”, encoding=”utf-8″) as f:
for line in f.readlines():
nline = line.replace(“,”, “”).replace(“.”, “”).replace(“(“, “”).replace(“)”,””).replace(“:”,””).replace(“””, “”).replace(“?”, “”).replace(“‘”, “”).strip().split(” “)
#replacing any characters with spaces#
encode = review_encode(nline)
encode = keras.preprocessing.sequence.pad_sequences([encode], value=word_index["<PAD>"], padding="post", maxlen=250)
predict = model.predict(encode)
print(line)
print(encode)
print(predict[0])
But when I run the code through a command prompt, it gives me a list of encoded numbers which the encoder has converted from strings into integers, but the error reads:
AttributeError: ‘str’ object has no attribute ‘decode’
I’ve tried trying to write a line that decodes the integers back into string form but this error still persists. Can anyone please shed some light on this issue? It’s probably quite straightforward but this is my first foray into neural network architecture and would appreciate an enlightened mind to give me some guidance.
Jake Thomas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.