NIPS '17 Workshop: Criteo Ad Placement Challenge

Counterfactual policy learning for display advertising


a bytes-like object is required, not 'str' when writing to file

Posted by Shubhi 4 months ago

Hi, I am using Python 3.5 on Windows. When I run the command “python –test_set=data/criteo_test_release_small.txt.gz –output_path=data/predictions.gz”, I get the following error:

Reading test set from : data/criteo_test_release_small.txt.gz Traceback (most recent call last): File “”, line 32, in for _idx, _impression in enumerate(data): File "C:\Users\IBM_ADMIN\Desktop\Self Studies\NIPS ads\criteo_starter_kit\crit", line 41, in __next__ return File "C:\Users\IBM_ADMIN\Desktop\Self Studies\NIPS ads\criteo_starter_kit\crit", line 34, in next next_block = self.get_next_impression_block() File "C:\Users\IBM_ADMIN\Desktop\Self Studies\NIPS ads\criteo_starter_kit\crit", line 60, in get_next_impression_block block_impression_id = utils.extract_impression_id(line) File "C:\Users\IBM_ADMIN\Desktop\Self Studies\NIPS ads\criteo_starter_kit\util", line 10, in extract_impression_id return line[:line.index("|")].strip() TypeError: a bytes-like object is required, not 'str'

Its because in Python 3.5 , all data read from the file is returned as bytes objects, not str. You cannot then use a string for write back and test it. Does anyone have a solution to resolve this issue?

Thanks, Shubhi

7.screen shot 2017 02 22 at 12.48.51

Posted by spMohanty  4 months ago |  Quote

Thanks @Shubhi for pointing this out. This should be fixed in this commit.

Please pull the latest changes from the repository, and try again.


Avatar default

Posted by Shubhi  4 months ago |  Quote

I am not sure the problem got solved. Even though the test set processes 10,000 impressions for the small test set: Reading test set from : data/criteo_test_release_small.txt.gz Processed 0 impressions… Processed 500 impressions… Processed 1000 impressions… Processed 1500 impressions… Processed 2000 impressions… Processed 2500 impressions… Processed 3000 impressions… Processed 3500 impressions… Processed 4000 impressions… Processed 4500 impressions… Processed 5000 impressions… Processed 5500 impressions… Processed 6000 impressions… Processed 6500 impressions… Processed 7000 impressions… Processed 7500 impressions… Processed 8000 impressions… Processed 8500 impressions… Processed 9000 impressions… Processed 9500 impressions… Successfully Wrote predictions file to : data/predictions.gz

However when I run the command :python –api_key= --predictions=data/predictions.gz with my crowdai_api_key, I get the following error:

crowdai.challenges.crowdai_errors.CrowdAIExecuteFunctionError: The prediction file is expected to contain predictions for 10000 impressions. But the submitted file contains predictins for 0 impressions.

in predictions.gz, I see that the predictions are missing “\n” 896678244;0:9.653171228634976,1:1.6832024142539292,2:2.1606332593798783,3:4.884344977622973,4:7.1426290662561875,5:8.046190746253894,6:4.924386389116212,7:6.603867201820902,8:3.317023592721756,9:2.1252490852482255,10:9.5375547104972751332733630;0:6.519321399498372,1:9.939021971859344,2:8.678783932419998,3:1.2573023755679158,4:5.791924719057741,5:9.839883099238525,6:6.463823793583448,7:0.698148995051131,8:4.51337030376997,9:2.236802431877315,10:8.711642733654822642298222;0:1.3411986323066682,1:5.9326551704187,2:4.441277475303074,3:8.465107503391177,4:7.228464103949213,5:2.623431097985507,6:3.6160961806843295,7:0.05505625990972152,8:9.516235176978151,9:9.425532004502138,10:9.499176040767344,11:5.737000592241673,12:4.319398489265664113594215;0:9.252795187513854,1:2.9258981291318618,2:2.96508767016035,3:1.1902810494662797,4:7.338370618518124,5:3.003790935933679,6:5.485765260518349,7:1.056544188674563,8:0.8818437874991725,9:6.376236000482152,10:9.457723858796763289177935;0:9.114098971050108,1:4.7357452787725745,2:4.219671661999751,3:4.184895319901192,4:7.56348341507564,5:9.917292757050415,6:7.6078457407323805,7:6.629387071228856,8:2.2673447512991505,9:6.269401984647884,10:0.24624860377179925,11:3.6278702993368004912634132;0:2.419899501114803,1:3.

This could be a reason why the indicates having 0 predictions.

7.screen shot 2017 02 22 at 12.48.51

Posted by spMohanty  4 months ago |  Quote

Hi @Shubhi, That was because of a small typo in my code. It has been fixed. Can you pull the latest changes and try again ?