Commit
Β·
849684c
1
Parent(s):
43989d9
moved files and restructured
Browse files
.gitignore
CHANGED
@@ -42,3 +42,4 @@ logs/
|
|
42 |
|
43 |
# Ignore node_modules
|
44 |
node_modules/
|
|
|
|
42 |
|
43 |
# Ignore node_modules
|
44 |
node_modules/
|
45 |
+
Article-Bias-Prediction/
|
test.py β api.py
RENAMED
File without changes
|
datasettesting.py
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
from datasets import load_dataset
|
2 |
-
|
3 |
-
dataset = load_dataset("newsmediabias/instruction-safe-llm")
|
4 |
-
|
5 |
-
|
6 |
-
print(dataset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
politicalbiasbertmodel.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
-
import torch
|
3 |
-
|
4 |
-
# Load model and tokenizer
|
5 |
-
model_name = "bucketresearch/politicalBiasBERT"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
-
|
9 |
-
# Send model to GPU if available
|
10 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
-
model.to(device)
|
12 |
-
|
13 |
-
# Label mapping
|
14 |
-
label_mapping = {0: "Left", 1: "Center", 2: "Right"}
|
15 |
-
|
16 |
-
# Inference loop
|
17 |
-
def predict_bias(text):
|
18 |
-
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512).to(device)
|
19 |
-
with torch.no_grad():
|
20 |
-
outputs = model(**inputs)
|
21 |
-
logits = outputs.logits
|
22 |
-
probs = torch.softmax(logits, dim=-1)[0]
|
23 |
-
pred = torch.argmax(probs).item()
|
24 |
-
return label_mapping[pred], probs.tolist()
|
25 |
-
|
26 |
-
if __name__ == "__main__":
|
27 |
-
print("Political Bias Classifier (bucketresearch/politicalBiasBERT)")
|
28 |
-
while True:
|
29 |
-
text = input("\nEnter text to classify (or type 'exit' to quit): ")
|
30 |
-
if text.lower() == "exit":
|
31 |
-
break
|
32 |
-
label, confidence = predict_bias(text)
|
33 |
-
print(f"Predicted Bias: {label}")
|
34 |
-
print(f"Confidence Scores: {confidence}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
berttrainedonallsides.py β training/berttrainedonallsides.py
RENAMED
File without changes
|
training.py β training/training.py
RENAMED
File without changes
|
trainingfullbert.py β training/trainingfullbert.py
RENAMED
File without changes
|