{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fine-tune SciBERT\n", "\n", "We are planning to do a simple classification task on scientific text. For that, [SciBERT](https://github.com/allenai/scibert) is an ideal model to fine-tune since it has been pretrained of academic publications.\n", "\n", "This notebook was updated so that it can run in [Google Colab](https://colab.research.google.com/).\n", "\n", "First, we need to install the dependencies." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "executionInfo": { "elapsed": 2529, "status": "ok", "timestamp": 1656596749103, "user_tz": -120 }, "id": "j7l0nD9hDQbB", "outputId": "88a9931b-396a-4cf1-c659-8a7b098b3cdd" }, "outputs": [], "source": [ "!pip install transformers datasets great-ai > /dev/null" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the training data from S3. (We have uploaded this to S3 in the `data` notebook.)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[38;5;39mLatest version of summary-train-dataset-small is 0 (from versions: 0)\u001b[0m\n", "\u001b[38;5;39mFile summary-train-dataset-small-0 found in cache\u001b[0m\n" ] } ], "source": [ "from great_ai.large_file import LargeFileS3\n", "import json\n", "\n", "LargeFileS3.configure_credentials_from_file(\"config.ini\")\n", "\n", "with LargeFileS3(\"summary-train-dataset-small\", encoding=\"utf-8\") as f:\n", " # splitting training and test data is done later by `datasets`\n", " X, y = json.load(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finetune SciBERT, for more info about this step, check out [HuggingFace](https://huggingface.co/docs/transformers/training).\n", "If you're only here for `great-ai`, feel free to skip the next cell." ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "executionInfo": { "elapsed": 118131, "status": "ok", "timestamp": 1656593941974, "user_tz": -120 }, "id": "AL3etUQ3LtKN", "outputId": "fe00589f-64dd-4b70-e612-3873b504c00a" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9c57de70e68a41ecbde5093bd671715a", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1 [00:00, ?ba/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
| Epoch | \n", "Training Loss | \n", "Validation Loss | \n", "F1 | \n", "
|---|---|---|---|
| 1 | \n", "0.586800 | \n", "0.512138 | \n", "0.719101 | \n", "
| 2 | \n", "0.411600 | \n", "0.416675 | \n", "0.849057 | \n", "
| 3 | \n", "0.245600 | \n", "0.417070 | \n", "0.864000 | \n", "
| 4 | \n", "0.147800 | \n", "0.575878 | \n", "0.852459 | \n", "
| 5 | \n", "0.056800 | \n", "0.474259 | \n", "0.896552 | \n", "
| 6 | \n", "0.022500 | \n", "0.754236 | \n", "0.843137 | \n", "
| 7 | \n", "0.001000 | \n", "0.857636 | \n", "0.834783 | \n", "
| 8 | \n", "0.000500 | \n", "0.920232 | \n", "0.869565 | \n", "
| 9 | \n", "0.000300 | \n", "0.970790 | \n", "0.877193 | \n", "
| 10 | \n", "0.000300 | \n", "0.948689 | \n", "0.862385 | \n", "
"
],
"text/plain": [
"