Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with decode in test_review when deploying the model using PyTorch? #1

Closed
hpkhanh1610 opened this issue Dec 6, 2018 · 4 comments

Comments

@hpkhanh1610
Copy link

hpkhanh1610 commented Dec 6, 2018

Hi,

In the project, at Step 6 (again) - Deploy the model for the web app, at the function def test_reviews(data_dir='../data/aclImdb', stop=250):,
# Read in the review and convert to 'utf-8' for transmission via HTTP review_input = review.read().encode('utf-8') # Send the review to the predictor and store the results results.append(int(predictor.predict(review_input)))

I think the last line should be:
results.append(round(float(predictor.predict(review_input))))

The output from predictor.predict is in byte type, that is b' ', so we need to use float() to convert to real number and use round to round it to the nearest integer (int() is not correct in this case because it rounds all numbers from 0-1 down to 0 only).

@preetkhaturia
Copy link

Did you solve this? I am having the same issue.

@hpkhanh1610
Copy link
Author

Hi,

You just need to round the result in the predict.py first to either 0 or 1, then it will work in the main notebook. The result of predictor.predict(review_input) is in byte type but it does not matter. The int() function outside then converts it to int type because the value now is either 0 or 1 only.

I forgot to round the result in the predict.py so it get errors when using int() outside.

@preetkhaturia
Copy link

Can we see the intermediate outputs in predict function?? Because I am not really sure, I am having an error due to rounding.

@hpkhanh1610
Copy link
Author

The intermediate part is similar to what we need to do in the notebook in (TODO) More testing before we get to the predict.py:

input_data_cleaned = review_to_words(input_data)
data_X, data_len = convert_and_pad(model.word_dict, input_data_cleaned)
...
result = model(data).cpu().detach()
result = np.array(round(result.item()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants