jiangjiechen commited on
Commit
f62e242
1 Parent(s): 1717bf9

improved layout

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -52,9 +52,14 @@ except Exception as e:
52
 
53
 
54
  def highlight_phrase(text, phrase):
 
55
  return text.replace('<mask>', f'<i><b>{phrase}</b></i>')
56
 
57
 
 
 
 
 
58
  def gradio_formatter(js, output_type):
59
  zebra_css = '''
60
  tr:nth-child(even) {
@@ -64,14 +69,23 @@ def gradio_formatter(js, output_type):
64
  background: #f1f1f1;
65
  }'''
66
  if output_type == 'e':
67
- data = {'Evidence': [f'* {x}' for x in js['evidence']]}
68
  elif output_type == 'z':
 
 
 
 
 
 
 
 
 
69
  data = {
70
  'Claim Phrase': js['claim_phrases'],
71
  'Local Premise': [highlight_phrase(q, x[0]) for q, x in zip(js['cloze_qs'], js['evidential'])],
72
- 'p_SUP': ['%.4f' % x[2] for x in js['phrase_veracity']],
73
- 'p_REF': ['%.4f' % x[0] for x in js['phrase_veracity']],
74
- 'p_NEI': ['%.4f' % x[1] for x in js['phrase_veracity']],
75
  }
76
  else:
77
  raise NotImplementedError
 
52
 
53
 
54
  def highlight_phrase(text, phrase):
55
+ text = loren.fc_client.tokenizer.clean_up_tokenization(text)
56
  return text.replace('<mask>', f'<i><b>{phrase}</b></i>')
57
 
58
 
59
+ def highlight_entity(text, entity):
60
+ return text.replace(entity, f'<i><b>{entity}</b></i>')
61
+
62
+
63
  def gradio_formatter(js, output_type):
64
  zebra_css = '''
65
  tr:nth-child(even) {
 
69
  background: #f1f1f1;
70
  }'''
71
  if output_type == 'e':
72
+ data = {'Evidence': [highlight_entity(x, e) for x, e in zip(js['evidence'], js['entities'])]}
73
  elif output_type == 'z':
74
+ p_sup, p_ref, p_nei = [], [], []
75
+ for x in js['phrase_veracity']:
76
+ max_idx = torch.argmax(torch.tensor(x)).tolist()
77
+ x = ['%.4f' % xx for xx in x]
78
+ x[max_idx] = f'<i><b>{x[max_idx]}</b></i>'
79
+ p_sup.append(x[2])
80
+ p_ref.append(x[0])
81
+ p_nei.append(x[1])
82
+
83
  data = {
84
  'Claim Phrase': js['claim_phrases'],
85
  'Local Premise': [highlight_phrase(q, x[0]) for q, x in zip(js['cloze_qs'], js['evidential'])],
86
+ 'p_SUP': p_sup,
87
+ 'p_REF': p_ref,
88
+ 'p_NEI': p_nei,
89
  }
90
  else:
91
  raise NotImplementedError