{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "initial_id",
"metadata": {
"collapsed": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.10/dist-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"import dgl\n",
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from ogb.nodeproppred import DglNodePropPredDataset"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "eda87a2d",
"metadata": {},
"outputs": [],
"source": [
"dataset = DglNodePropPredDataset(name='ogbn-arxiv')\n",
"split_idx = dataset.get_idx_split()\n",
"train_idx, valid_idx, test_idx = split_idx[\"train\"], split_idx[\"valid\"], split_idx[\"test\"]\n",
"graph, label = dataset[0]\n",
"label = label.squeeze().numpy()\n",
"years = graph.ndata.pop('year').squeeze().numpy()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ef01bc53",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ID | \n",
" mag_id | \n",
" title | \n",
" abstract | \n",
" label_id | \n",
" category | \n",
" text | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 9657784 | \n",
" Title: evasion attacks against machine learnin... | \n",
" Abstract: In security-sensitive applications, ... | \n",
" 4 | \n",
" arxiv cs cr | \n",
" Title: evasion attacks against machine learnin... | \n",
"
\n",
" \n",
" 1 | \n",
" 1 | \n",
" 39886162 | \n",
" Title: how hard is computing parity with noisy... | \n",
" Abstract: We show a tight lower bound of $\\Ome... | \n",
" 5 | \n",
" arxiv cs dc | \n",
" Title: how hard is computing parity with noisy... | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" 116214155 | \n",
" Title: on the absence of the rip in real world... | \n",
" Abstract: The purpose of this paper is twofold... | \n",
" 28 | \n",
" arxiv cs it | \n",
" Title: on the absence of the rip in real world... | \n",
"
\n",
" \n",
" 3 | \n",
" 3 | \n",
" 121432379 | \n",
" Title: a promise theory perspective on data ne... | \n",
" Abstract: Networking is undergoing a transform... | \n",
" 8 | \n",
" arxiv cs ni | \n",
" Title: a promise theory perspective on data ne... | \n",
"
\n",
" \n",
" 4 | \n",
" 4 | \n",
" 231147053 | \n",
" Title: analysis of asymptotically optimal samp... | \n",
" Abstract: Over the last 20 years significant e... | \n",
" 27 | \n",
" arxiv cs ro | \n",
" Title: analysis of asymptotically optimal samp... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ID mag_id title \\\n",
"0 0 9657784 Title: evasion attacks against machine learnin... \n",
"1 1 39886162 Title: how hard is computing parity with noisy... \n",
"2 2 116214155 Title: on the absence of the rip in real world... \n",
"3 3 121432379 Title: a promise theory perspective on data ne... \n",
"4 4 231147053 Title: analysis of asymptotically optimal samp... \n",
"\n",
" abstract label_id category \\\n",
"0 Abstract: In security-sensitive applications, ... 4 arxiv cs cr \n",
"1 Abstract: We show a tight lower bound of $\\Ome... 5 arxiv cs dc \n",
"2 Abstract: The purpose of this paper is twofold... 28 arxiv cs it \n",
"3 Abstract: Networking is undergoing a transform... 8 arxiv cs ni \n",
"4 Abstract: Over the last 20 years significant e... 27 arxiv cs ro \n",
"\n",
" text \n",
"0 Title: evasion attacks against machine learnin... \n",
"1 Title: how hard is computing parity with noisy... \n",
"2 Title: on the absence of the rip in real world... \n",
"3 Title: a promise theory perspective on data ne... \n",
"4 Title: analysis of asymptotically optimal samp... "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"papers = pd.read_csv('Arxiv.csv')\n",
"papers.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b8090ead",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"169343"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper_id_map = dict(zip(papers['mag_id'].values.tolist(), papers['ID'].values.tolist()))\n",
"len(paper_id_map)"
]
},
{
"cell_type": "markdown",
"id": "49b90cd1",
"metadata": {},
"source": [
"## Paper-Author Links"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3d6fa82f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" PaperSeqid | \n",
" AuthorSeqid | \n",
" AffiliationSeqid | \n",
" AuthorSequenceNumber | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1963479517 | \n",
" 2167258348 | \n",
" 134161618.0 | \n",
" 2 | \n",
"
\n",
" \n",
" 1 | \n",
" 1963479517 | \n",
" 2506097535 | \n",
" 134161618.0 | \n",
" 3 | \n",
"
\n",
" \n",
" 2 | \n",
" 1963479517 | \n",
" 2296113232 | \n",
" 142823887.0 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" 2095588566 | \n",
" 2439736113 | \n",
" NaN | \n",
" 2 | \n",
"
\n",
" \n",
" 4 | \n",
" 2095588566 | \n",
" 2575410839 | \n",
" NaN | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" PaperSeqid AuthorSeqid AffiliationSeqid AuthorSequenceNumber\n",
"0 1963479517 2167258348 134161618.0 2\n",
"1 1963479517 2506097535 134161618.0 3\n",
"2 1963479517 2296113232 142823887.0 1\n",
"3 2095588566 2439736113 NaN 2\n",
"4 2095588566 2575410839 NaN 1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"authors = pd.read_csv('PAuAf_CS_20190919.tsv', sep='\\t')\n",
"authors.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cabfaf7f",
"metadata": {},
"outputs": [],
"source": [
"PaperSeqid = authors['PaperSeqid'].values\n",
"AuthorSeqid = authors['AuthorSeqid'].values\n",
"\n",
"mask = np.isin(PaperSeqid, papers['mag_id'].values)\n",
"PaperSeqid = PaperSeqid[mask]\n",
"AuthorSeqid = AuthorSeqid[mask]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c5f8c861",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of paper-author links 300807\n"
]
}
],
"source": [
"pa_pids = np.array([paper_id_map[_] for _ in PaperSeqid])\n",
"\n",
"author_id_encoder = LabelEncoder()\n",
"pa_aids = author_id_encoder.fit_transform(AuthorSeqid).astype(np.int32)\n",
"assert pa_pids.shape[0] == pa_aids.shape[0]\n",
"print('Number of paper-author links', pa_aids.shape[0])"
]
},
{
"cell_type": "markdown",
"id": "ff26e1bd",
"metadata": {},
"source": [
"## Paper-FoS Links"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f2dd9f8a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" PaperId | \n",
" FieldOfStudyId | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1963479517 | \n",
" 41008148 | \n",
"
\n",
" \n",
" 1 | \n",
" 1963479517 | \n",
" 19417346 | \n",
"
\n",
" \n",
" 2 | \n",
" 1963479517 | \n",
" 56739046 | \n",
"
\n",
" \n",
" 3 | \n",
" 1963479517 | \n",
" 85973986 | \n",
"
\n",
" \n",
" 4 | \n",
" 1963479517 | \n",
" 206103860 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" PaperId FieldOfStudyId\n",
"0 1963479517 41008148\n",
"1 1963479517 19417346\n",
"2 1963479517 56739046\n",
"3 1963479517 85973986\n",
"4 1963479517 206103860"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"FoSs = pd.read_csv('PF_CS_20190919.tsv', sep='\\t')\n",
"FoSs.head()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c8332b4a",
"metadata": {},
"outputs": [],
"source": [
"PaperId = FoSs['PaperId'].values\n",
"FieldOfStudyId = FoSs['FieldOfStudyId'].values\n",
"\n",
"mask = np.isin(PaperId, papers['mag_id'].values)\n",
"PaperId = PaperId[mask]\n",
"FieldOfStudyId = FieldOfStudyId[mask]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "f47343a2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of paper-fos links 755835\n"
]
}
],
"source": [
"pf_pids = np.array([paper_id_map[_] for _ in PaperId])\n",
"\n",
"fos_id_encoder = LabelEncoder()\n",
"pf_fids = fos_id_encoder.fit_transform(FieldOfStudyId).astype(np.int32)\n",
"assert pf_pids.shape[0] == pf_fids.shape[0]\n",
"print('Number of paper-fos links', pf_pids.shape[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "48eeeda8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3e81d6c2",
"metadata": {},
"source": [
"## Paper-Paper Links"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "6a617edd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1157799"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"graph = dgl.to_bidirected(graph)\n",
"src, dst = graph.edges()\n",
"mask = src < dst\n",
"src = src[mask].numpy()\n",
"dst = dst[mask].numpy()\n",
"src.shape[0]"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "dda0ddcc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 3, ..., 169186, 169187, 169188])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper_ids_with_author_fos = np.unique(np.concat((pa_pids, pf_pids)))\n",
"paper_ids_with_author_fos"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "963748a5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of paper-paper links 468995\n"
]
}
],
"source": [
"mask = np.isin(src, paper_ids_with_author_fos) & np.isin(dst, paper_ids_with_author_fos)\n",
"src = src[mask]\n",
"dst = dst[mask]\n",
"print('Number of paper-paper links', dst.shape[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b20b2aef",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "b9150194",
"metadata": {},
"source": [
"## Reset Id"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "74233e4d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of papers 81634\n"
]
},
{
"data": {
"text/plain": [
"array([ 0, 1, 3, ..., 169186, 169187, 169188])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper_id_encoder = LabelEncoder()\n",
"paper_id_encoder.fit(paper_ids_with_author_fos)\n",
"print('Number of papers', len(paper_id_encoder.classes_))\n",
"paper_id_encoder.classes_"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "3c8e3817",
"metadata": {},
"outputs": [],
"source": [
"pa_pids = paper_id_encoder.transform(pa_pids).astype(np.int32)\n",
"pf_pids = paper_id_encoder.transform(pf_pids).astype(np.int32)\n",
"src = paper_id_encoder.transform(src).astype(np.int32)\n",
"dst = paper_id_encoder.transform(dst).astype(np.int32)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "c89a92eb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[110, 15, 24, 30, 26]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper_labels = label[paper_id_encoder.classes_].astype(np.int8)\n",
"\n",
"from collections import Counter\n",
"list(Counter(paper_labels).values())[-5:]"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "84f21cdd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(81634,)"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper_years = years[paper_id_encoder.classes_].astype(np.int16)\n",
"paper_years.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad39969b",
"metadata": {},
"outputs": [],
"source": [
"data = {\n",
" 'paper_labels': paper_labels,\n",
" 'paper_years': paper_years,\n",
" 'paper-paper': (src, dst),\n",
" 'paper-author': (pa_pids, pa_aids),\n",
" 'paper-fos': (pf_pids, pf_fids),\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e9549b36",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 28,
"id": "f7bf606a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" mag_id | \n",
" title | \n",
" abstract | \n",
" label_id | \n",
" category | \n",
"
\n",
" \n",
" ID | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 9657784 | \n",
" Title: evasion attacks against machine learnin... | \n",
" Abstract: In security-sensitive applications, ... | \n",
" 4 | \n",
" arxiv cs cr | \n",
"
\n",
" \n",
" 1 | \n",
" 39886162 | \n",
" Title: how hard is computing parity with noisy... | \n",
" Abstract: We show a tight lower bound of $\\Ome... | \n",
" 5 | \n",
" arxiv cs dc | \n",
"
\n",
" \n",
" 3 | \n",
" 121432379 | \n",
" Title: a promise theory perspective on data ne... | \n",
" Abstract: Networking is undergoing a transform... | \n",
" 8 | \n",
" arxiv cs ni | \n",
"
\n",
" \n",
" 6 | \n",
" 1444859417 | \n",
" Title: webvrgis based city bigdata 3d visualiz... | \n",
" Abstract: This paper shows the WEBVRGIS platfo... | \n",
" 6 | \n",
" arxiv cs hc | \n",
"
\n",
" \n",
" 7 | \n",
" 1483430697 | \n",
" Title: information theoretic authentication an... | \n",
" Abstract: In the splitting model, information ... | \n",
" 4 | \n",
" arxiv cs cr | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" mag_id title \\\n",
"ID \n",
"0 9657784 Title: evasion attacks against machine learnin... \n",
"1 39886162 Title: how hard is computing parity with noisy... \n",
"3 121432379 Title: a promise theory perspective on data ne... \n",
"6 1444859417 Title: webvrgis based city bigdata 3d visualiz... \n",
"7 1483430697 Title: information theoretic authentication an... \n",
"\n",
" abstract label_id category \n",
"ID \n",
"0 Abstract: In security-sensitive applications, ... 4 arxiv cs cr \n",
"1 Abstract: We show a tight lower bound of $\\Ome... 5 arxiv cs dc \n",
"3 Abstract: Networking is undergoing a transform... 8 arxiv cs ni \n",
"6 Abstract: This paper shows the WEBVRGIS platfo... 6 arxiv cs hc \n",
"7 Abstract: In the splitting model, information ... 4 arxiv cs cr "
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"papers.set_index(keys='ID', inplace=True)\n",
"papers = papers.loc[paper_id_encoder.classes_]\n",
"papers.drop('text', inplace=True, axis=1)\n",
"papers.head()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "47e19edc",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" mag_id | \n",
" title | \n",
" abstract | \n",
" label_id | \n",
" category | \n",
"
\n",
" \n",
" ID | \n",
" | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 9657784 | \n",
" Evasion Attacks against Machine Learning at Te... | \n",
" In security-sensitive applications, the succes... | \n",
" 4 | \n",
" cs.CR | \n",
"
\n",
" \n",
" 1 | \n",
" 39886162 | \n",
" How Hard is Computing Parity with Noisy Commun... | \n",
" We show a tight lower bound of $\\Omega(N \\log\\... | \n",
" 5 | \n",
" cs.DC | \n",
"
\n",
" \n",
" 3 | \n",
" 121432379 | \n",
" A Promise Theory Perspective on Data Networks | \n",
" Networking is undergoing a transformation thro... | \n",
" 8 | \n",
" cs.NI | \n",
"
\n",
" \n",
" 6 | \n",
" 1444859417 | \n",
" Webvrgis Based City Bigdata 3d Visualization a... | \n",
" This paper shows the WEBVRGIS platform overlyi... | \n",
" 6 | \n",
" cs.HC | \n",
"
\n",
" \n",
" 7 | \n",
" 1483430697 | \n",
" Information Theoretic Authentication and Secre... | \n",
" In the splitting model, information theoretic ... | \n",
" 4 | \n",
" cs.CR | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" mag_id title \\\n",
"ID \n",
"0 9657784 Evasion Attacks against Machine Learning at Te... \n",
"1 39886162 How Hard is Computing Parity with Noisy Commun... \n",
"3 121432379 A Promise Theory Perspective on Data Networks \n",
"6 1444859417 Webvrgis Based City Bigdata 3d Visualization a... \n",
"7 1483430697 Information Theoretic Authentication and Secre... \n",
"\n",
" abstract label_id category \n",
"ID \n",
"0 In security-sensitive applications, the succes... 4 cs.CR \n",
"1 We show a tight lower bound of $\\Omega(N \\log\\... 5 cs.DC \n",
"3 Networking is undergoing a transformation thro... 8 cs.NI \n",
"6 This paper shows the WEBVRGIS platform overlyi... 6 cs.HC \n",
"7 In the splitting model, information theoretic ... 4 cs.CR "
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"papers['title'] = papers['title'].str[7:]\n",
"papers['abstract'] = papers['abstract'].str[10:]\n",
"papers['category'] = papers['category'].apply(lambda x: f'cs.{x[-2:].upper()}')\n",
"\n",
"def format_title(title):\n",
" exceptions = {'is', 'are', 'with', 'and', 'the', 'a', 'an', 'but', 'for', 'nor', 'on', 'at', 'to', 'by', 'of', 'against', 'over', 'in', 'via'}\n",
" words = title.split()\n",
" formatted_words = [\n",
" word.capitalize() if word not in exceptions or i == 0 else word\n",
" for i, word in enumerate(words)\n",
" ]\n",
" return ' '.join(formatted_words)\n",
"\n",
"papers['title'] = papers['title'].apply(format_title)\n",
"papers.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f069ba19",
"metadata": {},
"outputs": [],
"source": [
"papers.reset_index(drop=True, inplace=True)\n",
"papers.to_csv('Paper.csv', index=False)"
]
},
{
"cell_type": "markdown",
"id": "9788b560",
"metadata": {},
"source": [
"### Node Features\n",
"\n",
"We generate embeddings as features for each node in the graph. Node embeddings are generated by passing the title and the abstract through a Sentence-BERT model and obtaining a 384-embedding vector for each movie node.\n",
"\n",
"\n",
"According to [Sentence-Transformers docs](https://www.sbert.net/docs/pretrained_models.html), the **all-MiniLM-L6-v2** model provides the best quality. So we use it to generate node features.\n",
"\n",
"all-MiniLM-L6-v2\n",
"\n",
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
"Max Sequence Length:\t256\n",
"Dimensions:\t384\n",
"Normalized Embeddings:\ttrue\n",
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
"Size:\t80 MB\n",
"Pooling:\tMean Pooling\n",
"Training Data:\t1B+ training pairs. For details, see model card.\n",
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "8b547164",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"SentenceTransformer(\n",
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
" (1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})\n",
" (2): Normalize()\n",
")"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import torch\n",
"from sentence_transformers import SentenceTransformer\n",
"\n",
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
"model"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "290ad987",
"metadata": {},
"outputs": [],
"source": [
"text = papers['title'] + ' ' + papers['abstract']"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "7a001955",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Batches: 100%|██████████| 20/20 [01:04<00:00, 3.22s/it]\n"
]
}
],
"source": [
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "018e0582",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'paper_labels': array([ 4, 5, 8, ..., 16, 30, 30], dtype=int8),\n",
" 'paper_years': array([2013, 2015, 2014, ..., 2019, 2019, 2019], dtype=int16),\n",
" 'paper-paper': (array([ 0, 0, 0, ..., 81308, 81312, 81465], dtype=int32),\n",
" array([ 215, 347, 930, ..., 81577, 81345, 81519], dtype=int32)),\n",
" 'paper_author': (array([19239, 19239, 19239, ..., 35209, 53724, 53724], dtype=int32),\n",
" array([127457, 19897, 127067, ..., 20462, 87283, 1618], dtype=int32)),\n",
" 'paper_fos': (array([19239, 19239, 19239, ..., 53724, 53724, 53724], dtype=int32),\n",
" array([ 2826, 9870, 11927, ..., 2826, 14082, 8436], dtype=int32)),\n",
" 'paper_feats': array([[-0.09871526, -0.01083333, -0.05048474, ..., 0.01055331,\n",
" 0.03491311, -0.01338707],\n",
" [-0.00965661, -0.05066415, 0.05266945, ..., 0.09849689,\n",
" -0.06759875, -0.00852178],\n",
" [-0.06771555, -0.02296721, 0.07591261, ..., -0.04729789,\n",
" 0.01239418, -0.02592889],\n",
" ...,\n",
" [-0.0010215 , -0.09171138, 0.02063811, ..., 0.01867299,\n",
" -0.06674339, -0.00320282],\n",
" [-0.00800873, -0.09252207, -0.08150839, ..., 0.04762044,\n",
" 0.03962403, 0.01795155],\n",
" [-0.07200024, -0.0933908 , -0.02737658, ..., 0.09808387,\n",
" 0.03837816, -0.05359345]], dtype=float32)}"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data['paper_feats'] = feats\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a8550ed0",
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"\n",
"with open('arxiv.pkl', 'wb') as f:\n",
" pickle.dump(data, f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21703238",
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}