{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "511f4200",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "56c7e158",
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_learning_rate(file):\n",
    "    lines = open(file, \"r\").readlines()\n",
    "    epochs = []\n",
    "    lrs = []\n",
    "    for line in lines:\n",
    "        if \"learning_rate\" in line and \"epoch\" in line:\n",
    "            re = eval(line.strip())\n",
    "            lr = re[\"learning_rate\"]\n",
    "            epoch = re[\"epoch\"]\n",
    "            epochs.append(epoch)\n",
    "            lrs.append(lr)\n",
    "    return lrs, epochs\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2ca412c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "task=\"copa\"\n",
    "dis_res = []\n",
    "model=\"roberta-base\"\n",
    "model_task = \"copa-retrieval0.15\"\n",
    "span_rep_strategy=\"start_end\"\n",
    "\n",
    "base_dir=f\"/n/fs/nlp-mengzhou/space3/out/hf/train/useful-legacy/dis/{model}/{model_task}/{span_rep_strategy}\"\n",
    "epochs, lrs = load_learning_rate(os.path.join(base_dir, \"log.out\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "187c1155",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f15bce47",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7fdbe2fdf490>]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 13300 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(lrs, epochs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6433647",
   "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.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
