Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
|
|
5 |
|
6 |
# init important things
|
7 |
tokenizer = BertTokenizerFast.from_pretrained('bert-base-uncased')
|
8 |
-
model = BertForTokenClassification.from_pretrained('
|
9 |
model.eval()
|
10 |
model.to('cuda' if torch.cuda.is_available() else 'cpu')
|
11 |
|
@@ -40,4 +40,19 @@ def predict_ner_tags(sentence):
|
|
40 |
labels = [id2label[idx.item()] for idx in label_indices] if label_indices.numel() > 0 else ['O']
|
41 |
result.append({"token": token, "labels": labels})
|
42 |
|
43 |
-
return json.dumps(result, indent=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# init important things
|
7 |
tokenizer = BertTokenizerFast.from_pretrained('bert-base-uncased')
|
8 |
+
model = BertForTokenClassification.from_pretrained('maximuspowers/bias-detection-ner')
|
9 |
model.eval()
|
10 |
model.to('cuda' if torch.cuda.is_available() else 'cpu')
|
11 |
|
|
|
40 |
labels = [id2label[idx.item()] for idx in label_indices] if label_indices.numel() > 0 else ['O']
|
41 |
result.append({"token": token, "labels": labels})
|
42 |
|
43 |
+
return json.dumps(result, indent=4)
|
44 |
+
|
45 |
+
# startup gradio
|
46 |
+
iface = gr.Interface(
|
47 |
+
fn=predict_ner_tags,
|
48 |
+
inputs="text",
|
49 |
+
outputs="text",
|
50 |
+
title="Social Bias Named Entity Recognition (with BERT) 🕵",
|
51 |
+
description=("Enter a sentence to predict biased parts of speech tags. This model uses multi-label BertForTokenClassification, to label the entities: (GEN)eralizations, (UNFAIR)ness, and (STEREO)types. Labels follow BIO format. Try it out :)."
|
52 |
+
"<br><br>Read more about how this model was trained in this <a href='https://huggingface.co/blog/maximuspowers/bias-entity-recognition' target='_blank'>blog post</a>."
|
53 |
+
"<br>Model Page: <a href='https://huggingface.co/maximuspowers/bias-detection-ner' target='_blank'>Bias Detection NER</a>."),
|
54 |
+
allow_flagging="never"
|
55 |
+
)
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
iface.launch()
|