emanuelaboros commited on
Commit
9bbf34b
·
1 Parent(s): bffe103

added confidence

Browse files
Files changed (1) hide show
  1. generic_nel.py +1 -23
generic_nel.py CHANGED
@@ -125,34 +125,12 @@ class NelPipeline(Pipeline):
125
  transition_scores = self.model.compute_transition_scores(
126
  outputs.sequences, outputs.scores, normalize_logits=True
127
  )
128
- print(len(transition_scores), "!!!!")
129
- probabilities = transition_scores[0]
130
- print(probabilities, "!!!!", probabilities.shape)
131
  log_prob_sum = sum(transition_scores[0])
132
 
133
  # Calculate the probability for the entire sequence by exponentiating the sum of log probabilities
134
-
135
  sequence_confidence = torch.exp(log_prob_sum)
136
-
137
  percentages = sequence_confidence.cpu().numpy() * 100.0
138
 
139
- # # Process each score (logits for the generated tokens)
140
- # for i, score in enumerate(scores):
141
- # # Apply softmax to convert logits into probabilities
142
- # probabilities = F.softmax(score, dim=-1)
143
- #
144
- # # Get the probabilities for the top tokens
145
- # top_probabilities = (
146
- # probabilities.cpu().numpy()
147
- # ) # Move to CPU and convert to NumPy
148
- #
149
- # # Store the probabilities
150
- # all_probabilities.append(top_probabilities)
151
- # print(f"Top probabilities: {top_probabilities}")
152
- #
153
- # # Convert probabilities into percentages if needed
154
- # percentages = [(prob * 100.0).tolist() for prob in all_probabilities]
155
-
156
  # Return the predictions along with the extracted entity, lOffset, and rOffset
157
  return wikipedia_predictions, enclosed_entity, lOffset, rOffset, [percentages]
158
 
@@ -196,7 +174,7 @@ class NelPipeline(Pipeline):
196
  "wkd_id": qid,
197
  "url": url,
198
  "type": "UNK",
199
- "confidence_nel": percentages[idx],
200
  "lOffset": lOffset,
201
  "rOffset": rOffset,
202
  }
 
125
  transition_scores = self.model.compute_transition_scores(
126
  outputs.sequences, outputs.scores, normalize_logits=True
127
  )
 
 
 
128
  log_prob_sum = sum(transition_scores[0])
129
 
130
  # Calculate the probability for the entire sequence by exponentiating the sum of log probabilities
 
131
  sequence_confidence = torch.exp(log_prob_sum)
 
132
  percentages = sequence_confidence.cpu().numpy() * 100.0
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  # Return the predictions along with the extracted entity, lOffset, and rOffset
135
  return wikipedia_predictions, enclosed_entity, lOffset, rOffset, [percentages]
136
 
 
174
  "wkd_id": qid,
175
  "url": url,
176
  "type": "UNK",
177
+ "confidence_nel": round(percentages[idx], 2),
178
  "lOffset": lOffset,
179
  "rOffset": rOffset,
180
  }