Spaces:
Sleeping
Sleeping
update with model
Browse files- .gitattributes +1 -0
- data/lukash_speech.txt +0 -0
- data/source_text_lukash.txt +0 -0
- model_from_saved.py +77 -0
- results/Lukashenko_tarakan/fingerprint.pb +3 -0
- results/Lukashenko_tarakan/keras_metadata.pb +3 -0
- results/Lukashenko_tarakan/saved_model.pb +3 -0
- results/Lukashenko_tarakan/variables/variables.data-00000-of-00001 +3 -0
- results/Lukashenko_tarakan/variables/variables.index +0 -0
- results/config_lukash.json +1 -0
- results/weights_lukash.h5 +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
results/Lukashenko_tarakan/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
data/lukash_speech.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
data/source_text_lukash.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model_from_saved.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import copy
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
def generate_from_saved():
|
7 |
+
# add the start generation of the lukashenko speech from the simple seed
|
8 |
+
seed_text = 'я не глядя поддержу'
|
9 |
+
weights_path = 'results/weights_lukash.h5'
|
10 |
+
model_path = 'results/Lukashenko_tarakan'
|
11 |
+
|
12 |
+
model = tf.keras.models.load_model(model_path)
|
13 |
+
model.load_weights(weights_path)
|
14 |
+
# Show the Model summary
|
15 |
+
model.summary()
|
16 |
+
|
17 |
+
with open('data/source_text_lukash.txt', 'r') as source_text_file:
|
18 |
+
data = source_text_file.read().splitlines()
|
19 |
+
|
20 |
+
tmp_data = copy.deepcopy(data)
|
21 |
+
sent_length = 0
|
22 |
+
for idx, line in enumerate(data):
|
23 |
+
if len(line) < 5:
|
24 |
+
tmp_data.pop(idx)
|
25 |
+
else:
|
26 |
+
sent_length += len(line.split())
|
27 |
+
data = tmp_data
|
28 |
+
lstm_length = int(sent_length / len(data))
|
29 |
+
|
30 |
+
token = tf.keras.preprocessing.text.Tokenizer()
|
31 |
+
token.fit_on_texts(data)
|
32 |
+
encoded_text = token.texts_to_sequences(data)
|
33 |
+
# Vocabular size
|
34 |
+
vocab_size = len(token.word_counts) + 1
|
35 |
+
|
36 |
+
datalist = []
|
37 |
+
for d in encoded_text:
|
38 |
+
if len(d) > 1:
|
39 |
+
for i in range(2, len(d)):
|
40 |
+
datalist.append(d[:i])
|
41 |
+
|
42 |
+
max_length = 20
|
43 |
+
sequences = tf.keras.preprocessing.sequence.pad_sequences(datalist, maxlen=max_length, padding='pre')
|
44 |
+
|
45 |
+
# X - input data, y - target data
|
46 |
+
X = sequences[:, :-1]
|
47 |
+
y = sequences[:, -1]
|
48 |
+
|
49 |
+
y = tf.keras.utils.to_categorical(y, num_classes=vocab_size)
|
50 |
+
seq_length = X.shape[1]
|
51 |
+
print(f"Sequence length: {seq_length}")
|
52 |
+
|
53 |
+
generated_text = ''
|
54 |
+
number_lines = 3
|
55 |
+
for i in range(number_lines):
|
56 |
+
text_word_list = []
|
57 |
+
for _ in range(lstm_length * 2):
|
58 |
+
encoded = token.texts_to_sequences([seed_text])
|
59 |
+
encoded = tf.keras.preprocessing.sequence.pad_sequences(encoded, maxlen=seq_length, padding='pre')
|
60 |
+
|
61 |
+
y_pred = np.argmax(model.predict(encoded), axis=-1)
|
62 |
+
|
63 |
+
predicted_word = ""
|
64 |
+
for word, index in token.word_index.items():
|
65 |
+
if index == y_pred:
|
66 |
+
predicted_word = word
|
67 |
+
break
|
68 |
+
|
69 |
+
seed_text = seed_text + ' ' + predicted_word
|
70 |
+
text_word_list.append(predicted_word)
|
71 |
+
|
72 |
+
seed_text = text_word_list [-1]
|
73 |
+
generated_text = ' '.join(text_word_list)
|
74 |
+
generated_text += '\n'
|
75 |
+
|
76 |
+
print(f"Lukashenko are saying: {generated_text}")
|
77 |
+
return generated_text
|
results/Lukashenko_tarakan/fingerprint.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:079dd29ab6262d35662d96e408bf00d508ad36dbfc9017de7d82436c2985b8c7
|
3 |
+
size 55
|
results/Lukashenko_tarakan/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ec6e4a91836f74caa79e8ec8c6801ad84930127148d209fe9135ece7039ba1aa
|
3 |
+
size 17234
|
results/Lukashenko_tarakan/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:828577b478f24668800d2c8340b3b37142c5111effd706f21de4c9e44b544c29
|
3 |
+
size 898564
|
results/Lukashenko_tarakan/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a2d041fdd8e26762137da4a033b417ae7e4fff0b5be76089e5cdc112ff7553c2
|
3 |
+
size 7674664
|
results/Lukashenko_tarakan/variables/variables.index
ADDED
Binary file (2.87 kB). View file
|
|
results/config_lukash.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"name": "sequential", "layers": [{"module": "keras.layers", "class_name": "InputLayer", "config": {"batch_input_shape": [null, 19], "dtype": "float32", "sparse": false, "ragged": false, "name": "embedding_input"}, "registered_name": null}, {"module": "keras.layers", "class_name": "Embedding", "config": {"name": "embedding", "trainable": true, "dtype": "float32", "batch_input_shape": [null, 19], "input_dim": 6269, "output_dim": 48, "embeddings_initializer": {"module": "keras.initializers", "class_name": "RandomUniform", "config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "registered_name": null}, "embeddings_regularizer": null, "activity_regularizer": null, "embeddings_constraint": null, "mask_zero": false, "input_length": 19}, "registered_name": null, "build_config": {"input_shape": [null, 19]}}, {"module": "keras.layers", "class_name": "LSTM", "config": {"name": "lstm", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 48, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "recurrent_initializer": {"module": "keras.initializers", "class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}, "registered_name": null, "build_config": {"input_shape": [null, 19, 48]}}, {"module": "keras.layers", "class_name": "LSTM", "config": {"name": "lstm_1", "trainable": true, "dtype": "float32", "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 32, "activation": "relu", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "recurrent_initializer": {"module": "keras.initializers", "class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}, "registered_name": null, "build_config": {"input_shape": [null, 19, 48]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 48, "activation": "relu", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 32]}}, {"module": "keras.layers", "class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 6269, "activation": "softmax", "use_bias": true, "kernel_initializer": {"module": "keras.initializers", "class_name": "GlorotUniform", "config": {"seed": null}, "registered_name": null}, "bias_initializer": {"module": "keras.initializers", "class_name": "Zeros", "config": {}, "registered_name": null}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "registered_name": null, "build_config": {"input_shape": [null, 48]}}]}
|
results/weights_lukash.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0e370d4a3df876823e059affbd2f4a3ce3756cb9c841e4d2c82d206d5ce5dcdc
|
3 |
+
size 7721620
|