input: Write a python function to classify movie reviews or other texts as either positive or negative sentiment using a machine learning model. The function should utilize a recurrent neural network with a word-embedding layer or a logistic regression with a bag-of-words vectorizer to classify the text. The model should be trained on a labeled dataset and tested for accuracy on a held-out test set.
  assert classify_sentiment("The movie was fantastic!") == "positive"
  assert classify_sentiment("I did not like the film at all.") == "negative"
  assert classify_sentiment("It was an okay movie.") == "neutral"
output: import numpy as np
  from keras.models import Sequential
  from keras.layers import Embedding, LSTM, Dense, SpatialDropout1D
  from keras.preprocessing.text import Tokenizer
  from keras.preprocessing.sequence import pad_sequences
  from sklearn.model_selection import train_test_split
  from sklearn.metrics import accuracy_score
  
  # Example dataset
  texts = ["I loved the movie", "I hated the movie", "It was an okay movie", "Fantastic film", "Terrible experience"]
  labels = [1, 0, 2, 1, 0]  # 1: positive, 0: negative, 2: neutral
  
  # Preprocessing
  tokenizer = Tokenizer(num_words=5000)
  tokenizer.fit_on_texts(texts)
  X = tokenizer.texts_to_sequences(texts)
  X = pad_sequences(X, maxlen=100)
  y = np.array(labels)
  
  # Train-test split
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
  
  # Model definition
  model = Sequential()
  model.add(Embedding(input_dim=5000, output_dim=100, input_length=100))
  model.add(SpatialDropout1D(0.2))
  model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2))
  model.add(Dense(3, activation='softmax'))
  
  model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
  
  # Train the model
  model.fit(X_train, y_train, epochs=5, batch_size=32, validation_data=(X_test, y_test), verbose=2)
  
  # Function to classify sentiment
  def classify_sentiment(text):
      sequence = tokenizer.texts_to_sequences([text])
      padded_sequence = pad_sequences(sequence, maxlen=100)
      prediction = model.predict(padded_sequence)
      sentiment = np.argmax(prediction)
      if sentiment == 1:
          return "positive"
      elif sentiment == 0:
          return "negative"
      else:
          return "neutral"