Views
No views yet
| Property | Value |
|---|---|
| Base Model | bert-base-cased |
| Pretraining Tasks | TAMLM + DD |
| Temporal Granularity | Month-level |
| DD Labels | 246 month classes |
| Training Corpus | NYT Annotated Corpus |
| Framework | PyTorch / Transformers |
| Language | English |
seq_relationship head (246-class vs. standard 2-class NSP), you cannot load this model with the default from_pretrained() alone. Follow one of the methods below:1import torch
2import torch.nn as nn
3from transformers import BertForPreTraining, BertTokenizer, BertConfig
4from huggingface_hub import hf_hub_download
5import safetensors.torch as safetensors_lib
6
7def load_bitembert(model_id="JasonWang1/BiTimeBERT", device=None, num_temporal_labels=246):
8 if device is None:
9 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
10
11 # Load config and tokenizer
12 config = BertConfig.from_pretrained(model_id)
13 tokenizer = BertTokenizer.from_pretrained(model_id)
14
15 # Load model with mismatched sizes ignored
16 model = BertForPreTraining.from_pretrained(
17 model_id,
18 config=config,
19 ignore_mismatched_sizes=True
20 )
21
22 # Replace DD head with correct dimension
23 model.cls.seq_relationship = nn.Linear(config.hidden_size, num_temporal_labels)
24
25 # Download and load DD head weights from safetensors
26 weights_path = hf_hub_download(repo_id=model_id, filename="model.safetensors")
27 state_dict = safetensors_lib.load_file(weights_path, device='cpu')
28
29 if 'cls.seq_relationship.weight' in state_dict:
30 model.cls.seq_relationship.weight.data = state_dict['cls.seq_relationship.weight']
31 model.cls.seq_relationship.bias.data = state_dict['cls.seq_relationship.bias']
32
33 model.eval()
34 return model.to(device), tokenizer
35
36# ================= Usage =================
37model, tokenizer = load_bitembert("JasonWang1/BiTimeBERT")