Repository navigation
Limit categories in output multinouli distribution #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6616e7e
c743c9d
4f57692
eec51ee
529da4c
fd277cc
0d23501
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,25 @@ def _param_schema(cls): | |
| "probs": {"type": "array", "items": {"type": "number"}}, | ||
| } | ||
|
|
||
| @property | ||
| def _params_formatted(self) -> str: | ||
| n_categories = len(self.labels) | ||
| top_bottom_counts = (7, 3) | ||
| if n_categories <= top_bottom_counts[0]: | ||
|
MSVermet marked this conversation as resolved.
Resolved
|
||
| return super()._params_formatted | ||
| sorted_indices = np.argsort(-self.probs) | ||
| top_indices = sorted_indices[:top_bottom_counts[0]] | ||
| bottom_indices = sorted_indices[-top_bottom_counts[1]:] | ||
| top_labels = ", ".join(repr(label) for label in self.labels[top_indices].tolist()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess because it's a np._str?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make sure if label is not a string it can be joined. Not sure if this could ever happen, but just in case. |
||
| top_probs = ", ".join(f"{prob:.3f}" for prob in self.probs[top_indices]) | ||
| bottom_labels = ", ".join(repr(label) for label in self.labels[bottom_indices].tolist()) | ||
| bottom_probs = ", ".join(f"{prob:.3f}" for prob in self.probs[bottom_indices]) | ||
| return ( | ||
| f"\t- labels: [{top_labels}, ..., {bottom_labels}]\n" | ||
| f"\t- probs: [{top_probs}, ..., {bottom_probs}]\n" | ||
| f"\tShowing {top_bottom_counts[0]+top_bottom_counts[1]} of {n_categories} categories" | ||
| ) | ||
|
|
||
| def draw(self): | ||
| return np.random.choice(self.labels, p=self.probs) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.