<commit_before>{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Graph_regularization_for_Twitter_rumour_veracity_classification_using_natural_graphs.ipynb",
      "provenance": [],
      "private_outputs": true,
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ktxosp9yG6ci",
        "colab_type": "text"
      },
      "source": [
        "##### Copyright 2020 Google LLC\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oSo7RZo4WjRs",
        "colab_type": "code",
        "cellView": "form",
        "colab": {}
      },
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "#     https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wCliuvuHPi0W",
        "colab_type": "text"
      },
      "source": [
        "# Graph regularization for Twitter rumour veracity classification using natural graphs\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Sy4yBd23A_AN",
        "colab_type": "text"
      },
      "source": [
        "## Overview\n",
        "\n",
        "This tutorial uses the PHEME dataset for veracity classification of Twitter rumours, a binary classification task.\n",
        "\n",
        "Tweet texts are used as input for computing embeddings, e.g. with ALBERT. Those representations are then used as features for the baseline MLP classification model, as well as for the graph regularized version, which uses the structure defined by the tweet replies as a natural graph."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "a6jJnC6JvaOt",
        "colab_type": "text"
      },
      "source": [
        "## Install and import dependencies"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9pYjAVnf5j6s",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install --quiet neural-structured-learning\n",
        "!pip install --quiet transformers\n",
        "!pip install --quiet tokenizers"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mZN6xDms5tEu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import os\n",
        "import json\n",
        "import random\n",
        "import pprint\n",
        "\n",
        "import numpy as np\n",
        "\n",
        "import neural_structured_learning as nsl\n",
        "\n",
        "import tensorflow as tf\n",
        "import tensorflow_datasets as tfds\n",
        "\n",
        "from tokenizers import BertWordPieceTokenizer\n",
        "\n",
        "from transformers import BertConfig\n",
        "from transformers import BertTokenizer, TFBertModel\n",
        "from transformers import XLNetTokenizer, TFXLNetModel\n",
        "from transformers import RobertaTokenizer, TFRobertaModel\n",
        "from transformers import AlbertTokenizer, TFAlbertModel\n",
        "from transformers import T5Tokenizer, TFT5Model\n",
        "from transformers import ElectraTokenizer, TFElectraModel\n",
        "\n",
        "# Resets notebook state\n",
        "tf.keras.backend.clear_session()\n",
        "\n",
        "print(\"Version: \", tf.__version__)\n",
        "print(\"Eager mode: \", tf.executing_eagerly())\n",
        "print(\n",
        "    \"GPU is\",\n",
        "    \"available\" if tf.config.list_physical_devices(\"GPU\") else \"NOT AVAILABLE\")"<commit_msg>Install and import SentencePiece<commit_after>{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Graph_regularization_for_Twitter_rumour_veracity_classification_using_natural_graphs.ipynb",
      "provenance": [],
      "private_outputs": true,
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Ktxosp9yG6ci",
        "colab_type": "text"
      },
      "source": [
        "##### Copyright 2021 Google LLC\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oSo7RZo4WjRs",
        "colab_type": "code",
        "cellView": "form",
        "colab": {}
      },
      "source": [
        "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "#     https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wCliuvuHPi0W",
        "colab_type": "text"
      },
      "source": [
        "# Graph regularization for Twitter rumour veracity classification using natural graphs\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Sy4yBd23A_AN",
        "colab_type": "text"
      },
      "source": [
        "## Overview\n",
        "\n",
        "This tutorial uses the PHEME dataset for veracity classification of Twitter rumours, a binary classification task.\n",
        "\n",
        "Tweet texts are used as input for computing embeddings, e.g. with ALBERT. Those representations are then used as features for the baseline MLP classification model, as well as for the graph regularized version, which uses the structure defined by the tweet replies as a natural graph."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "a6jJnC6JvaOt",
        "colab_type": "text"
      },
      "source": [
        "## Install and import dependencies"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9pYjAVnf5j6s",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install --quiet neural-structured-learning\n",
        "!pip install --quiet transformers\n",
        "!pip install --quiet tokenizers\n",
        "!pip install --quiet sentencepiece"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mZN6xDms5tEu",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import os\n",
        "import json\n",
        "import random\n",
        "import pprint\n",
        "\n",
        "import numpy as np\n",
        "\n",
        "import neural_structured_learning as nsl\n",
        "\n",
        "import tensorflow as tf\n",
        "import tensorflow_datasets as tfds\n",
        "\n",
        "import sentencepiece\n",
        "\n",
        "from tokenizers import BertWordPieceTokenizer\n",
        "\n",
        "from transformers import BertConfig\n",
        "from transformers import BertTokenizer, TFBertModel\n",
        "from transformers import XLNetTokenizer, TFXLNetModel\n",
        "from transformers import RobertaTokenizer, TFRobertaModel\n",
        "from transformers import AlbertTokenizer, TFAlbertModel\n",
        "from transformers import T5Tokenizer, TFT5Model\n",
        "from transformers import ElectraTokenizer, TFElectraModel\n",
        "\n",
        "# Resets notebook state\n",
        "tf.keras.backend.clear_session()\n",
        "\n",
        "print(\"Version: \", tf.__version__)\n",
        "print(\"Eager mode: \", tf.executing_eagerly())\n",
        "print(\n",
        "    \"GPU is\",\n",
        "    \"available\" if tf.config.list_physical_devices(\"GPU\") else \"NOT AVAILABLE\")"
{'fraction_non_alphanumeric': 0.14745367802063686, 'fraction_numerical': 0.006435149228891601, 'mean_word_length': 2.0493910690121786, 'pattern_counts': {'":': 110, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1218559', 'n_tokens_mistral': 2863, 'n_tokens_neox': 2799, 'n_words': 715}