0

While loading pre-trained models I get the following error. I think it's because I am using python 3.7 and the code is written in python 2.* . So anyone can tell me how can I convert it into 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):
    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                        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)
5
  • It seems this thread has an answer. stackoverflow.com/questions/11305790/… Commented Dec 29, 2019 at 13:38
  • Does this answer your question? Pickle incompatibility of numpy arrays between Python 2 and 3 Commented Dec 29, 2019 at 17:45
  • @lenz No it doesn't solve my problem. I still get the same error. Commented Dec 29, 2019 at 20:21
  • @SanghyunLee Same. Still getting the same error. Commented Dec 29, 2019 at 20:22
  • 1
    Did you add encoding='latin1' to all four calls to pickle.load? Ie. for cv_file, tf_file, clf_file, and tagger_file? Commented Dec 29, 2019 at 20:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.