File size: 3,510 Bytes
d08dd00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "finetuning.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "duPhpC7UYvOb",
        "colab_type": "text"
      },
      "source": [
        "#**Setup**\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "08KZUbQnhKwE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "\n",
        "!git clone https://github.com/ai4bharat/indic-bert\n",
        "%cd indic-bert\n",
        "!pip3 install -r requirements.txt\n",
        "%cd ..\n",
        "!mkdir indic-glue outputs"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "u4TbQgpAYrSL",
        "colab_type": "text"
      },
      "source": [
        "#**Download Datasets**\n",
        "---\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "B8Te43TtV9OV",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "\n",
        "% cd indic-glue\n",
        "# Download the dataset -- insert link obtained from https://indicnlp.ai4bharat.org/indic-glue/#downloads\n",
        "!wget https://storage.googleapis.com/ai4bharat-public-indic-nlp-corpora/evaluations/wiki-cloze.tar.gz\n",
        "!tar -xaf wiki-cloze.tar.gz\n",
        "% cd ..\n"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cAs6r-QSUosR",
        "colab_type": "text"
      },
      "source": [
        "#**Fine-tune the Model**\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vUCIjREpQFhv",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "\n",
        "%cd indic-bert\n",
        "\n",
        "import os\n",
        "\n",
        "from fine_tune.cli import main as finetune_main\n",
        "\n",
        "argvec = ['--lang', 'gu',\n",
        "          '--dataset', 'wiki-cloze', # use the right dataset key, check https://github.com/AI4Bharat/indic-bert/blob/master/fine_tune/cli.py#L10\n",
        "          '--model', 'ai4bharat/indic-bert',\n",
        "          '--iglue_dir', '../indic-glue',\n",
        "          '--output_dir', '../outputs',\n",
        "          '--max_seq_length', '128',\n",
        "          '--learning_rate', '2e-5',\n",
        "          '--num_train_epochs', '3',\n",
        "          '--train_batch_size', '32'\n",
        "]\n",
        "\n",
        "finetune_main(argvec)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zUh3Vw7SUwMW",
        "colab_type": "text"
      },
      "source": [
        "#**Check the Results**\n",
        "---"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ic0Qpfl-U0Xw",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!cat /content/outputs/wiki-cloze/gu-gu/model-ai4bharat-indic-bert/test_results.txt"
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}