Downloads · 30 days
16
23% of all-time downloads
newsmediabias/UnBIAS-NER
UnBIAS-NER is a token classification model from newsmediabias. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as mit.
Downloads · 30 days
16
23% of all-time downloads
All-time downloads
71
Public
Repo size
871 MB
Likes
0
Public
Click a slice to open those files.
.bin436 MB · 100%
From the Hugging Face model README
license: mit language:
This model is a fine-tuned token classification model designed to predict entities in sentences. It's fine-tuned on a custom dataset that focuses on identifying certain types of entities, including biases in text.
The model is intended to be used for entity recognition tasks, especially for identifying biases in text passages. Users can input a sequence of text, and the model will highlight words or tokens or spans it believes are associated with a particular entity or bias.
https://www.sciencedirect.com/science/article/abs/pii/S0957417423020444
The model can be used for inference directly through the Hugging Face transformers library:
from transformers import AutoModelForTokenClassification, AutoTokenizer
import torch
device = torch.device("cpu")
# Load model directly
from transformers import AutoTokenizer, AutoModelForTokenClassification
tokenizer = AutoTokenizer.from_pretrained("newsmediabias/UnBIAS-NER")
model = AutoModelForTokenClassification.from_pretrained("newsmediabias/UnBIAS-NER")
def highlight_biased_entities(sentence):
tokens = tokenizer.tokenize(tokenizer.decode(tokenizer.encode(sentence)))
inputs = tokenizer.encode(sentence, return_tensors="pt")
inputs = inputs.to(device)
outputs = model(inputs).logits
predictions = torch.argmax(outputs, dim=2)
id2label = model.config.id2label
# Reconstruct words from subword tokens and highlight them
highlighted_sentence = ""
current_word = ""
is_biased = False
for token, prediction in zip(tokens, predictions[0]):
label = id2label[prediction.item()]
if label in ['B-BIAS', 'I-BIAS']:
if token.startswith('##'):
current_word += token[2:]
else:
if current_word:
if is_biased:
highlighted_sentence += f"BIAS[{current_word}] "
else:
highlighted_sentence += f"{current_word} "
current_word = token
else:
current_word = token
is_biased = True
else:
if current_word:
if is_biased:
highlighted_sentence += f"BIAS[{current_word}] "
else:
highlighted_sentence += f"{current_word} "
current_word = ""
highlighted_sentence += f"{token} "
is_biased = False
if current_word:
if is_biased:
highlighted_sentence += f"BIAS[{current_word}]"
else:
highlighted_sentence += current_word
# Filter out special tokens and subword tokens
highlighted_sentence = highlighted_sentence.replace(' [', '[').replace(' ]', ']').replace(' ##', '')
return highlighted_sentence
sentence = "due to your evil and dishonest nature, i am kind of tired and want to get rid of such cheapters. all people like you are evil and a disgrace to society and I must say to get rid of immigrants as they are filthy to culture"
highlighted_sentence = highlight_biased_entities(sentence)
print(highlighted_sentence)
Every model has limitations, and it's crucial to understand these when deploying models in real-world scenarios:
It's also essential to be aware of any potential biases in the training data, which might affect the model's predictions.
The model was fine-tuned on a custom dataset. Ask Shaina Raza [email protected] for dataset