Rafal commited on
Commit
6419576
·
1 Parent(s): 2f790d1

Fixed templating display issues

Browse files
Files changed (1) hide show
  1. mgr_bias_scoring.py +14 -4
mgr_bias_scoring.py CHANGED
@@ -277,8 +277,8 @@ def maskSentenceDifferences(sentence, rewrite, target_words, att_term):
277
  rewrite = rewrite.replace(no_space_att, att_term)
278
 
279
  # identify group term in both sentences
280
- sentence = sentence_to_template(sentence, target_words[0], "[T]")
281
- rewrite = sentence_to_template(rewrite, target_words[1], "[T]")
282
  #print(f'S1: {sentence}')
283
  #print(f'R1: {rewrite}')
284
 
@@ -301,7 +301,17 @@ def maskSentenceDifferences(sentence, rewrite, target_words, att_term):
301
  else:
302
  template += "[R]"
303
  template_tokens.append("[R]")
304
- add_refs.append((s.lower(),r.lower()))
 
 
 
 
 
 
 
 
 
 
305
  elif s in string.punctuation:
306
  template += s.strip(" ")
307
  template_tokens.append(s)
@@ -311,7 +321,7 @@ def maskSentenceDifferences(sentence, rewrite, target_words, att_term):
311
 
312
  template += " "
313
 
314
- return TreebankWordDetokenizer().detokenize(template_tokens), add_refs
315
 
316
  # turn generated sentence into a test templates - reference term aware version
317
  def ref_terms_sentence_to_template(row):
 
277
  rewrite = rewrite.replace(no_space_att, att_term)
278
 
279
  # identify group term in both sentences
280
+ sentence = sentence_to_template(sentence, target_words[0], "*")
281
+ rewrite = sentence_to_template(rewrite, target_words[1], "*")
282
  #print(f'S1: {sentence}')
283
  #print(f'R1: {rewrite}')
284
 
 
301
  else:
302
  template += "[R]"
303
  template_tokens.append("[R]")
304
+
305
+ l_mask = s.lower()
306
+ r_mask = r.lower()
307
+ if l_mask == "*" and r_mask != "*":
308
+ l_mask = target_words[0]
309
+ elif l_mask != "*" and r_mask == "*":
310
+ r_mask = target_words[1]
311
+
312
+ add_refs.append((l_mask, r_mask))
313
+
314
+ #add_refs.append((s.lower(),r.lower()))
315
  elif s in string.punctuation:
316
  template += s.strip(" ")
317
  template_tokens.append(s)
 
321
 
322
  template += " "
323
 
324
+ return TreebankWordDetokenizer().detokenize(template_tokens).replace("*","[T]"), add_refs
325
 
326
  # turn generated sentence into a test templates - reference term aware version
327
  def ref_terms_sentence_to_template(row):