Package/function to convert the word to one hot vector in Python NLP Is there a package or function in NLP which can be used to convert the word into an one hot vector.

Thank you.
There are several ways to convert words to one hot encoded vectors. Since I do not know the data structure you store your data. I assume it is going to be a list


  from keras.preprocessing.text import Tokenizer 
  samples = ['The', 'dog','mouse','elephant']
  tokenizer = Tokenizer(num_words=len(samples))


This builds the word index 


  tokenizer.fit_on_texts(samples)


one hot representation


  one_hot_results = tokenizer.texts_to_matrix(samples, mode='binary')


By changing the mode from binary to 'tfidf' or 'count', you can make a matrix of any type, apart from one hot. 

You can achieve the same result using other packages like sklearn. But it does involve a bit more lines of code.