title: IndexError: index -2 is out of bounds for axis 0 with size 1
body: <p><strong>Created a chatbot in Django using nltk and sklearn</strong></p>
  <p><em>while sending the message I am experiencing this error</em></p>
  <pre><code>C:\Users\xxx\django\project\env\lib\site-packages\sklearn\feature_extraction\text.py:388: UserWarning: Your stop_words may be inconsistent with your preprocessing. Tokenizing the stop words generated 
  tokens ['ha', 'le', 'u', 'wa'] not in stop_words.
    warnings.warn('Your stop_words may be inconsistent with '
  Internal Server Error: /addmsg
  Traceback (most recent call last):
    File &quot;C:\Users\xxx\django\project\env\lib\site-packages\django\core\handlers\exception.py&quot;, line 34, in inner
      response = get_response(request)
    File &quot;C:\Users\xxx\django\project\env\lib\site-packages\django\core\handlers\base.py&quot;, line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File &quot;C:\Users\xxx\django\project\env\lib\site-packages\django\core\handlers\base.py&quot;, line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;C:\Users\xxx\django\project\home\views.py&quot;, line 19, in addmsg        
      bot_msg(c)
    File &quot;C:\Users\xxx\django\project\home\views.py&quot;, line 23, in bot_msg       
      c = give_response(msg)
    File &quot;C:\Users\xxx\django\project\home\nlp.py&quot;, line 69, in give_response   
      return find_response(input_given)
    File &quot;C:\Users\xxx\django\project\home\nlp.py&quot;, line 42, in find_response   
      idx = values.argsort()[0][-2]
  IndexError: index -2 is out of bounds for axis 0 with size 1
  </code></pre>
  <p><strong>This is the Code that sends the response to the message</strong></p>
  <p><em>I am not aware of why the file somefile.txt used and how to store data in it</em></p>
  <pre><code>from sklearn.metrics.pairwise import cosine_similarity
  import nltk
  import numpy
  import random
  import string
  
  from sklearn.feature_extraction.text import TfidfVectorizer
  def find_response(response):
      chatbots_file = open(r'somefile.txt','r',errors = 'ignore')
      info_data = chatbots_file.read()
      info_data = info_data.lower()
      nltk.download('punkt')
      nltk.download('wordnet')
      sentence_tokens = nltk.sent_tokenize(info_data)
      word_tokens = nltk.word_tokenize(info_data)
      
      
      bot_response = ''
      sentence_tokens.append(response)
      TfidfVec = TfidfVectorizer(tokenizer = normalize, stop_words = 'english')
      tfidf = TfidfVec.fit_transform(sentence_tokens)
      
      values = cosine_similarity(tfidf[-1],tfidf)
      idx = values.argsort()[0][-2]
      flat = values.flatten()
      flat.sort()
      
      req_tfidf = flat[-2]
      if(req_tfidf==0):
          bot_response = bot_response + &quot;I am sorry! I don't understand you&quot;
      else:
          bot_response = bot_response + sentence_tokens[idx]
      return bot_response 
  </code></pre>