256 Kilobytes

Answers in Scripting and Automation | By Some Guy


2,717 views, 0 RAMs, and 1 comment

Tags: Python, Scripting, Errors, Programming, ValueError

Profile Photo - Some GuySome GuyBasic Subscriber

When running a code on Python, I keep getting an error that seems to be easy to fix. However, I cannot seem to find how I can fix this error and run my code successfully. This is the error I get: "ValueError: unsupported pickle protocol: 3 (also 4)". Does anyone know I can get rid of it?

Download more RAM. 🐏 ⨉ 0Posted by Some Guy 2 years ago 🕓 Posted at 13 January, 2019 06:11 AM PST

This is a debug account.

Profile Photo - roxbladeroxbladeIndiaAuthor

Pickle protocol can be simply referred to as the file format. The higher the protocol is, the more recent version of python is what you need to read the pickle. Pickle protocol 4 was added in Python 3 .4, but you are highly using a lower version of python. The two options you have is to either upgrade to Python 3.4 or 3.5 or use pickle 2 in 3rd parameter.

You will have to try passing `protocol=2` to `pkl.dump(worddict, f, protocol=2`, while the vocabulary has been created

from __future__ import print_function
import numpy
    import cPickle as pkl
    import pickle as pkl
import sys
import fileinput

from collections import OrderedDict
def main():
    for filename in sys.argv[1:]:
        print('Processing', filename)
        word_freqs = OrderedDict()
        with open(filename, 'r') as f:
            for line in f:
                words_in = line.strip().split(' ')
                for w in words_in:
                    if w not in word_freqs:
                        word_freqs[w] = 0
                    word_freqs[w] += 1
        words = list(word_freqs.keys())
        freqs = list(word_freqs.values())
        sorted_idx = numpy.argsort(freqs)
        sorted_words = [words[ii] for ii in sorted_idx[::-1]]
        worddict = OrderedDict()
        worddict['eos'] = 0
        worddict['UNK'] = 1
        for ii, ww in enumerate(sorted_words):
            worddict[ww] = ii+2
        with open('%s.pkl'%filename, 'wb') as f:
            pkl.dump(worddict, f)
if __name__ == '__main__':

Download more RAM. 🐏 ⨉ 0Posted by roxblade 2 years ago 🕓 Posted at 27 February, 2019 13:31 PM PST

Some design is good, some design is bad, and yet some design is just full retard Comic Sans with a rainbow gradient on it.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!