mpk001 / Sentiment_analysis

使用深度学习方法对IMDB电影评价做情感分析,使用的方法分别为:MLP、BiRNN、BiGRU+Attention Model
219 stars 85 forks source link

TypeError: cannot use a string pattern on a bytes-like object #4

Closed Eurus-Holmes closed 6 years ago

Eurus-Holmes commented 6 years ago

您好,运行IMDB_Classifier_MLP.py时报错:

Using TensorFlow backend. Traceback (most recent call last): (25000, 3) File "/Users/chenfeiyang/PycharmProjects/Sentiment_analysis_IMDB/IMDB_Classifier_MLP.py", line 45, in texts.append(clean_str(text.get_text().encode('ascii','ignore'))) File "/Users/chenfeiyang/PycharmProjects/Sentiment_analysis_IMDB/IMDB_Classifier_MLP.py", line 32, in clean_str string = re.sub(r"\", "", string) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 191, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: cannot use a string pattern on a bytes-like object

请问是为什么呢?

Eurus-Holmes commented 6 years ago

Solved! The Unicode string in python3 is the default format (that is, str type), ASCII-encoded string (which is the bytes type, bytes type contains byte values, in fact, not a string, python3 and byte array byte array type) to be in front The addition operator b or B; python2 is the opposite, the ASCII encoding string is the default, the Unicode string is preceded by the operator u or U...