{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":75254,"databundleVersionId":8467119,"sourceType":"competition"}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import torch\nif torch.cuda.is_available():\n# GPU enabled\n    !pip install  dgl==1.1.3 -f https://data.dgl.ai/wheels/cu121/repo.html\n    !pip install  dglgo -f https://data.dgl.ai/wheels-test/repo.html\nelse:\n# just use CPU\n    !pip install  dgl -f https://data.dgl.ai/wheels/repo.html\n    !pip install  dglgo -f https://data.dgl.ai/wheels-test/repo.html","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-06-12T07:14:21.193931Z","iopub.execute_input":"2024-06-12T07:14:21.194627Z","iopub.status.idle":"2024-06-12T07:14:45.979091Z","shell.execute_reply.started":"2024-06-12T07:14:21.194584Z","shell.execute_reply":"2024-06-12T07:14:45.977873Z"},"trusted":true},"execution_count":22,"outputs":[{"name":"stdout","text":"Looking in links: https://data.dgl.ai/wheels/cu121/repo.html\nRequirement already satisfied: dgl==1.1.3 in /opt/conda/lib/python3.10/site-packages (1.1.3+cu121)\nRequirement already satisfied: numpy>=1.14.0 in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (1.26.4)\nRequirement already satisfied: scipy>=1.1.0 in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (1.11.4)\nRequirement already satisfied: networkx>=2.1 in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (3.2.1)\nRequirement already satisfied: requests>=2.19.0 in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (2.31.0)\nRequirement already satisfied: tqdm in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (4.66.1)\nRequirement already satisfied: psutil>=5.8.0 in /opt/conda/lib/python3.10/site-packages (from dgl==1.1.3) (5.9.3)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests>=2.19.0->dgl==1.1.3) (3.3.2)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests>=2.19.0->dgl==1.1.3) (3.6)\nRequirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests>=2.19.0->dgl==1.1.3) (1.26.18)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests>=2.19.0->dgl==1.1.3) (2024.2.2)\nLooking in links: https://data.dgl.ai/wheels-test/repo.html\nRequirement already satisfied: dglgo in /opt/conda/lib/python3.10/site-packages (0.0.2)\nRequirement already satisfied: typer>=0.4.0 in /opt/conda/lib/python3.10/site-packages (from dglgo) (0.9.0)\nRequirement already satisfied: isort>=5.10.1 in /opt/conda/lib/python3.10/site-packages (from dglgo) (5.13.2)\nRequirement already satisfied: autopep8>=1.6.0 in /opt/conda/lib/python3.10/site-packages (from dglgo) (2.0.4)\nRequirement already satisfied: numpydoc>=1.1.0 in /opt/conda/lib/python3.10/site-packages (from dglgo) (1.7.0)\nRequirement already satisfied: pydantic>=1.9.0 in /opt/conda/lib/python3.10/site-packages (from dglgo) (2.5.3)\nRequirement already satisfied: ruamel.yaml>=0.17.20 in /opt/conda/lib/python3.10/site-packages (from dglgo) (0.17.40)\nRequirement already satisfied: PyYAML>=5.1 in /opt/conda/lib/python3.10/site-packages (from dglgo) (6.0.1)\nRequirement already satisfied: ogb>=1.3.3 in /opt/conda/lib/python3.10/site-packages (from dglgo) (1.3.6)\nRequirement already satisfied: rdkit-pypi in /opt/conda/lib/python3.10/site-packages (from dglgo) (2022.9.5)\nRequirement already satisfied: scikit-learn>=0.20.0 in /opt/conda/lib/python3.10/site-packages (from dglgo) (1.2.2)\nRequirement already satisfied: pycodestyle>=2.10.0 in /opt/conda/lib/python3.10/site-packages (from autopep8>=1.6.0->dglgo) (2.11.1)\nRequirement already satisfied: tomli in /opt/conda/lib/python3.10/site-packages (from autopep8>=1.6.0->dglgo) (2.0.1)\nRequirement already satisfied: sphinx>=6 in /opt/conda/lib/python3.10/site-packages (from numpydoc>=1.1.0->dglgo) (7.3.7)\nRequirement already satisfied: tabulate>=0.8.10 in /opt/conda/lib/python3.10/site-packages (from numpydoc>=1.1.0->dglgo) (0.9.0)\nRequirement already satisfied: torch>=1.6.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (2.1.2)\nRequirement already satisfied: numpy>=1.16.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (1.26.4)\nRequirement already satisfied: tqdm>=4.29.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (4.66.1)\nRequirement already satisfied: pandas>=0.24.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (2.1.4)\nRequirement already satisfied: six>=1.12.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (1.16.0)\nRequirement already satisfied: urllib3>=1.24.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (1.26.18)\nRequirement already satisfied: outdated>=0.2.0 in /opt/conda/lib/python3.10/site-packages (from ogb>=1.3.3->dglgo) (0.2.2)\nRequirement already satisfied: annotated-types>=0.4.0 in /opt/conda/lib/python3.10/site-packages (from pydantic>=1.9.0->dglgo) (0.6.0)\nRequirement already satisfied: pydantic-core==2.14.6 in /opt/conda/lib/python3.10/site-packages (from pydantic>=1.9.0->dglgo) (2.14.6)\nRequirement already satisfied: typing-extensions>=4.6.1 in /opt/conda/lib/python3.10/site-packages (from pydantic>=1.9.0->dglgo) (4.9.0)\nRequirement already satisfied: ruamel.yaml.clib>=0.2.7 in /opt/conda/lib/python3.10/site-packages (from ruamel.yaml>=0.17.20->dglgo) (0.2.7)\nRequirement already satisfied: scipy>=1.3.2 in /opt/conda/lib/python3.10/site-packages (from scikit-learn>=0.20.0->dglgo) (1.11.4)\nRequirement already satisfied: joblib>=1.1.1 in /opt/conda/lib/python3.10/site-packages (from scikit-learn>=0.20.0->dglgo) (1.4.0)\nRequirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit-learn>=0.20.0->dglgo) (3.2.0)\nRequirement already satisfied: click<9.0.0,>=7.1.1 in /opt/conda/lib/python3.10/site-packages (from typer>=0.4.0->dglgo) (8.1.7)\nRequirement already satisfied: Pillow in /opt/conda/lib/python3.10/site-packages (from rdkit-pypi->dglgo) (9.5.0)\nRequirement already satisfied: setuptools>=44 in /opt/conda/lib/python3.10/site-packages (from outdated>=0.2.0->ogb>=1.3.3->dglgo) (69.0.3)\nRequirement already satisfied: littleutils in /opt/conda/lib/python3.10/site-packages (from outdated>=0.2.0->ogb>=1.3.3->dglgo) (0.2.2)\nRequirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from outdated>=0.2.0->ogb>=1.3.3->dglgo) (2.31.0)\nRequirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.24.0->ogb>=1.3.3->dglgo) (2.9.0.post0)\nRequirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.24.0->ogb>=1.3.3->dglgo) (2023.3.post1)\nRequirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas>=0.24.0->ogb>=1.3.3->dglgo) (2023.4)\nRequirement already satisfied: sphinxcontrib-applehelp in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.0.8)\nRequirement already satisfied: sphinxcontrib-devhelp in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.0.6)\nRequirement already satisfied: sphinxcontrib-jsmath in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.0.1)\nRequirement already satisfied: sphinxcontrib-htmlhelp>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (2.0.5)\nRequirement already satisfied: sphinxcontrib-serializinghtml>=1.1.9 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.1.10)\nRequirement already satisfied: sphinxcontrib-qthelp in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.0.7)\nRequirement already satisfied: Jinja2>=3.0 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (3.1.2)\nRequirement already satisfied: Pygments>=2.14 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (2.17.2)\nRequirement already satisfied: docutils<0.22,>=0.18.1 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (0.21.1)\nRequirement already satisfied: snowballstemmer>=2.0 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (2.2.0)\nRequirement already satisfied: babel>=2.9 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (2.14.0)\nRequirement already satisfied: alabaster~=0.7.14 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (0.7.16)\nRequirement already satisfied: imagesize>=1.3 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (1.4.1)\nRequirement already satisfied: packaging>=21.0 in /opt/conda/lib/python3.10/site-packages (from sphinx>=6->numpydoc>=1.1.0->dglgo) (21.3)\nRequirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from torch>=1.6.0->ogb>=1.3.3->dglgo) (3.13.1)\nRequirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from torch>=1.6.0->ogb>=1.3.3->dglgo) (1.12)\nRequirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from torch>=1.6.0->ogb>=1.3.3->dglgo) (3.2.1)\nRequirement already satisfied: fsspec in /opt/conda/lib/python3.10/site-packages (from torch>=1.6.0->ogb>=1.3.3->dglgo) (2024.2.0)\nRequirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from Jinja2>=3.0->sphinx>=6->numpydoc>=1.1.0->dglgo) (2.1.3)\nRequirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/lib/python3.10/site-packages (from packaging>=21.0->sphinx>=6->numpydoc>=1.1.0->dglgo) (3.1.1)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests->outdated>=0.2.0->ogb>=1.3.3->dglgo) (3.3.2)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests->outdated>=0.2.0->ogb>=1.3.3->dglgo) (3.6)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests->outdated>=0.2.0->ogb>=1.3.3->dglgo) (2024.2.2)\nRequirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->torch>=1.6.0->ogb>=1.3.3->dglgo) (1.3.0)\n","output_type":"stream"}]},{"cell_type":"code","source":"import dgl.nn as dglnn\nimport dgl.function as fn\nfrom dgl.nn.pytorch import MetaPath2Vec\nimport os\nimport random\nfrom numpy.linalg import norm\nimport time\nfrom sklearn.metrics import precision_recall_fscore_support\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.utils.data import DataLoader\nimport tqdm","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:45.981625Z","iopub.execute_input":"2024-06-12T07:14:45.981964Z","iopub.status.idle":"2024-06-12T07:14:45.988184Z","shell.execute_reply.started":"2024-06-12T07:14:45.981934Z","shell.execute_reply":"2024-06-12T07:14:45.987247Z"},"trusted":true},"execution_count":23,"outputs":[]},{"cell_type":"code","source":"import os\nimport pickle as pkl\nimport numpy as np\n\ndef read_txt(file):\n    res_list = list()\n    with open(file, \"r\") as f:\n        line_list = f.readlines()\n    for line in line_list:\n        res_list.append(list(map(int, line.strip().split(' '))))      \n    return res_list\n\nbase_path = \"/kaggle/input/cs3319-01-project-2-recommendation-2024-spring/\"\n\ncite_file = \"paper_file_ann.txt\"\ntrain_ref_file = \"bipartite_train_ann.txt\"\ntest_ref_file = \"bipartite_test_ann.txt\"\ncoauthor_file = \"author_file_ann.txt\"\nfeature_file = \"feature.pkl\"\n\ncitation = read_txt(os.path.join(base_path, cite_file))\nexisting_refs = read_txt(os.path.join(base_path, train_ref_file))\nrefs_to_pred = read_txt(os.path.join(base_path, test_ref_file))\ncoauthor = read_txt(os.path.join(base_path, coauthor_file))\n\nfeature_file = os.path.join(base_path, feature_file)\nwith open(feature_file, 'rb') as f:\n      paper_feature = pkl.load(f)\n        \n\n\nprint(\"Number of citation edges: {}\\n\\\nNumber of existing references: {}\\n\\\nNumber of author-paper pairs to predict: {}\\n\\\nNumber of coauthor edges: {}\\n\\\nShape of paper features: {}\"\n.format(len(citation), len(existing_refs), len(refs_to_pred), len(coauthor), paper_feature.shape))","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:45.989865Z","iopub.execute_input":"2024-06-12T07:14:45.990231Z","iopub.status.idle":"2024-06-12T07:14:53.458786Z","shell.execute_reply.started":"2024-06-12T07:14:45.990199Z","shell.execute_reply":"2024-06-12T07:14:53.457711Z"},"trusted":true},"execution_count":24,"outputs":[{"name":"stdout","text":"Number of citation edges: 327113\nNumber of existing references: 682421\nNumber of author-paper pairs to predict: 2047262\nNumber of coauthor edges: 9663\nShape of paper features: torch.Size([79937, 512])\n","output_type":"stream"}]},{"cell_type":"code","source":"import pandas as pd\n\ncite_edges = pd.DataFrame(citation, columns=['source', 'target'])\ncite_edges = cite_edges.set_index(\n    \"c-\" + cite_edges.index.astype(str)\n)\n\nref_edges = pd.DataFrame(existing_refs, columns=['source', 'target'])\nref_edges = ref_edges.set_index(\n    \"r-\" + ref_edges.index.astype(str)\n)\n\ncoauthor_edges = pd.DataFrame(coauthor, columns=['source', 'target'])\ncoauthor_edges = coauthor_edges.set_index(\n    \"a-\" + coauthor_edges.index.astype(str)\n)\n\ncite_edges.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:53.461445Z","iopub.execute_input":"2024-06-12T07:14:53.461835Z","iopub.status.idle":"2024-06-12T07:14:55.06263Z","shell.execute_reply.started":"2024-06-12T07:14:53.46178Z","shell.execute_reply":"2024-06-12T07:14:55.061723Z"},"trusted":true},"execution_count":25,"outputs":[{"execution_count":25,"output_type":"execute_result","data":{"text/plain":"     source  target\nc-0   30034   79854\nc-1   30034   24303\nc-2   30034   36597\nc-3   30034   50888\nc-4   30034   76676","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>source</th>\n      <th>target</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>c-0</th>\n      <td>30034</td>\n      <td>79854</td>\n    </tr>\n    <tr>\n      <th>c-1</th>\n      <td>30034</td>\n      <td>24303</td>\n    </tr>\n    <tr>\n      <th>c-2</th>\n      <td>30034</td>\n      <td>36597</td>\n    </tr>\n    <tr>\n      <th>c-3</th>\n      <td>30034</td>\n      <td>50888</td>\n    </tr>\n    <tr>\n      <th>c-4</th>\n      <td>30034</td>\n      <td>76676</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"node_tmp = pd.concat([cite_edges.loc[:, 'source'], cite_edges.loc[:, 'target'], ref_edges.loc[:, 'target']])\nnode_papers = pd.DataFrame(index=pd.unique(node_tmp))\n\nnode_tmp = pd.concat([ref_edges['source'], coauthor_edges['source'], coauthor_edges['target']])\nnode_authors = pd.DataFrame(index=pd.unique(node_tmp))\n\nprint(\"Number of paper nodes: {}, number of author nodes: {}\".format(len(node_papers), len(node_authors)))","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:55.06395Z","iopub.execute_input":"2024-06-12T07:14:55.064363Z","iopub.status.idle":"2024-06-12T07:14:55.133227Z","shell.execute_reply.started":"2024-06-12T07:14:55.064328Z","shell.execute_reply":"2024-06-12T07:14:55.132259Z"},"trusted":true},"execution_count":26,"outputs":[{"name":"stdout","text":"Number of paper nodes: 79937, number of author nodes: 6611\n","output_type":"stream"}]},{"cell_type":"code","source":"train_refs = ref_edges.sample(frac=0.9,random_state=0,axis=0)\ntest_true_refs = ref_edges[~ref_edges.index.isin(train_refs.index)]\ntest_true_refs.loc[:, 'label'] = 1\n\nfalse_source = node_authors.sample(frac=test_true_refs.shape[0]/node_authors.shape[0],random_state=0,replace=True,axis=0)\nfalse_target = node_papers.sample(frac=test_true_refs.shape[0]/node_papers.shape[0],random_state=0,replace=True,axis=0)\nfalse_source = false_source.reset_index()\nfalse_target = false_target.reset_index()\ntest_false_refs = pd.concat([false_source, false_target], axis=1)\ntest_false_refs.columns = ['source', 'target']\ntest_false_refs = test_false_refs[test_false_refs.isin(ref_edges) == False]\ntest_false_refs.loc[:, 'label'] = 0\n\ntest_refs = pd.concat([test_true_refs, test_false_refs.iloc[:min(len(false_source), len(false_target))]])\ntest_refs = test_refs.sample(frac=1,random_state=0,axis=0)\ntest_refs.head()","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:55.134546Z","iopub.execute_input":"2024-06-12T07:14:55.134935Z","iopub.status.idle":"2024-06-12T07:14:55.694605Z","shell.execute_reply.started":"2024-06-12T07:14:55.134901Z","shell.execute_reply":"2024-06-12T07:14:55.693611Z"},"trusted":true},"execution_count":27,"outputs":[{"name":"stderr","text":"/tmp/ipykernel_34/6502966.py:3: SettingWithCopyWarning: \nA value is trying to be set on a copy of a slice from a DataFrame.\nTry using .loc[row_indexer,col_indexer] = value instead\n\nSee the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n  test_true_refs.loc[:, 'label'] = 1\n","output_type":"stream"},{"execution_count":27,"output_type":"execute_result","data":{"text/plain":"          source  target  label\n40969       3331   76967      0\n59187        622   46736      0\nr-390239    2374   66499      1\nr-219724     476   18903      1\nr-510031    2559     629      1","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>source</th>\n      <th>target</th>\n      <th>label</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>40969</th>\n      <td>3331</td>\n      <td>76967</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>59187</th>\n      <td>622</td>\n      <td>46736</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>r-390239</th>\n      <td>2374</td>\n      <td>66499</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>r-219724</th>\n      <td>476</td>\n      <td>18903</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>r-510031</th>\n      <td>2559</td>\n      <td>629</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"def train_metapath(g, path, ntype):\n    print('Training metapath2vec as initial author feature...')\n    model = dglnn.MetaPath2Vec(g, path, window_size=3, emb_dim=512)\n    dataloader = DataLoader(torch.arange(g.num_nodes(ntype)), batch_size=1024,\n                        shuffle=True, collate_fn=model.sample)\n    optimizer = torch.optim.SparseAdam(model.parameters(), lr=0.025)\n    for epoch in range(10):\n        for (pos_u, pos_v, neg_v) in dataloader:\n            loss = model(pos_u, pos_v, neg_v)\n            optimizer.zero_grad()\n            loss.backward()\n            optimizer.step()\n    nids = torch.LongTensor(model.local_to_global_nid[ntype])\n    emb = model.node_embed(nids)\n    return emb","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:55.695986Z","iopub.execute_input":"2024-06-12T07:14:55.69636Z","iopub.status.idle":"2024-06-12T07:14:55.704404Z","shell.execute_reply.started":"2024-06-12T07:14:55.696327Z","shell.execute_reply":"2024-06-12T07:14:55.703448Z"},"trusted":true},"execution_count":28,"outputs":[]},{"cell_type":"code","source":"import dgl\n\nos.environ['DGLBACKEND'] = 'pytorch'\ndevice = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\ntrain_ref_tensor = torch.from_numpy(train_refs.values)\ncite_tensor = torch.from_numpy(cite_edges.values)\ncoauthor_tensor = torch.from_numpy(coauthor_edges.values)\nrel_list = [('author', 'ref', 'paper'), ('paper', 'cite', 'paper'), ('author', 'coauthor', 'author'), ('paper', 'beref', 'author')]\ngraph_data = {\n   rel_list[0]: (train_ref_tensor[:, 0], train_ref_tensor[:, 1]),\n   rel_list[1]: (torch.cat([cite_tensor[:, 0], cite_tensor[:, 1]]), torch.cat([cite_tensor[:, 1], cite_tensor[:, 0]])),\n   rel_list[2]: (torch.cat([coauthor_tensor[:, 0], coauthor_tensor[:, 1]]), torch.cat([coauthor_tensor[:, 1], coauthor_tensor[:, 0]])),\n   rel_list[3]: (train_ref_tensor[:, 1], train_ref_tensor[:, 0])\n}\nhetero_graph = dgl.heterograph(graph_data)\n\nauthor_feature = train_metapath(hetero_graph, ['ref', 'beref'], 'author').detach()\n\nnode_features = {'author': author_feature, 'paper': paper_feature}\nhetero_graph.ndata['features'] = node_features\nhetero_graph = hetero_graph.to(device)\nhetero_graph","metadata":{"execution":{"iopub.status.busy":"2024-06-12T07:14:55.705584Z","iopub.execute_input":"2024-06-12T07:14:55.705901Z","iopub.status.idle":"2024-06-12T07:15:17.901189Z","shell.execute_reply.started":"2024-06-12T07:14:55.705867Z","shell.execute_reply":"2024-06-12T07:15:17.900263Z"},"trusted":true},"execution_count":29,"outputs":[{"name":"stdout","text":"Training metapath2vec as initial author feature...\n","output_type":"stream"},{"name":"stderr","text":"100%|██████████| 6611/6611 [00:03<00:00, 1836.34it/s]\n","output_type":"stream"},{"execution_count":29,"output_type":"execute_result","data":{"text/plain":"Graph(num_nodes={'author': 6611, 'paper': 79937},\n      num_edges={('author', 'coauthor', 'author'): 19326, ('author', 'ref', 'paper'): 614179, ('paper', 'beref', 'author'): 614179, ('paper', 'cite', 'paper'): 654226},\n      metagraph=[('author', 'author', 'coauthor'), ('author', 'paper', 'ref'), ('paper', 'author', 'beref'), ('paper', 'paper', 'cite')])"},"metadata":{}}]},{"cell_type":"code","source":"class RGCN(nn.Module):\n    def __init__(self, in_feats, hid_feats, out_feats, rel_names):\n        super().__init__()\n        self.hid_feats = hid_feats\n        self.out_feats = out_feats\n        self.convs = nn.ModuleList()\n        self.bns = nn.ModuleList()\n        self.bns2 = nn.ModuleList()\n        self.layernum = len(hid_feats)+1\n\n        self.convs.append(dglnn.HeteroGraphConv({\n            rel : dglnn.GATConv(in_feats, hid_feats[0] // 8, 8, attn_drop=0.3, residual = True)\n            for rel in rel_names}, aggregate='mean'))\n        self.bns.append(nn.BatchNorm1d(hid_feats[0]))\n        self.bns2.append(nn.BatchNorm1d(hid_feats[0]))\n\n        for i in range(1, self.layernum-1):\n            self.convs.append(dglnn.HeteroGraphConv({\n                rel: dglnn.GATConv(hid_feats[i-1], hid_feats[i] // 4, 4)\n                for rel in rel_names}, aggregate='mean'))\n            self.bns.append(nn.BatchNorm1d(hid_feats[i]))\n            self.bns2.append(nn.BatchNorm1d(hid_feats[i]))\n       \n        self.convs.append(dglnn.HeteroGraphConv({\n            rel: dglnn.GATConv(hid_feats[self.layernum-2], out_feats // 2, 2)\n            for rel in rel_names}, aggregate='mean'))\n\n    def forward(self, blocks, x):\n        rel_list = list(x.keys())\n        for i in range(self.layernum-2):\n            x = self.convs[i](blocks[i],x)\n            # x = {k: v.view(-1, self.hid_feats[i]) for k, v in x.items()}\n            # x = {k: self.bns[i](v) for k, v in x.items()}\n            # x = {k: F.leaky_relu(v) for k, v in x.items()}\n            x[rel_list[0]] = F.elu(self.bns[i](x[rel_list[0]].view(-1, self.hid_feats[i])))\n            x[rel_list[1]] = F.elu(self.bns2[i](x[rel_list[1]].view(-1, self.hid_feats[i])))\n\n        x = self.convs[self.layernum-2](blocks[self.layernum-2], x)\n        # x = {k: v.view(-1, self.hid_feats[self.layernum-2]) for k, v in x.items()}\n        # x = {k: self.bns[self.layernum-2](v) for k, v in x.items()}\n        # x = {k: F.tanh(v) for k, v in x.items()}\n        x[rel_list[0]] = F.tanh(self.bns[self.layernum-2](x[rel_list[0]].view(-1, self.hid_feats[self.layernum-2])))\n        x[rel_list[1]] = F.tanh(self.bns2[self.layernum-2](x[rel_list[1]].view(-1, self.hid_feats[self.layernum-2])))\n\n        x = self.convs[self.layernum-1](blocks[self.layernum-1], x)\n        x = {k: ((v.view(-1, self.out_feats))) for k, v in x.items()}\n        return x\n\nclass ScorePredictor(nn.Module):\n    def forward(self, edge_subgraph, h):\n        with edge_subgraph.local_scope():\n            edge_subgraph.ndata['h'] = h\n            for etype in edge_subgraph.canonical_etypes:\n                edge_subgraph.apply_edges(fn.u_dot_v('h', 'h', 'score'), etype=etype)\n            return edge_subgraph.edata['score']\n\nclass Model(nn.Module):\n    def __init__(self, in_features, hidden_features, out_features, etypes):\n        super().__init__()\n        self.rgcn = RGCN(\n            in_features, hidden_features, out_features, etypes)\n        self.pred = ScorePredictor()\n\n    def forward(self, positive_graph, negative_graph, blocks, x):\n        x = self.rgcn(blocks, x)\n        pos_score = self.pred(positive_graph, x)\n        neg_score = self.pred(negative_graph, x)\n        return pos_score, neg_score\n\ndef compute_loss(pos_score, neg_score, etype):\n    n_edges = pos_score[etype].shape[0]\n    return (1 - pos_score[etype].unsqueeze(1) + neg_score[etype].view(n_edges, -1)).clamp(min=0).mean()\n\ndef cos_sim(a, b):\n    cos_sim = np.sum(a * b, axis = 1) / (norm(a, axis = 1) * norm(b, axis = 1))\n    return cos_sim\n\n\ndef train(parameters, hetero_graph, test_refs, rel_list, device):\n    train_eid_dict = {\n        etype: hetero_graph.edges(etype=etype, form='eid')\n        for etype in hetero_graph.etypes}\n    sampler = dgl.dataloading.NeighborSampler([4] * (len(parameters['h_dim'])+1))\n    sampler = dgl.dataloading.as_edge_prediction_sampler(\n        sampler, negative_sampler=dgl.dataloading.negative_sampler.GlobalUniform(4))\n    dataloader = dgl.dataloading.DataLoader(\n        hetero_graph,                                 \n        train_eid_dict,  \n        sampler,                              \n        device=device,                          \n        batch_size=parameters['batch_size'],    \n        shuffle=True,       \n        drop_last=False,    \n        num_workers=0,     \n    )\n    num_epochs = parameters['num_epochs']\n    model = Model(parameters['in_dim'], parameters['h_dim'], parameters['out_dim'], rel_list).to(device)\n    opt = torch.optim.Adam(model.parameters(), lr=parameters['lr'], weight_decay=4e-4)\n    lr_sche = torch.optim.lr_scheduler.CosineAnnealingLR(opt, T_max=10, eta_min=1e-5)\n\n    best_f1 = 0\n    best_thresh = None\n    best_embed = None\n\n    for epoch in range(num_epochs):\n        model.train()\n        t1 = time.time()\n        with tqdm.tqdm(dataloader) as tq:\n            for step, (input_nodes, positive_graph, negative_graph, blocks) in enumerate(tq):\n                input_features = blocks[0].srcdata['features']\n                pos_score, neg_score = model(positive_graph, negative_graph, blocks, input_features)\n                loss = compute_loss(pos_score, neg_score, rel_list[-1])\n                opt.zero_grad()\n                loss.backward()\n                opt.step()\n                tq.set_description(\"Epoch {}\".format(epoch + 1))\n                tq.set_postfix({'loss': '%.03f' % loss.item()}, refresh=False)\n        lr_sche.step()\n        model.eval()\n        with torch.no_grad():\n            blocks = [dgl.to_block(hetero_graph) for _ in range(len(parameters['h_dim'])+1)]\n            node_embeddings = model.rgcn(blocks, hetero_graph.ndata['features'])\n        node_embeddings = {k: v.to('cpu') for k, v in node_embeddings.items()}\n\n        test_arr = np.array(test_refs.values)\n        res = cos_sim(np.array(node_embeddings['author'][test_arr[:, 0]]), np.array(node_embeddings['paper'][test_arr[:, 1]]))\n\n        lbl_true = test_refs.label.to_numpy()\n        lbl_true = lbl_true.flatten()\n        lbl_pred = np.array(res)\n        median = np.median(lbl_pred)\n\n        cur_best_f1 = 0\n        for i in range (-50, 50):\n            threshold = best_thresh + 0.001 * i if best_thresh is not None else median + 0.001 * i\n            lbl_pred_copy = lbl_pred.copy()\n            lbl_pred_copy[lbl_pred >= threshold] = 1\n            lbl_pred_copy[lbl_pred < threshold] = 0\n            precision, recall, f1, _ = precision_recall_fscore_support(lbl_true, lbl_pred_copy, average='binary')\n            if f1 > cur_best_f1:\n                cur_pr = precision\n                cur_re = recall\n                cur_best_f1 = f1\n                cur_best_thresh = threshold\n                cur_best_i = i\n                acc = (lbl_true == lbl_pred_copy).mean()\n        if cur_best_f1 > best_f1:\n            print('NEW BEST PREDICTION!')\n            best_f1 = cur_best_f1\n            best_embed = node_embeddings\n            best_thresh = cur_best_thresh\n        \n        t2 = time.time()\n        print(f\"acc:{acc:.4f}, precision:{cur_pr:.4f}, recall:{cur_re:.4f}, F1-Score: {cur_best_f1:.5f}, best: {best_f1:.5f}, time: {(t2-t1):.2f}s\")\n    return best_embed, best_thresh, best_f1\n\n\ndef csv_result(best_embed, refs_to_pred, threshold, test_f1):\n    test_arr = np.array(refs_to_pred)\n    res = cos_sim(np.array(best_embed['author'][test_arr[:, 0]]), np.array(best_embed['paper'][test_arr[:, 1]]))\n    res[res >= threshold] = 1\n    res[res < threshold] = 0\n    data = []\n    for index, p in enumerate(list(res)):\n        tp = [index, str(int(p))]\n        data.append(tp)\n    if not os.path.exists('csv_result'):\n        os.makedirs('csv_result')\n    df = pd.DataFrame(data, columns=[\"Index\", \"Predicted\"], dtype=object)\n    df.to_csv(f'csv_result/csv_result~{test_f1:.5f}.csv', index=False)\n\n\nparameters = {  \n    'num_epochs': 50,  \n    'batch_size':10000,\n    'in_dim':512,\n    'h_dim':[512,512,256,256],\n    'out_dim':128,\n    'lr': 2e-4,  \n}  \nbest_embed, best_thresh, best_f1 = train(parameters, hetero_graph, test_refs, rel_list, device)\nprint(best_embed['author'].shape, best_embed['paper'].shape)\ncsv_result(best_embed, refs_to_pred, best_thresh, best_f1)","metadata":{"execution":{"iopub.status.busy":"2024-06-12T10:34:36.482529Z","iopub.execute_input":"2024-06-12T10:34:36.482972Z","iopub.status.idle":"2024-06-12T12:30:43.983835Z","shell.execute_reply.started":"2024-06-12T10:34:36.482936Z","shell.execute_reply":"2024-06-12T12:30:43.98302Z"},"trusted":true},"execution_count":34,"outputs":[{"name":"stderr","text":"Epoch 1: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.116]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9023, precision:0.8875, recall:0.9215, F1-Score: 0.90416, best: 0.90416, time: 138.69s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 2: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.080]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9042, precision:0.9048, recall:0.9034, F1-Score: 0.90411, best: 0.90416, time: 138.78s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 3: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.046]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9062, precision:0.8729, recall:0.9509, F1-Score: 0.91022, best: 0.91022, time: 138.75s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 4: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.049]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9070, precision:0.8725, recall:0.9534, F1-Score: 0.91113, best: 0.91113, time: 138.76s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 5: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.046]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9154, precision:0.8903, recall:0.9476, F1-Score: 0.91805, best: 0.91805, time: 138.83s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 6: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.044]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9178, precision:0.8978, recall:0.9430, F1-Score: 0.91986, best: 0.91986, time: 139.05s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 7: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.039]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9226, precision:0.9054, recall:0.9438, F1-Score: 0.92421, best: 0.92421, time: 139.34s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 8: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.038]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9217, precision:0.9062, recall:0.9408, F1-Score: 0.92317, best: 0.92421, time: 139.31s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 9: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.035]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9234, precision:0.9090, recall:0.9410, F1-Score: 0.92473, best: 0.92473, time: 139.36s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 10: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.045]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9235, precision:0.9098, recall:0.9402, F1-Score: 0.92473, best: 0.92473, time: 139.34s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 11: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.037]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9235, precision:0.9108, recall:0.9390, F1-Score: 0.92470, best: 0.92473, time: 139.30s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 12: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.043]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9234, precision:0.9100, recall:0.9397, F1-Score: 0.92463, best: 0.92473, time: 139.31s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 13: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.032]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9246, precision:0.9115, recall:0.9404, F1-Score: 0.92574, best: 0.92574, time: 139.26s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 14: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.034]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9258, precision:0.9139, recall:0.9402, F1-Score: 0.92687, best: 0.92687, time: 139.45s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 15: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.044]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9266, precision:0.9156, recall:0.9398, F1-Score: 0.92754, best: 0.92754, time: 139.34s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 16: 100%|██████████| 191/191 [02:17<00:00,  1.38it/s, loss=0.039]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9294, precision:0.9199, recall:0.9408, F1-Score: 0.93022, best: 0.93022, time: 139.91s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 17: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.029]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9320, precision:0.9283, recall:0.9364, F1-Score: 0.93233, best: 0.93233, time: 139.24s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 18: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.031]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9309, precision:0.9233, recall:0.9400, F1-Score: 0.93156, best: 0.93233, time: 139.27s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 19: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.032]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9335, precision:0.9293, recall:0.9384, F1-Score: 0.93380, best: 0.93380, time: 139.13s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 20: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.036]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9342, precision:0.9311, recall:0.9378, F1-Score: 0.93441, best: 0.93441, time: 139.19s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 21: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.027]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9359, precision:0.9317, recall:0.9409, F1-Score: 0.93626, best: 0.93626, time: 138.67s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 22: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.032]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9365, precision:0.9291, recall:0.9451, F1-Score: 0.93703, best: 0.93703, time: 138.65s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 23: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.021]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9382, precision:0.9345, recall:0.9424, F1-Score: 0.93843, best: 0.93843, time: 138.64s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 24: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.024]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9372, precision:0.9351, recall:0.9397, F1-Score: 0.93739, best: 0.93843, time: 138.74s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 25: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.032]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9393, precision:0.9346, recall:0.9447, F1-Score: 0.93963, best: 0.93963, time: 138.66s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 26: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.021]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9409, precision:0.9370, recall:0.9455, F1-Score: 0.94119, best: 0.94119, time: 139.11s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 27: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.022]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9401, precision:0.9367, recall:0.9440, F1-Score: 0.94033, best: 0.94119, time: 138.82s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 28: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.025]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9414, precision:0.9357, recall:0.9480, F1-Score: 0.94178, best: 0.94178, time: 138.66s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 29: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.027]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9424, precision:0.9384, recall:0.9471, F1-Score: 0.94270, best: 0.94270, time: 138.71s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 30: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.018]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9422, precision:0.9375, recall:0.9476, F1-Score: 0.94254, best: 0.94270, time: 139.09s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 31: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.017]\n","output_type":"stream"},{"name":"stdout","text":"NEW BEST PREDICTION!\nacc:0.9433, precision:0.9410, recall:0.9459, F1-Score: 0.94343, best: 0.94343, time: 138.71s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 32: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.020]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9431, precision:0.9396, recall:0.9470, F1-Score: 0.94331, best: 0.94343, time: 139.11s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 33: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.022]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9429, precision:0.9417, recall:0.9443, F1-Score: 0.94301, best: 0.94343, time: 139.41s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 34: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.020]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9417, precision:0.9340, recall:0.9505, F1-Score: 0.94217, best: 0.94343, time: 139.44s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 35: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.025]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9426, precision:0.9362, recall:0.9500, F1-Score: 0.94305, best: 0.94343, time: 139.43s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 36: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.021]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9414, precision:0.9388, recall:0.9444, F1-Score: 0.94160, best: 0.94343, time: 139.45s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 37: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.024]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9406, precision:0.9356, recall:0.9465, F1-Score: 0.94099, best: 0.94343, time: 139.45s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 38: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.033]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9390, precision:0.9332, recall:0.9457, F1-Score: 0.93943, best: 0.94343, time: 139.50s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 39: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.031]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9387, precision:0.9299, recall:0.9489, F1-Score: 0.93928, best: 0.94343, time: 139.43s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 40: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.026]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9405, precision:0.9370, recall:0.9444, F1-Score: 0.94069, best: 0.94343, time: 139.42s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 41: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.030]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9379, precision:0.9269, recall:0.9508, F1-Score: 0.93872, best: 0.94343, time: 139.37s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 42: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.024]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9386, precision:0.9267, recall:0.9526, F1-Score: 0.93947, best: 0.94343, time: 139.34s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 43: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.023]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9370, precision:0.9203, recall:0.9570, F1-Score: 0.93825, best: 0.94343, time: 139.41s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 44: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.028]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9369, precision:0.9176, recall:0.9599, F1-Score: 0.93828, best: 0.94343, time: 139.37s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 45: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.025]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9369, precision:0.9175, recall:0.9601, F1-Score: 0.93831, best: 0.94343, time: 139.54s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 46: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.026]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9374, precision:0.9185, recall:0.9601, F1-Score: 0.93882, best: 0.94343, time: 139.53s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 47: 100%|██████████| 191/191 [02:17<00:00,  1.39it/s, loss=0.024]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9374, precision:0.9148, recall:0.9645, F1-Score: 0.93903, best: 0.94343, time: 139.06s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 48: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.027]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9374, precision:0.9163, recall:0.9626, F1-Score: 0.93891, best: 0.94343, time: 138.68s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 49: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.021]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9371, precision:0.9139, recall:0.9651, F1-Score: 0.93882, best: 0.94343, time: 138.79s\n","output_type":"stream"},{"name":"stderr","text":"Epoch 50: 100%|██████████| 191/191 [02:16<00:00,  1.40it/s, loss=0.020]\n","output_type":"stream"},{"name":"stdout","text":"acc:0.9364, precision:0.9118, recall:0.9664, F1-Score: 0.93828, best: 0.94343, time: 138.79s\ntorch.Size([6611, 128]) torch.Size([79937, 128])\n","output_type":"stream"}]}]}