Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```
|
2 |
+
import pandas as pd
|
3 |
+
import time
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForTokenClassification, AutoModelForCausalLM, pipeline, BitsAndBytesConfig, LogitsProcessor, LogitsProcessorList
|
5 |
+
import torch
|
6 |
+
|
7 |
+
debiaser_tokenizer = AutoTokenizer.from_pretrained("newsmediabias/UnBIAS-LLama2-Debiaser-Chat")
|
8 |
+
debiaser_model = AutoModelForCausalLM.from_pretrained("newsmediabias/UnBIAS-LLama2-Debiaser-Chat")
|
9 |
+
|
10 |
+
# <s>[INST] <<SYS>> System prompt <</SYS>> User prompt [/INST] Model answer </s>
|
11 |
+
|
12 |
+
instruction = "Debias this text:"
|
13 |
+
system_message = "You are a text debiasing bot, you take as input a text and you output its debiased version by rephrasing it to be free from any age, gender, political, social or socio-economic biases, without any extra outputs"
|
14 |
+
|
15 |
+
pipe = pipeline(task="text-generation", model=debiaser_model, tokenizer=debiaser_tokenizer,max_length=500)
|
16 |
+
debiased_text = pipe(f"<s>[INST] <<SYS>>{system_message}<</SYS>> {instruction} {text} [/INST]")
|
17 |
+
|
18 |
+
|
19 |
+
instruction = "Debias this text:"
|
20 |
+
system_message = "You are a text debiasing bot, you take as input a text and you output its debiased version by rephrasing it to be free from any age, gender, political, social or socio-economic biases, without any extra outputs"
|
21 |
+
text=" I hate the fact that asians are taking over all jobs "
|
22 |
+
pipe = pipeline(task="text-generation", model=debiaser_model, tokenizer=debiaser_tokenizer,max_length=500)
|
23 |
+
debiased_text = pipe(f"<s>[INST] <<SYS>>{system_message}<</SYS>> {instruction} {text} [/INST]")
|
24 |
+
|
25 |
+
debiased_text"""
|