svenwey commited on
Commit
e9cffd2
·
1 Parent(s): b341fbf

revert precompilation of timestamp regex due to error

Browse files
Files changed (1) hide show
  1. logscoremetric.py +4 -5
logscoremetric.py CHANGED
@@ -68,7 +68,6 @@ class LogScoreMetric(evaluate.Metric):
68
 
69
  # Constant regex to get timestrings
70
  timestamp_regex = r'(^\d{4}[-/.]\d{2}[-/.]\d{2}(?:[ T]\d{2}[:]\d{2}(?:[:]\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}[:]\d{2})?)?)'
71
- timestamp_pattern = re.compile(timestamp_regex, re.MULTILINE)
72
  sacrebleu = evaluate.load("sacrebleu")
73
 
74
  def _info(self):
@@ -102,8 +101,8 @@ class LogScoreMetric(evaluate.Metric):
102
  pred = pred.strip(' \t\n\r')
103
 
104
  # Find all timestrings in the log
105
- pred_timestrings = self.timestamp_pattern.findall(pred)
106
- ref_timestrings = self.timestamp_pattern.findall(ref)
107
 
108
  #Check if there is the correct amount of timestrings in the prediction
109
  if(len(pred_timestrings) != len(ref_timestrings)):
@@ -142,8 +141,8 @@ class LogScoreMetric(evaluate.Metric):
142
  t_before = time.perf_counter()
143
 
144
  timestamp_score = np.mean([self.getLogMetric(p,r) for p,r in zip(predictions,references)])
145
- predictions_without_timestamps = [self.timestamp_pattern.sub('', p) for p in predictions]
146
- references_without_timestamps = [self.timestamp_pattern.sub('', r) for r in references]
147
 
148
  # Sacrebleu score on logs without timestamps
149
  sb_results = self.sacrebleu.compute(predictions=predictions_without_timestamps, references=references_without_timestamps)
 
68
 
69
  # Constant regex to get timestrings
70
  timestamp_regex = r'(^\d{4}[-/.]\d{2}[-/.]\d{2}(?:[ T]\d{2}[:]\d{2}(?:[:]\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}[:]\d{2})?)?)'
 
71
  sacrebleu = evaluate.load("sacrebleu")
72
 
73
  def _info(self):
 
101
  pred = pred.strip(' \t\n\r')
102
 
103
  # Find all timestrings in the log
104
+ pred_timestrings = re.findall(self.timestamp_regex, pred, re.MULTILINE)
105
+ ref_timestrings = re.findall(self.timestamp_regex, ref, re.MULTILINE)
106
 
107
  #Check if there is the correct amount of timestrings in the prediction
108
  if(len(pred_timestrings) != len(ref_timestrings)):
 
141
  t_before = time.perf_counter()
142
 
143
  timestamp_score = np.mean([self.getLogMetric(p,r) for p,r in zip(predictions,references)])
144
+ predictions_without_timestamps = [re.sub(self.timestamp_regex, '', p, flags=re.MULTILINE) for p in predictions]
145
+ references_without_timestamps = [re.sub(self.timestamp_regex, '', r, flags=re.MULTILINE) for r in references]
146
 
147
  # Sacrebleu score on logs without timestamps
148
  sb_results = self.sacrebleu.compute(predictions=predictions_without_timestamps, references=references_without_timestamps)