Skip to content
Advertisement

Why does python not provide output in this code?

def prepareData(dataset):
    X,y=[],[]
    for words in dataset:
        X.append([features(untag(dataset), s) for s in range(len(dataset))])
        y.append([tag for word,tag in sentences])
    return X,y
ValueError: too many values to unpack (expected 2)

Here, dataset is a list and s is an integer value index of any object in the list.

Advertisement

Answer

The problem is with this line:

y.append([tag for word,tag in sentences])

You don’t tell us what sentences is, but it’s apparent it’s not what it needs to be.

For example:

sentences = ['this is a test','a quick brown fox']
[tag for word,tag in sentences]

ValueError: too many values to unpack (expected 2)

If your sentences was a list of two-tuples the code would work:

sentences = [('this is a test','tag1'),('a quick brown fox','tag2')]
In [15]: [tag for word,tag in sentences]
Out[15]: ['tag1', 'tag2']
Advertisement