diff --git a/gpu-environment-tensorflow.ipynb b/gpu-environment-tensorflow.ipynb
deleted file mode 100644
index 537d6b41..00000000
--- a/gpu-environment-tensorflow.ipynb
+++ /dev/null
@@ -1,425 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# GPU Environment Tensorflow"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "
\n",
- "\n",
- "This tutorial is available as an IPython notebook at [Malaya/example/gpu-environment-tensorflow](https://github.com/huseinzol05/Malaya/tree/master/example/gpu-environment-tensorflow).\n",
- " \n",
- "
"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "import os\n",
- "\n",
- "os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "CPU times: user 4.06 s, sys: 3.48 s, total: 7.54 s\n",
- "Wall time: 4.07 s\n"
- ]
- }
- ],
- "source": [
- "%%time\n",
- "\n",
- "import malaya\n",
- "import logging\n",
- "logging.basicConfig(level = logging.INFO)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### List available GPU\n",
- "\n",
- "**You must install Tensorflow GPU version first to enable GPU hardware acceleration**."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "2023-02-09 10:59:50.394171: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA\n",
- "To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
- "2023-02-09 10:59:50.676494: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:50.676776: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:50.689073: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:50.689336: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:50.689542: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:50.689706: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.518454: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.518763: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.519050: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.519236: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.519436: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.527725: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n",
- "2023-02-09 10:59:52.527766: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 1190 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6\n",
- "2023-02-09 10:59:52.529121: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2023-02-09 10:59:52.529492: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:39] Overriding allow_growth setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.\n",
- "2023-02-09 10:59:52.529525: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:1 with 2299 MB memory: -> device: 1, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:07:00.0, compute capability: 8.6\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "[name: \"/device:CPU:0\"\n",
- " device_type: \"CPU\"\n",
- " memory_limit: 268435456\n",
- " locality {\n",
- " }\n",
- " incarnation: 17455430732188064581,\n",
- " name: \"/device:GPU:0\"\n",
- " device_type: \"GPU\"\n",
- " memory_limit: 1248460800\n",
- " locality {\n",
- " bus_id: 1\n",
- " links {\n",
- " }\n",
- " }\n",
- " incarnation: 17187613631775953589\n",
- " physical_device_desc: \"device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6\",\n",
- " name: \"/device:GPU:1\"\n",
- " device_type: \"GPU\"\n",
- " memory_limit: 2411331584\n",
- " locality {\n",
- " bus_id: 1\n",
- " links {\n",
- " }\n",
- " }\n",
- " incarnation: 18149323579634163815\n",
- " physical_device_desc: \"device: 1, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:07:00.0, compute capability: 8.6\"]"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "from tensorflow.python.client import device_lib\n",
- "\n",
- "device_lib.list_local_devices()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Run model inside GPU\n",
- "\n",
- "We can follow steps from here https://www.tensorflow.org/guide/gpu"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "import tensorflow as tf\n",
- "\n",
- "tf.debugging.set_log_device_placement(True)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "INFO:malaya.sentiment:tested on test set at https://github.com/huseinzol05/malay-dataset/tree/master/sentiment/semisupervised-twitter-3class\n"
- ]
- },
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Size (MB) | \n",
- " Quantized Size (MB) | \n",
- " macro precision | \n",
- " macro recall | \n",
- " macro f1-score | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " bert | \n",
- " 425.6 | \n",
- " 111.00 | \n",
- " 0.93182 | \n",
- " 0.93442 | \n",
- " 0.93307 | \n",
- "
\n",
- " \n",
- " tiny-bert | \n",
- " 57.4 | \n",
- " 15.40 | \n",
- " 0.93390 | \n",
- " 0.93141 | \n",
- " 0.93262 | \n",
- "
\n",
- " \n",
- " albert | \n",
- " 48.6 | \n",
- " 12.80 | \n",
- " 0.91228 | \n",
- " 0.91929 | \n",
- " 0.91540 | \n",
- "
\n",
- " \n",
- " tiny-albert | \n",
- " 22.4 | \n",
- " 5.98 | \n",
- " 0.91442 | \n",
- " 0.91646 | \n",
- " 0.91521 | \n",
- "
\n",
- " \n",
- " xlnet | \n",
- " 446.6 | \n",
- " 118.00 | \n",
- " 0.92390 | \n",
- " 0.92629 | \n",
- " 0.92444 | \n",
- "
\n",
- " \n",
- " alxlnet | \n",
- " 46.8 | \n",
- " 13.30 | \n",
- " 0.91896 | \n",
- " 0.92589 | \n",
- " 0.92198 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Size (MB) Quantized Size (MB) macro precision macro recall \\\n",
- "bert 425.6 111.00 0.93182 0.93442 \n",
- "tiny-bert 57.4 15.40 0.93390 0.93141 \n",
- "albert 48.6 12.80 0.91228 0.91929 \n",
- "tiny-albert 22.4 5.98 0.91442 0.91646 \n",
- "xlnet 446.6 118.00 0.92390 0.92629 \n",
- "alxlnet 46.8 13.30 0.91896 0.92589 \n",
- "\n",
- " macro f1-score \n",
- "bert 0.93307 \n",
- "tiny-bert 0.93262 \n",
- "albert 0.91540 \n",
- "tiny-albert 0.91521 \n",
- "xlnet 0.92444 \n",
- "alxlnet 0.92198 "
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "malaya.sentiment.available_transformer()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Malaya frozen graph interfaces"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "#### load graph\n",
- "\n",
- "All the malaya tensorflow model interface will pass vector arguments to `malaya_boilerplate.frozen_graph.load_graph`,\n",
- "\n",
- "```python\n",
- "def load_graph(package, frozen_graph_filename, **kwargs):\n",
- " \"\"\"\n",
- " Load frozen graph from a checkpoint.\n",
- "\n",
- " Parameters\n",
- " ----------\n",
- " frozen_graph_filename: str\n",
- " precision_mode: str, optional (default='FP32')\n",
- " change precision frozen graph, only supported one of ['BFLOAT16', 'FP16', 'FP32', 'FP64'].\n",
- " device: str, optional (default='CPU:0')\n",
- " device to use for specific model, read more at https://www.tensorflow.org/guide/gpu\n",
- "\n",
- " Returns\n",
- " -------\n",
- " result : tensorflow.Graph\n",
- " \"\"\"\n",
- "```"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "#### generate session\n",
- "\n",
- "After get load into the graph, it will pass the graph into `malaya_boilerplate.frozen_graph.generate_session` to generate session for Tensorflow graph,\n",
- "\n",
- "```python\n",
- "def generate_session(graph, **kwargs):\n",
- " \"\"\"\n",
- " Load session for a Tensorflow graph.\n",
- "\n",
- " Parameters\n",
- " ----------\n",
- " graph: tensorflow.Graph\n",
- " gpu_limit: float, optional (default = 0.999)\n",
- " limit percentage to use a gpu memory.\n",
- "\n",
- " Returns\n",
- " -------\n",
- " result : tensorflow.Session\n",
- " \"\"\"\n",
- "```"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "2022-10-22 22:50:23.644489: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.645216: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.645807: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.646643: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.647257: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.647868: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.648500: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.649080: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:23.649400: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 17248 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6\n",
- "2022-10-22 22:50:26.837274: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:26.837995: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:26.838587: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:26.839201: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:26.839795: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:26.840379: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 17248 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6\n",
- "2022-10-22 22:50:27.023275: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:27.024056: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:27.024655: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:27.025307: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:27.025894: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero\n",
- "2022-10-22 22:50:27.026483: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 17248 MB memory: -> device: 0, name: NVIDIA GeForce RTX 3090 Ti, pci bus id: 0000:01:00.0, compute capability: 8.6\n"
- ]
- }
- ],
- "source": [
- "tiny_albert = malaya.sentiment.transformer(model = 'tiny-albert', device = 'GPU:0')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "2022-10-22 22:50:27.931657: I tensorflow/stream_executor/cuda/cuda_blas.cc:1760] TensorFloat-32 will be used for the matrix multiplication. This will only be logged once.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "[{'negative': 0.001145982, 'neutral': 0.99809974, 'positive': 0.0007543671}]"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "tiny_albert.predict_proba(['hello'])"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "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.8.10"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}
diff --git a/mock-tensorflow.ipynb b/mock-tensorflow.ipynb
deleted file mode 100644
index 8c351fdb..00000000
--- a/mock-tensorflow.ipynb
+++ /dev/null
@@ -1,322 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Mock Tensorflow"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "\n",
- "This tutorial is available as an IPython notebook at [Malaya/example/mock-tensorflow](https://github.com/huseinzol05/Malaya/tree/master/example/mock-tensorflow).\n",
- " \n",
- "
"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Starting with Malaya 5.0.1 and malaya-boilerplate 0.0.24, Tensorflow is no longer necessary to install and if Tensorflow absent, it will be replaced with mock object.\n",
- "\n",
- "Let say you installed Malaya on a fresh machine or using a virtual environment, and you start to install Malaya,"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "!~/huggingface/bin/pip3 freeze | grep 'tensorflow'"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "As you can see, this virtual environment does not have Tensorflow installed."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/home/husein/dev/malaya-boilerplate/malaya_boilerplate/frozen_graph.py:46: UserWarning: Cannot import beam_search_ops from Tensorflow 1, ['malaya.jawi_rumi.deep_model', 'malaya.phoneme.deep_model', 'malaya.rumi_jawi.deep_model', 'malaya.stem.deep_model'] for stemmer will not available to use, make sure Tensorflow 1 version >= 1.15\n",
- " warnings.warn(\n",
- "/home/husein/huggingface/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
- " from .autonotebook import tqdm as notebook_tqdm\n",
- "bs4 is not installed, `malaya.text.function.remove_html_tags` will use regex\n"
- ]
- }
- ],
- "source": [
- "import malaya"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- ""
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import tensorflow as tf\n",
- "\n",
- "tf.__version__"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "As you can see, everything is a Mock object, what happened if you tried to call a model using Tensorflow as backend?"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Call Tensorflow model"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Size (MB) | \n",
- " Quantized Size (MB) | \n",
- " macro precision | \n",
- " macro recall | \n",
- " macro f1-score | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " bert | \n",
- " 425.6 | \n",
- " 111.00 | \n",
- " 0.93182 | \n",
- " 0.93442 | \n",
- " 0.93307 | \n",
- "
\n",
- " \n",
- " tiny-bert | \n",
- " 57.4 | \n",
- " 15.40 | \n",
- " 0.93390 | \n",
- " 0.93141 | \n",
- " 0.93262 | \n",
- "
\n",
- " \n",
- " albert | \n",
- " 48.6 | \n",
- " 12.80 | \n",
- " 0.91228 | \n",
- " 0.91929 | \n",
- " 0.91540 | \n",
- "
\n",
- " \n",
- " tiny-albert | \n",
- " 22.4 | \n",
- " 5.98 | \n",
- " 0.91442 | \n",
- " 0.91646 | \n",
- " 0.91521 | \n",
- "
\n",
- " \n",
- " xlnet | \n",
- " 446.6 | \n",
- " 118.00 | \n",
- " 0.92390 | \n",
- " 0.92629 | \n",
- " 0.92444 | \n",
- "
\n",
- " \n",
- " alxlnet | \n",
- " 46.8 | \n",
- " 13.30 | \n",
- " 0.91896 | \n",
- " 0.92589 | \n",
- " 0.92198 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Size (MB) Quantized Size (MB) macro precision macro recall \\\n",
- "bert 425.6 111.00 0.93182 0.93442 \n",
- "tiny-bert 57.4 15.40 0.93390 0.93141 \n",
- "albert 48.6 12.80 0.91228 0.91929 \n",
- "tiny-albert 22.4 5.98 0.91442 0.91646 \n",
- "xlnet 446.6 118.00 0.92390 0.92629 \n",
- "alxlnet 46.8 13.30 0.91896 0.92589 \n",
- "\n",
- " macro f1-score \n",
- "bert 0.93307 \n",
- "tiny-bert 0.93262 \n",
- "albert 0.91540 \n",
- "tiny-albert 0.91521 \n",
- "xlnet 0.92444 \n",
- "alxlnet 0.92198 "
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "malaya.sentiment.available_transformer()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Downloading (…)\"model.pb\";: 100%|██████████| 49.0M/49.0M [00:04<00:00, 11.4MB/s]\n"
- ]
- },
- {
- "ename": "ValueError",
- "evalue": "tensorflow is not installed. Please install it and try again.",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mmalaya\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msentiment\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtransformer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43malxlnet\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/huggingface/lib/python3.8/site-packages/herpetologist/__init__.py:100\u001b[0m, in \u001b[0;36mcheck_type..check\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m p, v \u001b[38;5;129;01min\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mitems():\n\u001b[1;32m 98\u001b[0m nested_check(v, p)\n\u001b[0;32m--> 100\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/dev/malaya/malaya/sentiment.py:112\u001b[0m, in \u001b[0;36mtransformer\u001b[0;34m(model, quantized, **kwargs)\u001b[0m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m model \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m _transformer_availability:\n\u001b[1;32m 109\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 110\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel not supported, please check supported models from `malaya.sentiment.available_transformer()`.\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 111\u001b[0m )\n\u001b[0;32m--> 112\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mclassification\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtransformer\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 113\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodule\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msentiment-v2\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 114\u001b[0m \u001b[43m \u001b[49m\u001b[43mlabel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 115\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 116\u001b[0m \u001b[43m \u001b[49m\u001b[43mquantized\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mquantized\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 117\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\n\u001b[1;32m 118\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/dev/malaya/malaya/supervised/classification.py:141\u001b[0m, in \u001b[0;36mtransformer\u001b[0;34m(module, label, model, sigmoid, quantized, **kwargs)\u001b[0m\n\u001b[1;32m 122\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mtransformer\u001b[39m(\n\u001b[1;32m 123\u001b[0m module,\n\u001b[1;32m 124\u001b[0m label,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 129\u001b[0m ):\n\u001b[1;32m 130\u001b[0m path \u001b[38;5;241m=\u001b[39m check_file(\n\u001b[1;32m 131\u001b[0m file\u001b[38;5;241m=\u001b[39mmodel,\n\u001b[1;32m 132\u001b[0m module\u001b[38;5;241m=\u001b[39mmodule,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 139\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs,\n\u001b[1;32m 140\u001b[0m )\n\u001b[0;32m--> 141\u001b[0m g \u001b[38;5;241m=\u001b[39m \u001b[43mload_graph\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 143\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sigmoid:\n\u001b[1;32m 144\u001b[0m selected_model \u001b[38;5;241m=\u001b[39m SIGMOID_MODEL[model]\n",
- "File \u001b[0;32m~/dev/malaya/malaya/function/__init__.py:38\u001b[0m, in \u001b[0;36mload_graph\u001b[0;34m(frozen_graph_filename, **kwargs)\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload_graph\u001b[39m(frozen_graph_filename, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m---> 38\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfrozen_graph\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload_graph\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpackage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrozen_graph_filename\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/dev/malaya-boilerplate/malaya_boilerplate/frozen_graph.py:241\u001b[0m, in \u001b[0;36mload_graph\u001b[0;34m(package, frozen_graph_filename, **kwargs)\u001b[0m\n\u001b[1;32m 238\u001b[0m precision_mode \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mprecision_mode\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFP32\u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mupper()\n\u001b[1;32m 239\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mprecision_mode: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mprecision_mode\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m--> 241\u001b[0m device \u001b[38;5;241m=\u001b[39m \u001b[43mget_device\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 242\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdevice: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mdevice\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 244\u001b[0m t5_graph \u001b[38;5;241m=\u001b[39m kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt5_graph\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m)\n",
- "File \u001b[0;32m~/dev/malaya-boilerplate/malaya_boilerplate/frozen_graph.py:111\u001b[0m, in \u001b[0;36mget_device\u001b[0;34m(**kwargs)\u001b[0m\n\u001b[1;32m 107\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m device_type \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_CPU\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_CPU_JIT\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCPU\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGPU\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_GPU\u001b[39m\u001b[38;5;124m'\u001b[39m}:\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 109\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m`device` from `device:\u001b[39m\u001b[38;5;132;01m{no}\u001b[39;00m\u001b[38;5;124m` must one of [\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_CPU\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_CPU_JIT\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCPU\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGPU\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m, \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA_GPU\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m]\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 110\u001b[0m )\n\u001b[0;32m--> 111\u001b[0m gpus \u001b[38;5;241m=\u001b[39m \u001b[43mavailable_gpu\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 113\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGPU\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m device:\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(gpus):\n",
- "File \u001b[0;32m~/dev/malaya-boilerplate/malaya_boilerplate/utils.py:117\u001b[0m, in \u001b[0;36mavailable_gpu\u001b[0;34m(refresh)\u001b[0m\n\u001b[1;32m 108\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mavailable_gpu\u001b[39m(refresh\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[1;32m 109\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 110\u001b[0m \u001b[38;5;124;03m Get list of GPUs and memory limit from `tensorflow.python.client.device_lib.list_local_devices()`.\u001b[39;00m\n\u001b[1;32m 111\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 114\u001b[0m \u001b[38;5;124;03m result : List[str]\u001b[39;00m\n\u001b[1;32m 115\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 117\u001b[0m devices \u001b[38;5;241m=\u001b[39m \u001b[43mavailable_device\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrefresh\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrefresh\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m [d \u001b[38;5;28;01mfor\u001b[39;00m d \u001b[38;5;129;01min\u001b[39;00m devices \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGPU\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m d[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mXLA\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m d[\u001b[38;5;241m0\u001b[39m]]\n",
- "File \u001b[0;32m~/dev/malaya-boilerplate/malaya_boilerplate/utils.py:96\u001b[0m, in \u001b[0;36mavailable_device\u001b[0;34m(refresh)\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m DEVICES \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m refresh:\n\u001b[1;32m 94\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtensorflow\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpython\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mclient\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m device_lib\n\u001b[0;32m---> 96\u001b[0m DEVICES \u001b[38;5;241m=\u001b[39m \u001b[43mdevice_lib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlist_local_devices\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 97\u001b[0m DEVICES \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 98\u001b[0m (\n\u001b[1;32m 99\u001b[0m i\u001b[38;5;241m.\u001b[39mname\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/device:\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m),\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m DEVICES\n\u001b[1;32m 103\u001b[0m ]\n\u001b[1;32m 105\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m DEVICES\n",
- "File \u001b[0;32m~/dev/malaya-boilerplate/malaya_boilerplate/__init__.py:48\u001b[0m, in \u001b[0;36mMock.__call__\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m---> 48\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparent_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is not installed. Please install it and try again.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
- "\u001b[0;31mValueError\u001b[0m: tensorflow is not installed. Please install it and try again."
- ]
- }
- ],
- "source": [
- "model = malaya.sentiment.transformer(model = 'alxlnet')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Call PyTorch model\n",
- "\n",
- "Starting from malaya 4.9, we are going to focus Pytorch for main deep learning backend."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "scrolled": false
- },
- "outputs": [],
- "source": [
- "model = malaya.similarity.semantic.huggingface()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "You're using a T5TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "array([0.86549413], dtype=float32)"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "model.predict_proba(['tak suka ayam'], ['hate chicken'])"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "huggingface",
- "language": "python",
- "name": "huggingface"
- },
- "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.8.10"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 4
-}