Instructions to use RheaTinghe/stat214-lab3-bert-lora-r4-maxlen256 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use RheaTinghe/stat214-lab3-bert-lora-r4-maxlen256 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Add LoRA adapter (lora_r4_maxlen256) for stat214-lab3
Browse files- README.md +81 -0
- adapter_config.json +46 -0
- adapter_model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: bert-base-uncased
|
| 3 |
+
library_name: peft
|
| 4 |
+
tags:
|
| 5 |
+
- peft
|
| 6 |
+
- lora
|
| 7 |
+
- bert
|
| 8 |
+
- masked-lm
|
| 9 |
+
- fmri-encoding
|
| 10 |
+
- neuroscience
|
| 11 |
+
- stat214
|
| 12 |
+
license: apache-2.0
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# stat214-lab3-bert-lora-r4-maxlen256
|
| 16 |
+
|
| 17 |
+
LoRA adapter for `bert-base-uncased`, fine-tuned on transcripts from the
|
| 18 |
+
Huth Lab fMRI story-listening dataset for the **Stat 214 (Spring 2026)**
|
| 19 |
+
final project at UC Berkeley.
|
| 20 |
+
|
| 21 |
+
The adapter is used to extract context-aware word embeddings that are then
|
| 22 |
+
fed into a per-voxel ridge regression to predict whole-brain BOLD signal
|
| 23 |
+
from spoken-story stimuli.
|
| 24 |
+
|
| 25 |
+
## Configuration
|
| 26 |
+
|
| 27 |
+
| Hyperparameter | Value |
|
| 28 |
+
|---|---|
|
| 29 |
+
| Base model | `bert-base-uncased` |
|
| 30 |
+
| LoRA rank `r` | 4 |
|
| 31 |
+
| LoRA alpha | 8 |
|
| 32 |
+
| LoRA dropout | 0.1 |
|
| 33 |
+
| Target modules | `query`, `value` |
|
| 34 |
+
| Training objective | Masked Language Modeling (MLM, 15%) |
|
| 35 |
+
| Training stories | 86 (Huth Lab podcast transcripts) |
|
| 36 |
+
| MLM max sequence length | 256 |
|
| 37 |
+
| Epochs | 3 |
|
| 38 |
+
| Optimizer | AdamW, lr=2e-4 |
|
| 39 |
+
| Batch size | 16 |
|
| 40 |
+
| Final MLM training loss | — |
|
| 41 |
+
|
| 42 |
+
## Encoding-model performance
|
| 43 |
+
|
| 44 |
+
After extracting per-word embeddings from this adapter (using ±10 word
|
| 45 |
+
context windows + Lanczos downsampling + 4 TR delays) and fitting per-voxel
|
| 46 |
+
ridge regression on Subjects 2 and 3:
|
| 47 |
+
|
| 48 |
+
| Subject | Mean CC | Top 5% CC | Top 1% CC | Top-1 voxel |
|
| 49 |
+
|---|---|---|---|---|
|
| 50 |
+
| Subject 2 | 0.0643 | 0.2143 | 0.2906 | 0.4736 |
|
| 51 |
+
| Subject 3 | 0.0660 | 0.2176 | 0.3043 | 0.5159 |
|
| 52 |
+
|
| 53 |
+
(See full project repository for ridge weights, evaluation code, and SHAP /
|
| 54 |
+
LIME word-importance analyses.)
|
| 55 |
+
|
| 56 |
+
## Loading the adapter
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from transformers import BertForMaskedLM, BertTokenizerFast
|
| 60 |
+
from peft import PeftModel
|
| 61 |
+
|
| 62 |
+
tokenizer = BertTokenizerFast.from_pretrained("bert-base-uncased")
|
| 63 |
+
base = BertForMaskedLM.from_pretrained("bert-base-uncased")
|
| 64 |
+
model = PeftModel.from_pretrained(base, "RheaTinghe/stat214-lab3-bert-lora-r4-maxlen256")
|
| 65 |
+
model.eval()
|
| 66 |
+
|
| 67 |
+
# Extract per-word embeddings via ±10 word context windows
|
| 68 |
+
# (see scripts/run_bert_pretrained.py in the project repo for the
|
| 69 |
+
# complete extraction pipeline)
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Citation
|
| 73 |
+
|
| 74 |
+
```bibtex
|
| 75 |
+
@misc{stat214lab3,
|
| 76 |
+
author = {Galloro, Drew and Wang, Ruihang and Khothsombath, Benjamin and Zhang, Rhea},
|
| 77 |
+
title = {Stat 214 Lab 3: BERT-LoRA encoding model for fMRI},
|
| 78 |
+
year = {2026},
|
| 79 |
+
note = {UC Berkeley Spring 2026},
|
| 80 |
+
}
|
| 81 |
+
```
|
adapter_config.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": {
|
| 6 |
+
"base_model_class": "BertForMaskedLM",
|
| 7 |
+
"parent_library": "transformers.models.bert.modeling_bert"
|
| 8 |
+
},
|
| 9 |
+
"base_model_name_or_path": "bert-base-uncased",
|
| 10 |
+
"bias": "none",
|
| 11 |
+
"corda_config": null,
|
| 12 |
+
"ensure_weight_tying": false,
|
| 13 |
+
"eva_config": null,
|
| 14 |
+
"exclude_modules": null,
|
| 15 |
+
"fan_in_fan_out": false,
|
| 16 |
+
"inference_mode": true,
|
| 17 |
+
"init_lora_weights": true,
|
| 18 |
+
"layer_replication": null,
|
| 19 |
+
"layers_pattern": null,
|
| 20 |
+
"layers_to_transform": null,
|
| 21 |
+
"loftq_config": {},
|
| 22 |
+
"lora_alpha": 8,
|
| 23 |
+
"lora_bias": false,
|
| 24 |
+
"lora_dropout": 0.1,
|
| 25 |
+
"lora_ga_config": null,
|
| 26 |
+
"megatron_config": null,
|
| 27 |
+
"megatron_core": "megatron.core",
|
| 28 |
+
"modules_to_save": null,
|
| 29 |
+
"peft_type": "LORA",
|
| 30 |
+
"peft_version": "0.19.1",
|
| 31 |
+
"qalora_group_size": 16,
|
| 32 |
+
"r": 4,
|
| 33 |
+
"rank_pattern": {},
|
| 34 |
+
"revision": null,
|
| 35 |
+
"target_modules": [
|
| 36 |
+
"query",
|
| 37 |
+
"value"
|
| 38 |
+
],
|
| 39 |
+
"target_parameters": null,
|
| 40 |
+
"task_type": null,
|
| 41 |
+
"trainable_token_indices": null,
|
| 42 |
+
"use_bdlora": null,
|
| 43 |
+
"use_dora": false,
|
| 44 |
+
"use_qalora": false,
|
| 45 |
+
"use_rslora": false
|
| 46 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:57964f7ecab300222a0058c88b0698325d49acebe8426712374fb2121542054f
|
| 3 |
+
size 596480
|