Views
No views yet
python run_glue.py --model_name_or_path <model path> --task_name <task name> --do_train --do_eval --max_seq_length 128 --per_device_train_batch_size 32 --learning_rate 1e-4 --num_train_epochs 4 --output_dir outputs --trust-remote-code True| Model | Parameters | MNLI (acc m/mm) | MRPC (f1/acc) | SST-2 (acc) |
|---|---|---|---|---|
| baseline (bert-tiny) | 4.4M | 0.7114 / 0.7161 | 0.8318 / 0.7353 | 0.8222 |
| bert-hash-femto | 0.243M | 0.5697 / 0.5750 | 0.8122 / 0.6838 | 0.7821 |
| bert-hash-pico | 0.448M | 0.6228 / 0.6363 | 0.8205 / 0.7083 | 0.7878 |
| bert-hash-nano | 0.969M | 0.6565 / 0.6670 | 0.8172 / 0.7083 | 0.8131 |
trust_remote_code needs to be set.1from transformers import AutoModel
2
3model = AutoModel.from_pretrained("neuml/bert-hash-pico", trust_remote_code=True)1from datasets import concatenate_datasets, load_dataset
2from transformers import AutoTokenizer
3
4from txtai.pipeline import HFTrainer
5
6from configuration_bert_hash import *
7from modeling_bert_hash import *
8
9dataset = load_dataset("path to target HF dataset")
10
11tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
12
13config = BertHashConfig(
14 hidden_size=128,
15 num_hidden_layers=2,
16 num_attention_heads=2,
17 intermediate_size=512,
18 projections=16
19)
20model = BertHashForMaskedLM(config)
21
22print(config)
23print("Total parameters:", sum(p.numel() for p in model.bert.parameters()))
24
25train = HFTrainer()
26
27# Train using MLM
28train((model, tokenizer), dataset, task="language-modeling", output_dir="model",
29 fp16=True, learning_rate=1e-3, per_device_train_batch_size=64, num_train_epochs=3,
30 warmup_steps=2500, weight_decay=0.01, adam_epsilon=1e-6,
31 tokenizers=True, dataloader_num_workers=20,
32 save_strategy="steps", save_steps=5000, logging_steps=500,
33)