Downloads · 30 days
6
1% of all-time downloads
tzoulio/news-bias-finder-llama-3.2-1B
news-bias-finder-llama-3.2-1B is a text classification model from tzoulio. Use it when you need a label for a piece of text. It is set up for peft.
This model is designed to detect potential political bias in news articles. Given a text passage (e.g., a news article), the model returns probabilities indicating whether the text is leaning to the Left, Center, or R…
Downloads · 30 days
6
1% of all-time downloads
All-time downloads
502
Public
Repo size
1.4 GB
Likes
1
Public
Click a slice to open those files.
.pt904 MB · 57%
From the Hugging Face model README
This model is designed to detect potential political bias in news articles. Given a text passage (e.g., a news article), the model returns probabilities indicating whether the text is leaning to the Left, Center, or Right of the political spectrum.
Note: This model is not an authoritative arbiter of political bias. It can be used as a supplementary tool to help flag potential leanings.
Below is a sample code snippet demonstrating how to load the model and apply LoRA adapters for classification:
import transformers
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from peft import PeftModel
# 1. Load the *base* LLaMA model for sequence classification
base_model_name = "meta-llama/Llama-3.2-1B"
access_token = "YOUR_HF_ACCESS_TOKEN" # If needed
model = AutoModelForSequenceClassification.from_pretrained(
base_model_name,
use_auth_token=access_token,
num_labels=3,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
# 2. Load the LoRA adapter on top of the base model
adapter_path = "tzoulio/news-bias-finder-llama-3.2-1B"
model = PeftModel.from_pretrained(model, adapter_path)
# 3. Create the pipeline with the specified model and tokenizer
pipeline = transformers.pipeline(
"text-classification",
model=model,
tokenizer=tokenizer
)
# Example usage
text = "Insert the news article text here..."
prediction = pipeline(text)
print(prediction)
Input: A single string containing the text of a news article. Output: A list of dictionaries, where each dictionary contains:
Example Output: [[{"LABEL_0": 0.23, "LABEL_1": 0.30, "LABEL_2": 0.47}]]
Indicates 23% chance of Left, 30% chance of Center, 47% chance of Right.
# Precision & Quantization
load_in_4bit = True
bnb_4bit_use_double_quant = True
bnb_4bit_quant_type = "nf4"
bnb_4bit_compute_dtype = torch.bfloat16
# LoRA Configuration
lora_r = 16
lora_alpha = 64
lora_dropout = 0.1
bias = "none"
# Task Type
task_type = "SEQ_CLS"
# Training Setup
per_device_train_batch_size = 4
gradient_accumulation_steps = 4
learning_rate = 2e-4
optim = "paged_adamw_32bit"
num_train_epochs = 3
warmup_steps = 2
fp16 = True
logging_steps = 1
We report the F1-score on each dataset split.