Add scores
Browse files- pipeline.py +4 -7
pipeline.py
CHANGED
@@ -42,15 +42,12 @@ class PreTrainedPipeline():
|
|
42 |
similarities = distance.cdist(embeddings.reshape((1,300)), self.comparisons, "cosine")[0]
|
43 |
top_indices = similarities.argsort()[:10]
|
44 |
top_words = [[self.id2h[str(top_indices[i])]] for i in range(10)]
|
45 |
-
|
|
|
|
|
46 |
|
47 |
return [
|
48 |
-
[
|
49 |
-
{'label': top_words[0], 'score': 0},
|
50 |
-
{'label': top_words[1], 'score': 0},
|
51 |
-
{'label': top_words[2], 'score': 0},
|
52 |
-
{'label': top_words[3], 'score': 0},
|
53 |
-
]
|
54 |
]
|
55 |
|
56 |
|
|
|
42 |
similarities = distance.cdist(embeddings.reshape((1,300)), self.comparisons, "cosine")[0]
|
43 |
top_indices = similarities.argsort()[:10]
|
44 |
top_words = [[self.id2h[str(top_indices[i])]] for i in range(10)]
|
45 |
+
logits = np.exp(-10*np.array(similarities[top_indices]))
|
46 |
+
softmax_probs = tf.nn.softmax(logits).numpy()
|
47 |
+
top_scores = [round(float(softmax_probs[i]), 3) for i in range(10)]
|
48 |
|
49 |
return [
|
50 |
+
[{'lable': word, 'score': score} for word, score in zip(top_words, top_scores)]
|
|
|
|
|
|
|
|
|
|
|
51 |
]
|
52 |
|
53 |
|