Upload folder using huggingface_hub
Browse files- README.md +2 -3
- config.json +34 -0
- merges.txt +0 -0
- modeling_qalb.py +45 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +30 -0
- tokenizer.json +0 -0
- tokenizer_config.json +31 -0
- vocab.json +0 -0
README.md
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
---
|
|
|
|
| 1 |
+
# Qalb-Pro (Urdu Engram Model)
|
| 2 |
+
Experimental OPT-125M with DeepSeek Engram Module.
|
|
|
config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_remove_final_layer_norm": false,
|
| 3 |
+
"activation_dropout": 0.0,
|
| 4 |
+
"activation_function": "relu",
|
| 5 |
+
"architectures": [
|
| 6 |
+
"OPTForCausalLM"
|
| 7 |
+
],
|
| 8 |
+
"attention_dropout": 0.0,
|
| 9 |
+
"bos_token_id": 2,
|
| 10 |
+
"do_layer_norm_before": true,
|
| 11 |
+
"dropout": 0.1,
|
| 12 |
+
"dtype": "float16",
|
| 13 |
+
"enable_bias": true,
|
| 14 |
+
"eos_token_id": 2,
|
| 15 |
+
"ffn_dim": 3072,
|
| 16 |
+
"hidden_size": 768,
|
| 17 |
+
"init_std": 0.02,
|
| 18 |
+
"layer_norm_elementwise_affine": true,
|
| 19 |
+
"layerdrop": 0.0,
|
| 20 |
+
"max_position_embeddings": 2048,
|
| 21 |
+
"model_type": "qalb",
|
| 22 |
+
"num_attention_heads": 12,
|
| 23 |
+
"num_hidden_layers": 12,
|
| 24 |
+
"pad_token_id": 1,
|
| 25 |
+
"prefix": "</s>",
|
| 26 |
+
"transformers_version": "4.57.3",
|
| 27 |
+
"use_cache": true,
|
| 28 |
+
"vocab_size": 50272,
|
| 29 |
+
"word_embed_proj_dim": 768,
|
| 30 |
+
"auto_map": {
|
| 31 |
+
"AutoConfig": "modeling_qalb.QalbConfig",
|
| 32 |
+
"AutoModelForCausalLM": "modeling_qalb.FinalPerfectQalb"
|
| 33 |
+
}
|
| 34 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_qalb.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
from torch import nn
|
| 4 |
+
from transformers import OPTPreTrainedModel, OPTModel, OPTConfig
|
| 5 |
+
|
| 6 |
+
class QalbConfig(OPTConfig):
|
| 7 |
+
model_type = "qalb"
|
| 8 |
+
def __init__(self, table_size=500000, **kwargs):
|
| 9 |
+
super().__init__(**kwargs)
|
| 10 |
+
self.table_size = table_size
|
| 11 |
+
|
| 12 |
+
class DeepSeekEngramModule(nn.Module):
|
| 13 |
+
def __init__(self, config):
|
| 14 |
+
super().__init__()
|
| 15 |
+
self.table_size = getattr(config, "table_size", 500000)
|
| 16 |
+
self.dim = config.word_embed_proj_dim
|
| 17 |
+
self.memory_table = nn.Embedding(self.table_size, self.dim)
|
| 18 |
+
self.gate = nn.Linear(self.dim, 1)
|
| 19 |
+
self.polynomial_base = 31
|
| 20 |
+
|
| 21 |
+
def forward(self, input_ids, hidden_states):
|
| 22 |
+
batch_size, seq_len = input_ids.shape
|
| 23 |
+
hashes = torch.zeros_like(input_ids)
|
| 24 |
+
for t in range(seq_len):
|
| 25 |
+
hashes[:, t] = (input_ids[:, :t+1].sum(dim=1) * self.polynomial_base) % self.table_size
|
| 26 |
+
|
| 27 |
+
memory_features = self.memory_table(hashes.abs())
|
| 28 |
+
g = torch.sigmoid(self.gate(hidden_states))
|
| 29 |
+
return g * hidden_states + (1 - g) * memory_features.to(hidden_states.dtype)
|
| 30 |
+
|
| 31 |
+
class FinalPerfectQalb(OPTPreTrainedModel):
|
| 32 |
+
config_class = QalbConfig
|
| 33 |
+
def __init__(self, config):
|
| 34 |
+
super().__init__(config)
|
| 35 |
+
self.backbone = OPTModel(config)
|
| 36 |
+
self.engram = DeepSeekEngramModule(config)
|
| 37 |
+
self.post_init()
|
| 38 |
+
|
| 39 |
+
def forward(self, input_ids, attention_mask=None, **kwargs):
|
| 40 |
+
outputs = self.backbone(input_ids, attention_mask=attention_mask)
|
| 41 |
+
hidden_states = outputs.last_hidden_state
|
| 42 |
+
enhanced_states = self.engram(input_ids, hidden_states)
|
| 43 |
+
# Project to vocab using the backbone's embeddings
|
| 44 |
+
logits = torch.matmul(enhanced_states, self.backbone.decoder.embed_tokens.weight.T)
|
| 45 |
+
return torch.nn.utils.rnn.PackedSequence(logits) if isinstance(logits, tuple) else type('obj', (object,), {'logits': logits})
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2d974e2f5b592d615b960c21246611315afae88487d939c0bfca619f6e2d4ebf
|
| 3 |
+
size 452181515
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "</s>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": true,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "</s>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": true,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<pad>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": true,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"unk_token": {
|
| 24 |
+
"content": "</s>",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": true,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
}
|
| 30 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": true,
|
| 3 |
+
"add_prefix_space": false,
|
| 4 |
+
"added_tokens_decoder": {
|
| 5 |
+
"1": {
|
| 6 |
+
"content": "<pad>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": true,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false,
|
| 11 |
+
"special": true
|
| 12 |
+
},
|
| 13 |
+
"2": {
|
| 14 |
+
"content": "</s>",
|
| 15 |
+
"lstrip": false,
|
| 16 |
+
"normalized": true,
|
| 17 |
+
"rstrip": false,
|
| 18 |
+
"single_word": false,
|
| 19 |
+
"special": true
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"bos_token": "</s>",
|
| 23 |
+
"clean_up_tokenization_spaces": false,
|
| 24 |
+
"eos_token": "</s>",
|
| 25 |
+
"errors": "replace",
|
| 26 |
+
"extra_special_tokens": {},
|
| 27 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 28 |
+
"pad_token": "<pad>",
|
| 29 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 30 |
+
"unk_token": "</s>"
|
| 31 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|