IPython Widgets Separated by Character Rather Than Word

Viewed 32

As you can tell in the picture below, the table is separated by characters rather than full words.

def apply(f):
    text = f
    text = re.sub(r'\W+', ' ', text)
    res = LM().check_probabilities(text, topk=20)
    l = str(res)
    paraphrase_widget = widgets.SelectMultiple(
    options=l,
    description='Paraphrases',
    disabled=False,
    layout= widgets.Layout(width='100%')
   )
    display(paraphrase_widget)
    return {"result": res}


apply("In order to")

enter image description here

1 Answers

The issue here is in unpacking pytorch's prediction and passing those results to the widget in proper format (a list of tuples). Here's how you can do that:

# Modify your widget to the following
paraphrase_widget = widgets.SelectMultiple(
      options=res['pred_topk'][2],
      description='Paraphrases',
      disabled=False,
      layout= widgets.Layout(width='100%', height="300px")
   )

Here's what this looks like for me:

enter image description here

Related