Views
No views yet
meta-llama/Llama-3.1-8B for three-class stance classification in Portuguese climate change social media comments.A Decade of Climate Polarization on Brazilian YouTube using Language Models
Accepted at ASONAM 2026 — to be presented Aug 24–27, 2026, Rabat, Marrocos
meta-llama/Llama-3.1-8B.| Label | Class | Description |
|---|---|---|
| 0 | Denier | Explicitly expresses skepticism toward climate change; denies its occurrence; downplays its impacts; rejects anthropogenic responsibility; claims global warming is a "hoax," a "lie," a natural cycle, or a conspiracy; or articulates generalized denial of climate science. |
| 1 | Believer | Explicitly acknowledges climate change; agrees with the scientific consensus; expresses environmental concern; defends scientific evidence; or criticizes harmful practices such as deforestation or wildfires. |
| 2 | Inconclusive | Does not clearly belong to either of the above categories; contains ambiguous statements; expresses generic agreement or disagreement without clear stance; lacks sufficient information to infer position; or is irrelevant to the climate change debate. |
pip install torch transformers peft acceleratemeta-llama/Llama-3.1-8B is a gated model. You must:token= or run huggingface-cli login before loading the model1import warnings
2import logging
3import torch
4from transformers import AutoTokenizer, AutoModelForSequenceClassification
5from peft import PeftModel
6
7warnings.filterwarnings("ignore")
8logging.getLogger("transformers").setLevel(logging.ERROR)
9logging.getLogger("peft").setLevel(logging.ERROR)
10
11base_model = "meta-llama/Llama-3.1-8B"
12lora_model = "danielangelo1/llama-climate-change-stance-ptbr-lora"
13
14# Access token required - request access at:
15# https://huggingface.co/meta-llama/Llama-3.1-8B
16HF_TOKEN = "your_token_here"
17
18tokenizer = AutoTokenizer.from_pretrained(base_model, token=HF_TOKEN)
19tokenizer.pad_token = tokenizer.eos_token
20
21model = AutoModelForSequenceClassification.from_pretrained(
22 base_model,
23 num_labels=3,
24 torch_dtype=torch.float16,
25 device_map="auto",
26 token=HF_TOKEN,
27)
28model.config.pad_token_id = tokenizer.pad_token_id
29model = PeftModel.from_pretrained(model, lora_model, token=HF_TOKEN)
30model.eval()
31
32label_map = {0: "Denier", 1: "Believer", 2: "Inconclusive"}
33
34text = "O aquecimento global é uma ameaça real e precisamos agir agora."
35inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(model.device)
36
37with torch.no_grad():
38 logits = model(**inputs).logits
39 predicted_class = logits.argmax(dim=-1).item()
40
41print(f"Predicted class: {predicted_class} -> {label_map[predicted_class]}")| Hyperparameter | Value |
|---|---|
| Method | QLoRA (Quantized LoRA — PEFT) |
| Base Model | meta-llama/Llama-3.1-8B |
| Quantization | 4-bit NF4 with bfloat16 computation |
| LoRA rank (r) | 64 |
| LoRA alpha | 16 |
| LoRA dropout | — (not applied) |
| Target modules | q_proj, k_proj, v_proj |
| Max sequence length | 192 tokens |
| Epochs | Up to 20 (early stopping, patience = 3) |
| Batch size | 128 |
| Learning rate | 2 × 10⁻⁴ |
| Loss function | Weighted cross-entropy (inverse class frequency) |
| Validation metric | Macro F1 |
| Cross-validation | Stratified 5-fold |
| Precision | Mixed (FP16) |
| Hardware | 1× NVIDIA A40 48GB · Intel Xeon Gold 6442Y 2.6GHz · 512GB RAM |
1@inproceedings{morais2026climate,
2 author = {Daniel Morais and Diego H. M. Magalhaes and Gabriel H. Silva and Andrea Failla and Valeria de C. Santos and Helen C. S. C. Lima and Carlos H. G. Ferreira},
3 title = {A Decade of Climate Polarization on Brazilian YouTube using Language Models},
4 booktitle = {Proceedings of the 18th International Conference on Advances in Social Networks Analysis and Mining-ASONAM 2026},
5 year = {2026},
6 month = {Aug},
7 address = {Rabat, Morocco},
8 publisher = {Springer Nature},
9 note = {To appear}
10}