Home > Blockchain >  Reverse from POS tagging to sentence using pandas
Reverse from POS tagging to sentence using pandas

Time:10-07

I have pos_token dataset and I want to transform them to be a sentence again using pandas

pos_token sentence
[(No, DT), (you, PRP), (lying, VBG)] No you lying

CodePudding user response:

if pos_token is a list values then try this;

df = pd.DataFrame({"pos_token":[[("No", "DT"), ("you", "PRP"), ("lying", "VBG")]]})

df["sentence"] = df["pos_token"].apply(lambda x: " ".join([i[0] for i in x]))

#  output
                              pos_token      sentence
0  [(No, DT), (you, PRP), (lying, VBG)]  No you lying
  • Related