-3

i am following a yt tutorial and my programm shows "NameError: name 'input_shape' is not defined" did i forget to import something ?? or did the name change of the 7 months since this video was released. Thank you for your help.

yt video https://www.youtube.com/watch?v=tEV_Jtmx2cc at 18:30 min

import random
import pickle

import numpy as np
import pandas as pd
from nltk.tokenize import RegexpTokenizer

from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import LSTM, Dense, Activation
from tensorflow.keras.optimizers import RMSprop

from tensorflow.keras.layers import InputLayer
from keras.models import Sequential, load_model
from keras.layers import LSTM, Dense, Activation
from keras.optimizers import RMSprop
import keras


text = "This is an interisting text this is a text and i need to make this text longer otherwise it wont work"

tokenizer = RegexpTokenizer(r"\w+")
tokens = tokenizer.tokenize(text)    # list of individual word with duplicates
#print(tokens)

unique_tokens = np.unique(tokens)
unique_token_index = {token: idx for idx, token in enumerate(unique_tokens)}   


n_words = 10
input_words = []
next_words = []

for i in range(len(tokens)- n_words):
    input_words.append(tokens[i:i + n_words])  
    next_words.append(tokens[i + n_words])   


X = np.zeros((len(input_words), n_words, len(unique_tokens)), dtype=bool)  
Y = np.zeros((len(next_words),len(unique_tokens)),dtype=bool)



for i, words in enumerate(input_words):
    for j, word in enumerate(words):
        X[i, j, unique_token_index[word]] = 1
        Y[i, unique_token_index[next_words[i]]] = 1



model = Sequential()


model.add(LSTM(128, input_shape(n_words, len(unique_tokens)), return_sequence=True))   

is also tried a nother method which didnt wort either

model.add(LSTM(128, InputLayer.input_shape(n_words, len(unique_tokens)), return_sequence=True))

1
  • 1
    Watch the video for 15 more seconds after the timestamp you referenced. input_shape=(...) Commented Oct 13, 2023 at 23:40

1 Answer 1

0

(len(tokens)- n_words): the subtract sign wont come at the middle, probably you have missed a comma and you also can't use some operators in the range of for loop

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.