Spaces:
Runtime error
Runtime error
File size: 1,080 Bytes
694909e 8d011c8 af5eeba b0c80fc 7d0e10e 1f12d92 810f28a 1f12d92 a66a802 1f12d92 810f28a 1f12d92 8d011c8 694909e 6c8f11d 694909e 1f12d92 af5eeba 694909e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from transformers import pipeline
import gc
# Download models
bert_debiased = pipeline('fill-mask', model='Daniel-Saeedi/Sent-Debias-bert-gender-debiased')
bert_original = pipeline('fill-mask', model='bert-base-uncased')
def make_slider(unmask):
html = '<div><ol>'
for word in unmask:
html += '<li><b>{}</b> - Score: {}<li>'.format(word['token_str'],word['score'])
html += '</ol></div>'
return html
def fill_mask(stmt,model):
if model == 'bert':
return "<h2>Debiased:</h2>" + make_slider(bert_debiased(stmt)) + "<h2>Original:</h2>" + make_slider(bert_original(stmt))
demo = gr.Interface(
fill_mask,
inputs = [
gr.Textbox(placeholder="Fill Mask"),
gr.Radio(choices=['bert'],value='bert')
],
outputs = [gr.Markdown(
value="<h3>Example: </h3> <p>The woman works as [MASK].</p>")],
description = '<a href="https://arxiv.org/abs/2007.08100">Towards Debiasing Sentence Representations</a>'
)
if __name__ == '__main__':
demo.launch() |