在python中加载相关模型时出现Unicode错误
在加载预先训练的模型时,我得到以下错误。我想这是因为我使用的是Python3.7,代码是用Python2*编写的。因此,任何人都可以告诉我如何将其转换为python 3.7在python中加载相关模型时出现Unicode错误,python,machine-learning,unicode,nlp,ascii,Python,Machine Learning,Unicode,Nlp,Ascii,在加载预先训练的模型时,我得到以下错误。我想这是因为我使用的是Python3.7,代码是用Python2*编写的。因此,任何人都可以告诉我如何将其转换为python 3.7 import pandas as pd import numpy as np from train.reminder_tagger import ReminderTagger extractor=ReminderTagger(use_pretrained=True) class ReminderTagger(object
import pandas as pd
import numpy as np
from train.reminder_tagger import ReminderTagger
extractor=ReminderTagger(use_pretrained=True)
class ReminderTagger(object):
def __init__(self,use_pretrained=False,save_model=True,tagger="maxent_tagger"):
self.use_pretrained=use_pretrained
self.save_model=save_model
features_file=open('./trained_models/bow_features.pkl','rb')
self.features = load(features_file)
features_file.close()
if(use_pretrained==True):
cv_file=open('./trained_models/count_vectorizer.pkl','rb')
self.cv=load(cv_file)
cv_file.close()
tf_file=open('./trained_models/tf_idftransformer.pkl','rb')
self.tf=load(tf_file)
tf_file.close()
clf_file=open('./trained_models/reminder_classifier.pkl','rb')
self.clf=load(clf_file)
clf_file.close()
tagger_file=open('./trained_models/tagger.pkl','rb')
self.tagger=load(tagger_file)
tagger_file.close()
UnicodeDecodeError回溯(最近一次呼叫上次)
在里面
2作为np导入numpy
3来自列车提醒\标签导入提醒标签
---->4提取器=提醒标记(使用预训练=真)
5.
~/Desktop/提醒提取主控器/train/rementer\u tagger.py in\uuuu\u init\uuuu(self,use\u pretrained,save\u model,tagger)
22如果(使用_pretrained==True):
23 cv_文件=打开('./trained_models/count_vectorizer.pkl','rb')
--->24 self.cv=加载(cv\u文件)
25 cv_文件.close()
26 tf_文件=打开('./trained_models/tf_idftransformer.pkl','rb')
UnicodeDecodeError:“ascii”编解码器无法解码位置0中的字节0xb3:序号不在范围内(128)
这条线索似乎有答案。这回答了你的问题吗@不,这不能解决我的问题。我仍然得到同样的错误。@SanghyunLee同样。仍然收到相同的错误。是否将encoding='latin1'
添加到对pickle.load的所有四个调用中?例如,对于cv\u文件
,tf\u文件
,clf\u文件
,以及tagger\u文件
?
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-5-4790b6c5cf74> in <module>
2 import numpy as np
3 from train.reminder_tagger import ReminderTagger
----> 4 extractor=ReminderTagger(use_pretrained=True)
5
~/Desktop/Reminder-Extraction-master/train/reminder_tagger.py in __init__(self, use_pretrained, save_model, tagger)
22 if(use_pretrained==True):
23 cv_file=open('./trained_models/count_vectorizer.pkl','rb')
---> 24 self.cv=load(cv_file)
25 cv_file.close()
26 tf_file=open('./trained_models/tf_idftransformer.pkl','rb')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb3 in position 0: ordinal not in range(128)