NLP for ChatBots : How to Train Simple Neural Networks for Sentiment Analysis

Data File: D:/mystuff/comments.txt Data: i love you,pos i hate you,neg i kill you,neg i love to kill you,neg i admire you,pos import numpy as np from sklearn.feature_extraction.text import TfidfVectorizer def tfidf(x): vec = TfidfVectorizer() vec.fit(x) return vec.transform(x).toarray() f = open('D:/mystuff/comments.txt') lines = f.readlines() text =[] y=[] for line in lines: w = line.lower().strip().split(",") text.append(w[0]) l=0 if w[1]=='pos': l=1 y.append(l) X = tfidf(text) Y = np.c_[y] print(X) [[0. 0. 0. 0.861037 0. 0.50854232] [0. 0.90275015 0. 0. 0. 0.43016528] [0. 0. 0.861037 0. 0. 0.50854232] [0. 0. 0.50733821 0.50733821 0.62883263 0.29964212] [0.90275015 0. 0. 0. ...