Stack Exchange
I have an autoencoder that is supposed to create variation of the input text but this is the output and the whole code
my code_here:
loaded_model = load_model("vectorize_model")
loaded_layer = loaded_model.layers[0]
vocab = loaded_layer.get_vocabulary()


def get_word(v):
   v = tf.convert_to_tensor(v)
   transformed = ""
   for each in tf.squeeze(v):
      transformed= transformed+ " "+ vocab[each]
   return transformed

The start of the whole model here
inputs = Input(shape=(max_len,))
encoder1 = Embedding(vocab_size, 128)(inputs)
encoder2 = LSTM(128)(encoder1)
encoder3 = RepeatVector(max_len)(encoder2)
decoder1 = LSTM(128, return_sequences=True)(encoder3)
outputs = TimeDistributed(Dense(vocab_size, activation='softmax'))(decoder1)
model = keras.Model(inputs=inputs, outputs=outputs)

weights saved during training the model
model accuracy during evaluation was 76% and same as during training
model.load_weights("weights-improvement-01-0.76.hdf5")

model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.save("drugs_model", save_format="tf")
saved_model = load_model("drugs_model")

inputs = Input(shape=(1,), dtype='string')
x = vectorize_text(inputs)
x = tf.reshape(x,[1,120])

output = saved_model(x)

end_model = keras.Model(inputs, output)
end_model.compile(loss="sparse_categorical_crossentropy", optimizer="adam", metrics=['accuracy'])
end_model.save("full_model", save_format="tf")
full_model = load_model("full_model")


def generate_text(seed_text,model):  
     words = []
     prediction = model.predict([seed_text])
    for i in np.round(prediction[0],3):            words.append(np.argmax(i))
    
    words = np.array(words)
    output_text = get_word(words)

    return output_text

seed = "Do not use in larger or smaller amounts or for longer than recommended."
created_text = generate_text(seed,full_model)
print(created_text)

##every seed i enter is producing the same output
output :  or or or or or or or or or or or or or or or or or or or or or or or or

First, start with creating sequences that can perform with the Tensorflows model, For these sample codes you found on this website I adjusted and fixed some line to make them works. It is a good sample you can convert text input to target sequences by using tf.constant as an input.
Sample create a sequence from text to ngrams you can work with speech or text.
vocab = ["a", "b", "c", "d", "e", "f", "g"]

def train_ngram_model(data, batch_size=32, vocab=vocab):
    
    embedding_layer = tf.keras.layers.Embedding(input_vocab_size, embedding_size)
    ###
    decoder_cell = tf.keras.layers.LSTMCell(hidden_size)
    sampler = tfa.seq2seq.TrainingSampler()
    output_layer = tf.keras.layers.Dense(output_vocab_size)
    decoder = tfa.seq2seq.BasicDecoder(decoder_cell, sampler, output_layer)
    
    ########################## 
    input_ids = tf.random.uniform(
    [n_blocks, n_sizes], maxval=input_vocab_size, dtype=tf.int64)
    
    layer = tf.keras.layers.StringLookup(vocabulary=vocab)
    input_ids = layer(data)
    ##########################    

    input_lengths = tf.fill([batch_size], max_time)
    input_tensors = embedding_layer(input_ids)
    initial_state = decoder_cell.get_initial_state(input_tensors)
    
    output, state, lengths = decoder( input_tensors, sequence_length=input_lengths, initial_state=initial_state )
    logits = output.rnn_output

    return output, logits

You can de-serialize by mapping with windows length support.
input_word = tf.constant(' \'Cause it\'s easy as an ice cream sundae Slipping outta your hand into the dirt Easy as an ice cream sundae Every dancer gets a little hurt Easy as an ice cream sundae Slipping outta your hand into the dirt Easy as an ice cream sundae Every dancer gets a little hurt Easy as an ice cream sundae Oh, easy as an ice cream sundae ')

dataset = tf.data.Dataset.from_tensors( tf.strings.bytes_split(input_word) )
print( dataset )

window_size = 6
dataset = dataset.map(lambda x: tft.sliding_window(x, width=window_size, axis=0)).flat_map(tf.data.Dataset.from_tensor_slices)

for d in dataset:
    print(d)

I think this should provide a good example for your function generator, any questions?
Sample
