Skip to content

Only extract one word from gumbel softmax #14

@allanj

Description

@allanj

In the code https://github.com/yala/text_nn/blob/master/rationale_net/utils/learn.py#L71-L85

def get_hard_mask(z, return_ind=False):
    '''
        -z: torch Tensor where each element probablity of element
        being selected
        -args: experiment level config
        returns: A torch variable that is binary mask of z >= .5
    '''
    max_z, ind = torch.max(z, dim=-1)
    if return_ind:
        del z
        return ind
    masked = torch.ge(z, max_z.unsqueeze(-1)).float()
    del z
    return masked

because we take the max, usually, only one position will have the max value.
In this case, if we have 100 words in the sentence, we only select one word as the rationale?
I thought we should select independently and choose those words with >0.5 probability.

Maybe we should change

masked = torch.ge(z, max_z.unsqueeze(-1)).float()

to

masked = torch.ge(z, 0.5).float()

instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions