my code:
import numpy as np
def pos_tag_fun(x_list, tag):
tagged_sentences = []
for sentence in x_list:
tagged = nltk.pos_tag(sentence)
tagged_sentences.append(tagged)
print(tagged_sentences[0])
# Extract the sentences and the corresponding POS tags
train_x_list, train_tag_tags =[], []
for tagged_sentence in tagged_sentences:
** sentence, tags = zip(*tagged_sentence)
** train_x_list.append(np.array(sentence))
train_tag_tags.append(np.array(tags))
print(tagged_sentences[0])
print("Tagged sentences: ", len(tagged_sentences))
print("Tagged words:", len(tag))
print(train_x_list[0])
print(train_tag_tags[0])
ques_list = pos_tag_fun(question_list, ques_tag)
getting error:
[('glacier', 'NN'), ('cave', 'VBP'), ('form', 'NN')]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-46-7073281060f4> in <cell line: 26>()
24 print(train_tag_tags[0])
25
---> 26 ques_list = pos_tag_fun(question_list, ques_tag)
<ipython-input-46-7073281060f4> in pos_tag_fun(x_list, tag)
13 train_x_list, train_tag_tags =[], []
14 for tagged_sentence in tagged_sentences:
---> 15 sentence, tags = zip(*tagged_sentence)
16 train_x_list.append(np.array(sentence))
17 train_tag_tags.append(np.array(tags))
ValueError: not enough values to unpack (expected 2, got 0)
it is giving expected output if I run w/o the defining it as a function else it gives not enough value error. But when I print the output for tagged_sentence; it is a tuple of two items like this:
('glacier', 'NN')
('direct', 'JJ')
('apollo', 'NNS')
('long', 'JJ')
('beretta', 'NN')
('vul', 'NN')
I am confused why when calling the function it is giving this error.