DOsinga / deep_learning_cookbook

Deep Learning Cookbox
Apache License 2.0
689 stars 338 forks source link

inverse_vocab is not defined #17

Closed StevenBorg closed 5 years ago

StevenBorg commented 6 years ago

In 07.1 Text Classification.ipynb, cell 8, the call to inverse_vocab fails as not

from collections import Counter, defaultdict by_cls = defaultdict(Counter) for word_idx, pred in enumerate(word_pred): for class_idx, score in enumerate(pred): cls = labelencoder.classes[class_idx] by_cls[cls][inverse_vocab[word_idx]] = score

results in


NameError Traceback (most recent call last)

in () 4 for class_idx, score in enumerate(pred): 5 cls = label_encoder.classes_[class_idx] ----> 6 by_cls[cls][inverse_vocab[word_idx]] = score NameError: name 'inverse_vocab' is not defined I'm on a Macbook pro, followed the install steps from the book exactly, pip installed the requirements into a clean virtual environment, opened this as my first notebook to run, and got the failure. Unfortunately, a Google search for inverse_vocab was not defined, so I'm struggling to see what additional requirements I should install to have it work correctly. Thanks, everyone!
DOsinga commented 6 years ago

Thanks for the report. I'll have a look at this tomorrow. I ran things on Linux, but I have a macbook here too - it could just me being sloppy.

nicksexton commented 6 years ago

I think the notebook is missing a line of code. @StevenBorg if you add the following line of code prior to cell 8 it should run: inverse_vocab = {idx: word for word, idx in tfidf_vec.vocabulary_.items()}

DFreeMind commented 5 years ago

I think the notebook is missing a line of code. @StevenBorg if you add the following line of code prior to cell 8 it should run: inverse_vocab = {idx: word for word, idx in tfidf_vec.vocabulary_.items()}

Nice, now it work

DOsinga commented 5 years ago

Thanks. Updating.