hello i make a translation machine with tensorflow your goal is to optilmize a cell for…
- User
hello i make a translation machine with tensorflow your goal is to optilmize a cell for being faster this cells : max_length = 200
fr_sequences = [fr_tokenizer.tokenize(french_sentence.numpy().decode('utf-8')).merge_dims(-2,-1) for french_sentence, _ in dataset.take(127085)] fr_ragged = tf.ragged.stack(fr_sequences) fr_padded = fr_ragged.to_tensor(default_value=0, shape=[None, None, max_length])
print("fr sequences YES") fr_sequencesdeocde = [fr_tokenizer.tokenize("[START] "+french_sentence.numpy().decode('utf-8')+" [END]").merge_dims(-2,-1) for french_sentence, _ in dataset.take(127085)] fr_raggeddecode = tf.ragged.stack(fr_sequences) fr_paddeddecode = fr_ragged.to_tensor(default_value=0, shape=[None, None, max_length]) print("sequencesdeocde Yes") fr_sequences en_sequences = [en_tokenizer.tokenize(english_sentence.numpy().decode('utf-8')+" [END]").merge_dims(-2,-1) for _, english_sentence in dataset.take(127085)] en_ragged = tf.ragged.stack(en_sequences) en_padded = en_ragged.to_tensor(default_value=0, shape=[None, None, max_length])
print("en_sequences yes") x_train = fr_padded x2_train = fr_paddeddecode y_train = en_padded
and this is the full code : { "cells": [ { "cell_type": "markdown", "metadata": { "id": "3UeycYCyxDfE" }, "source": [ "# TRANSLATOR" ] }, { "cell_type": "markdown", "metadata": { "id": "8BfUjVxBcz5N" }, "source": [ "## instalation" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "WXqM38xBRHu2", "outputId": "075e90fc-7ba6-4b54-9bb9-414037cc352e" }, "outputs": [], "source": [ "%%time\n", "!pip install -q -U tensorflow-text\n", "!pip install datasets\n", "!pip install -q tensorflow_datasets\n", "!pip install pydot\n", "!pip install tensorflow\n", "!pip install numpy\n", "!cd /content\n", "!clear" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Ukvs1XfMG7aG" }, "outputs": [], "source": [ "import tensorflow as tf\n", "import tensorflow_text as tf_text\n", "import tensorflow_datasets as tfds\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import requests\n", "import functools\n", "import collections\n", "import os\n", "import pathlib\n", "import re\n", "import string\n", "import tempfile\n", "import time\n", "import matplotlib.pyplot as plt\n", "import os\n", "import re\n", "import shutil\n", "import string\n", "import tensorflow as tf\n", "\n", "from tensorflow.keras import layers\n", "from tensorflow.keras import losses\n", "import pydot" ] }, { "cell_type": "markdown", "metadata": { "id": "7V7igFwpc6Hs" }, "source": [ "## dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 280, "referenced_widgets": [ "a5b60d70fc784178aae195ba50aa17fb", "2f81a198eff14fd9baf1c44eba10e66a", "da5df7f8dc8b4efa9ef1fe766fda07e4", "3cbdaac2925e4f259f8daa74f4a4b0e7", "131339a75d4f4b10900f433780ceda69", "684fe6b833ae4964952c6480fae46f57", "895fece0320d4e4c80971bb9341e4e1c", "25efff7c11d3468fb91d922a42371142", "1641d12ee23646c5bc9f59438ca76468", "89a141e6736947538de57a715aca30bd", "da1528b34ff745e3b7cc2363dd9dea69", "ffcb28bfdc0d4341a5cb2fe0b14d3657", "37a47c1b7eac4d4fb3ee224fdf0392ee", "18e9a5f3d42f4a93b003876b7bcd199c", "9842e84a76e64f1e862bc39a06582a71", "52fd339b0e944e74b7df1b176ee90f5b", "78a4e11bb5f742a4b755cd60137b65c4", "c646272c9a86474c9bda867e57035aaf", "1840095e6efe495a960a1fd6d3060f1c", "c832fdd570f4460c8f37640c20db5089", "9a29068ca9fd478ab4b2b64b29a30452", "617134a74765472b9d621d8d806e6f90", "f1cd45d36c604216bd526f4ee135edcc", "bf7382bdfe9c46c39cc0e48487aa3e7e", "ee55c21104a548938945911d1be5e8bd", "e793e43e37b14498bc34c4f36296d2ac", "0433034eb2744785b33f79961a2c04e4", "8b1fd60dc6fb4094bfecc63c824cdda5", "17879bad90954e9cb888b3675c472f9b", "df815e17a0014f94b2ed81fdca2b8a30", "7b1e2448b06e4235b8502ed17084482a", "cedda31df2a34e97935d72c8dfd5da74", "a4d33f99d00348a6a733e8936feac62c" ] }, "id": "ZaMtoUtAREzs", "outputId": "f8dadd74-5e04-4fa6-9392-6ccd6b2cb458" }, "outputs": [], "source": [ "from datasets import load_dataset\n", "\n", "dataset = load_dataset("Helsinki-NLP/opus_books", "en-fr")\n", "data = dataset["train"]\n", "\n", "french_sentences = [example["fr"] for example in data["translation"][:127085]]\n", "english_sentences = [example["en"] for example in data["translation"][:127085]]\n", "dataset = tf.data.Dataset.from_tensor_slices((french_sentences, english_sentences))\n", "\n", "french_sentences_decoded = []\n", "english_sentences_decoded = []\n", "\n", "for french_sentence, english_sentence in dataset.take(12708):\n", " french_sentences_decoded.append("b '"+french_sentence.numpy().decode('utf-8'))\n", " english_sentences_decoded.append("b '"+english_sentence.numpy().decode('utf-8'))\n", "\n", "print("Nombre de phrases en français :", len(french_sentences_decoded))\n", "print("Nombre de phrases en anglais :", len(english_sentences_decoded))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "2tb7H5uFQoBA" }, "outputs": [], "source": [ "train_fr = french_sentences\n", "train_en = english_sentences" ] }, { "cell_type": "markdown", "metadata": { "id": "NzS8h0budHWv" }, "source": [ "## vocab" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "72uMXsQhFIx8" }, "outputs": [], "source": [ "from tensorflow_text.tools.wordpiece_vocab import bert_vocab_from_dataset as bert_vocab\n", "\n", "bert_tokenizer_params = dict(lower_case=True)\n", "reserved_tokens = ["[PAD]", "[UNK]", "[START]", "[END]"]\n", "\n", "bert_vocab_args = {\n", " 'vocab_size': 8000,\n", " 'reserved_tokens': reserved_tokens,\n", " 'bert_tokenizer_params': bert_tokenizer_params,\n", " 'learn_params': {},\n", "}\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "q6f3mrA-DK0n", "outputId": "b5413b20-51a6-4b79-9bad-ae1aeae4cf42" }, "outputs": [], "source": [ "%%time\n", "en_vocab = bert_vocab.bert_vocab_from_dataset(\n", " tf.data.Dataset.from_tensor_slices(english_sentences).batch(1000).prefetch(2),\n", " **bert_vocab_args\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "EJZzz1x5YY0x", "outputId": "64c27808-53ad-48b9-9a08-ee65c322a6e4" }, "outputs": [], "source": [ "%%time\n", "fr_vocab = bert_vocab.bert_vocab_from_dataset(\n", " tf.data.Dataset.from_tensor_slices(french_sentences).batch(1000).prefetch(2),\n", " **bert_vocab_args\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "1hmXuHHNcBHg" }, "outputs": [], "source": [ "def write_vocab_file(filepath, vocab):\n", " with open(filepath, 'w') as f:\n", " for token in vocab:\n", " print(token, file=f)\n", "write_vocab_file('en_vocab.txt', en_vocab)\n", "write_vocab_file('fr_vocab.txt', fr_vocab)" ] }, { "cell_type": "markdown", "metadata": { "id": "kLTf_mEvfNR9" }, "source": [ "#\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jGshnQ2idy8I" }, "outputs": [], "source": [ "fr_tokenizer = tf_text.BertTokenizer('fr_vocab.txt', **bert_tokenizer_params)\n", "en_tokenizer = tf_text.BertTokenizer('en_vocab.txt', **bert_tokenizer_params)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "bbQyYKhHkkDe", "outputId": "ef6ba4a4-7bab-432e-adcf-6a85440f2c22" }, "outputs": [], "source": [ "# Tokenize the examples -> (batch, word, word-piece)\n", "en_tokenizere = en_tokenizer.tokenize("hello how are you Vadim")\n", "# Merge the word and word-piece axes -> (batch, tokens)\n", "en_tokenizere= en_tokenizere.merge_dims(-2,-1)\n", "\n", "for ex in en_tokenizere.to_list():\n", " print(ex)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "k0m1461Gwy3e" }, "outputs": [], "source": [ "words = en_tokenizer.detokenize(token_batch)\n", "tf.strings.reduce_join(words, separator=' ', axis=-1)" ] }, { "cell_type": "markdown", "metadata": { "id": "BjoPdwoxBWw2" }, "source": [ "## model" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "7OqoDOybbwi6" }, "outputs": [], "source": [ "max_length = 200\n", "\n", "fr_sequences = [fr_tokenizer.tokenize(french_sentence.numpy().decode('utf-8')).merge_dims(-2,-1)\n", " for french_sentence, _ in dataset.take(2000)]\n", "fr_ragged = tf.ragged.stack(fr_sequences)\n", "fr_padded = fr_ragged.to_tensor(default_value=0, shape=[None, None, max_length])\n", "\n", "fr_sequencesdeocde = [fr_tokenizer.tokenize("[START]"+french_sentence.numpy().decode('utf-8')+"[END]").merge_dims(-2,-1)\n", " for french_sentence, _ in dataset.take(2000)]\n", "fr_raggeddecode = tf.ragged.stack(fr_sequences)\n", "fr_paddeddecode = fr_ragged.to_tensor(default_value=0, shape=[None, None, max_length])\n", "\n", "en_sequences = [en_tokenizer.tokenize(english_sentence.numpy().decode('utf-8')).merge_dims(-2,-1)\n", " for _, english_sentence in dataset.take(2000)]\n", "en_ragged = tf.ragged.stack(en_sequences)\n", "en_padded = en_ragged.to_tensor(default_value=0, shape=[None, None, max_length])\n", "\n", "x_train = fr_padded\n", "x2_train = fr_paddeddecode\n", "y_train = en_padded\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 493 }, "id": "FIp6S-MR7Pls", "outputId": "8f187fbe-4f57-4a4f-bb91-c1dc9e098552" }, "outputs": [], "source": [ "inputs = tf.keras.Input(shape=(1,200))\n", "embedding_dim = 512\n", "lstm_units = 1024\n", "vocab_size_en = len(en_vocab) + len(reserved_tokens)\n", "vocab_size_fr = len(fr_vocab) + len(reserved_tokens)\n", "\n", "encoder_inputs = tf.keras.layers.Input(shape=(200,))\n", "encoder_embedding = tf.keras.layers.Embedding(input_dim=vocab_size_en, output_dim=embedding_dim, mask_zero=True)(encoder_inputs)\n", "encoder_outputs, state_h, state_c = tf.keras.layers.LSTM(lstm_units, return_state=True)(encoder_embedding)\n", "encoder_states = [state_h, state_c]\n", "\n", "decoder_inputs = tf.keras.layers.Input(shape=(200,))\n", "decoder_embedding = tf.keras.layers.Embedding(input_dim=vocab_size_fr, output_dim=embedding_dim, mask_zero=True)(decoder_inputs)\n", "decoder_lstm = tf.keras.layers.LSTM(lstm_units, return_sequences=True, return_state=True)\n", "decoder_outputs, _, _ = decoder_lstm(decoder_embedding, initial_state=encoder_states)\n", "decoder_dense = tf.keras.layers.Dense(vocab_size_fr, activation='softmax')\n", "decoder_outputs = decoder_dense(decoder_outputs)\n", "model = tf.keras.models.Model(inputs=[encoder_inputs, decoder_inputs], outputs=decoder_outputs)\n", "model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n", "\n", "\n", "model.summary()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "YOryNiyc15Tf" }, "outputs": [], "source": [ "def format_sequences(tokenizer, sentences, max_length):\n", " sequences = tokenizer.tokenize(sentences).merge_dims(-2, -1)\n", " padded_sequences = sequences.to_tensor(default_value=0, shape=[None, max_length])\n", " return padded_sequences\n", "\n", "encoder_input_data = format_sequences(en_tokenizer, train_en, max_length)\n", "decoder_input_data = format_sequences(fr_tokenizer, ["[START] " + sentence for sentence in train_fr], max_length)\n", "decoder_target_data = format_sequences(fr_tokenizer, [sentence + " [END]" for sentence in train_fr], max_length)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "0oKPxeCMPcsF", "outputId": "0a2d9241-1984-4aa7-c1d1-c5a8d982e542" }, "outputs": [], "source": [ "batch_size = 2\n", "epochs = 3\n", "\n", "model.fit([encoder_input_data, decoder_input_data], decoder_target_data,\n", " batch_size=batch_size,\n", " epochs=epochs,\n", " validation_split=0.2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "avXVDSHx18KC" }, "outputs": [], "source": [ "encoder_model = tf.keras.models.Model(encoder_inputs, encoder_states)\n", "\n", "decoder_state_input_h = tf.keras.Input(shape=(lstm_units,))\n", "decoder_state_input_c = tf.keras.Input(shape=(lstm_units,))\n", "decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]\n", "\n", "decoder_outputs, state_h, state_c = decoder_lstm(\n", " decoder_embedding, initial_state=decoder_states_inputs)\n", "decoder_states = [state_h, state_c]\n", "decoder_outputs = decoder_dense(decoder_outputs)\n", "\n", "decoder_model = tf.keras.models.Model(\n", " [decoder_inputs] + decoder_states_inputs,\n", " [decoder_outputs] + decoder_states)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "tu-NqIEA19if" }, "outputs": [], "source": [ "def translate(input_sentence):\n", " # Prepare the input sentence\n", " input_seq = format_sequences(en_tokenizer, [input_sentence], max_length)\n", " states_value = encoder_model.predict(input_seq)\n", "\n", " # Generate empty target sequence of length 1 with only the start token\n", " target_seq = np.zeros((1, 1))\n", " target_seq[0, 0] = fr_tokenizer.vocab['[START]']\n", "\n", " # Sampling loop for a batch of sequences\n", " stop_condition = False\n", " decoded_sentence = ''\n", " while not stop_condition:\n", " output_tokens, h, c = decoder_model.predict([target_seq] + states_value)\n", "\n", " # Sample a token and add the corresponding character to the decoded sentence\n", " sampled_token_index = np.argmax(output_tokens[0, -1, :])\n", " sampled_char = fr_tokenizer.detokenize([[sampled_token_index]]).numpy()[0].decode('utf-8')\n", " decoded_sentence += sampled_char + ' '\n", "\n", " # Exit condition: either hit max length or find stop token.\n", " if (sampled_char == '[END]' or len(decoded_sentence) > max_length):\n", " stop_condition = True\n", "\n", " # Update the target sequence (length 1).\n", " target_seq = np.zeros((1, 1))\n", " target_seq[0, 0] = sampled_token_index\n", "\n", " # Update states\n", " states_value = [h, c]\n", "\n", " return decoded_sentence" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 447 }, "id": "KimJ6ANPMz6r", "outputId": "95dcfad1-3d7f-410d-ac24-adcc3215741f" }, "outputs": [], "source": [ "history = model.fit([x_train,x2_train], y_train, epochs=10, batch_size=2)" ] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.9" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "0433034eb2744785b33f79961a2c04e4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "131339a75d4f4b10900f433780ceda69": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "1641d12ee23646c5bc9f59438ca76468": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "17879bad90954e9cb888b3675c472f9b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "1840095e6efe495a960a1fd6d3060f1c": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "18e9a5f3d42f4a93b003876b7bcd199c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_1840095e6efe495a960a1fd6d3060f1c", "max": 20985324, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_c832fdd570f4460c8f37640c20db5089", "value": 20985324 } }, "25efff7c11d3468fb91d922a42371142": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "2f81a198eff14fd9baf1c44eba10e66a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_684fe6b833ae4964952c6480fae46f57", "placeholder": "", "style": "IPY_MODEL_895fece0320d4e4c80971bb9341e4e1c", "value": "Downloading readme: 100%" } }, "37a47c1b7eac4d4fb3ee224fdf0392ee": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_78a4e11bb5f742a4b755cd60137b65c4", "placeholder": "", "style": "IPY_MODEL_c646272c9a86474c9bda867e57035aaf", "value": "Downloading data: 100%" } }, "3cbdaac2925e4f259f8daa74f4a4b0e7": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_89a141e6736947538de57a715aca30bd", "placeholder": "", "style": "IPY_MODEL_da1528b34ff745e3b7cc2363dd9dea69", "value": " 28.1k/28.1k [00:00<00:00, 1.51MB/s]" } }, "52fd339b0e944e74b7df1b176ee90f5b": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "617134a74765472b9d621d8d806e6f90": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "684fe6b833ae4964952c6480fae46f57": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "78a4e11bb5f742a4b755cd60137b65c4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "7b1e2448b06e4235b8502ed17084482a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "895fece0320d4e4c80971bb9341e4e1c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "89a141e6736947538de57a715aca30bd": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "8b1fd60dc6fb4094bfecc63c824cdda5": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "9842e84a76e64f1e862bc39a06582a71": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_9a29068ca9fd478ab4b2b64b29a30452", "placeholder": "", "style": "IPY_MODEL_617134a74765472b9d621d8d806e6f90", "value": " 21.0M/21.0M [00:00<00:00, 29.9MB/s]" } }, "9a29068ca9fd478ab4b2b64b29a30452": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "a4d33f99d00348a6a733e8936feac62c": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "a5b60d70fc784178aae195ba50aa17fb": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_2f81a198eff14fd9baf1c44eba10e66a", "IPY_MODEL_da5df7f8dc8b4efa9ef1fe766fda07e4", "IPY_MODEL_3cbdaac2925e4f259f8daa74f4a4b0e7" ], "layout": "IPY_MODEL_131339a75d4f4b10900f433780ceda69" } }, "bf7382bdfe9c46c39cc0e48487aa3e7e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_8b1fd60dc6fb4094bfecc63c824cdda5", "placeholder": "", "style": "IPY_MODEL_17879bad90954e9cb888b3675c472f9b", "value": "Generating train split: 100%" } }, "c646272c9a86474c9bda867e57035aaf": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "c832fdd570f4460c8f37640c20db5089": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "ProgressStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "ProgressStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "bar_color": null, "description_width": "" } }, "cedda31df2a34e97935d72c8dfd5da74": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "da1528b34ff745e3b7cc2363dd9dea69": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "da5df7f8dc8b4efa9ef1fe766fda07e4": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_25efff7c11d3468fb91d922a42371142", "max": 28064, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_1641d12ee23646c5bc9f59438ca76468", "value": 28064 } }, "df815e17a0014f94b2ed81fdca2b8a30": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "e793e43e37b14498bc34c4f36296d2ac": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_cedda31df2a34e97935d72c8dfd5da74", "placeholder": "", "style": "IPY_MODEL_a4d33f99d00348a6a733e8936feac62c", "value": " 127085/127085 [00:00<00:00, 284966.50 examples/s]" } }, "ee55c21104a548938945911d1be5e8bd": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "FloatProgressModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "FloatProgressModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "ProgressView", "bar_style": "success", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_df815e17a0014f94b2ed81fdca2b8a30", "max": 127085, "min": 0, "orientation": "horizontal", "style": "IPY_MODEL_7b1e2448b06e4235b8502ed17084482a", "value": 127085 } }, "f1cd45d36c604216bd526f4ee135edcc": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_bf7382bdfe9c46c39cc0e48487aa3e7e", "IPY_MODEL_ee55c21104a548938945911d1be5e8bd", "IPY_MODEL_e793e43e37b14498bc34c4f36296d2ac" ], "layout": "IPY_MODEL_0433034eb2744785b33f79961a2c04e4" } }, "ffcb28bfdc0d4341a5cb2fe0b14d3657": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HBoxModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HBoxView", "box_style": "", "children": [ "IPY_MODEL_37a47c1b7eac4d4fb3ee224fdf0392ee", "IPY_MODEL_18e9a5f3d42f4a93b003876b7bcd199c", "IPY_MODEL_9842e84a76e64f1e862bc39a06582a71" ], "layout": "IPY_MODEL_52fd339b0e944e74b7df1b176ee90f5b" } } } } }, "nbformat": 4, "nbformat_minor": 0 }
- Assistant
Optimizing TensorFlow code for speed and efficiency involves identifying and addressing bottlenecks in the data processing and model training pipeline. Your TensorFlow code snippet is focused on preparing data for a translation model, involving tokenization and padding of sequences. Here are some optimization tips: