Commit
•
0a0a61e
1
Parent(s):
f4439b9
Upload Bilma
Browse files- config.json +3 -2
- configuration_bilma.py +4 -4
- modeling_bilma.py +10 -3
- tf_model.h5 +1 -1
config.json
CHANGED
@@ -4,13 +4,14 @@
|
|
4 |
],
|
5 |
"auto_map": {
|
6 |
"AutoConfig": "configuration_bilma.BilmaConfig",
|
7 |
-
"
|
8 |
},
|
9 |
"drop_rate": 0.1,
|
10 |
"embedding_dim": 512,
|
11 |
-
"model_type": "
|
12 |
"num_attention_heads": 4,
|
13 |
"num_encoders": 2,
|
|
|
14 |
"transformers_version": "4.30.2",
|
15 |
"vocab_size": 28949,
|
16 |
"weights": "spanish"
|
|
|
4 |
],
|
5 |
"auto_map": {
|
6 |
"AutoConfig": "configuration_bilma.BilmaConfig",
|
7 |
+
"TFAutoModel": "modeling_bilma.Bilma"
|
8 |
},
|
9 |
"drop_rate": 0.1,
|
10 |
"embedding_dim": 512,
|
11 |
+
"model_type": "bert",
|
12 |
"num_attention_heads": 4,
|
13 |
"num_encoders": 2,
|
14 |
+
"seq_max_length": 280,
|
15 |
"transformers_version": "4.30.2",
|
16 |
"vocab_size": 28949,
|
17 |
"weights": "spanish"
|
configuration_bilma.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
from transformers import PretrainedConfig
|
2 |
|
3 |
class BilmaConfig(PretrainedConfig):
|
4 |
-
model_type = "
|
5 |
|
6 |
def __init__(
|
7 |
self,
|
8 |
weights="spanish",
|
9 |
num_attention_heads: int = 4,
|
10 |
num_encoders: int = 2,
|
11 |
-
|
12 |
embedding_dim: int = 512,
|
13 |
vocab_size: int = 28949,
|
14 |
drop_rate: float = 0.1,
|
@@ -20,7 +20,7 @@ class BilmaConfig(PretrainedConfig):
|
|
20 |
self.weights = weights
|
21 |
self.num_attention_heads = 4
|
22 |
self.num_encoders = 2
|
23 |
-
self.
|
24 |
self.embedding_dim = 512
|
25 |
self.vocab_size = 28949
|
26 |
self.drop_rate = 0.1
|
@@ -30,7 +30,7 @@ class BilmaConfig(PretrainedConfig):
|
|
30 |
self.weights = weights
|
31 |
self.num_attention_heads = num_attention_heads
|
32 |
self.num_encoders = num_encoders
|
33 |
-
self.
|
34 |
self.embedding_dim = embedding_dim
|
35 |
self.vocab_size = vocab_size
|
36 |
self.drop_rate = drop_rate
|
|
|
1 |
from transformers import PretrainedConfig
|
2 |
|
3 |
class BilmaConfig(PretrainedConfig):
|
4 |
+
model_type = "bert"
|
5 |
|
6 |
def __init__(
|
7 |
self,
|
8 |
weights="spanish",
|
9 |
num_attention_heads: int = 4,
|
10 |
num_encoders: int = 2,
|
11 |
+
seq_max_length: int = 280,
|
12 |
embedding_dim: int = 512,
|
13 |
vocab_size: int = 28949,
|
14 |
drop_rate: float = 0.1,
|
|
|
20 |
self.weights = weights
|
21 |
self.num_attention_heads = 4
|
22 |
self.num_encoders = 2
|
23 |
+
self.seq_max_length = 280
|
24 |
self.embedding_dim = 512
|
25 |
self.vocab_size = 28949
|
26 |
self.drop_rate = 0.1
|
|
|
30 |
self.weights = weights
|
31 |
self.num_attention_heads = num_attention_heads
|
32 |
self.num_encoders = num_encoders
|
33 |
+
self.seq_max_length = seq_max_length
|
34 |
self.embedding_dim = embedding_dim
|
35 |
self.vocab_size = vocab_size
|
36 |
self.drop_rate = drop_rate
|
modeling_bilma.py
CHANGED
@@ -4,6 +4,8 @@ from tensorflow.keras.layers import Layer, Dense, concatenate, Input, add, Dropo
|
|
4 |
import tensorflow as tf
|
5 |
import numpy as np
|
6 |
|
|
|
|
|
7 |
import re
|
8 |
import unicodedata
|
9 |
|
@@ -41,13 +43,18 @@ class Bilma(TFPreTrainedModel):
|
|
41 |
#else:
|
42 |
self.model = bilma(num_enc=config.num_encoders,
|
43 |
embed_dim=config.embedding_dim,
|
44 |
-
max_length=config.
|
45 |
num_heads=config.num_attention_heads,
|
46 |
ff_dim=config.embedding_dim,
|
47 |
vocab_size=config.vocab_size,
|
48 |
rate=config.drop_rate)
|
49 |
-
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
def call(self, tensor):
|
52 |
return self.model(tensor)
|
53 |
|
@@ -459,7 +466,7 @@ def accuracy_function(ignore_id=0):
|
|
459 |
|
460 |
def bilma(num_enc=6, embed_dim=300, max_length=50, num_heads=6, ff_dim=512, vocab_size=9739, rate=0.1):
|
461 |
capt_inputs_ids = Input(shape=(max_length, ), name='capt_input')
|
462 |
-
capt_embedding = Embedding(vocab_size, embed_dim, mask_zero=False
|
463 |
capt_inputs = capt_embedding(capt_inputs_ids)
|
464 |
|
465 |
enc = Encoder(num_enc, embed_dim, max_length, num_heads, ff_dim, rate=rate)
|
|
|
4 |
import tensorflow as tf
|
5 |
import numpy as np
|
6 |
|
7 |
+
from typing import Dict
|
8 |
+
|
9 |
import re
|
10 |
import unicodedata
|
11 |
|
|
|
43 |
#else:
|
44 |
self.model = bilma(num_enc=config.num_encoders,
|
45 |
embed_dim=config.embedding_dim,
|
46 |
+
max_length=config.seq_max_length,
|
47 |
num_heads=config.num_attention_heads,
|
48 |
ff_dim=config.embedding_dim,
|
49 |
vocab_size=config.vocab_size,
|
50 |
rate=config.drop_rate)
|
51 |
+
self.call(np.zeros((1, config.seq_max_length)))
|
52 |
|
53 |
+
@property
|
54 |
+
def dummy_inputs(self) -> Dict[str, tf.Tensor]:
|
55 |
+
dummies = {"capt_input":self.model.inputs[0]}
|
56 |
+
return dummies
|
57 |
+
|
58 |
def call(self, tensor):
|
59 |
return self.model(tensor)
|
60 |
|
|
|
466 |
|
467 |
def bilma(num_enc=6, embed_dim=300, max_length=50, num_heads=6, ff_dim=512, vocab_size=9739, rate=0.1):
|
468 |
capt_inputs_ids = Input(shape=(max_length, ), name='capt_input')
|
469 |
+
capt_embedding = Embedding(vocab_size, embed_dim, mask_zero=False)
|
470 |
capt_inputs = capt_embedding(capt_inputs_ids)
|
471 |
|
472 |
enc = Encoder(num_enc, embed_dim, max_length, num_heads, ff_dim, rate=rate)
|
tf_model.h5
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 156561684
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b7113392a0c53e8294014d1c64e57f7a25553b037fb880370f9f68c76261d7dc
|
3 |
size 156561684
|