title: Can not squeeze dim[1], expected a dimension of 1, got 4 for 'metrics/accuracy/Squeeze' (op: 'Squeeze') with input shapes: [?,4]
body: <p>Tensorflow - 2.1.0</p>
  
  <p>Python - 3.6</p>
  
  <p>I have searched this issue on stackoverflow but could not find solution.</p>
  
  <p>I am trying to create a chatbot using tensorflow. This is error:</p>
  
  <blockquote>
    <p>Can not squeeze dim[1], expected a dimension of 1, got 4 for
    'metrics/accuracy/Squeeze' (op: 'Squeeze') with input shapes: [?,4].</p>
  </blockquote>
  
  <p>This is code:</p>
  
  <pre><code>words = []
      classes = []
      documents = []
      ignore_words = ['?', '!']
      data_file = open('fil.json').read()
      intents = json.loads(data_file)
      for intent in intents['intents']:
          for pattern in intent['question']:
              w = nltk.word_tokenize(pattern)
              words.extend(w)
              documents.append((w, intent['tag']))
              if intent['tag'] not in classes:
                  classes.append(intent['tag'])
      words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
      words = sorted(list(set(words)))
      classes = sorted(list(set(classes)))
      pickle.dump(words, open('words.pkl', 'wb'))
      pickle.dump(classes, open('classes.pkl', 'wb'))
      training = []
      output_empty = [0] * len(classes)
      for doc in documents:
          bag = []
          pattern_words = doc[0]
          pattern_words = [lemmatizer.lemmatize(word.lower()) for word in pattern_words]
          for w in words:
              bag.append(1) if w in pattern_words else bag.append(0)
          output_row = list(output_empty)
          output_row[classes.index(doc[1])] = 1
  
          training.append([bag, output_row])
      random.shuffle(training)
      training = np.array(training)
      train_x = list(training[:, 0])
      train_y = list(training[:, 1])
      print("Training data created")
      model = tf.keras.models.Sequential([
          tf.keras.layers.Dense(128, input_shape=(len(train_x[0]),), activation='relu'),
          tf.keras.layers.Dropout(0.2),
          tf.keras.layers.Dense(len(train_y[0]), activation='softmax')
      ])
      model.compile(optimizer='adam',
                    loss='sparse_categorical_crossentropy',
                    metrics=['accuracy'])
      hist = model.fit(train_x, train_y, epochs=5)
      model.save('chatbot_model.h5', hist)
  
      print("model created")
  </code></pre>