Add main & ema weights for ace
Browse files- README.md +140 -0
- config.json +28 -0
- configuration_gpt_bert.py +22 -0
- model.safetensors +3 -0
- model_ema.safetensors +3 -0
- modeling_gpt_bert.py +130 -0
- original_project_config.json +12 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +141 -0
README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# haznitrama/babybabellm-gpt_bert-ace-causal
|
| 2 |
+
|
| 3 |
+
GPT-BERT style BabyBabyLLM monolingual model for language **ace**.
|
| 4 |
+
|
| 5 |
+
This repository mirrors the layout of the multi-all reference models: it may contain both *main* and *EMA* variants.
|
| 6 |
+
|
| 7 |
+
**Default variant exposed to generic loaders:** `ema`
|
| 8 |
+
|
| 9 |
+
## Variants Available
|
| 10 |
+
ema, main
|
| 11 |
+
|
| 12 |
+
## Files
|
| 13 |
+
- model.safetensors (alias of default variant)
|
| 14 |
+
- model_ema.safetensors
|
| 15 |
+
- pytorch_model.bin (legacy PyTorch format)
|
| 16 |
+
|
| 17 |
+
## Configuration
|
| 18 |
+
```json
|
| 19 |
+
{
|
| 20 |
+
"attention_probs_dropout_prob": 0.1,
|
| 21 |
+
"hidden_dropout_prob": 0.1,
|
| 22 |
+
"hidden_size": 384,
|
| 23 |
+
"intermediate_size": 1280,
|
| 24 |
+
"max_position_embeddings": 512,
|
| 25 |
+
"position_bucket_size": 32,
|
| 26 |
+
"num_attention_heads": 6,
|
| 27 |
+
"num_hidden_layers": 12,
|
| 28 |
+
"vocab_size": 8192,
|
| 29 |
+
"layer_norm_eps": 1e-05,
|
| 30 |
+
"auto_map": {
|
| 31 |
+
"AutoConfig": "configuration_gpt_bert.GPTBertConfig",
|
| 32 |
+
"AutoModel": "modeling_gpt_bert.GPTBertForMaskedLM",
|
| 33 |
+
"AutoModelForCausalLM": "modeling_gpt_bert.GPTBertForMaskedLM",
|
| 34 |
+
"AutoModelForMaskedLM": "modeling_gpt_bert.GPTBertForMaskedLM"
|
| 35 |
+
},
|
| 36 |
+
"return_dict": true,
|
| 37 |
+
"output_hidden_states": false,
|
| 38 |
+
"torchscript": false,
|
| 39 |
+
"dtype": "float32",
|
| 40 |
+
"pruned_heads": {},
|
| 41 |
+
"tie_word_embeddings": true,
|
| 42 |
+
"chunk_size_feed_forward": 0,
|
| 43 |
+
"is_encoder_decoder": false,
|
| 44 |
+
"is_decoder": false,
|
| 45 |
+
"cross_attention_hidden_size": null,
|
| 46 |
+
"add_cross_attention": false,
|
| 47 |
+
"tie_encoder_decoder": false,
|
| 48 |
+
"architectures": [
|
| 49 |
+
"GPTBertForMaskedLM"
|
| 50 |
+
],
|
| 51 |
+
"finetuning_task": null,
|
| 52 |
+
"id2label": {
|
| 53 |
+
"0": "LABEL_0",
|
| 54 |
+
"1": "LABEL_1"
|
| 55 |
+
},
|
| 56 |
+
"label2id": {
|
| 57 |
+
"LABEL_0": 0,
|
| 58 |
+
"LABEL_1": 1
|
| 59 |
+
},
|
| 60 |
+
"task_specific_params": null,
|
| 61 |
+
"problem_type": null,
|
| 62 |
+
"tokenizer_class": null,
|
| 63 |
+
"prefix": null,
|
| 64 |
+
"bos_token_id": null,
|
| 65 |
+
"pad_token_id": null,
|
| 66 |
+
"eos_token_id": null,
|
| 67 |
+
"sep_token_id": null,
|
| 68 |
+
"decoder_start_token_id": null,
|
| 69 |
+
"max_length": 20,
|
| 70 |
+
"min_length": 0,
|
| 71 |
+
"do_sample": false,
|
| 72 |
+
"early_stopping": false,
|
| 73 |
+
"num_beams": 1,
|
| 74 |
+
"num_beam_groups": 1,
|
| 75 |
+
"diversity_penalty": 0.0,
|
| 76 |
+
"temperature": 1.0,
|
| 77 |
+
"top_k": 50,
|
| 78 |
+
"top_p": 1.0,
|
| 79 |
+
"typical_p": 1.0,
|
| 80 |
+
"repetition_penalty": 1.0,
|
| 81 |
+
"length_penalty": 1.0,
|
| 82 |
+
"no_repeat_ngram_size": 0,
|
| 83 |
+
"encoder_no_repeat_ngram_size": 0,
|
| 84 |
+
"bad_words_ids": null,
|
| 85 |
+
"num_return_sequences": 1,
|
| 86 |
+
"output_scores": false,
|
| 87 |
+
"return_dict_in_generate": false,
|
| 88 |
+
"forced_bos_token_id": null,
|
| 89 |
+
"forced_eos_token_id": null,
|
| 90 |
+
"remove_invalid_values": false,
|
| 91 |
+
"exponential_decay_length_penalty": null,
|
| 92 |
+
"suppress_tokens": null,
|
| 93 |
+
"begin_suppress_tokens": null,
|
| 94 |
+
"_name_or_path": "",
|
| 95 |
+
"transformers_version": "4.56.1",
|
| 96 |
+
"tf_legacy_loss": false,
|
| 97 |
+
"use_bfloat16": false,
|
| 98 |
+
"model_type": "gpt_bert",
|
| 99 |
+
"output_attentions": false
|
| 100 |
+
}
|
| 101 |
+
```
|
| 102 |
+
Tokenizer file: `tokenizer_ace_vs8192.json`
|
| 103 |
+
|
| 104 |
+
## Quick Usage
|
| 105 |
+
```python
|
| 106 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
| 107 |
+
model_id = 'haznitrama/babybabellm-gpt_bert-ace-causal'
|
| 108 |
+
tok = AutoTokenizer.from_pretrained(model_id)
|
| 109 |
+
model = AutoModelForMaskedLM.from_pretrained(model_id, trust_remote_code=True)
|
| 110 |
+
out = model(**tok('Hello world', return_tensors='pt'))
|
| 111 |
+
```
|
| 112 |
+
Select a specific variant explicitly (when both present):
|
| 113 |
+
```python
|
| 114 |
+
# Load EMA weights explicitly if both are present
|
| 115 |
+
from safetensors.torch import load_file
|
| 116 |
+
import torch
|
| 117 |
+
from transformers import AutoConfig, AutoModelForMaskedLM
|
| 118 |
+
model_id = 'haznitrama/babybabellm-gpt_bert-ace-causal'
|
| 119 |
+
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
| 120 |
+
model = AutoModelForMaskedLM.from_config(config, trust_remote_code=True)
|
| 121 |
+
state_dict = torch.load('pytorch_model.bin') # or load_file('model_ema.safetensors')
|
| 122 |
+
model.load_state_dict(state_dict, strict=False)
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
### Causal LM Wrapper
|
| 126 |
+
This repo includes a lightweight GPTBertForCausalLM wrapper.
|
| 127 |
+
Generation example:
|
| 128 |
+
```python
|
| 129 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 130 |
+
mid='haznitrama/babybabellm-gpt_bert-ace-causal'
|
| 131 |
+
tok=AutoTokenizer.from_pretrained(mid)
|
| 132 |
+
model=AutoModelForCausalLM.from_pretrained(mid, trust_remote_code=True)
|
| 133 |
+
print(tok.decode(model.generate(**tok('Hello', return_tensors='pt'), max_new_tokens=20)[0], skip_special_tokens=True))
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Notes
|
| 137 |
+
- Converted on 2025-09-16T06:15:08.548402Z
|
| 138 |
+
- Safe serialization (safetensors) used; `pytorch_model.bin` added for legacy tools.
|
| 139 |
+
- Requires `trust_remote_code=True` due to custom architecture.
|
| 140 |
+
- EMA (Exponential Moving Average) weights can yield slightly better evaluation metrics; choose according to your needs.
|
config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"GPTBertForMaskedLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "configuration_gpt_bert.GPTBertConfig",
|
| 8 |
+
"AutoModel": "modeling_gpt_bert.GPTBertForMaskedLM",
|
| 9 |
+
"AutoModelForCausalLM": "modeling_gpt_bert.GPTBertForMaskedLM",
|
| 10 |
+
"AutoModelForMaskedLM": "modeling_gpt_bert.GPTBertForMaskedLM"
|
| 11 |
+
},
|
| 12 |
+
"bos_token_id": 1,
|
| 13 |
+
"dtype": "float32",
|
| 14 |
+
"eos_token_id": 2,
|
| 15 |
+
"hidden_dropout_prob": 0.1,
|
| 16 |
+
"hidden_size": 384,
|
| 17 |
+
"intermediate_size": 1280,
|
| 18 |
+
"layer_norm_eps": 1e-05,
|
| 19 |
+
"mask_token_id": 4,
|
| 20 |
+
"max_position_embeddings": 512,
|
| 21 |
+
"model_type": "gpt_bert",
|
| 22 |
+
"num_attention_heads": 6,
|
| 23 |
+
"num_hidden_layers": 12,
|
| 24 |
+
"pad_token_id": 3,
|
| 25 |
+
"position_bucket_size": 32,
|
| 26 |
+
"transformers_version": "4.56.1",
|
| 27 |
+
"vocab_size": 8192
|
| 28 |
+
}
|
configuration_gpt_bert.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class GPTBertConfig(PretrainedConfig):
|
| 4 |
+
model_type = 'gpt_bert'
|
| 5 |
+
def __init__(self, **kwargs):
|
| 6 |
+
self.attention_probs_dropout_prob = kwargs.pop('attention_probs_dropout_prob', 0.1)
|
| 7 |
+
self.hidden_dropout_prob = kwargs.pop('hidden_dropout_prob', 0.1)
|
| 8 |
+
self.hidden_size = kwargs.pop('hidden_size', 768)
|
| 9 |
+
self.intermediate_size = kwargs.pop('intermediate_size', 2560)
|
| 10 |
+
self.max_position_embeddings = kwargs.pop('max_position_embeddings', 512)
|
| 11 |
+
self.position_bucket_size = kwargs.pop('position_bucket_size', 32)
|
| 12 |
+
self.num_attention_heads = kwargs.pop('num_attention_heads', 12)
|
| 13 |
+
self.num_hidden_layers = kwargs.pop('num_hidden_layers', 12)
|
| 14 |
+
self.vocab_size = kwargs.pop('vocab_size', 16384)
|
| 15 |
+
self.layer_norm_eps = kwargs.pop('layer_norm_eps', 1e-5)
|
| 16 |
+
self.auto_map = {
|
| 17 |
+
'AutoConfig': 'configuration_gpt_bert.GPTBertConfig',
|
| 18 |
+
'AutoModel': 'modeling_gpt_bert.GPTBertForCausalLM',
|
| 19 |
+
'AutoModelForCausalLM': 'modeling_gpt_bert.GPTBertForCausalLM',
|
| 20 |
+
'AutoModelForMaskedLM': 'modeling_gpt_bert.GPTBertForMaskedLM',
|
| 21 |
+
}
|
| 22 |
+
super().__init__(**kwargs)
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b8f00b242a43531ca7223948132041c432f71d0b46ece868224b242f9f26092c
|
| 3 |
+
size 144750928
|
model_ema.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b8f00b242a43531ca7223948132041c432f71d0b46ece868224b242f9f26092c
|
| 3 |
+
size 144750928
|
modeling_gpt_bert.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math, torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
from transformers import PreTrainedModel
|
| 5 |
+
from transformers.modeling_outputs import MaskedLMOutput, CausalLMOutputWithCrossAttentions
|
| 6 |
+
from .configuration_gpt_bert import GPTBertConfig
|
| 7 |
+
|
| 8 |
+
class GeGLU(nn.Module):
|
| 9 |
+
def forward(self, x):
|
| 10 |
+
x, gate = x.chunk(2, dim=-1)
|
| 11 |
+
return x * F.gelu(gate, approximate='tanh')
|
| 12 |
+
|
| 13 |
+
class FeedForward(nn.Module):
|
| 14 |
+
def __init__(self, config):
|
| 15 |
+
super().__init__()
|
| 16 |
+
self.mlp = nn.Sequential(
|
| 17 |
+
nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps, elementwise_affine=False)
|
| 18 |
+
,nn.Linear(config.hidden_size, 2*config.intermediate_size, bias=False)
|
| 19 |
+
,GeGLU()
|
| 20 |
+
,nn.LayerNorm(config.intermediate_size, eps=config.layer_norm_eps, elementwise_affine=False)
|
| 21 |
+
,nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 22 |
+
,nn.Dropout(config.hidden_dropout_prob)
|
| 23 |
+
)
|
| 24 |
+
self._init(config.hidden_size)
|
| 25 |
+
def _init(self, h):
|
| 26 |
+
std = math.sqrt(2.0 / (5.0 * h))
|
| 27 |
+
nn.init.trunc_normal_(self.mlp[1].weight, mean=0.0, std=std, a=-2*std, b=2*std)
|
| 28 |
+
nn.init.trunc_normal_(self.mlp[-2].weight, mean=0.0, std=std, a=-2*std, b=2*std)
|
| 29 |
+
def forward(self, x): return self.mlp(x)
|
| 30 |
+
|
| 31 |
+
class Attention(nn.Module):
|
| 32 |
+
def __init__(self, config):
|
| 33 |
+
super().__init__()
|
| 34 |
+
if config.hidden_size % config.num_attention_heads != 0:
|
| 35 |
+
raise ValueError('hidden not divisible by heads')
|
| 36 |
+
self.nh = config.num_attention_heads
|
| 37 |
+
self.dh = config.hidden_size // config.num_attention_heads
|
| 38 |
+
self.qkv = nn.Linear(config.hidden_size, 3*config.hidden_size, bias=False)
|
| 39 |
+
self.o = nn.Linear(config.hidden_size, config.hidden_size, bias=False)
|
| 40 |
+
self.drop = nn.Dropout(config.hidden_dropout_prob)
|
| 41 |
+
def forward(self, x, attn_mask, rel):
|
| 42 |
+
B,S,H = x.shape
|
| 43 |
+
qkv = self.qkv(x).view(B,S,3,self.nh,self.dh).permute(2,0,3,1,4)
|
| 44 |
+
q,k,v = qkv[0],qkv[1],qkv[2]
|
| 45 |
+
attn = (q @ k.transpose(-1,-2)) / math.sqrt(self.dh)
|
| 46 |
+
if attn_mask is not None: attn = attn.masked_fill(attn_mask[:,None,:, :]==0, float('-inf'))
|
| 47 |
+
attn = torch.softmax(attn, dim=-1)
|
| 48 |
+
attn = self.drop(attn)
|
| 49 |
+
y = attn @ v
|
| 50 |
+
y = y.transpose(1,2).contiguous().view(B,S,H)
|
| 51 |
+
return self.o(y)
|
| 52 |
+
|
| 53 |
+
class Block(nn.Module):
|
| 54 |
+
def __init__(self, config):
|
| 55 |
+
super().__init__()
|
| 56 |
+
self.attn = Attention(config)
|
| 57 |
+
self.ff = FeedForward(config)
|
| 58 |
+
def forward(self, x, attn_mask, rel):
|
| 59 |
+
x = x + self.attn(x, attn_mask, rel)
|
| 60 |
+
x = x + self.ff(x)
|
| 61 |
+
return x
|
| 62 |
+
|
| 63 |
+
class Encoder(nn.Module):
|
| 64 |
+
def __init__(self, config):
|
| 65 |
+
super().__init__()
|
| 66 |
+
self.layers = nn.ModuleList([Block(config) for _ in range(config.num_hidden_layers)])
|
| 67 |
+
def forward(self, x, attn_mask, rel):
|
| 68 |
+
for layer in self.layers:
|
| 69 |
+
x = layer(x, attn_mask, rel)
|
| 70 |
+
return x
|
| 71 |
+
|
| 72 |
+
class Embedding(nn.Module):
|
| 73 |
+
def __init__(self, config):
|
| 74 |
+
super().__init__()
|
| 75 |
+
self.word_embedding = nn.Embedding(config.vocab_size, config.hidden_size)
|
| 76 |
+
self.pos_embedding = nn.Embedding(config.max_position_embeddings, config.hidden_size)
|
| 77 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob)
|
| 78 |
+
def forward(self, input_ids):
|
| 79 |
+
B,S = input_ids.shape
|
| 80 |
+
pos = torch.arange(0,S, device=input_ids.device).unsqueeze(0).expand(B,S)
|
| 81 |
+
x = self.word_embedding(input_ids) + self.pos_embedding(pos)
|
| 82 |
+
return self.dropout(x), None
|
| 83 |
+
|
| 84 |
+
class CoreModel(nn.Module):
|
| 85 |
+
def __init__(self, config):
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.embedding = Embedding(config)
|
| 88 |
+
self.transformer = Encoder(config)
|
| 89 |
+
self.layer_norm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps, elementwise_affine=False)
|
| 90 |
+
self.head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 91 |
+
self.head.weight = self.embedding.word_embedding.weight
|
| 92 |
+
def forward(self, input_ids, attention_mask=None):
|
| 93 |
+
x,_ = self.embedding(input_ids)
|
| 94 |
+
if attention_mask is not None: attn = attention_mask.unsqueeze(1)
|
| 95 |
+
else: attn = None
|
| 96 |
+
x = self.transformer(x, attn, None)
|
| 97 |
+
x = self.layer_norm(x)
|
| 98 |
+
return self.head(x)
|
| 99 |
+
|
| 100 |
+
class GPTBertForMaskedLM(PreTrainedModel):
|
| 101 |
+
config_class = GPTBertConfig
|
| 102 |
+
base_model_prefix = 'gpt_bert'
|
| 103 |
+
def __init__(self, config: GPTBertConfig):
|
| 104 |
+
super().__init__(config)
|
| 105 |
+
self.model = CoreModel(config)
|
| 106 |
+
def forward(self, input_ids, attention_mask=None, labels=None):
|
| 107 |
+
logits = self.model(input_ids, attention_mask)
|
| 108 |
+
loss=None
|
| 109 |
+
if labels is not None:
|
| 110 |
+
loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
|
| 111 |
+
loss = loss_fct(logits.view(-1, logits.size(-1)), labels.view(-1))
|
| 112 |
+
return MaskedLMOutput(loss=loss, logits=logits)
|
| 113 |
+
|
| 114 |
+
class GPTBertForCausalLM(PreTrainedModel):
|
| 115 |
+
config_class = GPTBertConfig
|
| 116 |
+
base_model_prefix = 'gpt_bert'
|
| 117 |
+
def __init__(self, config: GPTBertConfig):
|
| 118 |
+
super().__init__(config)
|
| 119 |
+
self.model = CoreModel(config)
|
| 120 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 121 |
+
return {'input_ids': input_ids}
|
| 122 |
+
def forward(self, input_ids, attention_mask=None, labels=None):
|
| 123 |
+
logits = self.model(input_ids, attention_mask)
|
| 124 |
+
loss=None
|
| 125 |
+
if labels is not None:
|
| 126 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 127 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 128 |
+
loss_fct = nn.CrossEntropyLoss(ignore_index=-100)
|
| 129 |
+
loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
|
| 130 |
+
return CausalLMOutputWithCrossAttentions(loss=loss, logits=logits)
|
original_project_config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"attention_probs_dropout_prob": 0.1,
|
| 3 |
+
"hidden_dropout_prob": 0.1,
|
| 4 |
+
"hidden_size": 384,
|
| 5 |
+
"intermediate_size": 1280,
|
| 6 |
+
"max_position_embeddings": 512,
|
| 7 |
+
"position_bucket_size": 32,
|
| 8 |
+
"num_attention_heads": 6,
|
| 9 |
+
"num_hidden_layers": 12,
|
| 10 |
+
"vocab_size": 8192,
|
| 11 |
+
"layer_norm_eps": 1e-05
|
| 12 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:60831fe97fd7fa50ab77364bbc6ccd2d9aad85e48ca260b7104e5d1936870d41
|
| 3 |
+
size 144791119
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"eos_token": "</s>",
|
| 4 |
+
"mask_token": "<mask>",
|
| 5 |
+
"pad_token": "<pad>",
|
| 6 |
+
"unk_token": "<unk>"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "<unk>",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "<s>",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "</s>",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "<pad>",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"4": {
|
| 36 |
+
"content": "<mask>",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
},
|
| 43 |
+
"5": {
|
| 44 |
+
"content": "<special_0>",
|
| 45 |
+
"lstrip": false,
|
| 46 |
+
"normalized": false,
|
| 47 |
+
"rstrip": false,
|
| 48 |
+
"single_word": false,
|
| 49 |
+
"special": true
|
| 50 |
+
},
|
| 51 |
+
"6": {
|
| 52 |
+
"content": "<special_1>",
|
| 53 |
+
"lstrip": false,
|
| 54 |
+
"normalized": false,
|
| 55 |
+
"rstrip": false,
|
| 56 |
+
"single_word": false,
|
| 57 |
+
"special": true
|
| 58 |
+
},
|
| 59 |
+
"7": {
|
| 60 |
+
"content": "<special_2>",
|
| 61 |
+
"lstrip": false,
|
| 62 |
+
"normalized": false,
|
| 63 |
+
"rstrip": false,
|
| 64 |
+
"single_word": false,
|
| 65 |
+
"special": true
|
| 66 |
+
},
|
| 67 |
+
"8": {
|
| 68 |
+
"content": "<special_3>",
|
| 69 |
+
"lstrip": false,
|
| 70 |
+
"normalized": false,
|
| 71 |
+
"rstrip": false,
|
| 72 |
+
"single_word": false,
|
| 73 |
+
"special": true
|
| 74 |
+
},
|
| 75 |
+
"9": {
|
| 76 |
+
"content": "<special_4>",
|
| 77 |
+
"lstrip": false,
|
| 78 |
+
"normalized": false,
|
| 79 |
+
"rstrip": false,
|
| 80 |
+
"single_word": false,
|
| 81 |
+
"special": true
|
| 82 |
+
},
|
| 83 |
+
"10": {
|
| 84 |
+
"content": "<special_5>",
|
| 85 |
+
"lstrip": false,
|
| 86 |
+
"normalized": false,
|
| 87 |
+
"rstrip": false,
|
| 88 |
+
"single_word": false,
|
| 89 |
+
"special": true
|
| 90 |
+
},
|
| 91 |
+
"11": {
|
| 92 |
+
"content": "<special_6>",
|
| 93 |
+
"lstrip": false,
|
| 94 |
+
"normalized": false,
|
| 95 |
+
"rstrip": false,
|
| 96 |
+
"single_word": false,
|
| 97 |
+
"special": true
|
| 98 |
+
},
|
| 99 |
+
"12": {
|
| 100 |
+
"content": "<special_7>",
|
| 101 |
+
"lstrip": false,
|
| 102 |
+
"normalized": false,
|
| 103 |
+
"rstrip": false,
|
| 104 |
+
"single_word": false,
|
| 105 |
+
"special": true
|
| 106 |
+
},
|
| 107 |
+
"13": {
|
| 108 |
+
"content": "<special_8>",
|
| 109 |
+
"lstrip": false,
|
| 110 |
+
"normalized": false,
|
| 111 |
+
"rstrip": false,
|
| 112 |
+
"single_word": false,
|
| 113 |
+
"special": true
|
| 114 |
+
},
|
| 115 |
+
"14": {
|
| 116 |
+
"content": "<special_9>",
|
| 117 |
+
"lstrip": false,
|
| 118 |
+
"normalized": false,
|
| 119 |
+
"rstrip": false,
|
| 120 |
+
"single_word": false,
|
| 121 |
+
"special": true
|
| 122 |
+
},
|
| 123 |
+
"15": {
|
| 124 |
+
"content": "<special_10>",
|
| 125 |
+
"lstrip": false,
|
| 126 |
+
"normalized": false,
|
| 127 |
+
"rstrip": false,
|
| 128 |
+
"single_word": false,
|
| 129 |
+
"special": true
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
"bos_token": "<s>",
|
| 133 |
+
"clean_up_tokenization_spaces": false,
|
| 134 |
+
"eos_token": "</s>",
|
| 135 |
+
"extra_special_tokens": {},
|
| 136 |
+
"mask_token": "<mask>",
|
| 137 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 138 |
+
"pad_token": "<pad>",
|
| 139 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 140 |
+
"unk_token": "<unk>"
|
| 141 |
+
}
|