Spaces:
Runtime error
Runtime error
feat : edit process for load weight
Browse files
app.py
CHANGED
@@ -18,6 +18,18 @@ tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-base",max_length=60) #xlm
|
|
18 |
transformer_model = TFAutoModel.from_pretrained("xlm-roberta-base") #philschmid/tiny-bert-sst2-distilled
|
19 |
max_seq_length = 32
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def create_model():
|
22 |
|
23 |
inputs = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32)
|
@@ -68,7 +80,18 @@ def create_model():
|
|
68 |
output_layer7 = Dense(25, activation='softmax', name='output7')(x7)
|
69 |
output_layer8 = Dense(61, activation='softmax', name='output8')(x8)
|
70 |
|
|
|
|
|
|
|
71 |
model = Model(inputs=inputs , outputs=[output_layer1, output_layer2, output_layer3,output_layer4,output_layer5,output_layer6,output_layer7,output_layer8])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
model.load_weights("t1_m1.h5")
|
73 |
return model
|
74 |
|
@@ -127,7 +150,7 @@ def predict(text):
|
|
127 |
iface = gr.Interface(
|
128 |
fn=predict,
|
129 |
inputs='text',
|
130 |
-
outputs='
|
131 |
examples=[["Hello! My name is Omar"]]
|
132 |
)
|
133 |
|
|
|
18 |
transformer_model = TFAutoModel.from_pretrained("xlm-roberta-base") #philschmid/tiny-bert-sst2-distilled
|
19 |
max_seq_length = 32
|
20 |
|
21 |
+
env_decode ={}
|
22 |
+
with open('tf_labels6.json', encoding='utf-8') as fh:
|
23 |
+
env_decode = json.load(fh)
|
24 |
+
|
25 |
+
hour_decode={}
|
26 |
+
with open('tf_labels7.json', encoding='utf-8') as fh:
|
27 |
+
hour_decode = json.load(fh)
|
28 |
+
|
29 |
+
minute_decode={}
|
30 |
+
with open('tf_labels8.json', encoding='utf-8') as fh:
|
31 |
+
minute_decode = json.load(fh)
|
32 |
+
|
33 |
def create_model():
|
34 |
|
35 |
inputs = tf.keras.layers.Input(shape=(max_seq_length,), dtype=tf.int32)
|
|
|
80 |
output_layer7 = Dense(25, activation='softmax', name='output7')(x7)
|
81 |
output_layer8 = Dense(61, activation='softmax', name='output8')(x8)
|
82 |
|
83 |
+
for i,layer in enumerate(transformer_model.roberta.encoder.layer[:-1]):
|
84 |
+
transformer_model.roberta.encoder.layer[i].trainable = False
|
85 |
+
# define the model #input_layer inputs
|
86 |
model = Model(inputs=inputs , outputs=[output_layer1, output_layer2, output_layer3,output_layer4,output_layer5,output_layer6,output_layer7,output_layer8])
|
87 |
+
|
88 |
+
opt = keras.optimizers.Adam(learning_rate=3e-5)
|
89 |
+
model.compile(loss=['binary_crossentropy','binary_crossentropy','binary_crossentropy','binary_crossentropy','binary_crossentropy', 'categorical_crossentropy', 'categorical_crossentropy', 'categorical_crossentropy'], optimizer=opt,
|
90 |
+
metrics=[
|
91 |
+
tf.keras.metrics.BinaryAccuracy(),
|
92 |
+
'categorical_accuracy'
|
93 |
+
])
|
94 |
+
|
95 |
model.load_weights("t1_m1.h5")
|
96 |
return model
|
97 |
|
|
|
150 |
iface = gr.Interface(
|
151 |
fn=predict,
|
152 |
inputs='text',
|
153 |
+
outputs='label',
|
154 |
examples=[["Hello! My name is Omar"]]
|
155 |
)
|
156 |
|