Coder Social home page Coder Social logo

timoschick / self-debiasing Goto Github PK

View Code? Open in Web Editor NEW
84.0 84.0 25.0 24 KB

This repository contains the code for "Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP".

Home Page: https://arxiv.org/abs/2103.00453

License: Apache License 2.0

Python 100.00%

self-debiasing's People

Contributors

timoschick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

self-debiasing's Issues

perplexity computation for self debiasing

Hi,

Thanks for open-sourcing the code!

I found that line 220-239 in modeling.py a little bit confusing. Specifically, I have the following questions:

  1. Why do we need to flip the attention mask for input prefixes (input_prefixes['attention_mask'] = torch.flip(input_prefixes['attention_mask'], dims=[1]))?
  2. Why do we need to roll the input_prefixes['input_ids'] by the length of input_prefixes?
  3. From my understanding, we can simply concat the input_prefixes without padding to input_ids_repeated (same for attention mask) and it is done.
  4. Why do we need to use shifts[0]? Isn't shifts[0] always 0 because the first prefix is ['']?

Thanks in advance!

Numerical Instability for apply_decay_mask

apply_dacy_mask convert logits to probability via softmax. In generation.py, the probability is then converted back to logits via torch.log, which may cause numerical instability. In my case, during the ppl evaluation, I encountered some probabilities became 0 and the logits became -inf, which makes the ppl extremely large.

To solve the issue, I wrote an equivalent version below:

def apply_decay_mask_logits(args, logits: torch.Tensor, decay_mask: torch.Tensor) -> torch.Tensor:
    """Applies exponential decay to a tensor of logits"""
    decay_mask = torch.exp(- decay_mask * args.decay_constant)
    decay_mask = torch.max(decay_mask, torch.tensor([args.epsilon], device=decay_mask.device))
    log_decay_mask = torch.log(decay_mask)
    logits += log_decay_mask
    return logits

Please advise. If it looks good to you, I can submit a pull request :)

`generate_self_debiasing` not implemented for `T5`

Hi, I noticed that the generate_self_debiasing function is not implemented for the T5 model:

self-debiasing/modeling.py

Lines 131 to 133 in c9764e5

def generate_self_debiasing(self, input_texts: List[str], debiasing_prefixes: List[str], decay_constant: float = 50,
epsilon: float = 0.01, debug: bool = False, **kwargs) -> List[str]:
raise NotImplementedError()

However, in Figure 1 of your paper you give examples of using T5 with self-debiasing.

Screenshot 2022-02-16 at 11 33 53

Would you mind publishing the code for self-debiasing with T5?

Given that T5 is an encoder-decoder model, I assume that self-debiasing has to be performed differently to GPT2, i.e. instead of debiasing the continuation of a prompt, T5 debiases the input sentence itself, or more precisely, the text that is generated for the span in the input sentence that is replaced by a sentinel token. Is it also possible to use self-debiasing with T5 if there are more than one sentinel tokens in the input sentence? Moreover, I'm wondering if it is possible to debias an input sentence with T5 without having to first replace the biased words by sentinel tokens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.