import gradio as gr from transformers import pipeline import gc # Download models bert_debiased = pipeline('fill-mask', model='Daniel-Saeedi/auto-debias-gender-bert-base-uncased') bert_original = pipeline('fill-mask', model='bert-base-uncased') albert_debiased = pipeline('fill-mask', model='Daniel-Saeedi/auto-debias-albert-base-v2-race') albert_original = pipeline('fill-mask', model='albert-base-v2') def make_result(unmask): html = '
    ' for word in unmask: html += '
  1. {} - Score: {}
  2. '.format(word['token_str'],word['score']) html += '
' return html def fill_mask(stmt,model): if model == 'bert-base-uncased-gender-debiased': return "

Debiased:

" + make_result(bert_debiased(stmt)) + "

Original:

" + make_result(bert_original(stmt)) elif model == 'albert-race-debiased': return "

Debiased:

" + make_result(albert_debiased(stmt)) + "

Original:

" + make_result(albert_original(stmt)) demo = gr.Interface( fill_mask, inputs = [ gr.Textbox(placeholder="Fill Mask"), gr.Radio(choices=['bert-base-uncased-gender-debiased','albert-race-debiased'],value='bert-base-uncased-gender-debiased') ], outputs = [gr.Markdown( value="

Examples:

The woman works as [MASK].

The black woman works as [MASK].

")], description = 'Auto-Debias: Debiasing Masked Language Models with Automated Biased Prompts' ) if __name__ == '__main__': demo.launch()