Spaces:
Runtime error
Runtime error
hm-auch
commited on
Commit
•
70b5fc5
1
Parent(s):
5a4e613
inital commit
Browse files- .gitattributes +2 -0
- app.py +56 -0
- save/modelV1/keras_metadata.pb +3 -0
- save/modelV1/saved_model.pb +3 -0
- save/modelV1/variables/variables.data-00000-of-00001 +3 -0
- save/modelV1/variables/variables.index +0 -0
.gitattributes
CHANGED
@@ -26,3 +26,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.data- filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import transformers
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import tensorflow as tf
|
5 |
+
|
6 |
+
from official.nlp import optimization # to create AdamW optimizer
|
7 |
+
|
8 |
+
MODEL_DIRECTORY = 'save/modelV1'
|
9 |
+
PRETRAINED_MODEL_NAME = 'dbmdz/bert-base-german-cased'
|
10 |
+
TOKENIZER = transformers.BertTokenizer.from_pretrained(PRETRAINED_MODEL_NAME)
|
11 |
+
MAX_SEQUENCE_LENGTH = 256
|
12 |
+
EPOCHS = 2
|
13 |
+
OPTIMIZER = 'adamw'
|
14 |
+
INIT_LR = 3e-5
|
15 |
+
LOSS = tf.keras.losses.BinaryCrossentropy(from_logits=False)
|
16 |
+
METRICS = tf.metrics.BinaryAccuracy()
|
17 |
+
|
18 |
+
def compile_model(model):
|
19 |
+
steps_per_epoch = 10
|
20 |
+
num_train_steps = steps_per_epoch * EPOCHS
|
21 |
+
num_warmup_steps = int(0.1*num_train_steps)
|
22 |
+
|
23 |
+
optimizer = optimization.create_optimizer(
|
24 |
+
init_lr=INIT_LR,
|
25 |
+
num_train_steps=steps_per_epoch,
|
26 |
+
num_warmup_steps=num_warmup_steps,
|
27 |
+
optimizer_type=OPTIMIZER
|
28 |
+
)
|
29 |
+
|
30 |
+
model.compile(optimizer=optimizer, loss=LOSS, metrics=[METRICS])
|
31 |
+
return model
|
32 |
+
|
33 |
+
hs_detection_model = tf.keras.models.load_model(MODEL_DIRECTORY, compile=False) #tf.keras.models.load_model('save/kerasmodel/model.h5') #tf.saved_model.load('save/model') #tf.keras.models.load_model('save/model')
|
34 |
+
compile_model(hs_detection_model)
|
35 |
+
|
36 |
+
def encode(sentences):
|
37 |
+
return TOKENIZER.batch_encode_plus(
|
38 |
+
sentences,
|
39 |
+
max_length=MAX_SEQUENCE_LENGTH, # set the length of the sequences
|
40 |
+
add_special_tokens=True, # add [CLS] and [SEP] tokens
|
41 |
+
return_attention_mask=True,
|
42 |
+
return_token_type_ids=False, # not needed for this type of ML task
|
43 |
+
pad_to_max_length=True, # add 0 pad tokens to the sequences less than max_length
|
44 |
+
return_tensors='tf'
|
45 |
+
)
|
46 |
+
|
47 |
+
def inference(sentence):
|
48 |
+
print(sentence)
|
49 |
+
encoded_sentence = encode([sentence])
|
50 |
+
print(encoded_sentence)
|
51 |
+
predicition = hs_detection_model.predict(encoded_sentence.values())
|
52 |
+
print(predicition)
|
53 |
+
return predicition
|
54 |
+
|
55 |
+
iface = gr.Interface(fn=inference, inputs="text", outputs="text") #, live=True)
|
56 |
+
iface.launch()
|
save/modelV1/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5972b15e2cc31b72e34a938e1d9614cf6a9d2b1872abbc654453ab5f613693a2
|
3 |
+
size 155363
|
save/modelV1/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ccb2afb1ffb3c867ae345e7d43af0e20f3f476c83cb86c838a07bf703c216fa4
|
3 |
+
size 6651882
|
save/modelV1/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7940b2394fa52153c18be7b6007423ca74bb4d346b1f808c5ca94e4951090140
|
3 |
+
size 1319391849
|
save/modelV1/variables/variables.index
ADDED
Binary file (40.6 kB). View file
|
|