Update app.py
Browse files
app.py
CHANGED
@@ -90,6 +90,7 @@ from allennlp.predictors.predictor import Predictor
|
|
90 |
import allennlp_models.tagging
|
91 |
predictor = Predictor.from_path("structured-prediction-srl-bert.tar.gz")
|
92 |
|
|
|
93 |
#---------------------------------------------------------------
|
94 |
def claim(text):
|
95 |
import re
|
@@ -148,163 +149,150 @@ def claim(text):
|
|
148 |
#----------FOR COLUMN "WHO"------------#
|
149 |
df['who'] = ''
|
150 |
for j in range(len(df['modified'])):
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
167 |
else:
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
who.append(substr)
|
173 |
-
else:
|
174 |
-
pass
|
175 |
-
# who=list(set(who))
|
176 |
-
df['who'][j] = "<sep>".join(who)
|
177 |
# else:
|
178 |
# continue
|
179 |
#----------FOR COLUMN "WHAT"------------#
|
180 |
df['what'] = ''
|
181 |
for j in range(len(df['modified'])):
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
else:
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
if len(substr)!= 0:
|
203 |
-
what.append(substr)
|
204 |
-
else:
|
205 |
-
pass
|
206 |
-
|
207 |
-
df['what'][j] = "<sep>".join(what)
|
208 |
-
# else:
|
209 |
-
# continue
|
210 |
|
211 |
#----------FOR COLUMN "WHY"------------#
|
212 |
df['why'] = ''
|
213 |
for j in range(len(df['modified'])):
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
230 |
else:
|
231 |
-
|
232 |
-
else:
|
233 |
-
pass
|
234 |
-
if len(substr)!= 0:
|
235 |
-
why.append(substr)
|
236 |
-
else:
|
237 |
-
pass
|
238 |
-
# why=list(set(why))
|
239 |
|
240 |
-
|
241 |
-
# else:
|
242 |
-
# continue
|
243 |
|
244 |
#----------FOR COLUMN "WHEN"------------#
|
245 |
df['when'] = ''
|
246 |
for j in range(len(df['modified'])):
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
263 |
else:
|
264 |
-
|
265 |
-
else:
|
266 |
-
pass
|
267 |
-
if len(substr)!= 0:
|
268 |
-
when.append(substr)
|
269 |
-
else:
|
270 |
-
pass
|
271 |
-
# when=list(set(when))
|
272 |
|
273 |
-
|
274 |
-
# else:
|
275 |
-
# continue
|
276 |
|
277 |
|
278 |
#----------FOR COLUMN "WHERE"------------#
|
279 |
df['where'] = ''
|
280 |
for j in range(len(df['modified'])):
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
297 |
else:
|
298 |
-
|
299 |
-
else:
|
300 |
-
pass
|
301 |
-
if len(substr)!= 0:
|
302 |
-
where.append(substr)
|
303 |
-
else:
|
304 |
-
pass
|
305 |
-
# where=list(set(where))
|
306 |
|
307 |
-
|
308 |
|
309 |
|
310 |
data=df[["claim","who","what","why","when","where"]].copy()
|
@@ -626,7 +614,6 @@ def gen_qa_where(df):
|
|
626 |
list_of_evidence_answer_where="No mention of 'where'in any related documents."
|
627 |
rouge_l_scores="Not verifiable"
|
628 |
return list_of_ques_where,list_of_ans_where,rouge_l_scores,list_of_evidence_answer_where
|
629 |
-
|
630 |
#------------------------------------------------------
|
631 |
|
632 |
|
|
|
90 |
import allennlp_models.tagging
|
91 |
predictor = Predictor.from_path("structured-prediction-srl-bert.tar.gz")
|
92 |
|
93 |
+
#---------------------------------------------------------------
|
94 |
#---------------------------------------------------------------
|
95 |
def claim(text):
|
96 |
import re
|
|
|
149 |
#----------FOR COLUMN "WHO"------------#
|
150 |
df['who'] = ''
|
151 |
for j in range(len(df['modified'])):
|
152 |
+
val_list = []
|
153 |
+
val_string = ''
|
154 |
+
for k,v in df['modified'][j].items():
|
155 |
+
val_list.append(v)
|
156 |
+
|
157 |
+
who = set() # use set to remove duplicates
|
158 |
+
for indx in range(len(val_list)):
|
159 |
+
val_string = val_list[indx]
|
160 |
+
pos = val_string.find("who: ")
|
161 |
+
substr = ''
|
162 |
+
|
163 |
+
if pos != -1:
|
164 |
+
for i in range(pos+5, len(val_string)):
|
165 |
+
if val_string[i] == "]":
|
166 |
+
break
|
167 |
+
else:
|
168 |
+
substr = substr + val_string[i]
|
169 |
+
substr = substr.strip() # remove leading/trailing white space
|
170 |
+
pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
|
171 |
+
if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
|
172 |
+
who.add(substr)
|
173 |
else:
|
174 |
+
pass
|
175 |
+
|
176 |
+
df['who'][j] = "<sep>".join(who)
|
177 |
+
|
|
|
|
|
|
|
|
|
|
|
178 |
# else:
|
179 |
# continue
|
180 |
#----------FOR COLUMN "WHAT"------------#
|
181 |
df['what'] = ''
|
182 |
for j in range(len(df['modified'])):
|
183 |
+
val_list = []
|
184 |
+
val_string = ''
|
185 |
+
for k,v in df['modified'][j].items():
|
186 |
+
val_list.append(v)
|
187 |
+
|
188 |
+
what = set() # use set to remove duplicates
|
189 |
+
for indx in range(len(val_list)):
|
190 |
+
val_string = val_list[indx]
|
191 |
+
pos = val_string.find("what: ")
|
192 |
+
substr = ''
|
193 |
+
|
194 |
+
if pos != -1:
|
195 |
+
for i in range(pos+5, len(val_string)):
|
196 |
+
if val_string[i] == "]":
|
197 |
+
break
|
198 |
+
else:
|
199 |
+
substr = substr + val_string[i]
|
200 |
+
substr = substr.strip() # remove leading/trailing white space
|
201 |
+
pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
|
202 |
+
if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
|
203 |
+
what.add(substr)
|
204 |
else:
|
205 |
+
pass
|
206 |
+
|
207 |
+
df['what'][j] = "<sep>".join(what)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
#----------FOR COLUMN "WHY"------------#
|
210 |
df['why'] = ''
|
211 |
for j in range(len(df['modified'])):
|
212 |
+
val_list = []
|
213 |
+
val_string = ''
|
214 |
+
for k,v in df['modified'][j].items():
|
215 |
+
val_list.append(v)
|
216 |
+
|
217 |
+
why = set() # use set to remove duplicates
|
218 |
+
for indx in range(len(val_list)):
|
219 |
+
val_string = val_list[indx]
|
220 |
+
pos = val_string.find("why: ")
|
221 |
+
substr = ''
|
222 |
+
|
223 |
+
if pos != -1:
|
224 |
+
for i in range(pos+5, len(val_string)):
|
225 |
+
if val_string[i] == "]":
|
226 |
+
break
|
227 |
+
else:
|
228 |
+
substr = substr + val_string[i]
|
229 |
+
substr = substr.strip() # remove leading/trailing white space
|
230 |
+
pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
|
231 |
+
if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
|
232 |
+
why.add(substr)
|
233 |
else:
|
234 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
+
df['why'][j] = "<sep>".join(why)
|
|
|
|
|
237 |
|
238 |
#----------FOR COLUMN "WHEN"------------#
|
239 |
df['when'] = ''
|
240 |
for j in range(len(df['modified'])):
|
241 |
+
val_list = []
|
242 |
+
val_string = ''
|
243 |
+
for k,v in df['modified'][j].items():
|
244 |
+
val_list.append(v)
|
245 |
+
|
246 |
+
when = set() # use set to remove duplicates
|
247 |
+
for indx in range(len(val_list)):
|
248 |
+
val_string = val_list[indx]
|
249 |
+
pos = val_string.find("when: ")
|
250 |
+
substr = ''
|
251 |
+
|
252 |
+
if pos != -1:
|
253 |
+
for i in range(pos+5, len(val_string)):
|
254 |
+
if val_string[i] == "]":
|
255 |
+
break
|
256 |
+
else:
|
257 |
+
substr = substr + val_string[i]
|
258 |
+
substr = substr.strip() # remove leading/trailing white space
|
259 |
+
pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
|
260 |
+
if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
|
261 |
+
when.add(substr)
|
262 |
else:
|
263 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
+
df['when'][j] = "<sep>".join(when)
|
|
|
|
|
266 |
|
267 |
|
268 |
#----------FOR COLUMN "WHERE"------------#
|
269 |
df['where'] = ''
|
270 |
for j in range(len(df['modified'])):
|
271 |
+
val_list = []
|
272 |
+
val_string = ''
|
273 |
+
for k,v in df['modified'][j].items():
|
274 |
+
val_list.append(v)
|
275 |
+
|
276 |
+
where = set() # use set to remove duplicates
|
277 |
+
for indx in range(len(val_list)):
|
278 |
+
val_string = val_list[indx]
|
279 |
+
pos = val_string.find("where: ")
|
280 |
+
substr = ''
|
281 |
+
|
282 |
+
if pos != -1:
|
283 |
+
for i in range(pos+5, len(val_string)):
|
284 |
+
if val_string[i] == "]":
|
285 |
+
break
|
286 |
+
else:
|
287 |
+
substr = substr + val_string[i]
|
288 |
+
substr = substr.strip() # remove leading/trailing white space
|
289 |
+
pronouns = ['he', 'she', 'they', 'it', 'him', 'her', 'them', 'its', 'himself', 'herself', 'themselves']
|
290 |
+
if substr.lower() not in pronouns and not substr.lower().endswith("'s"): # remove pronouns and possessive pronouns
|
291 |
+
where.add(substr)
|
292 |
else:
|
293 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
|
295 |
+
df['where'][j] = "<sep>".join(where)
|
296 |
|
297 |
|
298 |
data=df[["claim","who","what","why","when","where"]].copy()
|
|
|
614 |
list_of_evidence_answer_where="No mention of 'where'in any related documents."
|
615 |
rouge_l_scores="Not verifiable"
|
616 |
return list_of_ques_where,list_of_ans_where,rouge_l_scores,list_of_evidence_answer_where
|
|
|
617 |
#------------------------------------------------------
|
618 |
|
619 |
|