Reputation: 51
I am having the aforementioned error in my python code. I am working on a google colab.
def create_dataset(path, num_examples):
lines = io.open(path, encoding='UTF-8').read().strip().split('\n')
#print(lines)
word_pairs = [[preprocess_sentence(w) for w in l.split('\t')] for l in lines[:num_examples]]
print(path)
return zip(*word_pairs)
sample_size=60000
source, target = create_dataset(data_path, sample_size)
print(source[-1])
print(target[-1])
type(target)
Following error appears while I try to compile the code:
1 sample_size=60000
----> 2 source, target = create_dataset(data_path, sample_size)
3 print(source[-1])
4 print(target[-1])
5 type(target)
ValueError: too many values to unpack (expected 2)
Guidance will be highly appreciated.
Upvotes: 0
Views: 605
Reputation: 888
You are returning a zip object which is an iterator of tuples. Your tuple size is > 2 and so you are getting that error on source, target = create_dataset(data_path, sample_size)
.
Simple example of same is below:
>>> a = [['a', 'b', 'c'], [1, 2, 3]]
>>> x,y = zip(*a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
>>> tuple(zip(*a))
(('a', 1), ('b', 2), ('c', 3))
>>>
Upvotes: 1