0
def addSpaces(text, minLength):
    while(len(text) < minLength):
        text += " "
    return text

def convertToTokens(text):
    return [ord(token) for token in text]

def buildExamples(text, paddedLength):
    trainExamples = []
    for i in range(len(text)):
        trainExample = addSpaces(text[:i], paddedLength)
        trainExamples.append(convertToTokens(trainExample))
    return trainExamples
        

paddedLength = 100
trainExamples = list(buildExamples(trainText[:-1], paddedLength))
trainLabels = [ord(token) for token in trainText[:-1]]
testExamples = list(buildExamples(testText[:-1], paddedLength))
testLabels = [ord(token) for token in testText[1:]]
trainDataset = tf.data.Dataset.from_tensor_slices((trainExamples, trainLabels))
testDataset = tf.data.Dataset.from_tensor_slices((testExamples, testLabels))
model = tf.keras.Sequential([
    tf.keras.layers.Flatten(input_shape=(100,)),
    tf.keras.layers.Dense(128, activation="relu"),
    tf.keras.layers.Dense(128)
])

I am attempting to construct a simple text generative model. Obviously, an RNN or transformer network would be more efficient but I'm not that skilled. On this sequential model, I receive the following error. Input 0 of layer "dense_22" is incompatible with the layer: expected axis -1 of input shape to have value 100, but received input with shape (100, 1) Unfortunately, I am unsure as what to do.

I have tried adjusting the input shape to no avail.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82

0 Answers0