我正在努力减轻我的工作。我需要对 BERT 为我提供的数千个文件的答案进行一些分析。我的主要目标是遍历每个文件并提出一个问题。
我一直在尝试使用以下代码使其自动化
import os
directory = '/content/dva/'
for filename in os.listdir(directory):
with open(directory + filename) as infile:
try:
nlp({
'question': 'How is artificial intelligence being used in real time health delivery?',
'context': data
})
except:
print(filename + ' is throwing an error')
上面的代码什么也不返回。然而,如果我一一做。它工作正常。所以我试着改变它。
x = ["How is artificial intelligence being used in real time health delivery?",\
"What adjunctive or supportive methods can help patients?",\
"How does hypertension affect patients?",\
"What does the computer do?"]
y = [item.strip() for item in x]
def testing(theList):
nlp = pipeline('question-answering')
for each_element in theList:
nlp({'question': each_element,'context': data})
testing(y) # returns nothing
print(testing(y)) # returns None
有没有人有任何见解?上面的代码非常适合 Allen 的 ELMo。