Adding final version of entropy entropy acquisitions with test cases#14
Open
rishabh-mondal wants to merge 3 commits intosustainability-lab:mainfrom
Open
Adding final version of entropy entropy acquisitions with test cases#14rishabh-mondal wants to merge 3 commits intosustainability-lab:mainfrom
rishabh-mondal wants to merge 3 commits intosustainability-lab:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented Entropy acquisition and test cases on commit 2944d64
Files added:
Passes all test cases, including those already existing 2944d64
Explanations:
class EntropyAcquisition(MCAcquisition, EnsembleAcquisition, DeterministicAcquisition):This line defines a new Python class called EntropyAcquisition. This class inherits from three parent classes: MCAcquisition, EnsembleAcquisition, and DeterministicAcquisition.
def acquire_scores(self, logits: torch.Tensor): if logits.dim() == 3:If the logits tensor has three dimensions, this line computes the log probabilities (log-softmax) along the last dimension (dim=2) using PyTorch's F.log_softmax function and stores the result in the log_probs variable.
entropy = -torch.sum(torch.exp(log_probs) * log_probs, dim=2)This line calculates the entropy of the logits.
entropy = torch.sum(entropy, dim=0)This line sums up the calculated entropies across all samples in the sequence by summing along the first dimension (dim=0), resulting in a single entropy list.
else: log_probs = F.log_softmax(logits, dim=1) entropy = -torch.sum(torch.exp(log_probs) * log_probs, dim=1) return entropyIf it is deterministic, it is just returns a list of entropy.