input: Write a python function to create and train a text classification model using Keras, given a dataset. The function should preprocess the text data, tokenize it, pad sequences, convert labels to categorical, build a Sequential model with an Embedding layer, an LSTM layer, and a Dense layer, and compile and train the model. The function should save the trained model to a file named 'recipe_generator.h5'.
  assert os.path.exists('recipe_generator.h5')
output: def create_and_train_model(dataset):
      import os
      import numpy as np
      from keras.preprocessing.text import Tokenizer
      from keras.preprocessing.sequence import pad_sequences
      from keras.utils import to_categorical
      from keras.models import Sequential
      from keras.layers import Embedding, LSTM, Dense
      from sklearn.model_selection import train_test_split
      
      # Assuming dataset is a list of tuples (text, label)
      texts, labels = zip(*dataset)
      
      # Tokenize the text
      tokenizer = Tokenizer()
      tokenizer.fit_on_texts(texts)
      sequences = tokenizer.texts_to_sequences(texts)
      word_index = tokenizer.word_index
      
      # Pad sequences
      max_sequence_length = max(len(seq) for seq in sequences)
      data = pad_sequences(sequences, maxlen=max_sequence_length)
      
      # Convert labels to categorical
      labels = to_categorical(np.asarray(labels))
      
      # Split the data into a training set and a validation set
      x_train, x_val, y_train, y_val = train_test_split(data, labels, test_size=0.2, random_state=42)
      
      # Build the model
      model = Sequential()
      model.add(Embedding(input_dim=len(word_index) + 1, output_dim=128, input_length=max_sequence_length))
      model.add(LSTM(128, return_sequences=False))
      model.add(Dense(labels.shape[1], activation='softmax'))
      
      # Compile the model
      model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
      
      # Train the model
      model.fit(x_train, y_train, epochs=10, batch_size=32, validation_data=(x_val, y_val))
      
      # Save the model
      model.save('recipe_generator.h5')