Closed mukesh-mehta closed 5 years ago
Hi mukesh-metha,
did you try to open the training file via
ftrain = open(os.path.join(Data_dir,"training.txt"),'r')
I've made the experience that the examples in the book are written for Python 2.x. The binary option is not necessary in Python 3 since there have been some changes in the API (see https://docs.python.org/3.0/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit).
lines = [] fin = open("../data/alice_in_wonderland.txt", "r") for line in fin: line = line.strip().encode("utf-8").decode("ascii", "ignore") if len(line) == 0: continue lines.append(line) fin.close()
ipython-input-11-cde6afe50c78 in module() 5 ftrain=open(os.path.join(Data_dir,"training.txt"),'rb') 6 for line in ftrain: ----> 7 label, sentence = line.strip().split("\t") 8 words=nltk.word_tokenize(sentence.decode().lower()) 9 if len(words)>maxlen:
I am using Python3.6