{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cache location\n",
    "\n",
    "You actually can know where is your Malaya caching folder."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import malaya"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/huseinzol/Malaya'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "malaya.home"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Cache subdirectories\n",
    "\n",
    "Start from version 1.0, Malaya put models in subdirectories, you can print it by simply,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Malaya/\n",
      "├── dependency/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-dependency.json\n",
      "│   │   ├── bahdanau-dependency.pb\n",
      "│   │   └── version\n",
      "│   ├── concat/\n",
      "│   │   ├── concat-dependency.json\n",
      "│   │   ├── concat-dependency.pb\n",
      "│   │   └── version\n",
      "│   ├── crf/\n",
      "│   │   ├── crf-depend.pkl\n",
      "│   │   ├── crf-label.pkl\n",
      "│   │   └── version\n",
      "│   └── luong/\n",
      "│       ├── luong-dependency.json\n",
      "│       ├── luong-dependency.pb\n",
      "│       └── version\n",
      "├── dictionary/\n",
      "│   └── malay-text.txt\n",
      "├── emotion/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-emotion.json\n",
      "│   │   ├── bahdanau-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── bert/\n",
      "│   │   ├── bert-emotion.json\n",
      "│   │   ├── bert-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── bidirectional/\n",
      "│   │   ├── bidirectional-emotion.json\n",
      "│   │   ├── bidirectional-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-emotion.json\n",
      "│   │   ├── entity-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text/\n",
      "│   │   ├── fasttext-emotion.json\n",
      "│   │   ├── fasttext-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text-char/\n",
      "│   │   ├── model.ckpt.data-00000-of-00001\n",
      "│   │   ├── model.ckpt.index\n",
      "│   │   ├── model.ckpt.meta\n",
      "│   │   ├── vectorizer-sparse-emotion.pkl\n",
      "│   │   └── version\n",
      "│   ├── hierarchical/\n",
      "│   │   ├── hierarchical-emotion.json\n",
      "│   │   ├── hierarchical-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── luong/\n",
      "│   │   ├── luong-emotion.json\n",
      "│   │   ├── luong-emotion.pb\n",
      "│   │   └── version\n",
      "│   ├── multinomial/\n",
      "│   │   ├── multinomial-emotion-tfidf.pkl\n",
      "│   │   ├── multinomial-emotion.pkl\n",
      "│   │   └── version\n",
      "│   └── xgb/\n",
      "│       ├── version\n",
      "│       ├── xgboost-emotion-tfidf.pkl\n",
      "│       └── xgboost-emotion.pkl\n",
      "├── english.json\n",
      "├── entity/\n",
      "│   ├── attention/\n",
      "│   │   ├── attention-entities.json\n",
      "│   │   ├── attention-entities.pb\n",
      "│   │   └── version\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-entities.json\n",
      "│   │   ├── bahdanau-entities.pb\n",
      "│   │   └── version\n",
      "│   ├── concat/\n",
      "│   ├── crf/\n",
      "│   │   ├── crf-entities.pkl\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-entities.json\n",
      "│   │   ├── entity-entities.pb\n",
      "│   │   └── version\n",
      "│   └── luong/\n",
      "│       ├── luong-entities.json\n",
      "│       ├── luong-entities.pb\n",
      "│       └── version\n",
      "├── fasttext-wiki/\n",
      "│   └── word2vec.p\n",
      "├── language-detection/\n",
      "│   ├── deep/\n",
      "│   │   ├── model.ckpt.data-00000-of-00001\n",
      "│   │   ├── model.ckpt.index\n",
      "│   │   ├── model.ckpt.meta\n",
      "│   │   └── version\n",
      "│   ├── multinomial/\n",
      "│   │   ├── multinomial-language-detection.pkl\n",
      "│   │   ├── vectorizer-language-detection.pkl\n",
      "│   │   └── version\n",
      "│   ├── sgd/\n",
      "│   │   ├── sgd-language-detection.pkl\n",
      "│   │   └── version\n",
      "│   └── xgb/\n",
      "│       ├── version\n",
      "│       └── xgb-language-detection.pkl\n",
      "├── normalizer/\n",
      "│   ├── normalizer-deep.json\n",
      "│   ├── normalizer-deep.pb\n",
      "│   └── version\n",
      "├── pos/\n",
      "│   ├── attention/\n",
      "│   │   ├── attention-pos.json\n",
      "│   │   ├── attention-pos.pb\n",
      "│   │   └── version\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-pos.json\n",
      "│   │   ├── bahdanau-pos.pb\n",
      "│   │   └── version\n",
      "│   ├── concat/\n",
      "│   │   ├── concat-pos.json\n",
      "│   │   ├── concat-pos.pb\n",
      "│   │   └── version\n",
      "│   ├── crf/\n",
      "│   │   ├── crf-pos.pkl\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-pos.pb\n",
      "│   │   └── version\n",
      "│   └── luong/\n",
      "│       ├── luong-pos.json\n",
      "│       ├── luong-pos.pb\n",
      "│       └── version\n",
      "├── rules-based/\n",
      "│   ├── calon.csv\n",
      "│   ├── negeri.csv\n",
      "│   ├── person-normalized\n",
      "│   ├── short-normalized\n",
      "│   └── topic-normalized\n",
      "├── rules-based.zip\n",
      "├── sentiment/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-sentiment.json\n",
      "│   │   ├── bahdanau-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── bert/\n",
      "│   │   ├── bert-sentiment.json\n",
      "│   │   ├── bert-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── bidirectional/\n",
      "│   │   ├── bidirectional-sentiment.json\n",
      "│   │   ├── bidirectional-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-sentiment.json\n",
      "│   │   ├── entity-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text/\n",
      "│   │   ├── fasttext-sentiment.json\n",
      "│   │   ├── fasttext-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text-char/\n",
      "│   │   ├── model.ckpt.data-00000-of-00001\n",
      "│   │   ├── model.ckpt.index\n",
      "│   │   ├── model.ckpt.meta\n",
      "│   │   ├── vectorizer-sparse-sentiment.pkl\n",
      "│   │   └── version\n",
      "│   ├── hierarchical/\n",
      "│   │   ├── hierarchical-sentiment.json\n",
      "│   │   ├── hierarchical-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── luong/\n",
      "│   │   ├── luong-sentiment.json\n",
      "│   │   ├── luong-sentiment.pb\n",
      "│   │   └── version\n",
      "│   ├── multinomial/\n",
      "│   │   ├── multinomial-sentiment-tfidf.pkl\n",
      "│   │   ├── multinomial-sentiment.pkl\n",
      "│   │   └── version\n",
      "│   └── xgb/\n",
      "│       ├── version\n",
      "│       ├── xgboost-sentiment-tfidf.pkl\n",
      "│       └── xgboost-sentiment.pkl\n",
      "├── stem/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-stem.json\n",
      "│   │   ├── bahdanau-stem.pb\n",
      "│   │   └── version\n",
      "│   ├── lstm/\n",
      "│   │   ├── lstm-stem.json\n",
      "│   │   ├── lstm-stem.pb\n",
      "│   │   └── version\n",
      "│   ├── luong/\n",
      "│   │   ├── luong-stem.json\n",
      "│   │   ├── luong-stem.pb\n",
      "│   │   └── version\n",
      "│   ├── stemmer-deep.json\n",
      "│   ├── stemmer-deep.pb\n",
      "│   └── version\n",
      "├── stop-word-kerulnet\n",
      "├── subjective/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-subjective.json\n",
      "│   │   ├── bahdanau-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── bert/\n",
      "│   │   ├── bert-subjective.json\n",
      "│   │   ├── bert-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── bidirectional/\n",
      "│   │   ├── bidirectional-subjective.json\n",
      "│   │   ├── bidirectional-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-subjective.json\n",
      "│   │   ├── entity-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text/\n",
      "│   │   ├── fasttext-subjective.json\n",
      "│   │   ├── fasttext-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text-char/\n",
      "│   │   ├── model.ckpt.data-00000-of-00001\n",
      "│   │   ├── model.ckpt.index\n",
      "│   │   ├── model.ckpt.meta\n",
      "│   │   ├── vectorizer-sparse-subjective.pkl\n",
      "│   │   └── version\n",
      "│   ├── hierarchical/\n",
      "│   │   ├── hierarchical-subjective.json\n",
      "│   │   ├── hierarchical-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── luong/\n",
      "│   │   ├── luong-subjective.json\n",
      "│   │   ├── luong-subjective.pb\n",
      "│   │   └── version\n",
      "│   ├── multinomial/\n",
      "│   │   ├── multinomial-subjective-tfidf.pkl\n",
      "│   │   ├── multinomial-subjective.pkl\n",
      "│   │   └── version\n",
      "│   └── xgb/\n",
      "│       ├── version\n",
      "│       ├── xgboost-subjective-tfidf.pkl\n",
      "│       └── xgboost-subjective.pkl\n",
      "├── summarize/\n",
      "│   ├── dictionary-summary.json\n",
      "│   ├── summary-news.json\n",
      "│   ├── summary-news.pb\n",
      "│   ├── summary-wiki.json\n",
      "│   ├── summary-wiki.pb\n",
      "│   └── summary_frozen_model.pb\n",
      "├── toxic/\n",
      "│   ├── bahdanau/\n",
      "│   │   ├── bahdanau-toxic.json\n",
      "│   │   ├── bahdanau-toxic.pb\n",
      "│   │   └── version\n",
      "│   ├── entity-network/\n",
      "│   │   ├── entity-toxic.json\n",
      "│   │   ├── entity-toxic.pb\n",
      "│   │   └── version\n",
      "│   ├── fast-text/\n",
      "│   │   ├── fasttext-toxic.json\n",
      "│   │   ├── fasttext-toxic.pb\n",
      "│   │   ├── fasttext-toxic.pkl\n",
      "│   │   └── version\n",
      "│   ├── hierarchical/\n",
      "│   │   ├── hierarchical-toxic.json\n",
      "│   │   ├── hierarchical-toxic.pb\n",
      "│   │   └── version\n",
      "│   ├── logistic/\n",
      "│   │   ├── logistics-toxic.pkl\n",
      "│   │   ├── vectorizer-toxic.pkl\n",
      "│   │   └── version\n",
      "│   ├── luong/\n",
      "│   │   ├── luong-toxic.json\n",
      "│   │   ├── luong-toxic.pb\n",
      "│   │   └── version\n",
      "│   └── multinomial/\n",
      "│       ├── multinomials-toxic.pkl\n",
      "│       ├── vectorizer-toxic.pkl\n",
      "│       └── version\n",
      "├── version\n",
      "├── word2vec-128/\n",
      "├── word2vec-256/\n",
      "│   └── word2vec.p\n",
      "├── word2vec-256.p\n",
      "└── word2vec-wiki/\n",
      "    └── word2vec.p\n"
     ]
    }
   ],
   "source": [
    "malaya.print_cache()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deleting specific model\n",
    "\n",
    "Let say you want to clear some spaces, start from version 1.0, you can specifically choose which model you want to delete."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "malaya.clear_cache('word2vec-128')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What happen if a directory does not exist?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "Exception",
     "evalue": "folder not exist, please check path from malaya.print_cache()",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mException\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-5-715b00624659>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmalaya\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclear_cache\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'word2vec-300'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Documents/Malaya/malaya/__init__.py\u001b[0m in \u001b[0;36mclear_cache\u001b[0;34m(location)\u001b[0m\n\u001b[1;32m    109\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    110\u001b[0m         raise Exception(\n\u001b[0;32m--> 111\u001b[0;31m             \u001b[0;34m'folder not exist, please check path from malaya.print_cache()'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    112\u001b[0m         )\n\u001b[1;32m    113\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mException\u001b[0m: folder not exist, please check path from malaya.print_cache()"
     ]
    }
   ],
   "source": [
    "malaya.clear_cache('word2vec-300')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purge cache\n",
    "\n",
    "You can simply delete all models, totally purge it. By simply,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function malaya.clear_all_cache()>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "malaya.clear_all_cache"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I am not gonna to run it, because I prefer to keep it for now?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
