diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/favicon.ico | 0 | ||||
-rw-r--r-- | web/index.html | 14 | ||||
-rw-r--r-- | web/jsmodel/group1-shard1of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard2of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard3of4.bin | bin | 0 -> 4194304 bytes | |||
-rw-r--r-- | web/jsmodel/group1-shard4of4.bin | bin | 0 -> 3491076 bytes | |||
-rw-r--r-- | web/jsmodel/model.json | 1 | ||||
-rw-r--r-- | web/script.js | 27 |
8 files changed, 42 insertions, 0 deletions
diff --git a/web/favicon.ico b/web/favicon.ico new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/web/favicon.ico diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..3fcc91d --- /dev/null +++ b/web/index.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta http-equiv="X-UA-Compatible" content="ie=edge"> + <title>MyApp</title> + <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script> + </head> + <body> + <h1>Hello</h1> + <script src="script.js"></script> + </body> +</html> diff --git a/web/jsmodel/group1-shard1of4.bin b/web/jsmodel/group1-shard1of4.bin Binary files differnew file mode 100644 index 0000000..50f742e --- /dev/null +++ b/web/jsmodel/group1-shard1of4.bin diff --git a/web/jsmodel/group1-shard2of4.bin b/web/jsmodel/group1-shard2of4.bin Binary files differnew file mode 100644 index 0000000..f60c458 --- /dev/null +++ b/web/jsmodel/group1-shard2of4.bin diff --git a/web/jsmodel/group1-shard3of4.bin b/web/jsmodel/group1-shard3of4.bin Binary files differnew file mode 100644 index 0000000..e682033 --- /dev/null +++ b/web/jsmodel/group1-shard3of4.bin diff --git a/web/jsmodel/group1-shard4of4.bin b/web/jsmodel/group1-shard4of4.bin Binary files differnew file mode 100644 index 0000000..200da57 --- /dev/null +++ b/web/jsmodel/group1-shard4of4.bin diff --git a/web/jsmodel/model.json b/web/jsmodel/model.json new file mode 100644 index 0000000..0de300d --- /dev/null +++ b/web/jsmodel/model.json @@ -0,0 +1 @@ +{"format": "layers-model", "generatedBy": "keras v2.4.0", "convertedBy": "TensorFlow.js Converter v4.2.0", "modelTopology": {"keras_version": "2.4.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential_1", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [1, null], "dtype": "float32", "sparse": false, "ragged": false, "name": "embedding_1_input"}}, {"class_name": "Embedding", "config": {"name": "embedding_1", "trainable": true, "batch_input_shape": [1, null], "dtype": "float32", "input_dim": 65, "output_dim": 256, "embeddings_initializer": {"class_name": "RandomUniform", "config": {"minval": -0.05, "maxval": 0.05, "seed": null}}, "embeddings_regularizer": null, "activity_regularizer": null, "embeddings_constraint": null, "mask_zero": false, "input_length": null}}, {"class_name": "GRU", "config": {"name": "gru_1", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": true, "unroll": false, "time_major": false, "units": 1024, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "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, "reset_after": false}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 65, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}}}, "weightsManifest": [{"paths": ["group1-shard1of4.bin", "group1-shard2of4.bin", "group1-shard3of4.bin", "group1-shard4of4.bin"], "weights": [{"name": "dense_1/kernel", "shape": [1024, 65], "dtype": "float32"}, {"name": "dense_1/bias", "shape": [65], "dtype": "float32"}, {"name": "embedding_1/embeddings", "shape": [65, 256], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/kernel", "shape": [256, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/recurrent_kernel", "shape": [1024, 3072], "dtype": "float32"}, {"name": "gru_1/gru_cell_1/bias", "shape": [3072], "dtype": "float32"}]}]}
\ No newline at end of file diff --git a/web/script.js b/web/script.js new file mode 100644 index 0000000..07fdd6b --- /dev/null +++ b/web/script.js @@ -0,0 +1,27 @@ +async function generate_text(model, idx2char, char2idx, start_string = 'ROMEO:', num_generate = 1000, temperature = 0.7) { + let input_eval = start_string.split('').map(s => char2idx[s]); + input_eval = tf.tensor1d(input_eval); + input_eval = tf.reshape(input_eval, [1, input_eval.size]); + + let text_generated = []; + + model.resetStates(); + for (let i = 0; i < num_generate; i++) { + let predictions = model.predict(input_eval); + predictions = predictions.squeeze(); + predictions = predictions.div(temperature); + let predicted_id = await tf.multinomial(predictions, 1).dataSync()[0]; + input_eval = tf.expandDims([predicted_id], 0); + text_generated.push(idx2char[predicted_id]); + console.log(i) + } + + console.log(text_generated.join('')); +} + +async function runModel() { + char2idx = {'\n': 0, ' ': 1, '!': 2, '$': 3, '&': 4, "'": 5, ',': 6, '-': 7, '.': 8, '3': 9, ':': 10, ';': 11, '?': 12, 'A': 13, 'B': 14, 'C': 15, 'D': 16, 'E': 17, 'F': 18, 'G': 19, 'H': 20, 'I': 21, 'J': 22, 'K': 23, 'L': 24, 'M': 25, 'N': 26, 'O': 27, 'P': 28, 'Q': 29, 'R': 30, 'S': 31, 'T': 32, 'U': 33, 'V': 34, 'W': 35, 'X': 36, 'Y': 37, 'Z': 38, 'a': 39, 'b': 40, 'c': 41, 'd': 42, 'e': 43, 'f': 44, 'g': 45, 'h': 46, 'i': 47, 'j': 48, 'k': 49, 'l': 50, 'm': 51, 'n': 52, 'o': 53, 'p': 54, 'q': 55, 'r': 56, 's': 57, 't': 58, 'u': 59, 'v': 60, 'w': 61, 'x': 62, 'y': 63, 'z': 64} + idx2char = ['\n', ' ', '!', '$', '&', "'", ',', '-', '.', '3', ':', ';', '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + const model = await tf.loadLayersModel('/jsmodel/model.json'); + generate_text(model, idx2char, char2idx); +} |