machinelearning

Machine learning code
git clone git://git.laack.co/machinelearning.git
Log | Files | Refs

EmbedUsingPretrainedModel.ipynb (1951B)


      1 {
      2  "cells": [
      3   {
      4    "cell_type": "code",
      5    "execution_count": 5,
      6    "metadata": {},
      7    "outputs": [
      8     {
      9      "data": {
     10       "text/plain": [
     11        "array([[-0.25,  0.28,  0.01,  0.1 ,  0.14,  0.16,  0.25,  0.02,  0.07,\n",
     12        "         0.13, -0.19,  0.06, -0.04, -0.07,  0.  , -0.08, -0.14, -0.16,\n",
     13        "         0.02, -0.24,  0.16, -0.16, -0.03,  0.03, -0.14,  0.03, -0.09,\n",
     14        "        -0.04, -0.14, -0.19,  0.07,  0.15,  0.18, -0.23, -0.07, -0.08,\n",
     15        "         0.01, -0.01,  0.09,  0.14, -0.03,  0.03,  0.08,  0.1 , -0.01,\n",
     16        "        -0.03, -0.07, -0.1 ,  0.05,  0.31],\n",
     17        "       [-0.2 ,  0.2 , -0.08,  0.02,  0.19,  0.05,  0.22, -0.09,  0.02,\n",
     18        "         0.19, -0.02, -0.14, -0.2 , -0.04,  0.01, -0.07, -0.22, -0.1 ,\n",
     19        "         0.16, -0.44,  0.31, -0.1 ,  0.23,  0.15, -0.05,  0.15, -0.13,\n",
     20        "        -0.04, -0.08, -0.16, -0.1 ,  0.13,  0.13, -0.18, -0.04,  0.03,\n",
     21        "        -0.1 , -0.07,  0.07,  0.03, -0.08,  0.02,  0.05,  0.07, -0.14,\n",
     22        "        -0.1 , -0.18, -0.13, -0.04,  0.15]], dtype=float32)"
     23       ]
     24      },
     25      "execution_count": 5,
     26      "metadata": {},
     27      "output_type": "execute_result"
     28     }
     29    ],
     30    "source": [
     31     "import tensorflow_hub as hub\n",
     32     "import tensorflow as tf\n",
     33     "\n",
     34     "hub_layer = hub.KerasLayer(\"https://tfhub.dev/google/nnlm-en-dim50/2\")\n",
     35     "sentence_embeddings = hub_layer(tf.constant([\"To be\", \"Not to be\"]))\n",
     36     "sentence_embeddings.numpy().round(2)"
     37    ]
     38   }
     39  ],
     40  "metadata": {
     41   "kernelspec": {
     42    "display_name": ".venv",
     43    "language": "python",
     44    "name": "python3"
     45   },
     46   "language_info": {
     47    "codemirror_mode": {
     48     "name": "ipython",
     49     "version": 3
     50    },
     51    "file_extension": ".py",
     52    "mimetype": "text/x-python",
     53    "name": "python",
     54    "nbconvert_exporter": "python",
     55    "pygments_lexer": "ipython3",
     56    "version": "3.11.2"
     57   }
     58  },
     59  "nbformat": 4,
     60  "nbformat_minor": 2
     61 }