Spaces:
Running
Running
kovacsvi
commited on
Commit
·
882055b
1
Parent(s):
af68a82
prettify output for flat pred
Browse files
interfaces/cap_minor_media.py
CHANGED
@@ -165,16 +165,29 @@ def predict_flat(text, model_id, tokenizer_id, HF_TOKEN=None):
|
|
165 |
top_indices = np.argsort(probs)[::-1][:10]
|
166 |
|
167 |
CAP_MIN_MEDIA_LABEL_NAMES = CAP_MEDIA_LABEL_NAMES | CAP_MIN_LABEL_NAMES
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
interpretation_info = """
|
175 |
## How to Interpret These Values (Flat Classification)
|
176 |
|
177 |
-
This method returns predictions made by a single model. Both media codes and minor topics may appear in the output list. Only the top 10 most confident labels are displayed
|
178 |
"""
|
179 |
|
180 |
return interpretation_info, output_pred, output_info
|
|
|
165 |
top_indices = np.argsort(probs)[::-1][:10]
|
166 |
|
167 |
CAP_MIN_MEDIA_LABEL_NAMES = CAP_MEDIA_LABEL_NAMES | CAP_MIN_LABEL_NAMES
|
168 |
+
|
169 |
+
output_pred = {}
|
170 |
+
for i in top_indices:
|
171 |
+
code = CAP_MIN_MEDIA_NUM_DICT[i]
|
172 |
+
prob = probs[i]
|
173 |
+
|
174 |
+
if code in CAP_MEDIA_LABEL_NAMES:
|
175 |
+
# Media (major) topic
|
176 |
+
label = CAP_MEDIA_LABEL_NAMES[code]
|
177 |
+
display = f"[{code}] {label}"
|
178 |
+
else:
|
179 |
+
# Minor topic
|
180 |
+
major_code = code // 100
|
181 |
+
major_label = CAP_MEDIA_LABEL_NAMES[major_code]
|
182 |
+
minor_label = CAP_LABEL_NAMES[code]
|
183 |
+
display = f"[{major_code}] {major_label} [{code}] {minor_label}"
|
184 |
+
|
185 |
+
output_pred[display] = prob
|
186 |
|
187 |
interpretation_info = """
|
188 |
## How to Interpret These Values (Flat Classification)
|
189 |
|
190 |
+
This method returns predictions made by a single model. Both media codes and minor topics may appear in the output list. **Only the top 10 most confident labels are displayed**.
|
191 |
"""
|
192 |
|
193 |
return interpretation_info, output_pred, output_info
|