Datasets:
Tasks:
Token Classification
Languages:
English
Size:
10K<n<100K
Tags:
Not-For-All-Audiences
License:
query_tags: fix oob errors with frequency filters
Browse files- query_tags.py +3 -4
query_tags.py
CHANGED
@@ -45,15 +45,14 @@ def dothething(args):
|
|
45 |
top_k = args.topk
|
46 |
if top_k is None:
|
47 |
top_k = int(1.5 * global_topk / len(sel_idxs))
|
48 |
-
rank_tresh = int(tag_freq_to_rank(args.min_frequency))
|
49 |
-
print(f"{rank_tresh=}")
|
50 |
|
51 |
# Score and filter
|
52 |
scores = Xt[:rank_tresh] @ Xt[sel_idxs].T
|
53 |
-
scores[sel_idxs, :] = float("-inf") # Mask self-matches
|
54 |
if args.category:
|
55 |
categories = [tag_category2id[cat] for cat in args.category]
|
56 |
-
scores[~np.isin(tag_categories, categories), :] = float("-inf")
|
57 |
|
58 |
# Per query top-k
|
59 |
neigh_idxs = np.argpartition(-scores, top_k, axis=0)[:top_k]
|
|
|
45 |
top_k = args.topk
|
46 |
if top_k is None:
|
47 |
top_k = int(1.5 * global_topk / len(sel_idxs))
|
48 |
+
rank_tresh = min(N_vocab, int(tag_freq_to_rank(args.min_frequency)))
|
|
|
49 |
|
50 |
# Score and filter
|
51 |
scores = Xt[:rank_tresh] @ Xt[sel_idxs].T
|
52 |
+
scores[sel_idxs[sel_idxs < rank_tresh], :] = float("-inf") # Mask self-matches
|
53 |
if args.category:
|
54 |
categories = [tag_category2id[cat] for cat in args.category]
|
55 |
+
scores[~np.isin(tag_categories[:rank_tresh], categories), :] = float("-inf")
|
56 |
|
57 |
# Per query top-k
|
58 |
neigh_idxs = np.argpartition(-scores, top_k, axis=0)[:top_k]
|