Skip to content
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

Feature Request: Allow sampling of log probs and logits for Likelihood.CLASSIFICATION #241

Open
BlackHC opened this issue Sep 12, 2024 · 3 comments · May be fixed by #243
Open

Feature Request: Allow sampling of log probs and logits for Likelihood.CLASSIFICATION #241

BlackHC opened this issue Sep 12, 2024 · 3 comments · May be fixed by #243
Assignees
Labels
enhancement New feature or request

Comments

@BlackHC
Copy link

BlackHC commented Sep 12, 2024

The code in _glm_predictive_samples always applies torch.softmax to the results under classification.

For numerical stability supporting torch.log_softmax here would be helpful. Similarly, it would be helpful if there was an easy way to obtain the logits without having to change self.likelihood intermittently.

Thanks,
Andreas

@wiseodd
Copy link
Collaborator

wiseodd commented Sep 13, 2024

Thanks for the input, Andreas! I wonder if something like this works for your case:

def _glm_predictive_samples(
    self,
    f_mu: torch.Tensor,
    f_var: torch.Tensor,
+   link_function: Optional[Callable[[torch.Tensor], torch.Tensor]]
    n_samples: int,
    diagonal_output: bool = False,
    generator: torch.Generator | None = None,
) -> torch.Tensor:

Where

  • link_function = None restores the current implementation
  • link_function = lambda f: f gets you a sample logits
  • link_function = functools.partial(torch.log_softmax, dim=-1) gets you a sample log-softmax.
  • This can also be used to compute an arbitrary expectation.

@aleximmer, @runame feel free to chime in.

Looking for feedback before implementing this.

@wiseodd wiseodd self-assigned this Sep 13, 2024
@wiseodd wiseodd added the enhancement New feature or request label Sep 13, 2024
@BlackHC
Copy link
Author

BlackHC commented Sep 14, 2024

Aww, yeah, that would be great! It would cover all my use cases and provide a nice extensible interface.

@runame
Copy link
Collaborator

runame commented Sep 14, 2024

Sounds like a good improvement!

@wiseodd wiseodd linked a pull request Sep 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants