I am using one of the pretrained language models from Huggingface for Question Answering but I am struggling to connect the jupyter widgets with the nlp pipeline.
I have this snippet which shows the user a set of questions that they can use for their QA.
w = widgets.Dropdown(
options=['What are the risks of defamation?', 'Are there risks?', \
'What are the risks of the trial?', \
'Is the trial risky?'],
value='What are the risks of defamation?',
description='Question:',
)
def on_change(change):
if change['type'] == 'change' and change['name'] == 'value':
trial_q = change['new']
#print(trial_q) works fine
w.observe(on_change)
display(w)
The selection works perfectly fine. However, I have trouble connecting it with the pipeline.
def QA(q, a):
print(nlp({
'question': q,
'context': a
}))
def transcriptName():
with open('data/uploaded_file.txt', 'r') as myfile:
data=myfile.read().replace('\n', '')
trial_q = QA('What are you randomised for?', data)
When calling the function, I get ValueError: Input is not valid. Should be a string, a list/tuple of strings or a list/tuple of integers.
So I assume it would be a problem with the context. However, if I change the trial_q inside the function with the string representation or 'What is the risk?', it works perfectly fine. What could be the issue?
It was a scope issue. The scope is within the widget.
w = widgets.Dropdown(
options=['What are the risks of defamation?', 'Are there risks?', \
'What are the risks of the trial?', \
'Is the trial risky?'],
value='What are the risks of defamation?',
description='Question:',
)
def on_change(change):
if change['type'] == 'change' and change['name'] == 'value':
trial_q = change['new']
...pipeline here...
w.observe(on_change)
display(w)