chapter 16 Sentiment Analysis
When I run this line of code I get this error
vocabulary = Counter()
for X_batch, y_batch in datasets["train"].batch(32).map(preprocess):
for review in X_batch:
vocabulary.update(list(review.numpy()))
AttributeError: 'SparseTensor' object has no attribute 'to_tensor'
Hi @massamuel ,
I just ran the code, and I cannot reproduce this error. Did you manage to find the cause? If not, could you please make sure you have the latest version of the notebook, and the latest version of all libraries, and run all the cells in order?
Thanks!
Hi @massamuel ,
The issue is in your implementation of preprocess function. In the book-implementation last statement converts RaggedTensor to Tensor (this is where you are getting error). Root cause is that you applying .to_tensor()-attribute to SparseTensor instead of RaggedTensor. Probably you are using numpy/Python - native function to split a sentence to words. Use tf.strings.split instead.