Upload datasets
Browse files- .gitattributes +2 -0
- README.md +76 -0
- arxiv/ArXiv.csv +3 -0
- arxiv/README.md +31 -0
- arxiv/arxiv.pkl +3 -0
- arxiv/graph_builder.ipynb +1093 -0
- book/Book.csv.zip +3 -0
- book/README.md +30 -0
- book/book.pkl +3 -0
- book/extract_from_gbgd.py +66 -0
- book/graph_builder.ipynb +1522 -0
- croval/CroVal.csv +3 -0
- croval/README.md +28 -0
- croval/croval.pkl +3 -0
- croval/extract_from_croval.py +85 -0
- croval/graph_builder.ipynb +1757 -0
- dblp/DBLP.csv.zip +3 -0
- dblp/README.md +31 -0
- dblp/dblp.pkl +3 -0
- dblp/extract_from_dblp.py +62 -0
- dblp/graph_builder.ipynb +944 -0
- patent/Patent.csv.zip +3 -0
- patent/README.md +31 -0
- patent/extract_from_hupd.py +46 -0
- patent/graph_builder.ipynb +1065 -0
- patent/patent.pkl +3 -0
- tmdb/README.md +30 -0
- tmdb/TMDB.csv +0 -0
- tmdb/graph_builder.ipynb +641 -0
- tmdb/tmdb.pkl +3 -0
- tmdb/tmdb_fetcher.ipynb +0 -0
.gitattributes
CHANGED
|
@@ -57,3 +57,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
arxiv/ArXiv.csv filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
croval/CroVal.csv filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```
|
| 2 |
---
|
| 3 |
license: mit
|
| 4 |
---
|
| 5 |
+
```
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Multi-Scale Heterogeneous Text-Attributed Graph Datasets From Diverse Domains
|
| 10 |
+
|
| 11 |
+
- **Multi Scales.** Our HTAG datasets span multiple scales, ranging from small (24K nodes, 104K edges) to large (5.6M nodes, 29.8M edges). Smaller datasets are suitable for testing computationally intensive algorithms, while larger datasets, such as DBLP and Patent, support the development of scalable models that leverage mini-batching and distributed training.
|
| 12 |
+
- **Diverse Domains.** Our HTAG datasets include heterogeneous graphs that are representative of a wide range of domains: movie collaboration, community question answering, academic, book publication, and patent application. The broad coverage of domains empowers the development and demonstration of graph foundation models and helps differentiate them from domain-specific approaches.
|
| 13 |
+
- **Realistic and Reproducible Evaluation.** We provide an automated evaluation pipeline for HTAGs that streamlines data processing, loading, and model evaluation, ensuring seamless reproducibility. Additionally, we employ time-based data splits for each dataset, which offer a more realistic and meaningful evaluation compared to traditional random splits.
|
| 14 |
+
- **Open-source Code for Dataset Construction.** We have released the complete code for constructing our HTAG datasets, allowing researchers to build larger and more complex heterogeneous text-attribute graph datasets. For example, the CroVal dataset construction code can be used to create web-scale community question-answering networks, such as those derived from [StackExchange data dumps](https://archive.org/download/stackexchange). This initiative aims to further advance the field by providing the tools necessary for replicating and extending our datasets for a wide range of applications.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
## Dataset Format
|
| 19 |
+
|
| 20 |
+
The dataset includes heterogeneous graph edges, raw text, PLM-based features, labels, and years associated with text-attributed nodes. Raw text is provided in `.csv` or `.csv.zip` files, while the remaining data are stored in a dictionary object within a `.pkl` file. For example, by reading the `tmdb.pkl` file, the following dictionary can be obtained:
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
{'movie-actor': (array([ 0, 0, 0, ..., 7504, 7504, 7504], dtype=int16),
|
| 24 |
+
array([ 0, 1, 2, ..., 11870, 1733, 11794], dtype=int16)),
|
| 25 |
+
'movie-director': (array([ 0, 0, 0, ..., 7503, 7503, 7504], dtype=int16),
|
| 26 |
+
array([ 0, 1, 2, ..., 3423, 966, 2890], dtype=int16)),
|
| 27 |
+
'movie_labels': array([3, 1, 1, ..., 1, 1, 2], dtype=int8),
|
| 28 |
+
'movie_feats': array([[ 0.00635284, 0.00649689, 0.01250827, ..., 0.06342042,
|
| 29 |
+
-0.01747945, 0.0134356 ],
|
| 30 |
+
[-0.14075027, 0.02825641, 0.02670695, ..., -0.12270895,
|
| 31 |
+
0.08417314, 0.02486392],
|
| 32 |
+
[ 0.00014208, -0.02286632, 0.00615967, ..., -0.03311544,
|
| 33 |
+
0.04735276, -0.07458566],
|
| 34 |
+
...,
|
| 35 |
+
[ 0.01835816, 0.07484645, -0.08099765, ..., -0.00150019,
|
| 36 |
+
0.01669764, 0.00456595],
|
| 37 |
+
[-0.00821487, -0.10434289, 0.01928608, ..., -0.06343049,
|
| 38 |
+
0.05060194, -0.04229118],
|
| 39 |
+
[-0.06465845, 0.13461556, -0.01640793, ..., -0.06274845,
|
| 40 |
+
0.04002513, -0.00751513]], dtype=float32),
|
| 41 |
+
'movie_years': array([2013, 1995, 1989, ..., 1939, 1941, 1965], dtype=int16)}
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
## Dataset Statistics
|
| 47 |
+
|
| 48 |
+
| | # Nodes | # Edges | # Classes | # Splits |
|
| 49 |
+
| ------ | ------------------- | -------------------------- | --------- | ---------------- |
|
| 50 |
+
| TMDB | **24,412** | **104,858** | 4 | Train: 5,698 |
|
| 51 |
+
| | Movie: 7,505 | Movie-Actor: 86,517 | | Valid: 711 |
|
| 52 |
+
| | Actor: 13,016 | Movie-Director: 18,341 | | Test: 1,096 |
|
| 53 |
+
| | Director: 3,891 | | | |
|
| 54 |
+
| CroVal | **44386** | **164,981** | 6 | Train: 9,699 |
|
| 55 |
+
| | Question: 34153 | Question-Question: 46,269 | | Valid: 9,889 |
|
| 56 |
+
| | User: 8898 | Question-User: 34,153 | | Test: 14,565 |
|
| 57 |
+
| | Tag: 1335 | Question-Tag: 84,559 | | |
|
| 58 |
+
| ArXiv | **231,111** | **2,075,692** | 40 | Train: 47,084 |
|
| 59 |
+
| | Paper: 81,634 | Paper-Paper: 1,019,624 | | Valid: 18,170 |
|
| 60 |
+
| | Author: 127,590 | Paper-Author: 300,233 | | Test: 16,380 |
|
| 61 |
+
| | FoS: 21,887 | Paper-FoS: 755,835 | | |
|
| 62 |
+
| Book | **786,257** | **9,035,291** | 8 | Train: 330,201 |
|
| 63 |
+
| | Book | Book-Book: 7,614,902 | | Valid: 57,220 |
|
| 64 |
+
| | Author | Book-Author: 825,905 | | Test: 207,063 |
|
| 65 |
+
| | Publisher | Book-Publisher: 594,484 | | |
|
| 66 |
+
| DBLP | **1,989,010** | **29,830,033** | 9 | Train: 508,464 |
|
| 67 |
+
| | Paper: 964350 | Paper-Paper: 16,679,526 | | Valid: 158,891 |
|
| 68 |
+
| | Author: 958961 | Paper-Author: 3,070,343 | | Test: 296,995 |
|
| 69 |
+
| | FoS: 65699 | Paper-FoS: 10,080,164 | | |
|
| 70 |
+
| Patent | **5,646,139** | **8,833,738** | 120 | Train: 1,705,155 |
|
| 71 |
+
| | Patent: 2,762,187 | Patent-Inventor: 6,071,551 | | Valid: 374,275 |
|
| 72 |
+
| | Inventor: 2,873,311 | Patent-Examiner: 2,762,187 | | Test: 682,757 |
|
| 73 |
+
| | Examiner: 10,641 | | | |
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
## Dataset Construction
|
| 78 |
+
|
| 79 |
+
The code for dataset construction can be found in each `graph_builder.ipynb` file. Please see `README.md` in each subfolder for more details .
|
arxiv/ArXiv.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4711b2a729e4597e1bc71fae160132be5fdeee27904c279083618a8589b125c3
|
| 3 |
+
size 97423090
|
arxiv/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ArXiv: Academic Network
|
| 2 |
+
|
| 3 |
+
The ArXiv dataset is a heterogeneous academic network constructed from [arXiv CS](https://arxiv.org/search/cs) and the Microsoft Academic Graph [1]. It contains three types of entities—papers (81,634 nodes), authors (127,590 nodes), and fields of study (FoS, 21,887 nodes)—as well as three types of directed relations connecting three types of entities—a paper “cites" another paper, an author "writes" a paper, and a paper “has a topic of" a field of study. Papers are associated with their titles and abstracts, and all the other types of entities are textless. We concatenate the paper title and abstract and pass it to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each paper node. Papers are categorized into 40 subject areas of [arXiv CS papers](https://arxiv.org/archive/cs), such as cs.LG, cs.DB, and cs.OS. In addition, each paper is associated with the year of publication.
|
| 4 |
+
|
| 5 |
+
**Prediction task.**
|
| 6 |
+
The task is to predict the 40 subject areas of arXiv Computer Science papers, which are manually assigned by the paper's authors and arXiv moderators. Given the rapid growth of scientific publications, doubling every 12 years over the past century \citep{dong2017century}, automating the classification of papers into relevant areas is of significant practical value. Formally, the task is formulated as a 40-class classification problem, with evaluation metrics including the Micro-F1 and Macro-F1 scores.
|
| 7 |
+
|
| 8 |
+
**Dataset splitting.**
|
| 9 |
+
For the dataset split, we use a temporal approach. The model is trained on papers published up until 2017, validated on those from 2018, and tested on papers published from 2019 onward. This temporal split reflects a practical scenario of helping the authors and moderators annotate the subject areas of the newly-published arXiv papers.
|
| 10 |
+
|
| 11 |
+
**Dataset statistics.**
|
| 12 |
+
|
| 13 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 14 |
+
| --------------- | ---------------------- | --------- | ------------- |
|
| 15 |
+
| **231,111** | **2,075,692** | 40 | Train: 47,084 |
|
| 16 |
+
| Paper: 81,634 | Paper-Paper: 1,019,624 | | Valid: 18,170 |
|
| 17 |
+
| Author: 127,590 | Paper-Author: 300,233 | | Test: 16,380 |
|
| 18 |
+
| FoS: 21,887 | Paper-FoS: 755,835 | | |
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
[1] Wang, K., Shen, Z., Huang, C., Wu, C. H., Dong, Y., & Kanakia, A. (2020). Microsoft academic graph: When experts are not enough. *Quantitative Science Studies*, *1*(1), 396-413.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Dataset Construction
|
| 27 |
+
|
| 28 |
+
1. Install [ogb](https://ogb.stanford.edu/) and [dgl](https://www.dgl.ai/)
|
| 29 |
+
2. Download source data [Arxiv.csv](https://huggingface.co/datasets/Sherirto/CSTAG/tree/main/Arxiv)
|
| 30 |
+
3. Download [PAuAf_CS_20190919.tsv and PF_CS_20190919.tsv](https://drive.google.com/drive/folders/1yDdVaartOCOSsQlUZs8cJcAUhmvRiBSz)
|
| 31 |
+
4. Run `graph_builder.ipynb`
|
arxiv/arxiv.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5fba9f943e04defe5a635e4c33d225474a02eb71d86b11fab86f59b7955c152
|
| 3 |
+
size 137840546
|
arxiv/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,1093 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"id": "initial_id",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"collapsed": true
|
| 9 |
+
},
|
| 10 |
+
"outputs": [
|
| 11 |
+
{
|
| 12 |
+
"name": "stderr",
|
| 13 |
+
"output_type": "stream",
|
| 14 |
+
"text": [
|
| 15 |
+
"/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",
|
| 16 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 17 |
+
]
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"source": [
|
| 21 |
+
"import dgl\n",
|
| 22 |
+
"import numpy as np\n",
|
| 23 |
+
"import pandas as pd\n",
|
| 24 |
+
"from sklearn.preprocessing import LabelEncoder\n",
|
| 25 |
+
"from ogb.nodeproppred import DglNodePropPredDataset"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"cell_type": "code",
|
| 30 |
+
"execution_count": 19,
|
| 31 |
+
"id": "eda87a2d",
|
| 32 |
+
"metadata": {},
|
| 33 |
+
"outputs": [],
|
| 34 |
+
"source": [
|
| 35 |
+
"dataset = DglNodePropPredDataset(name='ogbn-arxiv')\n",
|
| 36 |
+
"split_idx = dataset.get_idx_split()\n",
|
| 37 |
+
"train_idx, valid_idx, test_idx = split_idx[\"train\"], split_idx[\"valid\"], split_idx[\"test\"]\n",
|
| 38 |
+
"graph, label = dataset[0]\n",
|
| 39 |
+
"label = label.squeeze().numpy()\n",
|
| 40 |
+
"years = graph.ndata.pop('year').squeeze().numpy()"
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"cell_type": "code",
|
| 45 |
+
"execution_count": 3,
|
| 46 |
+
"id": "ef01bc53",
|
| 47 |
+
"metadata": {},
|
| 48 |
+
"outputs": [
|
| 49 |
+
{
|
| 50 |
+
"data": {
|
| 51 |
+
"text/html": [
|
| 52 |
+
"<div>\n",
|
| 53 |
+
"<style scoped>\n",
|
| 54 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 55 |
+
" vertical-align: middle;\n",
|
| 56 |
+
" }\n",
|
| 57 |
+
"\n",
|
| 58 |
+
" .dataframe tbody tr th {\n",
|
| 59 |
+
" vertical-align: top;\n",
|
| 60 |
+
" }\n",
|
| 61 |
+
"\n",
|
| 62 |
+
" .dataframe thead th {\n",
|
| 63 |
+
" text-align: right;\n",
|
| 64 |
+
" }\n",
|
| 65 |
+
"</style>\n",
|
| 66 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 67 |
+
" <thead>\n",
|
| 68 |
+
" <tr style=\"text-align: right;\">\n",
|
| 69 |
+
" <th></th>\n",
|
| 70 |
+
" <th>ID</th>\n",
|
| 71 |
+
" <th>mag_id</th>\n",
|
| 72 |
+
" <th>title</th>\n",
|
| 73 |
+
" <th>abstract</th>\n",
|
| 74 |
+
" <th>label_id</th>\n",
|
| 75 |
+
" <th>category</th>\n",
|
| 76 |
+
" <th>text</th>\n",
|
| 77 |
+
" </tr>\n",
|
| 78 |
+
" </thead>\n",
|
| 79 |
+
" <tbody>\n",
|
| 80 |
+
" <tr>\n",
|
| 81 |
+
" <th>0</th>\n",
|
| 82 |
+
" <td>0</td>\n",
|
| 83 |
+
" <td>9657784</td>\n",
|
| 84 |
+
" <td>Title: evasion attacks against machine learnin...</td>\n",
|
| 85 |
+
" <td>Abstract: In security-sensitive applications, ...</td>\n",
|
| 86 |
+
" <td>4</td>\n",
|
| 87 |
+
" <td>arxiv cs cr</td>\n",
|
| 88 |
+
" <td>Title: evasion attacks against machine learnin...</td>\n",
|
| 89 |
+
" </tr>\n",
|
| 90 |
+
" <tr>\n",
|
| 91 |
+
" <th>1</th>\n",
|
| 92 |
+
" <td>1</td>\n",
|
| 93 |
+
" <td>39886162</td>\n",
|
| 94 |
+
" <td>Title: how hard is computing parity with noisy...</td>\n",
|
| 95 |
+
" <td>Abstract: We show a tight lower bound of $\\Ome...</td>\n",
|
| 96 |
+
" <td>5</td>\n",
|
| 97 |
+
" <td>arxiv cs dc</td>\n",
|
| 98 |
+
" <td>Title: how hard is computing parity with noisy...</td>\n",
|
| 99 |
+
" </tr>\n",
|
| 100 |
+
" <tr>\n",
|
| 101 |
+
" <th>2</th>\n",
|
| 102 |
+
" <td>2</td>\n",
|
| 103 |
+
" <td>116214155</td>\n",
|
| 104 |
+
" <td>Title: on the absence of the rip in real world...</td>\n",
|
| 105 |
+
" <td>Abstract: The purpose of this paper is twofold...</td>\n",
|
| 106 |
+
" <td>28</td>\n",
|
| 107 |
+
" <td>arxiv cs it</td>\n",
|
| 108 |
+
" <td>Title: on the absence of the rip in real world...</td>\n",
|
| 109 |
+
" </tr>\n",
|
| 110 |
+
" <tr>\n",
|
| 111 |
+
" <th>3</th>\n",
|
| 112 |
+
" <td>3</td>\n",
|
| 113 |
+
" <td>121432379</td>\n",
|
| 114 |
+
" <td>Title: a promise theory perspective on data ne...</td>\n",
|
| 115 |
+
" <td>Abstract: Networking is undergoing a transform...</td>\n",
|
| 116 |
+
" <td>8</td>\n",
|
| 117 |
+
" <td>arxiv cs ni</td>\n",
|
| 118 |
+
" <td>Title: a promise theory perspective on data ne...</td>\n",
|
| 119 |
+
" </tr>\n",
|
| 120 |
+
" <tr>\n",
|
| 121 |
+
" <th>4</th>\n",
|
| 122 |
+
" <td>4</td>\n",
|
| 123 |
+
" <td>231147053</td>\n",
|
| 124 |
+
" <td>Title: analysis of asymptotically optimal samp...</td>\n",
|
| 125 |
+
" <td>Abstract: Over the last 20 years significant e...</td>\n",
|
| 126 |
+
" <td>27</td>\n",
|
| 127 |
+
" <td>arxiv cs ro</td>\n",
|
| 128 |
+
" <td>Title: analysis of asymptotically optimal samp...</td>\n",
|
| 129 |
+
" </tr>\n",
|
| 130 |
+
" </tbody>\n",
|
| 131 |
+
"</table>\n",
|
| 132 |
+
"</div>"
|
| 133 |
+
],
|
| 134 |
+
"text/plain": [
|
| 135 |
+
" ID mag_id title \\\n",
|
| 136 |
+
"0 0 9657784 Title: evasion attacks against machine learnin... \n",
|
| 137 |
+
"1 1 39886162 Title: how hard is computing parity with noisy... \n",
|
| 138 |
+
"2 2 116214155 Title: on the absence of the rip in real world... \n",
|
| 139 |
+
"3 3 121432379 Title: a promise theory perspective on data ne... \n",
|
| 140 |
+
"4 4 231147053 Title: analysis of asymptotically optimal samp... \n",
|
| 141 |
+
"\n",
|
| 142 |
+
" abstract label_id category \\\n",
|
| 143 |
+
"0 Abstract: In security-sensitive applications, ... 4 arxiv cs cr \n",
|
| 144 |
+
"1 Abstract: We show a tight lower bound of $\\Ome... 5 arxiv cs dc \n",
|
| 145 |
+
"2 Abstract: The purpose of this paper is twofold... 28 arxiv cs it \n",
|
| 146 |
+
"3 Abstract: Networking is undergoing a transform... 8 arxiv cs ni \n",
|
| 147 |
+
"4 Abstract: Over the last 20 years significant e... 27 arxiv cs ro \n",
|
| 148 |
+
"\n",
|
| 149 |
+
" text \n",
|
| 150 |
+
"0 Title: evasion attacks against machine learnin... \n",
|
| 151 |
+
"1 Title: how hard is computing parity with noisy... \n",
|
| 152 |
+
"2 Title: on the absence of the rip in real world... \n",
|
| 153 |
+
"3 Title: a promise theory perspective on data ne... \n",
|
| 154 |
+
"4 Title: analysis of asymptotically optimal samp... "
|
| 155 |
+
]
|
| 156 |
+
},
|
| 157 |
+
"execution_count": 3,
|
| 158 |
+
"metadata": {},
|
| 159 |
+
"output_type": "execute_result"
|
| 160 |
+
}
|
| 161 |
+
],
|
| 162 |
+
"source": [
|
| 163 |
+
"papers = pd.read_csv('Arxiv.csv')\n",
|
| 164 |
+
"papers.head()"
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"cell_type": "code",
|
| 169 |
+
"execution_count": 4,
|
| 170 |
+
"id": "b8090ead",
|
| 171 |
+
"metadata": {},
|
| 172 |
+
"outputs": [
|
| 173 |
+
{
|
| 174 |
+
"data": {
|
| 175 |
+
"text/plain": [
|
| 176 |
+
"169343"
|
| 177 |
+
]
|
| 178 |
+
},
|
| 179 |
+
"execution_count": 4,
|
| 180 |
+
"metadata": {},
|
| 181 |
+
"output_type": "execute_result"
|
| 182 |
+
}
|
| 183 |
+
],
|
| 184 |
+
"source": [
|
| 185 |
+
"paper_id_map = dict(zip(papers['mag_id'].values.tolist(), papers['ID'].values.tolist()))\n",
|
| 186 |
+
"len(paper_id_map)"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"cell_type": "markdown",
|
| 191 |
+
"id": "49b90cd1",
|
| 192 |
+
"metadata": {},
|
| 193 |
+
"source": [
|
| 194 |
+
"## Paper-Author Links"
|
| 195 |
+
]
|
| 196 |
+
},
|
| 197 |
+
{
|
| 198 |
+
"cell_type": "code",
|
| 199 |
+
"execution_count": 5,
|
| 200 |
+
"id": "3d6fa82f",
|
| 201 |
+
"metadata": {},
|
| 202 |
+
"outputs": [
|
| 203 |
+
{
|
| 204 |
+
"data": {
|
| 205 |
+
"text/html": [
|
| 206 |
+
"<div>\n",
|
| 207 |
+
"<style scoped>\n",
|
| 208 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 209 |
+
" vertical-align: middle;\n",
|
| 210 |
+
" }\n",
|
| 211 |
+
"\n",
|
| 212 |
+
" .dataframe tbody tr th {\n",
|
| 213 |
+
" vertical-align: top;\n",
|
| 214 |
+
" }\n",
|
| 215 |
+
"\n",
|
| 216 |
+
" .dataframe thead th {\n",
|
| 217 |
+
" text-align: right;\n",
|
| 218 |
+
" }\n",
|
| 219 |
+
"</style>\n",
|
| 220 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 221 |
+
" <thead>\n",
|
| 222 |
+
" <tr style=\"text-align: right;\">\n",
|
| 223 |
+
" <th></th>\n",
|
| 224 |
+
" <th>PaperSeqid</th>\n",
|
| 225 |
+
" <th>AuthorSeqid</th>\n",
|
| 226 |
+
" <th>AffiliationSeqid</th>\n",
|
| 227 |
+
" <th>AuthorSequenceNumber</th>\n",
|
| 228 |
+
" </tr>\n",
|
| 229 |
+
" </thead>\n",
|
| 230 |
+
" <tbody>\n",
|
| 231 |
+
" <tr>\n",
|
| 232 |
+
" <th>0</th>\n",
|
| 233 |
+
" <td>1963479517</td>\n",
|
| 234 |
+
" <td>2167258348</td>\n",
|
| 235 |
+
" <td>134161618.0</td>\n",
|
| 236 |
+
" <td>2</td>\n",
|
| 237 |
+
" </tr>\n",
|
| 238 |
+
" <tr>\n",
|
| 239 |
+
" <th>1</th>\n",
|
| 240 |
+
" <td>1963479517</td>\n",
|
| 241 |
+
" <td>2506097535</td>\n",
|
| 242 |
+
" <td>134161618.0</td>\n",
|
| 243 |
+
" <td>3</td>\n",
|
| 244 |
+
" </tr>\n",
|
| 245 |
+
" <tr>\n",
|
| 246 |
+
" <th>2</th>\n",
|
| 247 |
+
" <td>1963479517</td>\n",
|
| 248 |
+
" <td>2296113232</td>\n",
|
| 249 |
+
" <td>142823887.0</td>\n",
|
| 250 |
+
" <td>1</td>\n",
|
| 251 |
+
" </tr>\n",
|
| 252 |
+
" <tr>\n",
|
| 253 |
+
" <th>3</th>\n",
|
| 254 |
+
" <td>2095588566</td>\n",
|
| 255 |
+
" <td>2439736113</td>\n",
|
| 256 |
+
" <td>NaN</td>\n",
|
| 257 |
+
" <td>2</td>\n",
|
| 258 |
+
" </tr>\n",
|
| 259 |
+
" <tr>\n",
|
| 260 |
+
" <th>4</th>\n",
|
| 261 |
+
" <td>2095588566</td>\n",
|
| 262 |
+
" <td>2575410839</td>\n",
|
| 263 |
+
" <td>NaN</td>\n",
|
| 264 |
+
" <td>1</td>\n",
|
| 265 |
+
" </tr>\n",
|
| 266 |
+
" </tbody>\n",
|
| 267 |
+
"</table>\n",
|
| 268 |
+
"</div>"
|
| 269 |
+
],
|
| 270 |
+
"text/plain": [
|
| 271 |
+
" PaperSeqid AuthorSeqid AffiliationSeqid AuthorSequenceNumber\n",
|
| 272 |
+
"0 1963479517 2167258348 134161618.0 2\n",
|
| 273 |
+
"1 1963479517 2506097535 134161618.0 3\n",
|
| 274 |
+
"2 1963479517 2296113232 142823887.0 1\n",
|
| 275 |
+
"3 2095588566 2439736113 NaN 2\n",
|
| 276 |
+
"4 2095588566 2575410839 NaN 1"
|
| 277 |
+
]
|
| 278 |
+
},
|
| 279 |
+
"execution_count": 5,
|
| 280 |
+
"metadata": {},
|
| 281 |
+
"output_type": "execute_result"
|
| 282 |
+
}
|
| 283 |
+
],
|
| 284 |
+
"source": [
|
| 285 |
+
"authors = pd.read_csv('PAuAf_CS_20190919.tsv', sep='\\t')\n",
|
| 286 |
+
"authors.head()"
|
| 287 |
+
]
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"cell_type": "code",
|
| 291 |
+
"execution_count": 6,
|
| 292 |
+
"id": "cabfaf7f",
|
| 293 |
+
"metadata": {},
|
| 294 |
+
"outputs": [],
|
| 295 |
+
"source": [
|
| 296 |
+
"PaperSeqid = authors['PaperSeqid'].values\n",
|
| 297 |
+
"AuthorSeqid = authors['AuthorSeqid'].values\n",
|
| 298 |
+
"\n",
|
| 299 |
+
"mask = np.isin(PaperSeqid, papers['mag_id'].values)\n",
|
| 300 |
+
"PaperSeqid = PaperSeqid[mask]\n",
|
| 301 |
+
"AuthorSeqid = AuthorSeqid[mask]"
|
| 302 |
+
]
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"cell_type": "code",
|
| 306 |
+
"execution_count": 7,
|
| 307 |
+
"id": "c5f8c861",
|
| 308 |
+
"metadata": {},
|
| 309 |
+
"outputs": [
|
| 310 |
+
{
|
| 311 |
+
"name": "stdout",
|
| 312 |
+
"output_type": "stream",
|
| 313 |
+
"text": [
|
| 314 |
+
"Number of paper-author links 300807\n"
|
| 315 |
+
]
|
| 316 |
+
}
|
| 317 |
+
],
|
| 318 |
+
"source": [
|
| 319 |
+
"pa_pids = np.array([paper_id_map[_] for _ in PaperSeqid])\n",
|
| 320 |
+
"\n",
|
| 321 |
+
"author_id_encoder = LabelEncoder()\n",
|
| 322 |
+
"pa_aids = author_id_encoder.fit_transform(AuthorSeqid).astype(np.int32)\n",
|
| 323 |
+
"assert pa_pids.shape[0] == pa_aids.shape[0]\n",
|
| 324 |
+
"print('Number of paper-author links', pa_aids.shape[0])"
|
| 325 |
+
]
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"cell_type": "markdown",
|
| 329 |
+
"id": "ff26e1bd",
|
| 330 |
+
"metadata": {},
|
| 331 |
+
"source": [
|
| 332 |
+
"## Paper-FoS Links"
|
| 333 |
+
]
|
| 334 |
+
},
|
| 335 |
+
{
|
| 336 |
+
"cell_type": "code",
|
| 337 |
+
"execution_count": 8,
|
| 338 |
+
"id": "f2dd9f8a",
|
| 339 |
+
"metadata": {},
|
| 340 |
+
"outputs": [
|
| 341 |
+
{
|
| 342 |
+
"data": {
|
| 343 |
+
"text/html": [
|
| 344 |
+
"<div>\n",
|
| 345 |
+
"<style scoped>\n",
|
| 346 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 347 |
+
" vertical-align: middle;\n",
|
| 348 |
+
" }\n",
|
| 349 |
+
"\n",
|
| 350 |
+
" .dataframe tbody tr th {\n",
|
| 351 |
+
" vertical-align: top;\n",
|
| 352 |
+
" }\n",
|
| 353 |
+
"\n",
|
| 354 |
+
" .dataframe thead th {\n",
|
| 355 |
+
" text-align: right;\n",
|
| 356 |
+
" }\n",
|
| 357 |
+
"</style>\n",
|
| 358 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 359 |
+
" <thead>\n",
|
| 360 |
+
" <tr style=\"text-align: right;\">\n",
|
| 361 |
+
" <th></th>\n",
|
| 362 |
+
" <th>PaperId</th>\n",
|
| 363 |
+
" <th>FieldOfStudyId</th>\n",
|
| 364 |
+
" </tr>\n",
|
| 365 |
+
" </thead>\n",
|
| 366 |
+
" <tbody>\n",
|
| 367 |
+
" <tr>\n",
|
| 368 |
+
" <th>0</th>\n",
|
| 369 |
+
" <td>1963479517</td>\n",
|
| 370 |
+
" <td>41008148</td>\n",
|
| 371 |
+
" </tr>\n",
|
| 372 |
+
" <tr>\n",
|
| 373 |
+
" <th>1</th>\n",
|
| 374 |
+
" <td>1963479517</td>\n",
|
| 375 |
+
" <td>19417346</td>\n",
|
| 376 |
+
" </tr>\n",
|
| 377 |
+
" <tr>\n",
|
| 378 |
+
" <th>2</th>\n",
|
| 379 |
+
" <td>1963479517</td>\n",
|
| 380 |
+
" <td>56739046</td>\n",
|
| 381 |
+
" </tr>\n",
|
| 382 |
+
" <tr>\n",
|
| 383 |
+
" <th>3</th>\n",
|
| 384 |
+
" <td>1963479517</td>\n",
|
| 385 |
+
" <td>85973986</td>\n",
|
| 386 |
+
" </tr>\n",
|
| 387 |
+
" <tr>\n",
|
| 388 |
+
" <th>4</th>\n",
|
| 389 |
+
" <td>1963479517</td>\n",
|
| 390 |
+
" <td>206103860</td>\n",
|
| 391 |
+
" </tr>\n",
|
| 392 |
+
" </tbody>\n",
|
| 393 |
+
"</table>\n",
|
| 394 |
+
"</div>"
|
| 395 |
+
],
|
| 396 |
+
"text/plain": [
|
| 397 |
+
" PaperId FieldOfStudyId\n",
|
| 398 |
+
"0 1963479517 41008148\n",
|
| 399 |
+
"1 1963479517 19417346\n",
|
| 400 |
+
"2 1963479517 56739046\n",
|
| 401 |
+
"3 1963479517 85973986\n",
|
| 402 |
+
"4 1963479517 206103860"
|
| 403 |
+
]
|
| 404 |
+
},
|
| 405 |
+
"execution_count": 8,
|
| 406 |
+
"metadata": {},
|
| 407 |
+
"output_type": "execute_result"
|
| 408 |
+
}
|
| 409 |
+
],
|
| 410 |
+
"source": [
|
| 411 |
+
"FoSs = pd.read_csv('PF_CS_20190919.tsv', sep='\\t')\n",
|
| 412 |
+
"FoSs.head()"
|
| 413 |
+
]
|
| 414 |
+
},
|
| 415 |
+
{
|
| 416 |
+
"cell_type": "code",
|
| 417 |
+
"execution_count": 9,
|
| 418 |
+
"id": "c8332b4a",
|
| 419 |
+
"metadata": {},
|
| 420 |
+
"outputs": [],
|
| 421 |
+
"source": [
|
| 422 |
+
"PaperId = FoSs['PaperId'].values\n",
|
| 423 |
+
"FieldOfStudyId = FoSs['FieldOfStudyId'].values\n",
|
| 424 |
+
"\n",
|
| 425 |
+
"mask = np.isin(PaperId, papers['mag_id'].values)\n",
|
| 426 |
+
"PaperId = PaperId[mask]\n",
|
| 427 |
+
"FieldOfStudyId = FieldOfStudyId[mask]"
|
| 428 |
+
]
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
"cell_type": "code",
|
| 432 |
+
"execution_count": 10,
|
| 433 |
+
"id": "f47343a2",
|
| 434 |
+
"metadata": {},
|
| 435 |
+
"outputs": [
|
| 436 |
+
{
|
| 437 |
+
"name": "stdout",
|
| 438 |
+
"output_type": "stream",
|
| 439 |
+
"text": [
|
| 440 |
+
"Number of paper-fos links 755835\n"
|
| 441 |
+
]
|
| 442 |
+
}
|
| 443 |
+
],
|
| 444 |
+
"source": [
|
| 445 |
+
"pf_pids = np.array([paper_id_map[_] for _ in PaperId])\n",
|
| 446 |
+
"\n",
|
| 447 |
+
"fos_id_encoder = LabelEncoder()\n",
|
| 448 |
+
"pf_fids = fos_id_encoder.fit_transform(FieldOfStudyId).astype(np.int32)\n",
|
| 449 |
+
"assert pf_pids.shape[0] == pf_fids.shape[0]\n",
|
| 450 |
+
"print('Number of paper-fos links', pf_pids.shape[0])"
|
| 451 |
+
]
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"cell_type": "code",
|
| 455 |
+
"execution_count": null,
|
| 456 |
+
"id": "48eeeda8",
|
| 457 |
+
"metadata": {},
|
| 458 |
+
"outputs": [],
|
| 459 |
+
"source": []
|
| 460 |
+
},
|
| 461 |
+
{
|
| 462 |
+
"cell_type": "markdown",
|
| 463 |
+
"id": "3e81d6c2",
|
| 464 |
+
"metadata": {},
|
| 465 |
+
"source": [
|
| 466 |
+
"## Paper-Paper Links"
|
| 467 |
+
]
|
| 468 |
+
},
|
| 469 |
+
{
|
| 470 |
+
"cell_type": "code",
|
| 471 |
+
"execution_count": 11,
|
| 472 |
+
"id": "6a617edd",
|
| 473 |
+
"metadata": {},
|
| 474 |
+
"outputs": [
|
| 475 |
+
{
|
| 476 |
+
"data": {
|
| 477 |
+
"text/plain": [
|
| 478 |
+
"1157799"
|
| 479 |
+
]
|
| 480 |
+
},
|
| 481 |
+
"execution_count": 11,
|
| 482 |
+
"metadata": {},
|
| 483 |
+
"output_type": "execute_result"
|
| 484 |
+
}
|
| 485 |
+
],
|
| 486 |
+
"source": [
|
| 487 |
+
"graph = dgl.to_bidirected(graph)\n",
|
| 488 |
+
"src, dst = graph.edges()\n",
|
| 489 |
+
"mask = src < dst\n",
|
| 490 |
+
"src = src[mask].numpy()\n",
|
| 491 |
+
"dst = dst[mask].numpy()\n",
|
| 492 |
+
"src.shape[0]"
|
| 493 |
+
]
|
| 494 |
+
},
|
| 495 |
+
{
|
| 496 |
+
"cell_type": "code",
|
| 497 |
+
"execution_count": 12,
|
| 498 |
+
"id": "dda0ddcc",
|
| 499 |
+
"metadata": {},
|
| 500 |
+
"outputs": [
|
| 501 |
+
{
|
| 502 |
+
"data": {
|
| 503 |
+
"text/plain": [
|
| 504 |
+
"array([ 0, 1, 3, ..., 169186, 169187, 169188])"
|
| 505 |
+
]
|
| 506 |
+
},
|
| 507 |
+
"execution_count": 12,
|
| 508 |
+
"metadata": {},
|
| 509 |
+
"output_type": "execute_result"
|
| 510 |
+
}
|
| 511 |
+
],
|
| 512 |
+
"source": [
|
| 513 |
+
"paper_ids_with_author_fos = np.unique(np.concat((pa_pids, pf_pids)))\n",
|
| 514 |
+
"paper_ids_with_author_fos"
|
| 515 |
+
]
|
| 516 |
+
},
|
| 517 |
+
{
|
| 518 |
+
"cell_type": "code",
|
| 519 |
+
"execution_count": 13,
|
| 520 |
+
"id": "963748a5",
|
| 521 |
+
"metadata": {},
|
| 522 |
+
"outputs": [
|
| 523 |
+
{
|
| 524 |
+
"name": "stdout",
|
| 525 |
+
"output_type": "stream",
|
| 526 |
+
"text": [
|
| 527 |
+
"Number of paper-paper links 468995\n"
|
| 528 |
+
]
|
| 529 |
+
}
|
| 530 |
+
],
|
| 531 |
+
"source": [
|
| 532 |
+
"mask = np.isin(src, paper_ids_with_author_fos) & np.isin(dst, paper_ids_with_author_fos)\n",
|
| 533 |
+
"src = src[mask]\n",
|
| 534 |
+
"dst = dst[mask]\n",
|
| 535 |
+
"print('Number of paper-paper links', dst.shape[0])"
|
| 536 |
+
]
|
| 537 |
+
},
|
| 538 |
+
{
|
| 539 |
+
"cell_type": "code",
|
| 540 |
+
"execution_count": null,
|
| 541 |
+
"id": "b20b2aef",
|
| 542 |
+
"metadata": {},
|
| 543 |
+
"outputs": [],
|
| 544 |
+
"source": []
|
| 545 |
+
},
|
| 546 |
+
{
|
| 547 |
+
"cell_type": "markdown",
|
| 548 |
+
"id": "b9150194",
|
| 549 |
+
"metadata": {},
|
| 550 |
+
"source": [
|
| 551 |
+
"## Reset Id"
|
| 552 |
+
]
|
| 553 |
+
},
|
| 554 |
+
{
|
| 555 |
+
"cell_type": "code",
|
| 556 |
+
"execution_count": 14,
|
| 557 |
+
"id": "74233e4d",
|
| 558 |
+
"metadata": {},
|
| 559 |
+
"outputs": [
|
| 560 |
+
{
|
| 561 |
+
"name": "stdout",
|
| 562 |
+
"output_type": "stream",
|
| 563 |
+
"text": [
|
| 564 |
+
"Number of papers 81634\n"
|
| 565 |
+
]
|
| 566 |
+
},
|
| 567 |
+
{
|
| 568 |
+
"data": {
|
| 569 |
+
"text/plain": [
|
| 570 |
+
"array([ 0, 1, 3, ..., 169186, 169187, 169188])"
|
| 571 |
+
]
|
| 572 |
+
},
|
| 573 |
+
"execution_count": 14,
|
| 574 |
+
"metadata": {},
|
| 575 |
+
"output_type": "execute_result"
|
| 576 |
+
}
|
| 577 |
+
],
|
| 578 |
+
"source": [
|
| 579 |
+
"paper_id_encoder = LabelEncoder()\n",
|
| 580 |
+
"paper_id_encoder.fit(paper_ids_with_author_fos)\n",
|
| 581 |
+
"print('Number of papers', len(paper_id_encoder.classes_))\n",
|
| 582 |
+
"paper_id_encoder.classes_"
|
| 583 |
+
]
|
| 584 |
+
},
|
| 585 |
+
{
|
| 586 |
+
"cell_type": "code",
|
| 587 |
+
"execution_count": 15,
|
| 588 |
+
"id": "3c8e3817",
|
| 589 |
+
"metadata": {},
|
| 590 |
+
"outputs": [],
|
| 591 |
+
"source": [
|
| 592 |
+
"pa_pids = paper_id_encoder.transform(pa_pids).astype(np.int32)\n",
|
| 593 |
+
"pf_pids = paper_id_encoder.transform(pf_pids).astype(np.int32)\n",
|
| 594 |
+
"src = paper_id_encoder.transform(src).astype(np.int32)\n",
|
| 595 |
+
"dst = paper_id_encoder.transform(dst).astype(np.int32)"
|
| 596 |
+
]
|
| 597 |
+
},
|
| 598 |
+
{
|
| 599 |
+
"cell_type": "code",
|
| 600 |
+
"execution_count": 24,
|
| 601 |
+
"id": "c89a92eb",
|
| 602 |
+
"metadata": {},
|
| 603 |
+
"outputs": [
|
| 604 |
+
{
|
| 605 |
+
"data": {
|
| 606 |
+
"text/plain": [
|
| 607 |
+
"[110, 15, 24, 30, 26]"
|
| 608 |
+
]
|
| 609 |
+
},
|
| 610 |
+
"execution_count": 24,
|
| 611 |
+
"metadata": {},
|
| 612 |
+
"output_type": "execute_result"
|
| 613 |
+
}
|
| 614 |
+
],
|
| 615 |
+
"source": [
|
| 616 |
+
"paper_labels = label[paper_id_encoder.classes_].astype(np.int8)\n",
|
| 617 |
+
"\n",
|
| 618 |
+
"from collections import Counter\n",
|
| 619 |
+
"list(Counter(paper_labels).values())[-5:]"
|
| 620 |
+
]
|
| 621 |
+
},
|
| 622 |
+
{
|
| 623 |
+
"cell_type": "code",
|
| 624 |
+
"execution_count": 26,
|
| 625 |
+
"id": "84f21cdd",
|
| 626 |
+
"metadata": {},
|
| 627 |
+
"outputs": [
|
| 628 |
+
{
|
| 629 |
+
"data": {
|
| 630 |
+
"text/plain": [
|
| 631 |
+
"(81634,)"
|
| 632 |
+
]
|
| 633 |
+
},
|
| 634 |
+
"execution_count": 26,
|
| 635 |
+
"metadata": {},
|
| 636 |
+
"output_type": "execute_result"
|
| 637 |
+
}
|
| 638 |
+
],
|
| 639 |
+
"source": [
|
| 640 |
+
"paper_years = years[paper_id_encoder.classes_].astype(np.int16)\n",
|
| 641 |
+
"paper_years.shape"
|
| 642 |
+
]
|
| 643 |
+
},
|
| 644 |
+
{
|
| 645 |
+
"cell_type": "code",
|
| 646 |
+
"execution_count": null,
|
| 647 |
+
"id": "ad39969b",
|
| 648 |
+
"metadata": {},
|
| 649 |
+
"outputs": [],
|
| 650 |
+
"source": [
|
| 651 |
+
"data = {\n",
|
| 652 |
+
" 'paper_labels': paper_labels,\n",
|
| 653 |
+
" 'paper_years': paper_years,\n",
|
| 654 |
+
" 'paper-paper': (src, dst),\n",
|
| 655 |
+
" 'paper-author': (pa_pids, pa_aids),\n",
|
| 656 |
+
" 'paper-fos': (pf_pids, pf_fids),\n",
|
| 657 |
+
"}"
|
| 658 |
+
]
|
| 659 |
+
},
|
| 660 |
+
{
|
| 661 |
+
"cell_type": "code",
|
| 662 |
+
"execution_count": null,
|
| 663 |
+
"id": "e9549b36",
|
| 664 |
+
"metadata": {},
|
| 665 |
+
"outputs": [],
|
| 666 |
+
"source": []
|
| 667 |
+
},
|
| 668 |
+
{
|
| 669 |
+
"cell_type": "code",
|
| 670 |
+
"execution_count": 28,
|
| 671 |
+
"id": "f7bf606a",
|
| 672 |
+
"metadata": {},
|
| 673 |
+
"outputs": [
|
| 674 |
+
{
|
| 675 |
+
"data": {
|
| 676 |
+
"text/html": [
|
| 677 |
+
"<div>\n",
|
| 678 |
+
"<style scoped>\n",
|
| 679 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 680 |
+
" vertical-align: middle;\n",
|
| 681 |
+
" }\n",
|
| 682 |
+
"\n",
|
| 683 |
+
" .dataframe tbody tr th {\n",
|
| 684 |
+
" vertical-align: top;\n",
|
| 685 |
+
" }\n",
|
| 686 |
+
"\n",
|
| 687 |
+
" .dataframe thead th {\n",
|
| 688 |
+
" text-align: right;\n",
|
| 689 |
+
" }\n",
|
| 690 |
+
"</style>\n",
|
| 691 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 692 |
+
" <thead>\n",
|
| 693 |
+
" <tr style=\"text-align: right;\">\n",
|
| 694 |
+
" <th></th>\n",
|
| 695 |
+
" <th>mag_id</th>\n",
|
| 696 |
+
" <th>title</th>\n",
|
| 697 |
+
" <th>abstract</th>\n",
|
| 698 |
+
" <th>label_id</th>\n",
|
| 699 |
+
" <th>category</th>\n",
|
| 700 |
+
" </tr>\n",
|
| 701 |
+
" <tr>\n",
|
| 702 |
+
" <th>ID</th>\n",
|
| 703 |
+
" <th></th>\n",
|
| 704 |
+
" <th></th>\n",
|
| 705 |
+
" <th></th>\n",
|
| 706 |
+
" <th></th>\n",
|
| 707 |
+
" <th></th>\n",
|
| 708 |
+
" </tr>\n",
|
| 709 |
+
" </thead>\n",
|
| 710 |
+
" <tbody>\n",
|
| 711 |
+
" <tr>\n",
|
| 712 |
+
" <th>0</th>\n",
|
| 713 |
+
" <td>9657784</td>\n",
|
| 714 |
+
" <td>Title: evasion attacks against machine learnin...</td>\n",
|
| 715 |
+
" <td>Abstract: In security-sensitive applications, ...</td>\n",
|
| 716 |
+
" <td>4</td>\n",
|
| 717 |
+
" <td>arxiv cs cr</td>\n",
|
| 718 |
+
" </tr>\n",
|
| 719 |
+
" <tr>\n",
|
| 720 |
+
" <th>1</th>\n",
|
| 721 |
+
" <td>39886162</td>\n",
|
| 722 |
+
" <td>Title: how hard is computing parity with noisy...</td>\n",
|
| 723 |
+
" <td>Abstract: We show a tight lower bound of $\\Ome...</td>\n",
|
| 724 |
+
" <td>5</td>\n",
|
| 725 |
+
" <td>arxiv cs dc</td>\n",
|
| 726 |
+
" </tr>\n",
|
| 727 |
+
" <tr>\n",
|
| 728 |
+
" <th>3</th>\n",
|
| 729 |
+
" <td>121432379</td>\n",
|
| 730 |
+
" <td>Title: a promise theory perspective on data ne...</td>\n",
|
| 731 |
+
" <td>Abstract: Networking is undergoing a transform...</td>\n",
|
| 732 |
+
" <td>8</td>\n",
|
| 733 |
+
" <td>arxiv cs ni</td>\n",
|
| 734 |
+
" </tr>\n",
|
| 735 |
+
" <tr>\n",
|
| 736 |
+
" <th>6</th>\n",
|
| 737 |
+
" <td>1444859417</td>\n",
|
| 738 |
+
" <td>Title: webvrgis based city bigdata 3d visualiz...</td>\n",
|
| 739 |
+
" <td>Abstract: This paper shows the WEBVRGIS platfo...</td>\n",
|
| 740 |
+
" <td>6</td>\n",
|
| 741 |
+
" <td>arxiv cs hc</td>\n",
|
| 742 |
+
" </tr>\n",
|
| 743 |
+
" <tr>\n",
|
| 744 |
+
" <th>7</th>\n",
|
| 745 |
+
" <td>1483430697</td>\n",
|
| 746 |
+
" <td>Title: information theoretic authentication an...</td>\n",
|
| 747 |
+
" <td>Abstract: In the splitting model, information ...</td>\n",
|
| 748 |
+
" <td>4</td>\n",
|
| 749 |
+
" <td>arxiv cs cr</td>\n",
|
| 750 |
+
" </tr>\n",
|
| 751 |
+
" </tbody>\n",
|
| 752 |
+
"</table>\n",
|
| 753 |
+
"</div>"
|
| 754 |
+
],
|
| 755 |
+
"text/plain": [
|
| 756 |
+
" mag_id title \\\n",
|
| 757 |
+
"ID \n",
|
| 758 |
+
"0 9657784 Title: evasion attacks against machine learnin... \n",
|
| 759 |
+
"1 39886162 Title: how hard is computing parity with noisy... \n",
|
| 760 |
+
"3 121432379 Title: a promise theory perspective on data ne... \n",
|
| 761 |
+
"6 1444859417 Title: webvrgis based city bigdata 3d visualiz... \n",
|
| 762 |
+
"7 1483430697 Title: information theoretic authentication an... \n",
|
| 763 |
+
"\n",
|
| 764 |
+
" abstract label_id category \n",
|
| 765 |
+
"ID \n",
|
| 766 |
+
"0 Abstract: In security-sensitive applications, ... 4 arxiv cs cr \n",
|
| 767 |
+
"1 Abstract: We show a tight lower bound of $\\Ome... 5 arxiv cs dc \n",
|
| 768 |
+
"3 Abstract: Networking is undergoing a transform... 8 arxiv cs ni \n",
|
| 769 |
+
"6 Abstract: This paper shows the WEBVRGIS platfo... 6 arxiv cs hc \n",
|
| 770 |
+
"7 Abstract: In the splitting model, information ... 4 arxiv cs cr "
|
| 771 |
+
]
|
| 772 |
+
},
|
| 773 |
+
"execution_count": 28,
|
| 774 |
+
"metadata": {},
|
| 775 |
+
"output_type": "execute_result"
|
| 776 |
+
}
|
| 777 |
+
],
|
| 778 |
+
"source": [
|
| 779 |
+
"papers.set_index(keys='ID', inplace=True)\n",
|
| 780 |
+
"papers = papers.loc[paper_id_encoder.classes_]\n",
|
| 781 |
+
"papers.drop('text', inplace=True, axis=1)\n",
|
| 782 |
+
"papers.head()"
|
| 783 |
+
]
|
| 784 |
+
},
|
| 785 |
+
{
|
| 786 |
+
"cell_type": "code",
|
| 787 |
+
"execution_count": 29,
|
| 788 |
+
"id": "47e19edc",
|
| 789 |
+
"metadata": {},
|
| 790 |
+
"outputs": [
|
| 791 |
+
{
|
| 792 |
+
"data": {
|
| 793 |
+
"text/html": [
|
| 794 |
+
"<div>\n",
|
| 795 |
+
"<style scoped>\n",
|
| 796 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 797 |
+
" vertical-align: middle;\n",
|
| 798 |
+
" }\n",
|
| 799 |
+
"\n",
|
| 800 |
+
" .dataframe tbody tr th {\n",
|
| 801 |
+
" vertical-align: top;\n",
|
| 802 |
+
" }\n",
|
| 803 |
+
"\n",
|
| 804 |
+
" .dataframe thead th {\n",
|
| 805 |
+
" text-align: right;\n",
|
| 806 |
+
" }\n",
|
| 807 |
+
"</style>\n",
|
| 808 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 809 |
+
" <thead>\n",
|
| 810 |
+
" <tr style=\"text-align: right;\">\n",
|
| 811 |
+
" <th></th>\n",
|
| 812 |
+
" <th>mag_id</th>\n",
|
| 813 |
+
" <th>title</th>\n",
|
| 814 |
+
" <th>abstract</th>\n",
|
| 815 |
+
" <th>label_id</th>\n",
|
| 816 |
+
" <th>category</th>\n",
|
| 817 |
+
" </tr>\n",
|
| 818 |
+
" <tr>\n",
|
| 819 |
+
" <th>ID</th>\n",
|
| 820 |
+
" <th></th>\n",
|
| 821 |
+
" <th></th>\n",
|
| 822 |
+
" <th></th>\n",
|
| 823 |
+
" <th></th>\n",
|
| 824 |
+
" <th></th>\n",
|
| 825 |
+
" </tr>\n",
|
| 826 |
+
" </thead>\n",
|
| 827 |
+
" <tbody>\n",
|
| 828 |
+
" <tr>\n",
|
| 829 |
+
" <th>0</th>\n",
|
| 830 |
+
" <td>9657784</td>\n",
|
| 831 |
+
" <td>Evasion Attacks against Machine Learning at Te...</td>\n",
|
| 832 |
+
" <td>In security-sensitive applications, the succes...</td>\n",
|
| 833 |
+
" <td>4</td>\n",
|
| 834 |
+
" <td>cs.CR</td>\n",
|
| 835 |
+
" </tr>\n",
|
| 836 |
+
" <tr>\n",
|
| 837 |
+
" <th>1</th>\n",
|
| 838 |
+
" <td>39886162</td>\n",
|
| 839 |
+
" <td>How Hard is Computing Parity with Noisy Commun...</td>\n",
|
| 840 |
+
" <td>We show a tight lower bound of $\\Omega(N \\log\\...</td>\n",
|
| 841 |
+
" <td>5</td>\n",
|
| 842 |
+
" <td>cs.DC</td>\n",
|
| 843 |
+
" </tr>\n",
|
| 844 |
+
" <tr>\n",
|
| 845 |
+
" <th>3</th>\n",
|
| 846 |
+
" <td>121432379</td>\n",
|
| 847 |
+
" <td>A Promise Theory Perspective on Data Networks</td>\n",
|
| 848 |
+
" <td>Networking is undergoing a transformation thro...</td>\n",
|
| 849 |
+
" <td>8</td>\n",
|
| 850 |
+
" <td>cs.NI</td>\n",
|
| 851 |
+
" </tr>\n",
|
| 852 |
+
" <tr>\n",
|
| 853 |
+
" <th>6</th>\n",
|
| 854 |
+
" <td>1444859417</td>\n",
|
| 855 |
+
" <td>Webvrgis Based City Bigdata 3d Visualization a...</td>\n",
|
| 856 |
+
" <td>This paper shows the WEBVRGIS platform overlyi...</td>\n",
|
| 857 |
+
" <td>6</td>\n",
|
| 858 |
+
" <td>cs.HC</td>\n",
|
| 859 |
+
" </tr>\n",
|
| 860 |
+
" <tr>\n",
|
| 861 |
+
" <th>7</th>\n",
|
| 862 |
+
" <td>1483430697</td>\n",
|
| 863 |
+
" <td>Information Theoretic Authentication and Secre...</td>\n",
|
| 864 |
+
" <td>In the splitting model, information theoretic ...</td>\n",
|
| 865 |
+
" <td>4</td>\n",
|
| 866 |
+
" <td>cs.CR</td>\n",
|
| 867 |
+
" </tr>\n",
|
| 868 |
+
" </tbody>\n",
|
| 869 |
+
"</table>\n",
|
| 870 |
+
"</div>"
|
| 871 |
+
],
|
| 872 |
+
"text/plain": [
|
| 873 |
+
" mag_id title \\\n",
|
| 874 |
+
"ID \n",
|
| 875 |
+
"0 9657784 Evasion Attacks against Machine Learning at Te... \n",
|
| 876 |
+
"1 39886162 How Hard is Computing Parity with Noisy Commun... \n",
|
| 877 |
+
"3 121432379 A Promise Theory Perspective on Data Networks \n",
|
| 878 |
+
"6 1444859417 Webvrgis Based City Bigdata 3d Visualization a... \n",
|
| 879 |
+
"7 1483430697 Information Theoretic Authentication and Secre... \n",
|
| 880 |
+
"\n",
|
| 881 |
+
" abstract label_id category \n",
|
| 882 |
+
"ID \n",
|
| 883 |
+
"0 In security-sensitive applications, the succes... 4 cs.CR \n",
|
| 884 |
+
"1 We show a tight lower bound of $\\Omega(N \\log\\... 5 cs.DC \n",
|
| 885 |
+
"3 Networking is undergoing a transformation thro... 8 cs.NI \n",
|
| 886 |
+
"6 This paper shows the WEBVRGIS platform overlyi... 6 cs.HC \n",
|
| 887 |
+
"7 In the splitting model, information theoretic ... 4 cs.CR "
|
| 888 |
+
]
|
| 889 |
+
},
|
| 890 |
+
"execution_count": 29,
|
| 891 |
+
"metadata": {},
|
| 892 |
+
"output_type": "execute_result"
|
| 893 |
+
}
|
| 894 |
+
],
|
| 895 |
+
"source": [
|
| 896 |
+
"papers['title'] = papers['title'].str[7:]\n",
|
| 897 |
+
"papers['abstract'] = papers['abstract'].str[10:]\n",
|
| 898 |
+
"papers['category'] = papers['category'].apply(lambda x: f'cs.{x[-2:].upper()}')\n",
|
| 899 |
+
"\n",
|
| 900 |
+
"def format_title(title):\n",
|
| 901 |
+
" exceptions = {'is', 'are', 'with', 'and', 'the', 'a', 'an', 'but', 'for', 'nor', 'on', 'at', 'to', 'by', 'of', 'against', 'over', 'in', 'via'}\n",
|
| 902 |
+
" words = title.split()\n",
|
| 903 |
+
" formatted_words = [\n",
|
| 904 |
+
" word.capitalize() if word not in exceptions or i == 0 else word\n",
|
| 905 |
+
" for i, word in enumerate(words)\n",
|
| 906 |
+
" ]\n",
|
| 907 |
+
" return ' '.join(formatted_words)\n",
|
| 908 |
+
"\n",
|
| 909 |
+
"papers['title'] = papers['title'].apply(format_title)\n",
|
| 910 |
+
"papers.head()"
|
| 911 |
+
]
|
| 912 |
+
},
|
| 913 |
+
{
|
| 914 |
+
"cell_type": "code",
|
| 915 |
+
"execution_count": null,
|
| 916 |
+
"id": "f069ba19",
|
| 917 |
+
"metadata": {},
|
| 918 |
+
"outputs": [],
|
| 919 |
+
"source": [
|
| 920 |
+
"papers.reset_index(drop=True, inplace=True)\n",
|
| 921 |
+
"papers.to_csv('Paper.csv', index=False)"
|
| 922 |
+
]
|
| 923 |
+
},
|
| 924 |
+
{
|
| 925 |
+
"cell_type": "markdown",
|
| 926 |
+
"id": "9788b560",
|
| 927 |
+
"metadata": {},
|
| 928 |
+
"source": [
|
| 929 |
+
"### Node Features\n",
|
| 930 |
+
"\n",
|
| 931 |
+
"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",
|
| 932 |
+
"\n",
|
| 933 |
+
"\n",
|
| 934 |
+
"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",
|
| 935 |
+
"\n",
|
| 936 |
+
"all-MiniLM-L6-v2\n",
|
| 937 |
+
"\n",
|
| 938 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 939 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 940 |
+
"Max Sequence Length:\t256\n",
|
| 941 |
+
"Dimensions:\t384\n",
|
| 942 |
+
"Normalized Embeddings:\ttrue\n",
|
| 943 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 944 |
+
"Size:\t80 MB\n",
|
| 945 |
+
"Pooling:\tMean Pooling\n",
|
| 946 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 947 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 948 |
+
]
|
| 949 |
+
},
|
| 950 |
+
{
|
| 951 |
+
"cell_type": "code",
|
| 952 |
+
"execution_count": 32,
|
| 953 |
+
"id": "8b547164",
|
| 954 |
+
"metadata": {},
|
| 955 |
+
"outputs": [
|
| 956 |
+
{
|
| 957 |
+
"data": {
|
| 958 |
+
"text/plain": [
|
| 959 |
+
"SentenceTransformer(\n",
|
| 960 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 961 |
+
" (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",
|
| 962 |
+
" (2): Normalize()\n",
|
| 963 |
+
")"
|
| 964 |
+
]
|
| 965 |
+
},
|
| 966 |
+
"execution_count": 32,
|
| 967 |
+
"metadata": {},
|
| 968 |
+
"output_type": "execute_result"
|
| 969 |
+
}
|
| 970 |
+
],
|
| 971 |
+
"source": [
|
| 972 |
+
"import torch\n",
|
| 973 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 974 |
+
"\n",
|
| 975 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 976 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 977 |
+
"model"
|
| 978 |
+
]
|
| 979 |
+
},
|
| 980 |
+
{
|
| 981 |
+
"cell_type": "code",
|
| 982 |
+
"execution_count": 42,
|
| 983 |
+
"id": "290ad987",
|
| 984 |
+
"metadata": {},
|
| 985 |
+
"outputs": [],
|
| 986 |
+
"source": [
|
| 987 |
+
"text = papers['title'] + ' ' + papers['abstract']"
|
| 988 |
+
]
|
| 989 |
+
},
|
| 990 |
+
{
|
| 991 |
+
"cell_type": "code",
|
| 992 |
+
"execution_count": 43,
|
| 993 |
+
"id": "7a001955",
|
| 994 |
+
"metadata": {},
|
| 995 |
+
"outputs": [
|
| 996 |
+
{
|
| 997 |
+
"name": "stderr",
|
| 998 |
+
"output_type": "stream",
|
| 999 |
+
"text": [
|
| 1000 |
+
"Batches: 100%|██████████| 20/20 [01:04<00:00, 3.22s/it]\n"
|
| 1001 |
+
]
|
| 1002 |
+
}
|
| 1003 |
+
],
|
| 1004 |
+
"source": [
|
| 1005 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
|
| 1006 |
+
]
|
| 1007 |
+
},
|
| 1008 |
+
{
|
| 1009 |
+
"cell_type": "code",
|
| 1010 |
+
"execution_count": 44,
|
| 1011 |
+
"id": "018e0582",
|
| 1012 |
+
"metadata": {},
|
| 1013 |
+
"outputs": [
|
| 1014 |
+
{
|
| 1015 |
+
"data": {
|
| 1016 |
+
"text/plain": [
|
| 1017 |
+
"{'paper_labels': array([ 4, 5, 8, ..., 16, 30, 30], dtype=int8),\n",
|
| 1018 |
+
" 'paper_years': array([2013, 2015, 2014, ..., 2019, 2019, 2019], dtype=int16),\n",
|
| 1019 |
+
" 'paper-paper': (array([ 0, 0, 0, ..., 81308, 81312, 81465], dtype=int32),\n",
|
| 1020 |
+
" array([ 215, 347, 930, ..., 81577, 81345, 81519], dtype=int32)),\n",
|
| 1021 |
+
" 'paper_author': (array([19239, 19239, 19239, ..., 35209, 53724, 53724], dtype=int32),\n",
|
| 1022 |
+
" array([127457, 19897, 127067, ..., 20462, 87283, 1618], dtype=int32)),\n",
|
| 1023 |
+
" 'paper_fos': (array([19239, 19239, 19239, ..., 53724, 53724, 53724], dtype=int32),\n",
|
| 1024 |
+
" array([ 2826, 9870, 11927, ..., 2826, 14082, 8436], dtype=int32)),\n",
|
| 1025 |
+
" 'paper_feats': array([[-0.09871526, -0.01083333, -0.05048474, ..., 0.01055331,\n",
|
| 1026 |
+
" 0.03491311, -0.01338707],\n",
|
| 1027 |
+
" [-0.00965661, -0.05066415, 0.05266945, ..., 0.09849689,\n",
|
| 1028 |
+
" -0.06759875, -0.00852178],\n",
|
| 1029 |
+
" [-0.06771555, -0.02296721, 0.07591261, ..., -0.04729789,\n",
|
| 1030 |
+
" 0.01239418, -0.02592889],\n",
|
| 1031 |
+
" ...,\n",
|
| 1032 |
+
" [-0.0010215 , -0.09171138, 0.02063811, ..., 0.01867299,\n",
|
| 1033 |
+
" -0.06674339, -0.00320282],\n",
|
| 1034 |
+
" [-0.00800873, -0.09252207, -0.08150839, ..., 0.04762044,\n",
|
| 1035 |
+
" 0.03962403, 0.01795155],\n",
|
| 1036 |
+
" [-0.07200024, -0.0933908 , -0.02737658, ..., 0.09808387,\n",
|
| 1037 |
+
" 0.03837816, -0.05359345]], dtype=float32)}"
|
| 1038 |
+
]
|
| 1039 |
+
},
|
| 1040 |
+
"execution_count": 44,
|
| 1041 |
+
"metadata": {},
|
| 1042 |
+
"output_type": "execute_result"
|
| 1043 |
+
}
|
| 1044 |
+
],
|
| 1045 |
+
"source": [
|
| 1046 |
+
"data['paper_feats'] = feats\n",
|
| 1047 |
+
"data"
|
| 1048 |
+
]
|
| 1049 |
+
},
|
| 1050 |
+
{
|
| 1051 |
+
"cell_type": "code",
|
| 1052 |
+
"execution_count": null,
|
| 1053 |
+
"id": "a8550ed0",
|
| 1054 |
+
"metadata": {},
|
| 1055 |
+
"outputs": [],
|
| 1056 |
+
"source": [
|
| 1057 |
+
"import pickle\n",
|
| 1058 |
+
"\n",
|
| 1059 |
+
"with open('arxiv.pkl', 'wb') as f:\n",
|
| 1060 |
+
" pickle.dump(data, f)"
|
| 1061 |
+
]
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"cell_type": "code",
|
| 1065 |
+
"execution_count": null,
|
| 1066 |
+
"id": "21703238",
|
| 1067 |
+
"metadata": {},
|
| 1068 |
+
"outputs": [],
|
| 1069 |
+
"source": []
|
| 1070 |
+
}
|
| 1071 |
+
],
|
| 1072 |
+
"metadata": {
|
| 1073 |
+
"kernelspec": {
|
| 1074 |
+
"display_name": "Python 3",
|
| 1075 |
+
"language": "python",
|
| 1076 |
+
"name": "python3"
|
| 1077 |
+
},
|
| 1078 |
+
"language_info": {
|
| 1079 |
+
"codemirror_mode": {
|
| 1080 |
+
"name": "ipython",
|
| 1081 |
+
"version": 3
|
| 1082 |
+
},
|
| 1083 |
+
"file_extension": ".py",
|
| 1084 |
+
"mimetype": "text/x-python",
|
| 1085 |
+
"name": "python",
|
| 1086 |
+
"nbconvert_exporter": "python",
|
| 1087 |
+
"pygments_lexer": "ipython3",
|
| 1088 |
+
"version": "3.10.12"
|
| 1089 |
+
}
|
| 1090 |
+
},
|
| 1091 |
+
"nbformat": 4,
|
| 1092 |
+
"nbformat_minor": 5
|
| 1093 |
+
}
|
book/Book.csv.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:92e3500b996618bb1452417c850ea29486e10d09a9ce4dc8ee6578ca83b31d07
|
| 3 |
+
size 297654438
|
book/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Book: Book Publication Network
|
| 2 |
+
|
| 3 |
+
The Book dataset is a heterogeneous literature network composed of a subset of [GoodReads](https://www.goodreads.com), the world's largest social cataloging website for book tracking, book recommendations, book reviews, and book discussions. We construct our HTAG based on the source data provided by [the Goodreads Book Graph dataset](https://mengtingwan.github.io/data/goodreads) [1]. After processing, it contains three types of entities-books (594,484 nodes), authors (147,863 nodes), and publishers (43,910 nodes)—as well as three types of directed relations connecting three types of entities—a book "is similar to" another book, an author "writes" a book, and a book "is published by" a publisher. Books are associated with their titles and descriptions, and all the other types of entities are textless. We concatenate the book title and description and pass it to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each book node. Each book is categorized into one or more of the following eight genres: "children", "poetry", "young-adult", "history, historical fiction, biography", "fantasy, paranormal", "mystery, thriller, crime", "comics, graphic", and "romance". Additionally, each book is associated with its year of publication.
|
| 4 |
+
|
| 5 |
+
**Prediction task.**
|
| 6 |
+
The task is to predict the genres of given books, which is formulated as a multi-label classification problem. We also use Micro-F1 and Macro-F1 scores to evaluate the performance.
|
| 7 |
+
|
| 8 |
+
**Dataset splitting.**
|
| 9 |
+
The dataset is split based on publication year. Specifically, we train on books published up to 2011, validate on books published in 2012, and test on books published since 2013.
|
| 10 |
+
|
| 11 |
+
**Dataset statistics.**
|
| 12 |
+
|
| 13 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 14 |
+
| ----------- | ----------------------- | --------- | -------------- |
|
| 15 |
+
| **786,257** | **9,035,291** | 8 | Train: 330,201 |
|
| 16 |
+
| Book | Book-Book: 7,614,902 | | Valid: 57,220 |
|
| 17 |
+
| Author | Book-Author: 825,905 | | Test: 207,063 |
|
| 18 |
+
| Publisher | Book-Publisher: 594,484 | | |
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
[1] Wan, M., & McAuley, J. (2018, September). Item recommendation on monotonic behavior chains. In *Proceedings of the 12th ACM conference on recommender systems* (pp. 86-94).
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Dataset Construction
|
| 27 |
+
|
| 28 |
+
1. Download `goodreads_books.json.gz` and `goodreads_book_genres_initial.json.gz` from [Goodreads Book Graph Datasets](https://mengtingwan.github.io/data/goodreads.html)
|
| 29 |
+
2. Run `extract_from_gbgd.py`
|
| 30 |
+
3. Run `graph_builder.ipynb`
|
book/book.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fddc329ea6cff81fee450dd7ffd53fc38ee26c6669fa39b818ccca47af9e8a37
|
| 3 |
+
size 961477007
|
book/extract_from_gbgd.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import json
|
| 3 |
+
import gzip
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
print('Extracting data from goodreads_books.json.gz...')
|
| 8 |
+
start_time = time.time()
|
| 9 |
+
with gzip.open('goodreads_books.json.gz', 'rt', encoding='utf-8') as f:
|
| 10 |
+
with open(f'goodreads_books.csv', 'w', encoding='utf-8', newline='') as csvfile:
|
| 11 |
+
writer = csv.writer(csvfile)
|
| 12 |
+
heads = ['book_id', 'title', 'description', 'publication_year', 'publisher', 'authors',
|
| 13 |
+
'similar_books']
|
| 14 |
+
writer.writerow(heads)
|
| 15 |
+
|
| 16 |
+
num = 0
|
| 17 |
+
rows = []
|
| 18 |
+
for line in f:
|
| 19 |
+
content = json.loads(line.strip())
|
| 20 |
+
description = content['description']
|
| 21 |
+
publication_year = content['publication_year']
|
| 22 |
+
title = content['title']
|
| 23 |
+
if description != '' and publication_year != '' and title != '':
|
| 24 |
+
language_code = content['language_code']
|
| 25 |
+
if language_code == '' or language_code.startswith('en'):
|
| 26 |
+
book_id = content['book_id']
|
| 27 |
+
publisher = content['publisher']
|
| 28 |
+
authors = [int(author['author_id']) for author in content['authors']]
|
| 29 |
+
similar_books = [int(similar_book) for similar_book in content['similar_books']]
|
| 30 |
+
row = [book_id, title, description, publication_year, publisher, authors, similar_books]
|
| 31 |
+
rows.append(row)
|
| 32 |
+
num += 1
|
| 33 |
+
if num % 5000 == 0:
|
| 34 |
+
writer.writerows(rows)
|
| 35 |
+
rows = []
|
| 36 |
+
print(num)
|
| 37 |
+
if len(rows) > 0:
|
| 38 |
+
writer.writerows(rows)
|
| 39 |
+
print(num, f'{time.time() - start_time}s', 'Done!')
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# print('Extracting data from goodreads_book_genres_initial.json.gz...')
|
| 43 |
+
# start_time = time.time()
|
| 44 |
+
# with gzip.open('goodreads_book_genres_initial.json.gz', 'rt', encoding='utf-8') as f:
|
| 45 |
+
# with open(f'goodreads_book_genres_initial.csv', 'w', encoding='utf-8', newline='') as csvfile:
|
| 46 |
+
# writer = csv.writer(csvfile)
|
| 47 |
+
# heads = ['book_id', 'genres']
|
| 48 |
+
# writer.writerow(heads)
|
| 49 |
+
#
|
| 50 |
+
# num = 0
|
| 51 |
+
# rows = []
|
| 52 |
+
# non_genres = ['fiction', 'non-fiction']
|
| 53 |
+
# for line in f:
|
| 54 |
+
# content = json.loads(line.strip())
|
| 55 |
+
# genres = [genre for genre in content['genres'] if genre not in non_genres]
|
| 56 |
+
# if len(genres) > 0:
|
| 57 |
+
# row = [content['book_id'], genres]
|
| 58 |
+
# rows.append(row)
|
| 59 |
+
# num += 1
|
| 60 |
+
# if num % 5000 == 0:
|
| 61 |
+
# writer.writerows(rows)
|
| 62 |
+
# rows = []
|
| 63 |
+
# print(num)
|
| 64 |
+
# if len(rows) > 0:
|
| 65 |
+
# writer.writerows(rows)
|
| 66 |
+
# print(num, f'{time.time() - start_time}s', 'Done!')
|
book/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,1522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "initial_id",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"ExecuteTime": {
|
| 9 |
+
"end_time": "2024-12-01T15:02:01.021005Z",
|
| 10 |
+
"start_time": "2024-12-01T15:01:58.161848Z"
|
| 11 |
+
},
|
| 12 |
+
"collapsed": true
|
| 13 |
+
},
|
| 14 |
+
"outputs": [],
|
| 15 |
+
"source": [
|
| 16 |
+
"import itertools\n",
|
| 17 |
+
"import numpy as np\n",
|
| 18 |
+
"import pandas as pd\n",
|
| 19 |
+
"from collections import Counter\n",
|
| 20 |
+
"from sklearn.preprocessing import LabelEncoder\n",
|
| 21 |
+
"from sklearn.preprocessing import MultiLabelBinarizer"
|
| 22 |
+
]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"cell_type": "code",
|
| 26 |
+
"execution_count": 2,
|
| 27 |
+
"id": "9b91b6a97eb2b9be",
|
| 28 |
+
"metadata": {
|
| 29 |
+
"ExecuteTime": {
|
| 30 |
+
"end_time": "2024-12-01T15:02:57.510795Z",
|
| 31 |
+
"start_time": "2024-12-01T15:02:01.039033Z"
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
"outputs": [
|
| 35 |
+
{
|
| 36 |
+
"name": "stdout",
|
| 37 |
+
"output_type": "stream",
|
| 38 |
+
"text": [
|
| 39 |
+
"(1259417, 7)\n"
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"data": {
|
| 44 |
+
"text/html": [
|
| 45 |
+
"<div>\n",
|
| 46 |
+
"<style scoped>\n",
|
| 47 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 48 |
+
" vertical-align: middle;\n",
|
| 49 |
+
" }\n",
|
| 50 |
+
"\n",
|
| 51 |
+
" .dataframe tbody tr th {\n",
|
| 52 |
+
" vertical-align: top;\n",
|
| 53 |
+
" }\n",
|
| 54 |
+
"\n",
|
| 55 |
+
" .dataframe thead th {\n",
|
| 56 |
+
" text-align: right;\n",
|
| 57 |
+
" }\n",
|
| 58 |
+
"</style>\n",
|
| 59 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 60 |
+
" <thead>\n",
|
| 61 |
+
" <tr style=\"text-align: right;\">\n",
|
| 62 |
+
" <th></th>\n",
|
| 63 |
+
" <th>book_id</th>\n",
|
| 64 |
+
" <th>title</th>\n",
|
| 65 |
+
" <th>description</th>\n",
|
| 66 |
+
" <th>publication_year</th>\n",
|
| 67 |
+
" <th>publisher</th>\n",
|
| 68 |
+
" <th>authors</th>\n",
|
| 69 |
+
" <th>similar_books</th>\n",
|
| 70 |
+
" </tr>\n",
|
| 71 |
+
" </thead>\n",
|
| 72 |
+
" <tbody>\n",
|
| 73 |
+
" <tr>\n",
|
| 74 |
+
" <th>0</th>\n",
|
| 75 |
+
" <td>1333909</td>\n",
|
| 76 |
+
" <td>Good Harbor</td>\n",
|
| 77 |
+
" <td>Anita Diamant's international bestseller \"The ...</td>\n",
|
| 78 |
+
" <td>2001</td>\n",
|
| 79 |
+
" <td>Simon & Schuster Audio</td>\n",
|
| 80 |
+
" <td>[626222]</td>\n",
|
| 81 |
+
" <td>[8709549, 17074050, 28937, 158816, 228563, 112...</td>\n",
|
| 82 |
+
" </tr>\n",
|
| 83 |
+
" <tr>\n",
|
| 84 |
+
" <th>1</th>\n",
|
| 85 |
+
" <td>7327624</td>\n",
|
| 86 |
+
" <td>The Unschooled Wizard (Sun Wolf and Starhawk, ...</td>\n",
|
| 87 |
+
" <td>Omnibus book club edition containing the Ladie...</td>\n",
|
| 88 |
+
" <td>1987</td>\n",
|
| 89 |
+
" <td>Nelson Doubleday, Inc.</td>\n",
|
| 90 |
+
" <td>[10333]</td>\n",
|
| 91 |
+
" <td>[19997, 828466, 1569323, 425389, 1176674, 2627...</td>\n",
|
| 92 |
+
" </tr>\n",
|
| 93 |
+
" <tr>\n",
|
| 94 |
+
" <th>2</th>\n",
|
| 95 |
+
" <td>6066819</td>\n",
|
| 96 |
+
" <td>Best Friends Forever</td>\n",
|
| 97 |
+
" <td>Addie Downs and Valerie Adler were eight when ...</td>\n",
|
| 98 |
+
" <td>2009</td>\n",
|
| 99 |
+
" <td>Atria Books</td>\n",
|
| 100 |
+
" <td>[9212]</td>\n",
|
| 101 |
+
" <td>[6604176, 6054190, 2285777, 82641, 7569453, 70...</td>\n",
|
| 102 |
+
" </tr>\n",
|
| 103 |
+
" <tr>\n",
|
| 104 |
+
" <th>3</th>\n",
|
| 105 |
+
" <td>287141</td>\n",
|
| 106 |
+
" <td>The Aeneid for Boys and Girls</td>\n",
|
| 107 |
+
" <td>Relates in vigorous prose the tale of Aeneas, ...</td>\n",
|
| 108 |
+
" <td>2006</td>\n",
|
| 109 |
+
" <td>Yesterday's Classics</td>\n",
|
| 110 |
+
" <td>[3041852]</td>\n",
|
| 111 |
+
" <td>[]</td>\n",
|
| 112 |
+
" </tr>\n",
|
| 113 |
+
" <tr>\n",
|
| 114 |
+
" <th>4</th>\n",
|
| 115 |
+
" <td>6066812</td>\n",
|
| 116 |
+
" <td>All's Fairy in Love and War (Avalon: Web of Ma...</td>\n",
|
| 117 |
+
" <td>To Kara's astonishment, she discovers that a p...</td>\n",
|
| 118 |
+
" <td>2009</td>\n",
|
| 119 |
+
" <td>Seven Seas</td>\n",
|
| 120 |
+
" <td>[19158]</td>\n",
|
| 121 |
+
" <td>[948696, 439885, 274955, 12978730, 372986, 216...</td>\n",
|
| 122 |
+
" </tr>\n",
|
| 123 |
+
" </tbody>\n",
|
| 124 |
+
"</table>\n",
|
| 125 |
+
"</div>"
|
| 126 |
+
],
|
| 127 |
+
"text/plain": [
|
| 128 |
+
" book_id title \\\n",
|
| 129 |
+
"0 1333909 Good Harbor \n",
|
| 130 |
+
"1 7327624 The Unschooled Wizard (Sun Wolf and Starhawk, ... \n",
|
| 131 |
+
"2 6066819 Best Friends Forever \n",
|
| 132 |
+
"3 287141 The Aeneid for Boys and Girls \n",
|
| 133 |
+
"4 6066812 All's Fairy in Love and War (Avalon: Web of Ma... \n",
|
| 134 |
+
"\n",
|
| 135 |
+
" description publication_year \\\n",
|
| 136 |
+
"0 Anita Diamant's international bestseller \"The ... 2001 \n",
|
| 137 |
+
"1 Omnibus book club edition containing the Ladie... 1987 \n",
|
| 138 |
+
"2 Addie Downs and Valerie Adler were eight when ... 2009 \n",
|
| 139 |
+
"3 Relates in vigorous prose the tale of Aeneas, ... 2006 \n",
|
| 140 |
+
"4 To Kara's astonishment, she discovers that a p... 2009 \n",
|
| 141 |
+
"\n",
|
| 142 |
+
" publisher authors \\\n",
|
| 143 |
+
"0 Simon & Schuster Audio [626222] \n",
|
| 144 |
+
"1 Nelson Doubleday, Inc. [10333] \n",
|
| 145 |
+
"2 Atria Books [9212] \n",
|
| 146 |
+
"3 Yesterday's Classics [3041852] \n",
|
| 147 |
+
"4 Seven Seas [19158] \n",
|
| 148 |
+
"\n",
|
| 149 |
+
" similar_books \n",
|
| 150 |
+
"0 [8709549, 17074050, 28937, 158816, 228563, 112... \n",
|
| 151 |
+
"1 [19997, 828466, 1569323, 425389, 1176674, 2627... \n",
|
| 152 |
+
"2 [6604176, 6054190, 2285777, 82641, 7569453, 70... \n",
|
| 153 |
+
"3 [] \n",
|
| 154 |
+
"4 [948696, 439885, 274955, 12978730, 372986, 216... "
|
| 155 |
+
]
|
| 156 |
+
},
|
| 157 |
+
"execution_count": 2,
|
| 158 |
+
"metadata": {},
|
| 159 |
+
"output_type": "execute_result"
|
| 160 |
+
}
|
| 161 |
+
],
|
| 162 |
+
"source": [
|
| 163 |
+
"df = pd.read_csv('goodreads_books.csv')\n",
|
| 164 |
+
"df = df[df['title'].notna()]\n",
|
| 165 |
+
"df['authors'] =df['authors'].apply(eval)\n",
|
| 166 |
+
"df['similar_books'] =df['similar_books'].apply(eval)\n",
|
| 167 |
+
"print(df.shape)\n",
|
| 168 |
+
"df.head()"
|
| 169 |
+
]
|
| 170 |
+
},
|
| 171 |
+
{
|
| 172 |
+
"cell_type": "code",
|
| 173 |
+
"execution_count": 3,
|
| 174 |
+
"id": "6ca5d8672eb45020",
|
| 175 |
+
"metadata": {
|
| 176 |
+
"ExecuteTime": {
|
| 177 |
+
"end_time": "2024-12-01T15:02:59.577742Z",
|
| 178 |
+
"start_time": "2024-12-01T15:02:57.692112Z"
|
| 179 |
+
}
|
| 180 |
+
},
|
| 181 |
+
"outputs": [
|
| 182 |
+
{
|
| 183 |
+
"name": "stdout",
|
| 184 |
+
"output_type": "stream",
|
| 185 |
+
"text": [
|
| 186 |
+
"Number of books that have similar books 640364\n"
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"data": {
|
| 191 |
+
"text/html": [
|
| 192 |
+
"<div>\n",
|
| 193 |
+
"<style scoped>\n",
|
| 194 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 195 |
+
" vertical-align: middle;\n",
|
| 196 |
+
" }\n",
|
| 197 |
+
"\n",
|
| 198 |
+
" .dataframe tbody tr th {\n",
|
| 199 |
+
" vertical-align: top;\n",
|
| 200 |
+
" }\n",
|
| 201 |
+
"\n",
|
| 202 |
+
" .dataframe thead th {\n",
|
| 203 |
+
" text-align: right;\n",
|
| 204 |
+
" }\n",
|
| 205 |
+
"</style>\n",
|
| 206 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 207 |
+
" <thead>\n",
|
| 208 |
+
" <tr style=\"text-align: right;\">\n",
|
| 209 |
+
" <th></th>\n",
|
| 210 |
+
" <th>book_id</th>\n",
|
| 211 |
+
" <th>title</th>\n",
|
| 212 |
+
" <th>description</th>\n",
|
| 213 |
+
" <th>publication_year</th>\n",
|
| 214 |
+
" <th>publisher</th>\n",
|
| 215 |
+
" <th>authors</th>\n",
|
| 216 |
+
" <th>similar_books</th>\n",
|
| 217 |
+
" </tr>\n",
|
| 218 |
+
" </thead>\n",
|
| 219 |
+
" <tbody>\n",
|
| 220 |
+
" <tr>\n",
|
| 221 |
+
" <th>0</th>\n",
|
| 222 |
+
" <td>1333909</td>\n",
|
| 223 |
+
" <td>Good Harbor</td>\n",
|
| 224 |
+
" <td>Anita Diamant's international bestseller \"The ...</td>\n",
|
| 225 |
+
" <td>2001</td>\n",
|
| 226 |
+
" <td>Simon & Schuster Audio</td>\n",
|
| 227 |
+
" <td>[626222]</td>\n",
|
| 228 |
+
" <td>[8709549, 17074050, 28937, 158816, 228563, 112...</td>\n",
|
| 229 |
+
" </tr>\n",
|
| 230 |
+
" <tr>\n",
|
| 231 |
+
" <th>1</th>\n",
|
| 232 |
+
" <td>7327624</td>\n",
|
| 233 |
+
" <td>The Unschooled Wizard (Sun Wolf and Starhawk, ...</td>\n",
|
| 234 |
+
" <td>Omnibus book club edition containing the Ladie...</td>\n",
|
| 235 |
+
" <td>1987</td>\n",
|
| 236 |
+
" <td>Nelson Doubleday, Inc.</td>\n",
|
| 237 |
+
" <td>[10333]</td>\n",
|
| 238 |
+
" <td>[19997, 828466, 1569323, 425389, 1176674, 2627...</td>\n",
|
| 239 |
+
" </tr>\n",
|
| 240 |
+
" <tr>\n",
|
| 241 |
+
" <th>2</th>\n",
|
| 242 |
+
" <td>6066819</td>\n",
|
| 243 |
+
" <td>Best Friends Forever</td>\n",
|
| 244 |
+
" <td>Addie Downs and Valerie Adler were eight when ...</td>\n",
|
| 245 |
+
" <td>2009</td>\n",
|
| 246 |
+
" <td>Atria Books</td>\n",
|
| 247 |
+
" <td>[9212]</td>\n",
|
| 248 |
+
" <td>[6604176, 6054190, 2285777, 82641, 7569453, 70...</td>\n",
|
| 249 |
+
" </tr>\n",
|
| 250 |
+
" <tr>\n",
|
| 251 |
+
" <th>4</th>\n",
|
| 252 |
+
" <td>6066812</td>\n",
|
| 253 |
+
" <td>All's Fairy in Love and War (Avalon: Web of Ma...</td>\n",
|
| 254 |
+
" <td>To Kara's astonishment, she discovers that a p...</td>\n",
|
| 255 |
+
" <td>2009</td>\n",
|
| 256 |
+
" <td>Seven Seas</td>\n",
|
| 257 |
+
" <td>[19158]</td>\n",
|
| 258 |
+
" <td>[948696, 439885, 274955, 12978730, 372986, 216...</td>\n",
|
| 259 |
+
" </tr>\n",
|
| 260 |
+
" <tr>\n",
|
| 261 |
+
" <th>6</th>\n",
|
| 262 |
+
" <td>287149</td>\n",
|
| 263 |
+
" <td>The Devil's Notebook</td>\n",
|
| 264 |
+
" <td>Wisdom, humor, and dark observations by the fo...</td>\n",
|
| 265 |
+
" <td>2000</td>\n",
|
| 266 |
+
" <td>Feral House</td>\n",
|
| 267 |
+
" <td>[2983296, 40075]</td>\n",
|
| 268 |
+
" <td>[287151, 1104760, 1172822, 440292, 287082, 630...</td>\n",
|
| 269 |
+
" </tr>\n",
|
| 270 |
+
" </tbody>\n",
|
| 271 |
+
"</table>\n",
|
| 272 |
+
"</div>"
|
| 273 |
+
],
|
| 274 |
+
"text/plain": [
|
| 275 |
+
" book_id title \\\n",
|
| 276 |
+
"0 1333909 Good Harbor \n",
|
| 277 |
+
"1 7327624 The Unschooled Wizard (Sun Wolf and Starhawk, ... \n",
|
| 278 |
+
"2 6066819 Best Friends Forever \n",
|
| 279 |
+
"4 6066812 All's Fairy in Love and War (Avalon: Web of Ma... \n",
|
| 280 |
+
"6 287149 The Devil's Notebook \n",
|
| 281 |
+
"\n",
|
| 282 |
+
" description publication_year \\\n",
|
| 283 |
+
"0 Anita Diamant's international bestseller \"The ... 2001 \n",
|
| 284 |
+
"1 Omnibus book club edition containing the Ladie... 1987 \n",
|
| 285 |
+
"2 Addie Downs and Valerie Adler were eight when ... 2009 \n",
|
| 286 |
+
"4 To Kara's astonishment, she discovers that a p... 2009 \n",
|
| 287 |
+
"6 Wisdom, humor, and dark observations by the fo... 2000 \n",
|
| 288 |
+
"\n",
|
| 289 |
+
" publisher authors \\\n",
|
| 290 |
+
"0 Simon & Schuster Audio [626222] \n",
|
| 291 |
+
"1 Nelson Doubleday, Inc. [10333] \n",
|
| 292 |
+
"2 Atria Books [9212] \n",
|
| 293 |
+
"4 Seven Seas [19158] \n",
|
| 294 |
+
"6 Feral House [2983296, 40075] \n",
|
| 295 |
+
"\n",
|
| 296 |
+
" similar_books \n",
|
| 297 |
+
"0 [8709549, 17074050, 28937, 158816, 228563, 112... \n",
|
| 298 |
+
"1 [19997, 828466, 1569323, 425389, 1176674, 2627... \n",
|
| 299 |
+
"2 [6604176, 6054190, 2285777, 82641, 7569453, 70... \n",
|
| 300 |
+
"4 [948696, 439885, 274955, 12978730, 372986, 216... \n",
|
| 301 |
+
"6 [287151, 1104760, 1172822, 440292, 287082, 630... "
|
| 302 |
+
]
|
| 303 |
+
},
|
| 304 |
+
"execution_count": 3,
|
| 305 |
+
"metadata": {},
|
| 306 |
+
"output_type": "execute_result"
|
| 307 |
+
}
|
| 308 |
+
],
|
| 309 |
+
"source": [
|
| 310 |
+
"has_similar_books1 = df['similar_books'].apply(len) > 0\n",
|
| 311 |
+
"has_similar_books1.head()\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"all_similar_books = np.array(list(itertools.chain(*(df['similar_books'].values))))\n",
|
| 314 |
+
"has_similar_books2 = np.isin(df['book_id'], all_similar_books)\n",
|
| 315 |
+
"\n",
|
| 316 |
+
"has_similar_books = has_similar_books1 | has_similar_books2\n",
|
| 317 |
+
"\n",
|
| 318 |
+
"df = df[has_similar_books]\n",
|
| 319 |
+
"print('Number of books that have similar books', df.shape[0])\n",
|
| 320 |
+
"df.head()"
|
| 321 |
+
]
|
| 322 |
+
},
|
| 323 |
+
{
|
| 324 |
+
"cell_type": "code",
|
| 325 |
+
"execution_count": null,
|
| 326 |
+
"id": "6846b3dccaf40875",
|
| 327 |
+
"metadata": {},
|
| 328 |
+
"outputs": [],
|
| 329 |
+
"source": []
|
| 330 |
+
},
|
| 331 |
+
{
|
| 332 |
+
"cell_type": "code",
|
| 333 |
+
"execution_count": 4,
|
| 334 |
+
"id": "d239e42cfd34de80",
|
| 335 |
+
"metadata": {
|
| 336 |
+
"ExecuteTime": {
|
| 337 |
+
"end_time": "2024-12-01T15:02:59.627408Z",
|
| 338 |
+
"start_time": "2024-12-01T15:02:59.621594Z"
|
| 339 |
+
}
|
| 340 |
+
},
|
| 341 |
+
"outputs": [],
|
| 342 |
+
"source": [
|
| 343 |
+
"data = {}"
|
| 344 |
+
]
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"cell_type": "markdown",
|
| 348 |
+
"id": "cffdf6de4137a3a0",
|
| 349 |
+
"metadata": {},
|
| 350 |
+
"source": [
|
| 351 |
+
"## Labels"
|
| 352 |
+
]
|
| 353 |
+
},
|
| 354 |
+
{
|
| 355 |
+
"cell_type": "code",
|
| 356 |
+
"execution_count": 5,
|
| 357 |
+
"id": "d3b34765c70b3dc0",
|
| 358 |
+
"metadata": {
|
| 359 |
+
"ExecuteTime": {
|
| 360 |
+
"end_time": "2024-12-01T15:03:23.519314Z",
|
| 361 |
+
"start_time": "2024-12-01T15:02:59.779801Z"
|
| 362 |
+
}
|
| 363 |
+
},
|
| 364 |
+
"outputs": [
|
| 365 |
+
{
|
| 366 |
+
"data": {
|
| 367 |
+
"text/html": [
|
| 368 |
+
"<div>\n",
|
| 369 |
+
"<style scoped>\n",
|
| 370 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 371 |
+
" vertical-align: middle;\n",
|
| 372 |
+
" }\n",
|
| 373 |
+
"\n",
|
| 374 |
+
" .dataframe tbody tr th {\n",
|
| 375 |
+
" vertical-align: top;\n",
|
| 376 |
+
" }\n",
|
| 377 |
+
"\n",
|
| 378 |
+
" .dataframe thead th {\n",
|
| 379 |
+
" text-align: right;\n",
|
| 380 |
+
" }\n",
|
| 381 |
+
"</style>\n",
|
| 382 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 383 |
+
" <thead>\n",
|
| 384 |
+
" <tr style=\"text-align: right;\">\n",
|
| 385 |
+
" <th></th>\n",
|
| 386 |
+
" <th>book_id</th>\n",
|
| 387 |
+
" <th>genres</th>\n",
|
| 388 |
+
" </tr>\n",
|
| 389 |
+
" </thead>\n",
|
| 390 |
+
" <tbody>\n",
|
| 391 |
+
" <tr>\n",
|
| 392 |
+
" <th>0</th>\n",
|
| 393 |
+
" <td>5333265</td>\n",
|
| 394 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 395 |
+
" </tr>\n",
|
| 396 |
+
" <tr>\n",
|
| 397 |
+
" <th>1</th>\n",
|
| 398 |
+
" <td>1333909</td>\n",
|
| 399 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 400 |
+
" </tr>\n",
|
| 401 |
+
" <tr>\n",
|
| 402 |
+
" <th>2</th>\n",
|
| 403 |
+
" <td>7327624</td>\n",
|
| 404 |
+
" <td>[fantasy, paranormal, mystery, thriller, crime...</td>\n",
|
| 405 |
+
" </tr>\n",
|
| 406 |
+
" <tr>\n",
|
| 407 |
+
" <th>3</th>\n",
|
| 408 |
+
" <td>6066819</td>\n",
|
| 409 |
+
" <td>[romance, mystery, thriller, crime]</td>\n",
|
| 410 |
+
" </tr>\n",
|
| 411 |
+
" <tr>\n",
|
| 412 |
+
" <th>4</th>\n",
|
| 413 |
+
" <td>287141</td>\n",
|
| 414 |
+
" <td>[history, historical fiction, biography, child...</td>\n",
|
| 415 |
+
" </tr>\n",
|
| 416 |
+
" </tbody>\n",
|
| 417 |
+
"</table>\n",
|
| 418 |
+
"</div>"
|
| 419 |
+
],
|
| 420 |
+
"text/plain": [
|
| 421 |
+
" book_id genres\n",
|
| 422 |
+
"0 5333265 [history, historical fiction, biography]\n",
|
| 423 |
+
"1 1333909 [history, historical fiction, biography]\n",
|
| 424 |
+
"2 7327624 [fantasy, paranormal, mystery, thriller, crime...\n",
|
| 425 |
+
"3 6066819 [romance, mystery, thriller, crime]\n",
|
| 426 |
+
"4 287141 [history, historical fiction, biography, child..."
|
| 427 |
+
]
|
| 428 |
+
},
|
| 429 |
+
"execution_count": 5,
|
| 430 |
+
"metadata": {},
|
| 431 |
+
"output_type": "execute_result"
|
| 432 |
+
}
|
| 433 |
+
],
|
| 434 |
+
"source": [
|
| 435 |
+
"genres = pd.read_csv('goodreads_book_genres_initial.csv')\n",
|
| 436 |
+
"genres['genres'] = genres['genres'].apply(eval)\n",
|
| 437 |
+
"genres.head()"
|
| 438 |
+
]
|
| 439 |
+
},
|
| 440 |
+
{
|
| 441 |
+
"cell_type": "code",
|
| 442 |
+
"execution_count": 6,
|
| 443 |
+
"id": "55c11b0fe27fe6e8",
|
| 444 |
+
"metadata": {
|
| 445 |
+
"ExecuteTime": {
|
| 446 |
+
"end_time": "2024-12-01T15:03:25.895897Z",
|
| 447 |
+
"start_time": "2024-12-01T15:03:23.616794Z"
|
| 448 |
+
}
|
| 449 |
+
},
|
| 450 |
+
"outputs": [
|
| 451 |
+
{
|
| 452 |
+
"name": "stdout",
|
| 453 |
+
"output_type": "stream",
|
| 454 |
+
"text": [
|
| 455 |
+
"(594484, 8)\n"
|
| 456 |
+
]
|
| 457 |
+
},
|
| 458 |
+
{
|
| 459 |
+
"data": {
|
| 460 |
+
"text/html": [
|
| 461 |
+
"<div>\n",
|
| 462 |
+
"<style scoped>\n",
|
| 463 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 464 |
+
" vertical-align: middle;\n",
|
| 465 |
+
" }\n",
|
| 466 |
+
"\n",
|
| 467 |
+
" .dataframe tbody tr th {\n",
|
| 468 |
+
" vertical-align: top;\n",
|
| 469 |
+
" }\n",
|
| 470 |
+
"\n",
|
| 471 |
+
" .dataframe thead th {\n",
|
| 472 |
+
" text-align: right;\n",
|
| 473 |
+
" }\n",
|
| 474 |
+
"</style>\n",
|
| 475 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 476 |
+
" <thead>\n",
|
| 477 |
+
" <tr style=\"text-align: right;\">\n",
|
| 478 |
+
" <th></th>\n",
|
| 479 |
+
" <th>book_id</th>\n",
|
| 480 |
+
" <th>title</th>\n",
|
| 481 |
+
" <th>description</th>\n",
|
| 482 |
+
" <th>publication_year</th>\n",
|
| 483 |
+
" <th>publisher</th>\n",
|
| 484 |
+
" <th>authors</th>\n",
|
| 485 |
+
" <th>similar_books</th>\n",
|
| 486 |
+
" <th>genres</th>\n",
|
| 487 |
+
" </tr>\n",
|
| 488 |
+
" </thead>\n",
|
| 489 |
+
" <tbody>\n",
|
| 490 |
+
" <tr>\n",
|
| 491 |
+
" <th>0</th>\n",
|
| 492 |
+
" <td>1333909</td>\n",
|
| 493 |
+
" <td>Good Harbor</td>\n",
|
| 494 |
+
" <td>Anita Diamant's international bestseller \"The ...</td>\n",
|
| 495 |
+
" <td>2001</td>\n",
|
| 496 |
+
" <td>Simon & Schuster Audio</td>\n",
|
| 497 |
+
" <td>[626222]</td>\n",
|
| 498 |
+
" <td>[8709549, 17074050, 28937, 158816, 228563, 112...</td>\n",
|
| 499 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 500 |
+
" </tr>\n",
|
| 501 |
+
" <tr>\n",
|
| 502 |
+
" <th>1</th>\n",
|
| 503 |
+
" <td>7327624</td>\n",
|
| 504 |
+
" <td>The Unschooled Wizard (Sun Wolf and Starhawk, ...</td>\n",
|
| 505 |
+
" <td>Omnibus book club edition containing the Ladie...</td>\n",
|
| 506 |
+
" <td>1987</td>\n",
|
| 507 |
+
" <td>Nelson Doubleday, Inc.</td>\n",
|
| 508 |
+
" <td>[10333]</td>\n",
|
| 509 |
+
" <td>[19997, 828466, 1569323, 425389, 1176674, 2627...</td>\n",
|
| 510 |
+
" <td>[fantasy, paranormal, mystery, thriller, crime...</td>\n",
|
| 511 |
+
" </tr>\n",
|
| 512 |
+
" <tr>\n",
|
| 513 |
+
" <th>2</th>\n",
|
| 514 |
+
" <td>6066819</td>\n",
|
| 515 |
+
" <td>Best Friends Forever</td>\n",
|
| 516 |
+
" <td>Addie Downs and Valerie Adler were eight when ...</td>\n",
|
| 517 |
+
" <td>2009</td>\n",
|
| 518 |
+
" <td>Atria Books</td>\n",
|
| 519 |
+
" <td>[9212]</td>\n",
|
| 520 |
+
" <td>[6604176, 6054190, 2285777, 82641, 7569453, 70...</td>\n",
|
| 521 |
+
" <td>[romance, mystery, thriller, crime]</td>\n",
|
| 522 |
+
" </tr>\n",
|
| 523 |
+
" <tr>\n",
|
| 524 |
+
" <th>3</th>\n",
|
| 525 |
+
" <td>6066812</td>\n",
|
| 526 |
+
" <td>All's Fairy in Love and War (Avalon: Web of Ma...</td>\n",
|
| 527 |
+
" <td>To Kara's astonishment, she discovers that a p...</td>\n",
|
| 528 |
+
" <td>2009</td>\n",
|
| 529 |
+
" <td>Seven Seas</td>\n",
|
| 530 |
+
" <td>[19158]</td>\n",
|
| 531 |
+
" <td>[948696, 439885, 274955, 12978730, 372986, 216...</td>\n",
|
| 532 |
+
" <td>[fantasy, paranormal, young-adult, children]</td>\n",
|
| 533 |
+
" </tr>\n",
|
| 534 |
+
" <tr>\n",
|
| 535 |
+
" <th>4</th>\n",
|
| 536 |
+
" <td>287149</td>\n",
|
| 537 |
+
" <td>The Devil's Notebook</td>\n",
|
| 538 |
+
" <td>Wisdom, humor, and dark observations by the fo...</td>\n",
|
| 539 |
+
" <td>2000</td>\n",
|
| 540 |
+
" <td>Feral House</td>\n",
|
| 541 |
+
" <td>[2983296, 40075]</td>\n",
|
| 542 |
+
" <td>[287151, 1104760, 1172822, 440292, 287082, 630...</td>\n",
|
| 543 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 544 |
+
" </tr>\n",
|
| 545 |
+
" </tbody>\n",
|
| 546 |
+
"</table>\n",
|
| 547 |
+
"</div>"
|
| 548 |
+
],
|
| 549 |
+
"text/plain": [
|
| 550 |
+
" book_id title \\\n",
|
| 551 |
+
"0 1333909 Good Harbor \n",
|
| 552 |
+
"1 7327624 The Unschooled Wizard (Sun Wolf and Starhawk, ... \n",
|
| 553 |
+
"2 6066819 Best Friends Forever \n",
|
| 554 |
+
"3 6066812 All's Fairy in Love and War (Avalon: Web of Ma... \n",
|
| 555 |
+
"4 287149 The Devil's Notebook \n",
|
| 556 |
+
"\n",
|
| 557 |
+
" description publication_year \\\n",
|
| 558 |
+
"0 Anita Diamant's international bestseller \"The ... 2001 \n",
|
| 559 |
+
"1 Omnibus book club edition containing the Ladie... 1987 \n",
|
| 560 |
+
"2 Addie Downs and Valerie Adler were eight when ... 2009 \n",
|
| 561 |
+
"3 To Kara's astonishment, she discovers that a p... 2009 \n",
|
| 562 |
+
"4 Wisdom, humor, and dark observations by the fo... 2000 \n",
|
| 563 |
+
"\n",
|
| 564 |
+
" publisher authors \\\n",
|
| 565 |
+
"0 Simon & Schuster Audio [626222] \n",
|
| 566 |
+
"1 Nelson Doubleday, Inc. [10333] \n",
|
| 567 |
+
"2 Atria Books [9212] \n",
|
| 568 |
+
"3 Seven Seas [19158] \n",
|
| 569 |
+
"4 Feral House [2983296, 40075] \n",
|
| 570 |
+
"\n",
|
| 571 |
+
" similar_books \\\n",
|
| 572 |
+
"0 [8709549, 17074050, 28937, 158816, 228563, 112... \n",
|
| 573 |
+
"1 [19997, 828466, 1569323, 425389, 1176674, 2627... \n",
|
| 574 |
+
"2 [6604176, 6054190, 2285777, 82641, 7569453, 70... \n",
|
| 575 |
+
"3 [948696, 439885, 274955, 12978730, 372986, 216... \n",
|
| 576 |
+
"4 [287151, 1104760, 1172822, 440292, 287082, 630... \n",
|
| 577 |
+
"\n",
|
| 578 |
+
" genres \n",
|
| 579 |
+
"0 [history, historical fiction, biography] \n",
|
| 580 |
+
"1 [fantasy, paranormal, mystery, thriller, crime... \n",
|
| 581 |
+
"2 [romance, mystery, thriller, crime] \n",
|
| 582 |
+
"3 [fantasy, paranormal, young-adult, children] \n",
|
| 583 |
+
"4 [history, historical fiction, biography] "
|
| 584 |
+
]
|
| 585 |
+
},
|
| 586 |
+
"execution_count": 6,
|
| 587 |
+
"metadata": {},
|
| 588 |
+
"output_type": "execute_result"
|
| 589 |
+
}
|
| 590 |
+
],
|
| 591 |
+
"source": [
|
| 592 |
+
"books = pd.merge(df, genres, on='book_id', how='left')\n",
|
| 593 |
+
"books = books[~books['genres'].isna()]\n",
|
| 594 |
+
"books = books[books['genres'].apply(len)>0]\n",
|
| 595 |
+
"print(books.shape)\n",
|
| 596 |
+
"books.head()"
|
| 597 |
+
]
|
| 598 |
+
},
|
| 599 |
+
{
|
| 600 |
+
"cell_type": "code",
|
| 601 |
+
"execution_count": 7,
|
| 602 |
+
"id": "c0a46d2d54eadc71",
|
| 603 |
+
"metadata": {
|
| 604 |
+
"ExecuteTime": {
|
| 605 |
+
"end_time": "2024-12-01T15:03:27.087963Z",
|
| 606 |
+
"start_time": "2024-12-01T15:03:26.056872Z"
|
| 607 |
+
}
|
| 608 |
+
},
|
| 609 |
+
"outputs": [],
|
| 610 |
+
"source": [
|
| 611 |
+
"label_encoder = MultiLabelBinarizer(sparse_output=True)\n",
|
| 612 |
+
"labels = label_encoder.fit_transform(books['genres']).astype(np.bool_)"
|
| 613 |
+
]
|
| 614 |
+
},
|
| 615 |
+
{
|
| 616 |
+
"cell_type": "code",
|
| 617 |
+
"execution_count": 8,
|
| 618 |
+
"id": "f30a5996f451165c",
|
| 619 |
+
"metadata": {
|
| 620 |
+
"ExecuteTime": {
|
| 621 |
+
"end_time": "2024-12-01T15:03:27.164320Z",
|
| 622 |
+
"start_time": "2024-12-01T15:03:27.157773Z"
|
| 623 |
+
}
|
| 624 |
+
},
|
| 625 |
+
"outputs": [],
|
| 626 |
+
"source": [
|
| 627 |
+
"data['book_labels'] = labels"
|
| 628 |
+
]
|
| 629 |
+
},
|
| 630 |
+
{
|
| 631 |
+
"cell_type": "markdown",
|
| 632 |
+
"id": "dd38e5df5bf7243c",
|
| 633 |
+
"metadata": {},
|
| 634 |
+
"source": [
|
| 635 |
+
"## Book-Author Links"
|
| 636 |
+
]
|
| 637 |
+
},
|
| 638 |
+
{
|
| 639 |
+
"cell_type": "code",
|
| 640 |
+
"execution_count": 9,
|
| 641 |
+
"id": "6ee5abdfe0caf84",
|
| 642 |
+
"metadata": {
|
| 643 |
+
"ExecuteTime": {
|
| 644 |
+
"end_time": "2024-12-01T15:03:28.025301Z",
|
| 645 |
+
"start_time": "2024-12-01T15:03:27.250118Z"
|
| 646 |
+
}
|
| 647 |
+
},
|
| 648 |
+
"outputs": [
|
| 649 |
+
{
|
| 650 |
+
"name": "stdout",
|
| 651 |
+
"output_type": "stream",
|
| 652 |
+
"text": [
|
| 653 |
+
"Number of authors 147863\n"
|
| 654 |
+
]
|
| 655 |
+
},
|
| 656 |
+
{
|
| 657 |
+
"data": {
|
| 658 |
+
"text/html": [
|
| 659 |
+
"<div>\n",
|
| 660 |
+
"<style scoped>\n",
|
| 661 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 662 |
+
" vertical-align: middle;\n",
|
| 663 |
+
" }\n",
|
| 664 |
+
"\n",
|
| 665 |
+
" .dataframe tbody tr th {\n",
|
| 666 |
+
" vertical-align: top;\n",
|
| 667 |
+
" }\n",
|
| 668 |
+
"\n",
|
| 669 |
+
" .dataframe thead th {\n",
|
| 670 |
+
" text-align: right;\n",
|
| 671 |
+
" }\n",
|
| 672 |
+
"</style>\n",
|
| 673 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 674 |
+
" <thead>\n",
|
| 675 |
+
" <tr style=\"text-align: right;\">\n",
|
| 676 |
+
" <th></th>\n",
|
| 677 |
+
" <th>author</th>\n",
|
| 678 |
+
" <th>count</th>\n",
|
| 679 |
+
" </tr>\n",
|
| 680 |
+
" </thead>\n",
|
| 681 |
+
" <tbody>\n",
|
| 682 |
+
" <tr>\n",
|
| 683 |
+
" <th>18</th>\n",
|
| 684 |
+
" <td>123715</td>\n",
|
| 685 |
+
" <td>2000</td>\n",
|
| 686 |
+
" </tr>\n",
|
| 687 |
+
" <tr>\n",
|
| 688 |
+
" <th>9</th>\n",
|
| 689 |
+
" <td>3389</td>\n",
|
| 690 |
+
" <td>1739</td>\n",
|
| 691 |
+
" </tr>\n",
|
| 692 |
+
" <tr>\n",
|
| 693 |
+
" <th>359</th>\n",
|
| 694 |
+
" <td>3780</td>\n",
|
| 695 |
+
" <td>1544</td>\n",
|
| 696 |
+
" </tr>\n",
|
| 697 |
+
" <tr>\n",
|
| 698 |
+
" <th>2111</th>\n",
|
| 699 |
+
" <td>947</td>\n",
|
| 700 |
+
" <td>1418</td>\n",
|
| 701 |
+
" </tr>\n",
|
| 702 |
+
" <tr>\n",
|
| 703 |
+
" <th>1534</th>\n",
|
| 704 |
+
" <td>625</td>\n",
|
| 705 |
+
" <td>1209</td>\n",
|
| 706 |
+
" </tr>\n",
|
| 707 |
+
" </tbody>\n",
|
| 708 |
+
"</table>\n",
|
| 709 |
+
"</div>"
|
| 710 |
+
],
|
| 711 |
+
"text/plain": [
|
| 712 |
+
" author count\n",
|
| 713 |
+
"18 123715 2000\n",
|
| 714 |
+
"9 3389 1739\n",
|
| 715 |
+
"359 3780 1544\n",
|
| 716 |
+
"2111 947 1418\n",
|
| 717 |
+
"1534 625 1209"
|
| 718 |
+
]
|
| 719 |
+
},
|
| 720 |
+
"execution_count": 9,
|
| 721 |
+
"metadata": {},
|
| 722 |
+
"output_type": "execute_result"
|
| 723 |
+
}
|
| 724 |
+
],
|
| 725 |
+
"source": [
|
| 726 |
+
"authors = list(itertools.chain(*(books['authors'].values)))\n",
|
| 727 |
+
"author_count_dict = Counter(authors)\n",
|
| 728 |
+
"author_count_df = pd.DataFrame(list(author_count_dict.items()), columns=['author', 'count'])\n",
|
| 729 |
+
"print('Number of authors', author_count_df.shape[0])\n",
|
| 730 |
+
"author_count_df.sort_values(by='count', ascending=False).head()"
|
| 731 |
+
]
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"cell_type": "code",
|
| 735 |
+
"execution_count": 10,
|
| 736 |
+
"id": "f8fdc6fae6ed6a11",
|
| 737 |
+
"metadata": {
|
| 738 |
+
"ExecuteTime": {
|
| 739 |
+
"end_time": "2024-12-01T15:03:31.862308Z",
|
| 740 |
+
"start_time": "2024-12-01T15:03:28.116806Z"
|
| 741 |
+
}
|
| 742 |
+
},
|
| 743 |
+
"outputs": [
|
| 744 |
+
{
|
| 745 |
+
"name": "stdout",
|
| 746 |
+
"output_type": "stream",
|
| 747 |
+
"text": [
|
| 748 |
+
"Number of book-author links: 826369\n"
|
| 749 |
+
]
|
| 750 |
+
}
|
| 751 |
+
],
|
| 752 |
+
"source": [
|
| 753 |
+
"book_ids = np.concatenate([np.full(count, i) \n",
|
| 754 |
+
" for i, count in enumerate(books['authors'].apply(len))])\n",
|
| 755 |
+
"\n",
|
| 756 |
+
"author_id_encoder = LabelEncoder()\n",
|
| 757 |
+
"author_ids = author_id_encoder.fit_transform(authors).astype(np.int32)\n",
|
| 758 |
+
"\n",
|
| 759 |
+
"print('Number of book-author links:', author_ids.shape[0])\n",
|
| 760 |
+
"\n",
|
| 761 |
+
"data['book-author'] = (book_ids, author_ids)"
|
| 762 |
+
]
|
| 763 |
+
},
|
| 764 |
+
{
|
| 765 |
+
"cell_type": "code",
|
| 766 |
+
"execution_count": null,
|
| 767 |
+
"id": "a5a30970b7fae165",
|
| 768 |
+
"metadata": {},
|
| 769 |
+
"outputs": [],
|
| 770 |
+
"source": []
|
| 771 |
+
},
|
| 772 |
+
{
|
| 773 |
+
"cell_type": "markdown",
|
| 774 |
+
"id": "1380cf57160349e2",
|
| 775 |
+
"metadata": {},
|
| 776 |
+
"source": [
|
| 777 |
+
"## Book-Publisher Links"
|
| 778 |
+
]
|
| 779 |
+
},
|
| 780 |
+
{
|
| 781 |
+
"cell_type": "code",
|
| 782 |
+
"execution_count": 11,
|
| 783 |
+
"id": "243f23406fe1c845",
|
| 784 |
+
"metadata": {
|
| 785 |
+
"ExecuteTime": {
|
| 786 |
+
"end_time": "2024-12-01T15:03:32.182494Z",
|
| 787 |
+
"start_time": "2024-12-01T15:03:31.968836Z"
|
| 788 |
+
}
|
| 789 |
+
},
|
| 790 |
+
"outputs": [],
|
| 791 |
+
"source": [
|
| 792 |
+
"books['publisher'] = books['publisher'].str.lower()"
|
| 793 |
+
]
|
| 794 |
+
},
|
| 795 |
+
{
|
| 796 |
+
"cell_type": "code",
|
| 797 |
+
"execution_count": 12,
|
| 798 |
+
"id": "36d25bd5e5d2b5ae",
|
| 799 |
+
"metadata": {
|
| 800 |
+
"ExecuteTime": {
|
| 801 |
+
"end_time": "2024-12-01T15:03:32.942637Z",
|
| 802 |
+
"start_time": "2024-12-01T15:03:32.260068Z"
|
| 803 |
+
}
|
| 804 |
+
},
|
| 805 |
+
"outputs": [
|
| 806 |
+
{
|
| 807 |
+
"name": "stdout",
|
| 808 |
+
"output_type": "stream",
|
| 809 |
+
"text": [
|
| 810 |
+
"Number of publishers: 43910\n"
|
| 811 |
+
]
|
| 812 |
+
}
|
| 813 |
+
],
|
| 814 |
+
"source": [
|
| 815 |
+
"publisher_id_encoder = LabelEncoder()\n",
|
| 816 |
+
"publisher_ids = publisher_id_encoder.fit_transform(books['publisher'])\n",
|
| 817 |
+
"print('Number of publishers:', publisher_ids.max()+1)"
|
| 818 |
+
]
|
| 819 |
+
},
|
| 820 |
+
{
|
| 821 |
+
"cell_type": "code",
|
| 822 |
+
"execution_count": 13,
|
| 823 |
+
"id": "14631f9a7bb9eb09",
|
| 824 |
+
"metadata": {
|
| 825 |
+
"ExecuteTime": {
|
| 826 |
+
"end_time": "2024-12-01T15:03:32.972437Z",
|
| 827 |
+
"start_time": "2024-12-01T15:03:32.962111Z"
|
| 828 |
+
}
|
| 829 |
+
},
|
| 830 |
+
"outputs": [
|
| 831 |
+
{
|
| 832 |
+
"name": "stdout",
|
| 833 |
+
"output_type": "stream",
|
| 834 |
+
"text": [
|
| 835 |
+
"Number of book-publisher links: 594484\n"
|
| 836 |
+
]
|
| 837 |
+
}
|
| 838 |
+
],
|
| 839 |
+
"source": [
|
| 840 |
+
"book_ids = np.arange(books.shape[0])\n",
|
| 841 |
+
"publisher_ids = publisher_ids.astype(np.uint16)\n",
|
| 842 |
+
"\n",
|
| 843 |
+
"print('Number of book-publisher links:', publisher_ids.shape[0])\n",
|
| 844 |
+
"data['book-publisher'] = (book_ids, publisher_ids)"
|
| 845 |
+
]
|
| 846 |
+
},
|
| 847 |
+
{
|
| 848 |
+
"cell_type": "code",
|
| 849 |
+
"execution_count": null,
|
| 850 |
+
"id": "6a7f6d07b544bcfb",
|
| 851 |
+
"metadata": {},
|
| 852 |
+
"outputs": [],
|
| 853 |
+
"source": []
|
| 854 |
+
},
|
| 855 |
+
{
|
| 856 |
+
"cell_type": "markdown",
|
| 857 |
+
"id": "5881666538c61e9b",
|
| 858 |
+
"metadata": {},
|
| 859 |
+
"source": [
|
| 860 |
+
"## Book-Book Links"
|
| 861 |
+
]
|
| 862 |
+
},
|
| 863 |
+
{
|
| 864 |
+
"cell_type": "code",
|
| 865 |
+
"execution_count": 14,
|
| 866 |
+
"id": "c3fae65aa006b6b",
|
| 867 |
+
"metadata": {
|
| 868 |
+
"ExecuteTime": {
|
| 869 |
+
"end_time": "2024-12-01T15:03:33.241692Z",
|
| 870 |
+
"start_time": "2024-12-01T15:03:33.214832Z"
|
| 871 |
+
}
|
| 872 |
+
},
|
| 873 |
+
"outputs": [
|
| 874 |
+
{
|
| 875 |
+
"data": {
|
| 876 |
+
"text/html": [
|
| 877 |
+
"<div>\n",
|
| 878 |
+
"<style scoped>\n",
|
| 879 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 880 |
+
" vertical-align: middle;\n",
|
| 881 |
+
" }\n",
|
| 882 |
+
"\n",
|
| 883 |
+
" .dataframe tbody tr th {\n",
|
| 884 |
+
" vertical-align: top;\n",
|
| 885 |
+
" }\n",
|
| 886 |
+
"\n",
|
| 887 |
+
" .dataframe thead th {\n",
|
| 888 |
+
" text-align: right;\n",
|
| 889 |
+
" }\n",
|
| 890 |
+
"</style>\n",
|
| 891 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 892 |
+
" <thead>\n",
|
| 893 |
+
" <tr style=\"text-align: right;\">\n",
|
| 894 |
+
" <th></th>\n",
|
| 895 |
+
" <th>book_id</th>\n",
|
| 896 |
+
" <th>title</th>\n",
|
| 897 |
+
" <th>description</th>\n",
|
| 898 |
+
" <th>publication_year</th>\n",
|
| 899 |
+
" <th>publisher</th>\n",
|
| 900 |
+
" <th>authors</th>\n",
|
| 901 |
+
" <th>similar_books</th>\n",
|
| 902 |
+
" <th>genres</th>\n",
|
| 903 |
+
" </tr>\n",
|
| 904 |
+
" </thead>\n",
|
| 905 |
+
" <tbody>\n",
|
| 906 |
+
" <tr>\n",
|
| 907 |
+
" <th>0</th>\n",
|
| 908 |
+
" <td>1333909</td>\n",
|
| 909 |
+
" <td>Good Harbor</td>\n",
|
| 910 |
+
" <td>Anita Diamant's international bestseller \"The ...</td>\n",
|
| 911 |
+
" <td>2001</td>\n",
|
| 912 |
+
" <td>simon & schuster audio</td>\n",
|
| 913 |
+
" <td>[626222]</td>\n",
|
| 914 |
+
" <td>[8709549, 17074050, 28937, 158816, 228563, 112...</td>\n",
|
| 915 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 916 |
+
" </tr>\n",
|
| 917 |
+
" <tr>\n",
|
| 918 |
+
" <th>1</th>\n",
|
| 919 |
+
" <td>7327624</td>\n",
|
| 920 |
+
" <td>The Unschooled Wizard (Sun Wolf and Starhawk, ...</td>\n",
|
| 921 |
+
" <td>Omnibus book club edition containing the Ladie...</td>\n",
|
| 922 |
+
" <td>1987</td>\n",
|
| 923 |
+
" <td>nelson doubleday, inc.</td>\n",
|
| 924 |
+
" <td>[10333]</td>\n",
|
| 925 |
+
" <td>[19997, 828466, 1569323, 425389, 1176674, 2627...</td>\n",
|
| 926 |
+
" <td>[fantasy, paranormal, mystery, thriller, crime...</td>\n",
|
| 927 |
+
" </tr>\n",
|
| 928 |
+
" <tr>\n",
|
| 929 |
+
" <th>2</th>\n",
|
| 930 |
+
" <td>6066819</td>\n",
|
| 931 |
+
" <td>Best Friends Forever</td>\n",
|
| 932 |
+
" <td>Addie Downs and Valerie Adler were eight when ...</td>\n",
|
| 933 |
+
" <td>2009</td>\n",
|
| 934 |
+
" <td>atria books</td>\n",
|
| 935 |
+
" <td>[9212]</td>\n",
|
| 936 |
+
" <td>[6604176, 6054190, 2285777, 82641, 7569453, 70...</td>\n",
|
| 937 |
+
" <td>[romance, mystery, thriller, crime]</td>\n",
|
| 938 |
+
" </tr>\n",
|
| 939 |
+
" <tr>\n",
|
| 940 |
+
" <th>3</th>\n",
|
| 941 |
+
" <td>6066812</td>\n",
|
| 942 |
+
" <td>All's Fairy in Love and War (Avalon: Web of Ma...</td>\n",
|
| 943 |
+
" <td>To Kara's astonishment, she discovers that a p...</td>\n",
|
| 944 |
+
" <td>2009</td>\n",
|
| 945 |
+
" <td>seven seas</td>\n",
|
| 946 |
+
" <td>[19158]</td>\n",
|
| 947 |
+
" <td>[948696, 439885, 274955, 12978730, 372986, 216...</td>\n",
|
| 948 |
+
" <td>[fantasy, paranormal, young-adult, children]</td>\n",
|
| 949 |
+
" </tr>\n",
|
| 950 |
+
" <tr>\n",
|
| 951 |
+
" <th>4</th>\n",
|
| 952 |
+
" <td>287149</td>\n",
|
| 953 |
+
" <td>The Devil's Notebook</td>\n",
|
| 954 |
+
" <td>Wisdom, humor, and dark observations by the fo...</td>\n",
|
| 955 |
+
" <td>2000</td>\n",
|
| 956 |
+
" <td>feral house</td>\n",
|
| 957 |
+
" <td>[2983296, 40075]</td>\n",
|
| 958 |
+
" <td>[287151, 1104760, 1172822, 440292, 287082, 630...</td>\n",
|
| 959 |
+
" <td>[history, historical fiction, biography]</td>\n",
|
| 960 |
+
" </tr>\n",
|
| 961 |
+
" </tbody>\n",
|
| 962 |
+
"</table>\n",
|
| 963 |
+
"</div>"
|
| 964 |
+
],
|
| 965 |
+
"text/plain": [
|
| 966 |
+
" book_id title \\\n",
|
| 967 |
+
"0 1333909 Good Harbor \n",
|
| 968 |
+
"1 7327624 The Unschooled Wizard (Sun Wolf and Starhawk, ... \n",
|
| 969 |
+
"2 6066819 Best Friends Forever \n",
|
| 970 |
+
"3 6066812 All's Fairy in Love and War (Avalon: Web of Ma... \n",
|
| 971 |
+
"4 287149 The Devil's Notebook \n",
|
| 972 |
+
"\n",
|
| 973 |
+
" description publication_year \\\n",
|
| 974 |
+
"0 Anita Diamant's international bestseller \"The ... 2001 \n",
|
| 975 |
+
"1 Omnibus book club edition containing the Ladie... 1987 \n",
|
| 976 |
+
"2 Addie Downs and Valerie Adler were eight when ... 2009 \n",
|
| 977 |
+
"3 To Kara's astonishment, she discovers that a p... 2009 \n",
|
| 978 |
+
"4 Wisdom, humor, and dark observations by the fo... 2000 \n",
|
| 979 |
+
"\n",
|
| 980 |
+
" publisher authors \\\n",
|
| 981 |
+
"0 simon & schuster audio [626222] \n",
|
| 982 |
+
"1 nelson doubleday, inc. [10333] \n",
|
| 983 |
+
"2 atria books [9212] \n",
|
| 984 |
+
"3 seven seas [19158] \n",
|
| 985 |
+
"4 feral house [2983296, 40075] \n",
|
| 986 |
+
"\n",
|
| 987 |
+
" similar_books \\\n",
|
| 988 |
+
"0 [8709549, 17074050, 28937, 158816, 228563, 112... \n",
|
| 989 |
+
"1 [19997, 828466, 1569323, 425389, 1176674, 2627... \n",
|
| 990 |
+
"2 [6604176, 6054190, 2285777, 82641, 7569453, 70... \n",
|
| 991 |
+
"3 [948696, 439885, 274955, 12978730, 372986, 216... \n",
|
| 992 |
+
"4 [287151, 1104760, 1172822, 440292, 287082, 630... \n",
|
| 993 |
+
"\n",
|
| 994 |
+
" genres \n",
|
| 995 |
+
"0 [history, historical fiction, biography] \n",
|
| 996 |
+
"1 [fantasy, paranormal, mystery, thriller, crime... \n",
|
| 997 |
+
"2 [romance, mystery, thriller, crime] \n",
|
| 998 |
+
"3 [fantasy, paranormal, young-adult, children] \n",
|
| 999 |
+
"4 [history, historical fiction, biography] "
|
| 1000 |
+
]
|
| 1001 |
+
},
|
| 1002 |
+
"execution_count": 14,
|
| 1003 |
+
"metadata": {},
|
| 1004 |
+
"output_type": "execute_result"
|
| 1005 |
+
}
|
| 1006 |
+
],
|
| 1007 |
+
"source": [
|
| 1008 |
+
"books.head()"
|
| 1009 |
+
]
|
| 1010 |
+
},
|
| 1011 |
+
{
|
| 1012 |
+
"cell_type": "code",
|
| 1013 |
+
"execution_count": 15,
|
| 1014 |
+
"id": "1b5c2f8770c233c1",
|
| 1015 |
+
"metadata": {
|
| 1016 |
+
"ExecuteTime": {
|
| 1017 |
+
"end_time": "2024-12-01T15:03:37.317930Z",
|
| 1018 |
+
"start_time": "2024-12-01T15:03:33.565952Z"
|
| 1019 |
+
}
|
| 1020 |
+
},
|
| 1021 |
+
"outputs": [],
|
| 1022 |
+
"source": [
|
| 1023 |
+
"book_ids = np.concatenate([np.full(count, i) \n",
|
| 1024 |
+
" for i, count in enumerate(books['similar_books'].apply(len))])"
|
| 1025 |
+
]
|
| 1026 |
+
},
|
| 1027 |
+
{
|
| 1028 |
+
"cell_type": "code",
|
| 1029 |
+
"execution_count": 16,
|
| 1030 |
+
"id": "d9a0f2ea5eafc2b7",
|
| 1031 |
+
"metadata": {
|
| 1032 |
+
"ExecuteTime": {
|
| 1033 |
+
"end_time": "2024-12-01T15:03:38.723310Z",
|
| 1034 |
+
"start_time": "2024-12-01T15:03:37.413450Z"
|
| 1035 |
+
}
|
| 1036 |
+
},
|
| 1037 |
+
"outputs": [],
|
| 1038 |
+
"source": [
|
| 1039 |
+
"similar_book_ids = np.array(list(itertools.chain(*(books['similar_books'].values))))"
|
| 1040 |
+
]
|
| 1041 |
+
},
|
| 1042 |
+
{
|
| 1043 |
+
"cell_type": "code",
|
| 1044 |
+
"execution_count": 17,
|
| 1045 |
+
"id": "98d12cf75643deb5",
|
| 1046 |
+
"metadata": {
|
| 1047 |
+
"ExecuteTime": {
|
| 1048 |
+
"end_time": "2024-12-01T15:03:39.188161Z",
|
| 1049 |
+
"start_time": "2024-12-01T15:03:38.734349Z"
|
| 1050 |
+
}
|
| 1051 |
+
},
|
| 1052 |
+
"outputs": [],
|
| 1053 |
+
"source": [
|
| 1054 |
+
"mask = np.isin(similar_book_ids, books['book_id'].values)\n",
|
| 1055 |
+
"book_ids = book_ids[mask]\n",
|
| 1056 |
+
"similar_book_ids = similar_book_ids[mask]"
|
| 1057 |
+
]
|
| 1058 |
+
},
|
| 1059 |
+
{
|
| 1060 |
+
"cell_type": "code",
|
| 1061 |
+
"execution_count": 18,
|
| 1062 |
+
"id": "71668c7c67f579a1",
|
| 1063 |
+
"metadata": {
|
| 1064 |
+
"ExecuteTime": {
|
| 1065 |
+
"end_time": "2024-12-01T15:03:48.529895Z",
|
| 1066 |
+
"start_time": "2024-12-01T15:03:39.420886Z"
|
| 1067 |
+
}
|
| 1068 |
+
},
|
| 1069 |
+
"outputs": [],
|
| 1070 |
+
"source": [
|
| 1071 |
+
"book_id_map = dict(zip(books['book_id'].values, range(len(book_ids))))\n",
|
| 1072 |
+
"similar_book_ids = np.array([book_id_map[_] for _ in similar_book_ids])"
|
| 1073 |
+
]
|
| 1074 |
+
},
|
| 1075 |
+
{
|
| 1076 |
+
"cell_type": "code",
|
| 1077 |
+
"execution_count": 19,
|
| 1078 |
+
"id": "fbfc9064c9306926",
|
| 1079 |
+
"metadata": {
|
| 1080 |
+
"ExecuteTime": {
|
| 1081 |
+
"end_time": "2024-12-01T15:03:49.570122Z",
|
| 1082 |
+
"start_time": "2024-12-01T15:03:49.436004Z"
|
| 1083 |
+
}
|
| 1084 |
+
},
|
| 1085 |
+
"outputs": [],
|
| 1086 |
+
"source": [
|
| 1087 |
+
"# Save memory\n",
|
| 1088 |
+
"mask = book_ids < similar_book_ids\n",
|
| 1089 |
+
"book_ids = book_ids[mask]\n",
|
| 1090 |
+
"similar_book_ids = similar_book_ids[mask]"
|
| 1091 |
+
]
|
| 1092 |
+
},
|
| 1093 |
+
{
|
| 1094 |
+
"cell_type": "code",
|
| 1095 |
+
"execution_count": 20,
|
| 1096 |
+
"id": "8edc9d69e5eadb21",
|
| 1097 |
+
"metadata": {
|
| 1098 |
+
"ExecuteTime": {
|
| 1099 |
+
"end_time": "2024-12-01T15:03:50.457376Z",
|
| 1100 |
+
"start_time": "2024-12-01T15:03:50.449784Z"
|
| 1101 |
+
}
|
| 1102 |
+
},
|
| 1103 |
+
"outputs": [
|
| 1104 |
+
{
|
| 1105 |
+
"name": "stdout",
|
| 1106 |
+
"output_type": "stream",
|
| 1107 |
+
"text": [
|
| 1108 |
+
"Number of book-book links: 3510209\n"
|
| 1109 |
+
]
|
| 1110 |
+
}
|
| 1111 |
+
],
|
| 1112 |
+
"source": [
|
| 1113 |
+
"print('Number of book-book links:', similar_book_ids.shape[0])\n",
|
| 1114 |
+
"data['book-book'] = (book_ids, similar_book_ids)"
|
| 1115 |
+
]
|
| 1116 |
+
},
|
| 1117 |
+
{
|
| 1118 |
+
"cell_type": "code",
|
| 1119 |
+
"execution_count": null,
|
| 1120 |
+
"id": "8cc7b055644c1d42",
|
| 1121 |
+
"metadata": {},
|
| 1122 |
+
"outputs": [],
|
| 1123 |
+
"source": []
|
| 1124 |
+
},
|
| 1125 |
+
{
|
| 1126 |
+
"cell_type": "code",
|
| 1127 |
+
"execution_count": 21,
|
| 1128 |
+
"id": "32ff5477051870d5",
|
| 1129 |
+
"metadata": {
|
| 1130 |
+
"ExecuteTime": {
|
| 1131 |
+
"end_time": "2024-12-01T15:03:51.333417Z",
|
| 1132 |
+
"start_time": "2024-12-01T15:03:51.323284Z"
|
| 1133 |
+
}
|
| 1134 |
+
},
|
| 1135 |
+
"outputs": [],
|
| 1136 |
+
"source": [
|
| 1137 |
+
"book_years = (books['publication_year']).values.astype(np.int16)\n",
|
| 1138 |
+
"data['book_years'] = book_years"
|
| 1139 |
+
]
|
| 1140 |
+
},
|
| 1141 |
+
{
|
| 1142 |
+
"cell_type": "code",
|
| 1143 |
+
"execution_count": 22,
|
| 1144 |
+
"id": "3f59be40f4948310",
|
| 1145 |
+
"metadata": {
|
| 1146 |
+
"ExecuteTime": {
|
| 1147 |
+
"end_time": "2024-12-01T15:03:52.244019Z",
|
| 1148 |
+
"start_time": "2024-12-01T15:03:52.229147Z"
|
| 1149 |
+
}
|
| 1150 |
+
},
|
| 1151 |
+
"outputs": [
|
| 1152 |
+
{
|
| 1153 |
+
"data": {
|
| 1154 |
+
"text/plain": [
|
| 1155 |
+
"{'book_labels': <Compressed Sparse Row sparse matrix of dtype 'bool'\n",
|
| 1156 |
+
" \twith 1304440 stored elements and shape (594484, 8)>,\n",
|
| 1157 |
+
" 'book-author': (array([ 0, 1, 2, ..., 594482, 594482, 594483]),\n",
|
| 1158 |
+
" array([ 53976, 3557, 3138, ..., 784, 81819, 128754])),\n",
|
| 1159 |
+
" 'book-publisher': (array([ 0, 1, 2, ..., 594481, 594482, 594483]),\n",
|
| 1160 |
+
" array([36145, 27416, 2948, ..., 16709, 27036, 16233], dtype=uint16)),\n",
|
| 1161 |
+
" 'book-book': (array([ 0, 0, 0, ..., 594468, 594476, 594476]),\n",
|
| 1162 |
+
" array([236765, 406277, 529992, ..., 594479, 594481, 594479])),\n",
|
| 1163 |
+
" 'book_years': array([2001, 1987, 2009, ..., 2007, 2015, 2014], dtype=int16)}"
|
| 1164 |
+
]
|
| 1165 |
+
},
|
| 1166 |
+
"execution_count": 22,
|
| 1167 |
+
"metadata": {},
|
| 1168 |
+
"output_type": "execute_result"
|
| 1169 |
+
}
|
| 1170 |
+
],
|
| 1171 |
+
"source": [
|
| 1172 |
+
"data"
|
| 1173 |
+
]
|
| 1174 |
+
},
|
| 1175 |
+
{
|
| 1176 |
+
"cell_type": "code",
|
| 1177 |
+
"execution_count": 23,
|
| 1178 |
+
"id": "a0867ffd9f4ee3f9",
|
| 1179 |
+
"metadata": {
|
| 1180 |
+
"ExecuteTime": {
|
| 1181 |
+
"end_time": "2024-12-01T15:03:53.251143Z",
|
| 1182 |
+
"start_time": "2024-12-01T15:03:53.174887Z"
|
| 1183 |
+
}
|
| 1184 |
+
},
|
| 1185 |
+
"outputs": [],
|
| 1186 |
+
"source": [
|
| 1187 |
+
"import pickle\n",
|
| 1188 |
+
"\n",
|
| 1189 |
+
"with open('book.pkl', 'wb') as f:\n",
|
| 1190 |
+
" pickle.dump(data, f)"
|
| 1191 |
+
]
|
| 1192 |
+
},
|
| 1193 |
+
{
|
| 1194 |
+
"cell_type": "code",
|
| 1195 |
+
"execution_count": 15,
|
| 1196 |
+
"id": "1d4bf279de35c717",
|
| 1197 |
+
"metadata": {
|
| 1198 |
+
"ExecuteTime": {
|
| 1199 |
+
"end_time": "2024-12-01T14:30:28.500440Z",
|
| 1200 |
+
"start_time": "2024-12-01T14:30:18.334222Z"
|
| 1201 |
+
}
|
| 1202 |
+
},
|
| 1203 |
+
"outputs": [],
|
| 1204 |
+
"source": [
|
| 1205 |
+
"books.to_csv('Book.csv', index=False)"
|
| 1206 |
+
]
|
| 1207 |
+
},
|
| 1208 |
+
{
|
| 1209 |
+
"cell_type": "markdown",
|
| 1210 |
+
"id": "7487e86adadcaec",
|
| 1211 |
+
"metadata": {},
|
| 1212 |
+
"source": [
|
| 1213 |
+
"### Node Features\n",
|
| 1214 |
+
"\n",
|
| 1215 |
+
"We generate embeddings as features for each node in the graph. Node embeddings are generated by passing the title and the description through a Sentence-BERT model and obtaining a 384-embedding vector for each movie node.\n",
|
| 1216 |
+
"\n",
|
| 1217 |
+
"\n",
|
| 1218 |
+
"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",
|
| 1219 |
+
"\n",
|
| 1220 |
+
"all-MiniLM-L6-v2\n",
|
| 1221 |
+
"\n",
|
| 1222 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 1223 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 1224 |
+
"Max Sequence Length:\t256\n",
|
| 1225 |
+
"Dimensions:\t384\n",
|
| 1226 |
+
"Normalized Embeddings:\ttrue\n",
|
| 1227 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 1228 |
+
"Size:\t80 MB\n",
|
| 1229 |
+
"Pooling:\tMean Pooling\n",
|
| 1230 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 1231 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 1232 |
+
]
|
| 1233 |
+
},
|
| 1234 |
+
{
|
| 1235 |
+
"cell_type": "code",
|
| 1236 |
+
"execution_count": 1,
|
| 1237 |
+
"id": "15e53898382782a0",
|
| 1238 |
+
"metadata": {},
|
| 1239 |
+
"outputs": [
|
| 1240 |
+
{
|
| 1241 |
+
"data": {
|
| 1242 |
+
"text/html": [
|
| 1243 |
+
"<div>\n",
|
| 1244 |
+
"<style scoped>\n",
|
| 1245 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 1246 |
+
" vertical-align: middle;\n",
|
| 1247 |
+
" }\n",
|
| 1248 |
+
"\n",
|
| 1249 |
+
" .dataframe tbody tr th {\n",
|
| 1250 |
+
" vertical-align: top;\n",
|
| 1251 |
+
" }\n",
|
| 1252 |
+
"\n",
|
| 1253 |
+
" .dataframe thead th {\n",
|
| 1254 |
+
" text-align: right;\n",
|
| 1255 |
+
" }\n",
|
| 1256 |
+
"</style>\n",
|
| 1257 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 1258 |
+
" <thead>\n",
|
| 1259 |
+
" <tr style=\"text-align: right;\">\n",
|
| 1260 |
+
" <th></th>\n",
|
| 1261 |
+
" <th>book_id</th>\n",
|
| 1262 |
+
" <th>title</th>\n",
|
| 1263 |
+
" <th>description</th>\n",
|
| 1264 |
+
" <th>publication_year</th>\n",
|
| 1265 |
+
" <th>publisher</th>\n",
|
| 1266 |
+
" <th>authors</th>\n",
|
| 1267 |
+
" <th>similar_books</th>\n",
|
| 1268 |
+
" <th>genres</th>\n",
|
| 1269 |
+
" </tr>\n",
|
| 1270 |
+
" </thead>\n",
|
| 1271 |
+
" <tbody>\n",
|
| 1272 |
+
" <tr>\n",
|
| 1273 |
+
" <th>0</th>\n",
|
| 1274 |
+
" <td>1333909</td>\n",
|
| 1275 |
+
" <td>Good Harbor</td>\n",
|
| 1276 |
+
" <td>Anita Diamant's international bestseller \"The ...</td>\n",
|
| 1277 |
+
" <td>2001</td>\n",
|
| 1278 |
+
" <td>simon & schuster audio</td>\n",
|
| 1279 |
+
" <td>[626222]</td>\n",
|
| 1280 |
+
" <td>[8709549, 17074050, 28937, 158816, 228563, 112...</td>\n",
|
| 1281 |
+
" <td>['history, historical fiction, biography']</td>\n",
|
| 1282 |
+
" </tr>\n",
|
| 1283 |
+
" <tr>\n",
|
| 1284 |
+
" <th>1</th>\n",
|
| 1285 |
+
" <td>7327624</td>\n",
|
| 1286 |
+
" <td>The Unschooled Wizard (Sun Wolf and Starhawk, ...</td>\n",
|
| 1287 |
+
" <td>Omnibus book club edition containing the Ladie...</td>\n",
|
| 1288 |
+
" <td>1987</td>\n",
|
| 1289 |
+
" <td>nelson doubleday, inc.</td>\n",
|
| 1290 |
+
" <td>[10333]</td>\n",
|
| 1291 |
+
" <td>[19997, 828466, 1569323, 425389, 1176674, 2627...</td>\n",
|
| 1292 |
+
" <td>['fantasy, paranormal', 'mystery, thriller, cr...</td>\n",
|
| 1293 |
+
" </tr>\n",
|
| 1294 |
+
" <tr>\n",
|
| 1295 |
+
" <th>2</th>\n",
|
| 1296 |
+
" <td>6066819</td>\n",
|
| 1297 |
+
" <td>Best Friends Forever</td>\n",
|
| 1298 |
+
" <td>Addie Downs and Valerie Adler were eight when ...</td>\n",
|
| 1299 |
+
" <td>2009</td>\n",
|
| 1300 |
+
" <td>atria books</td>\n",
|
| 1301 |
+
" <td>[9212]</td>\n",
|
| 1302 |
+
" <td>[6604176, 6054190, 2285777, 82641, 7569453, 70...</td>\n",
|
| 1303 |
+
" <td>['romance', 'mystery, thriller, crime']</td>\n",
|
| 1304 |
+
" </tr>\n",
|
| 1305 |
+
" <tr>\n",
|
| 1306 |
+
" <th>3</th>\n",
|
| 1307 |
+
" <td>6066812</td>\n",
|
| 1308 |
+
" <td>All's Fairy in Love and War (Avalon: Web of Ma...</td>\n",
|
| 1309 |
+
" <td>To Kara's astonishment, she discovers that a p...</td>\n",
|
| 1310 |
+
" <td>2009</td>\n",
|
| 1311 |
+
" <td>seven seas</td>\n",
|
| 1312 |
+
" <td>[19158]</td>\n",
|
| 1313 |
+
" <td>[948696, 439885, 274955, 12978730, 372986, 216...</td>\n",
|
| 1314 |
+
" <td>['fantasy, paranormal', 'young-adult', 'childr...</td>\n",
|
| 1315 |
+
" </tr>\n",
|
| 1316 |
+
" <tr>\n",
|
| 1317 |
+
" <th>4</th>\n",
|
| 1318 |
+
" <td>287149</td>\n",
|
| 1319 |
+
" <td>The Devil's Notebook</td>\n",
|
| 1320 |
+
" <td>Wisdom, humor, and dark observations by the fo...</td>\n",
|
| 1321 |
+
" <td>2000</td>\n",
|
| 1322 |
+
" <td>feral house</td>\n",
|
| 1323 |
+
" <td>[2983296, 40075]</td>\n",
|
| 1324 |
+
" <td>[287151, 1104760, 1172822, 440292, 287082, 630...</td>\n",
|
| 1325 |
+
" <td>['history, historical fiction, biography']</td>\n",
|
| 1326 |
+
" </tr>\n",
|
| 1327 |
+
" </tbody>\n",
|
| 1328 |
+
"</table>\n",
|
| 1329 |
+
"</div>"
|
| 1330 |
+
],
|
| 1331 |
+
"text/plain": [
|
| 1332 |
+
" book_id title \\\n",
|
| 1333 |
+
"0 1333909 Good Harbor \n",
|
| 1334 |
+
"1 7327624 The Unschooled Wizard (Sun Wolf and Starhawk, ... \n",
|
| 1335 |
+
"2 6066819 Best Friends Forever \n",
|
| 1336 |
+
"3 6066812 All's Fairy in Love and War (Avalon: Web of Ma... \n",
|
| 1337 |
+
"4 287149 The Devil's Notebook \n",
|
| 1338 |
+
"\n",
|
| 1339 |
+
" description publication_year \\\n",
|
| 1340 |
+
"0 Anita Diamant's international bestseller \"The ... 2001 \n",
|
| 1341 |
+
"1 Omnibus book club edition containing the Ladie... 1987 \n",
|
| 1342 |
+
"2 Addie Downs and Valerie Adler were eight when ... 2009 \n",
|
| 1343 |
+
"3 To Kara's astonishment, she discovers that a p... 2009 \n",
|
| 1344 |
+
"4 Wisdom, humor, and dark observations by the fo... 2000 \n",
|
| 1345 |
+
"\n",
|
| 1346 |
+
" publisher authors \\\n",
|
| 1347 |
+
"0 simon & schuster audio [626222] \n",
|
| 1348 |
+
"1 nelson doubleday, inc. [10333] \n",
|
| 1349 |
+
"2 atria books [9212] \n",
|
| 1350 |
+
"3 seven seas [19158] \n",
|
| 1351 |
+
"4 feral house [2983296, 40075] \n",
|
| 1352 |
+
"\n",
|
| 1353 |
+
" similar_books \\\n",
|
| 1354 |
+
"0 [8709549, 17074050, 28937, 158816, 228563, 112... \n",
|
| 1355 |
+
"1 [19997, 828466, 1569323, 425389, 1176674, 2627... \n",
|
| 1356 |
+
"2 [6604176, 6054190, 2285777, 82641, 7569453, 70... \n",
|
| 1357 |
+
"3 [948696, 439885, 274955, 12978730, 372986, 216... \n",
|
| 1358 |
+
"4 [287151, 1104760, 1172822, 440292, 287082, 630... \n",
|
| 1359 |
+
"\n",
|
| 1360 |
+
" genres \n",
|
| 1361 |
+
"0 ['history, historical fiction, biography'] \n",
|
| 1362 |
+
"1 ['fantasy, paranormal', 'mystery, thriller, cr... \n",
|
| 1363 |
+
"2 ['romance', 'mystery, thriller, crime'] \n",
|
| 1364 |
+
"3 ['fantasy, paranormal', 'young-adult', 'childr... \n",
|
| 1365 |
+
"4 ['history, historical fiction, biography'] "
|
| 1366 |
+
]
|
| 1367 |
+
},
|
| 1368 |
+
"execution_count": 1,
|
| 1369 |
+
"metadata": {},
|
| 1370 |
+
"output_type": "execute_result"
|
| 1371 |
+
}
|
| 1372 |
+
],
|
| 1373 |
+
"source": [
|
| 1374 |
+
"import pandas as pd\n",
|
| 1375 |
+
"\n",
|
| 1376 |
+
"books = pd.read_csv('Book.csv')\n",
|
| 1377 |
+
"books.head()"
|
| 1378 |
+
]
|
| 1379 |
+
},
|
| 1380 |
+
{
|
| 1381 |
+
"cell_type": "code",
|
| 1382 |
+
"execution_count": 2,
|
| 1383 |
+
"id": "b3cfbb60",
|
| 1384 |
+
"metadata": {},
|
| 1385 |
+
"outputs": [
|
| 1386 |
+
{
|
| 1387 |
+
"data": {
|
| 1388 |
+
"text/plain": [
|
| 1389 |
+
"{'book_labels': <Compressed Sparse Row sparse matrix of dtype 'bool'\n",
|
| 1390 |
+
" \twith 1304440 stored elements and shape (594484, 8)>,\n",
|
| 1391 |
+
" 'book-author': (array([ 0, 1, 2, ..., 594482, 594482, 594483], dtype=int32),\n",
|
| 1392 |
+
" array([ 53976, 3557, 3138, ..., 784, 81819, 128754], dtype=int32)),\n",
|
| 1393 |
+
" 'book-publisher': (array([ 0, 1, 2, ..., 594481, 594482, 594483], dtype=int32),\n",
|
| 1394 |
+
" array([36145, 27416, 2948, ..., 16709, 27036, 16233], dtype=uint16)),\n",
|
| 1395 |
+
" 'book-book': (array([ 0, 0, 0, ..., 594468, 594476, 594476], dtype=int32),\n",
|
| 1396 |
+
" array([236765, 406277, 529992, ..., 594479, 594481, 594479], dtype=int32)),\n",
|
| 1397 |
+
" 'book_years': array([2001, 1987, 2009, ..., 2007, 2015, 2014], dtype=int16)}"
|
| 1398 |
+
]
|
| 1399 |
+
},
|
| 1400 |
+
"execution_count": 2,
|
| 1401 |
+
"metadata": {},
|
| 1402 |
+
"output_type": "execute_result"
|
| 1403 |
+
}
|
| 1404 |
+
],
|
| 1405 |
+
"source": [
|
| 1406 |
+
"import pickle\n",
|
| 1407 |
+
"\n",
|
| 1408 |
+
"with open('book.pkl', 'rb') as f:\n",
|
| 1409 |
+
" data = pickle.load(f)\n",
|
| 1410 |
+
"data"
|
| 1411 |
+
]
|
| 1412 |
+
},
|
| 1413 |
+
{
|
| 1414 |
+
"cell_type": "code",
|
| 1415 |
+
"execution_count": 3,
|
| 1416 |
+
"id": "7bd49dd4",
|
| 1417 |
+
"metadata": {},
|
| 1418 |
+
"outputs": [
|
| 1419 |
+
{
|
| 1420 |
+
"name": "stderr",
|
| 1421 |
+
"output_type": "stream",
|
| 1422 |
+
"text": [
|
| 1423 |
+
"/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",
|
| 1424 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 1425 |
+
]
|
| 1426 |
+
},
|
| 1427 |
+
{
|
| 1428 |
+
"data": {
|
| 1429 |
+
"text/plain": [
|
| 1430 |
+
"SentenceTransformer(\n",
|
| 1431 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 1432 |
+
" (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",
|
| 1433 |
+
" (2): Normalize()\n",
|
| 1434 |
+
")"
|
| 1435 |
+
]
|
| 1436 |
+
},
|
| 1437 |
+
"execution_count": 3,
|
| 1438 |
+
"metadata": {},
|
| 1439 |
+
"output_type": "execute_result"
|
| 1440 |
+
}
|
| 1441 |
+
],
|
| 1442 |
+
"source": [
|
| 1443 |
+
"import torch\n",
|
| 1444 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 1445 |
+
"\n",
|
| 1446 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 1447 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 1448 |
+
"model"
|
| 1449 |
+
]
|
| 1450 |
+
},
|
| 1451 |
+
{
|
| 1452 |
+
"cell_type": "code",
|
| 1453 |
+
"execution_count": 4,
|
| 1454 |
+
"id": "b86eb9fc",
|
| 1455 |
+
"metadata": {},
|
| 1456 |
+
"outputs": [],
|
| 1457 |
+
"source": [
|
| 1458 |
+
"text = books['title'] + ' ' + books['description']"
|
| 1459 |
+
]
|
| 1460 |
+
},
|
| 1461 |
+
{
|
| 1462 |
+
"cell_type": "code",
|
| 1463 |
+
"execution_count": 5,
|
| 1464 |
+
"id": "ab1586ef",
|
| 1465 |
+
"metadata": {},
|
| 1466 |
+
"outputs": [
|
| 1467 |
+
{
|
| 1468 |
+
"name": "stderr",
|
| 1469 |
+
"output_type": "stream",
|
| 1470 |
+
"text": [
|
| 1471 |
+
"Batches: 100%|██████████| 146/146 [07:21<00:00, 3.02s/it]\n"
|
| 1472 |
+
]
|
| 1473 |
+
}
|
| 1474 |
+
],
|
| 1475 |
+
"source": [
|
| 1476 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
|
| 1477 |
+
]
|
| 1478 |
+
},
|
| 1479 |
+
{
|
| 1480 |
+
"cell_type": "code",
|
| 1481 |
+
"execution_count": 9,
|
| 1482 |
+
"id": "f6b5c92e",
|
| 1483 |
+
"metadata": {},
|
| 1484 |
+
"outputs": [],
|
| 1485 |
+
"source": [
|
| 1486 |
+
"data['book_feats'] = feats"
|
| 1487 |
+
]
|
| 1488 |
+
},
|
| 1489 |
+
{
|
| 1490 |
+
"cell_type": "code",
|
| 1491 |
+
"execution_count": 11,
|
| 1492 |
+
"id": "497721b0",
|
| 1493 |
+
"metadata": {},
|
| 1494 |
+
"outputs": [],
|
| 1495 |
+
"source": [
|
| 1496 |
+
"with open('book.pkl', 'wb') as f:\n",
|
| 1497 |
+
" pickle.dump(data, f)"
|
| 1498 |
+
]
|
| 1499 |
+
}
|
| 1500 |
+
],
|
| 1501 |
+
"metadata": {
|
| 1502 |
+
"kernelspec": {
|
| 1503 |
+
"display_name": "Python 3",
|
| 1504 |
+
"language": "python",
|
| 1505 |
+
"name": "python3"
|
| 1506 |
+
},
|
| 1507 |
+
"language_info": {
|
| 1508 |
+
"codemirror_mode": {
|
| 1509 |
+
"name": "ipython",
|
| 1510 |
+
"version": 3
|
| 1511 |
+
},
|
| 1512 |
+
"file_extension": ".py",
|
| 1513 |
+
"mimetype": "text/x-python",
|
| 1514 |
+
"name": "python",
|
| 1515 |
+
"nbconvert_exporter": "python",
|
| 1516 |
+
"pygments_lexer": "ipython3",
|
| 1517 |
+
"version": "3.10.12"
|
| 1518 |
+
}
|
| 1519 |
+
},
|
| 1520 |
+
"nbformat": 4,
|
| 1521 |
+
"nbformat_minor": 5
|
| 1522 |
+
}
|
croval/CroVal.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d536b4508832c250721862b5a764d1e7f39e4038406c3806b1c3dcad77a67100
|
| 3 |
+
size 42317642
|
croval/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CroVal: Community Question Answering Network
|
| 2 |
+
|
| 3 |
+
## Dataset Description
|
| 4 |
+
|
| 5 |
+
The CroVal dataset is a heterogeneous network composed of a subset of [Cross Validated](https://stats.stackexchange.com), a question-and-answer website for people interested in statistics, machine learning, data analysis, data mining, and data visualization. We construct our HTAG based on the [Cross Validated data dump](https://archive.org/download/stackexchange) released on April 6, 2024. After processing, it contains three types of entities—questions (34,153 nodes), users (8,898 nodes), and tags (1,335 nodes)—as well as three types of directed relations connecting three types of entities—a question "is related to" another question, a user "asks" a question, and a question "contains" a tag. Questions are associated with their titles and bodies, and all the other types of entities are textless. We concatenate the question title and body and pass it to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each question node. Questions are categorized into six classes ("regression", "hypothesis-testing", "distributions", "neural-networks", "classification", and "clustering") based on their topic. On the question nodes, we attach the creation date as meta information.
|
| 6 |
+
|
| 7 |
+
**Prediction task.**
|
| 8 |
+
Given the heterogeneous CroVal data, the task is to predict the primary topics of the given questions, which is cast as an ordinary multi-class classification problem. The metrics are the Micro-F1 and Macro-F1 scores.
|
| 9 |
+
|
| 10 |
+
**Dataset splitting.**
|
| 11 |
+
We also split the data according to time. Specifically, we train on questions asked up to 2011, validate on those asked in 2012, and test on those asked since 2013.
|
| 12 |
+
|
| 13 |
+
**Dataset Statistics.**
|
| 14 |
+
|
| 15 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 16 |
+
| --------------- | ------------------------- | --------- | ------------ |
|
| 17 |
+
| **44386** | **164,981** | 6 | Train: 9,699 |
|
| 18 |
+
| Question: 34153 | Question-Question: 46,269 | | Valid: 9,889 |
|
| 19 |
+
| User: 8898 | Question-User: 34,153 | | Test: 14,565 |
|
| 20 |
+
| Tag: 1335 | Question-Tag: 84,559 | | |
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
## Dataset Construction
|
| 25 |
+
|
| 26 |
+
1. Download `Posts.xml` and `PostLinks.xml` (i.e., `stats.stackexchange.com.7z`) from the [Cross Validated data dump](https://archive.org/download/stackexchange) released on April 6, 2024
|
| 27 |
+
2. Run `extract_from_croval.py` to convert .xml to .csv
|
| 28 |
+
3. Run `graph_builder.ipynb`
|
croval/croval.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e7d8d3c662362dccf9c4f64b4205b362d574c6100ebdb21e87e24228224ce32d
|
| 3 |
+
size 54078731
|
croval/extract_from_croval.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import csv
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
print('Extract Posts...')
|
| 7 |
+
start_time = time.time()
|
| 8 |
+
file_name = 'Posts'
|
| 9 |
+
xml_file = open('./raw/'+file_name+'.xml', 'r', encoding='utf-8')
|
| 10 |
+
csv_file = open('./csvs/'+file_name+'.csv', 'w', encoding='utf-8', newline='')
|
| 11 |
+
|
| 12 |
+
writer = csv.writer(csv_file)
|
| 13 |
+
heads = ['Id', 'Title', 'Body', 'Tags', 'PostTypeId', 'CreationDate', 'OwnerUserId', 'ParentId']
|
| 14 |
+
writer.writerow(heads)
|
| 15 |
+
|
| 16 |
+
num = 0
|
| 17 |
+
rows = []
|
| 18 |
+
for line in xml_file:
|
| 19 |
+
if line.startswith(' <row'):
|
| 20 |
+
r = r'(\w+)="([^"]+)'
|
| 21 |
+
key_values = re.findall(r, line)
|
| 22 |
+
content = dict(key_values)
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
PostTypeId = content['PostTypeId']
|
| 26 |
+
if PostTypeId == '1' or PostTypeId == '2':
|
| 27 |
+
Id = content['Id']
|
| 28 |
+
Body = content['Body']
|
| 29 |
+
CreationDate = content['CreationDate']
|
| 30 |
+
OwnerUserId = content['OwnerUserId']
|
| 31 |
+
if PostTypeId == '1':
|
| 32 |
+
Title = content['Title']
|
| 33 |
+
Tags = content['Tags']
|
| 34 |
+
ParentId = ''
|
| 35 |
+
else:
|
| 36 |
+
Title = ''
|
| 37 |
+
Tags = ''
|
| 38 |
+
ParentId = content['ParentId']
|
| 39 |
+
row = [Id,Title,Body,Tags,PostTypeId,CreationDate,OwnerUserId,ParentId]
|
| 40 |
+
rows.append(row)
|
| 41 |
+
num += 1
|
| 42 |
+
if num % 5000 == 0:
|
| 43 |
+
writer.writerows(rows)
|
| 44 |
+
rows = []
|
| 45 |
+
print(num)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
continue
|
| 48 |
+
if len(rows) > 0:
|
| 49 |
+
writer.writerows(rows)
|
| 50 |
+
print(num, f'{time.time() - start_time}s', 'Done!')
|
| 51 |
+
xml_file.close()
|
| 52 |
+
csv_file.close()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
################################################
|
| 56 |
+
print('Extract PostLinks...')
|
| 57 |
+
start_time = time.time()
|
| 58 |
+
file_name = 'PostLinks'
|
| 59 |
+
xml_file = open('./raw/'+file_name+'.xml', 'r', encoding='utf-8')
|
| 60 |
+
csv_file = open('./csvs/'+file_name+'.csv', 'w', encoding='utf-8', newline='')
|
| 61 |
+
|
| 62 |
+
writer = csv.writer(csv_file)
|
| 63 |
+
heads = ['Id', 'CreationDate', 'PostId', 'RelatedPostId', 'LinkTypeId']
|
| 64 |
+
writer.writerow(heads)
|
| 65 |
+
|
| 66 |
+
num = 0
|
| 67 |
+
rows = []
|
| 68 |
+
for line in xml_file:
|
| 69 |
+
if line.startswith(' <row'):
|
| 70 |
+
r = r'(\w+)="([^"]+)'
|
| 71 |
+
key_values = re.findall(r, line)
|
| 72 |
+
content = dict(key_values)
|
| 73 |
+
row = [content['Id'], content['CreationDate'], content['PostId'],
|
| 74 |
+
content['RelatedPostId'], content['LinkTypeId']]
|
| 75 |
+
rows.append(row)
|
| 76 |
+
num += 1
|
| 77 |
+
if num % 5000 == 0:
|
| 78 |
+
writer.writerows(rows)
|
| 79 |
+
rows = []
|
| 80 |
+
print(num)
|
| 81 |
+
if len(rows) > 0:
|
| 82 |
+
writer.writerows(rows)
|
| 83 |
+
print(num, f'{time.time() - start_time}s', 'Done!')
|
| 84 |
+
xml_file.close()
|
| 85 |
+
csv_file.close()
|
croval/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,1757 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Z",
|
| 10 |
+
"start_time": "2024-12-02T15:09:03.260703Z"
|
| 11 |
+
},
|
| 12 |
+
"collapsed": true
|
| 13 |
+
},
|
| 14 |
+
"outputs": [],
|
| 15 |
+
"source": [
|
| 16 |
+
"import itertools\n",
|
| 17 |
+
"import numpy as np\n",
|
| 18 |
+
"import pandas as pd\n",
|
| 19 |
+
"from sklearn.preprocessing import LabelEncoder"
|
| 20 |
+
]
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"cell_type": "markdown",
|
| 24 |
+
"id": "7352ff562a374adb",
|
| 25 |
+
"metadata": {},
|
| 26 |
+
"source": [
|
| 27 |
+
"## Preprocess"
|
| 28 |
+
]
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"cell_type": "code",
|
| 32 |
+
"execution_count": 2,
|
| 33 |
+
"id": "daae2a4dccfedf88",
|
| 34 |
+
"metadata": {
|
| 35 |
+
"ExecuteTime": {
|
| 36 |
+
"end_time": "2024-12-02T15:09:15.109798Z",
|
| 37 |
+
"start_time": "2024-12-02T15:09:05.188680Z"
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
"outputs": [
|
| 41 |
+
{
|
| 42 |
+
"name": "stdout",
|
| 43 |
+
"output_type": "stream",
|
| 44 |
+
"text": [
|
| 45 |
+
"Question Counts 210226\n",
|
| 46 |
+
"Answers Counts 206435\n"
|
| 47 |
+
]
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"data": {
|
| 51 |
+
"text/html": [
|
| 52 |
+
"<div>\n",
|
| 53 |
+
"<style scoped>\n",
|
| 54 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 55 |
+
" vertical-align: middle;\n",
|
| 56 |
+
" }\n",
|
| 57 |
+
"\n",
|
| 58 |
+
" .dataframe tbody tr th {\n",
|
| 59 |
+
" vertical-align: top;\n",
|
| 60 |
+
" }\n",
|
| 61 |
+
"\n",
|
| 62 |
+
" .dataframe thead th {\n",
|
| 63 |
+
" text-align: right;\n",
|
| 64 |
+
" }\n",
|
| 65 |
+
"</style>\n",
|
| 66 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 67 |
+
" <thead>\n",
|
| 68 |
+
" <tr style=\"text-align: right;\">\n",
|
| 69 |
+
" <th></th>\n",
|
| 70 |
+
" <th>Id</th>\n",
|
| 71 |
+
" <th>Title</th>\n",
|
| 72 |
+
" <th>Body</th>\n",
|
| 73 |
+
" <th>Tags</th>\n",
|
| 74 |
+
" <th>PostTypeId</th>\n",
|
| 75 |
+
" <th>CreationDate</th>\n",
|
| 76 |
+
" <th>OwnerUserId</th>\n",
|
| 77 |
+
" <th>ParentId</th>\n",
|
| 78 |
+
" </tr>\n",
|
| 79 |
+
" </thead>\n",
|
| 80 |
+
" <tbody>\n",
|
| 81 |
+
" <tr>\n",
|
| 82 |
+
" <th>0</th>\n",
|
| 83 |
+
" <td>437734</td>\n",
|
| 84 |
+
" <td>Effect of sex at specific point with confidenc...</td>\n",
|
| 85 |
+
" <td>&lt;p&gt;Assume I model PEFR (related to lung ...</td>\n",
|
| 86 |
+
" <td>|r|regression|confidence-interval|</td>\n",
|
| 87 |
+
" <td>1</td>\n",
|
| 88 |
+
" <td>2019-11-24T19:50:42.807</td>\n",
|
| 89 |
+
" <td>266724</td>\n",
|
| 90 |
+
" <td>NaN</td>\n",
|
| 91 |
+
" </tr>\n",
|
| 92 |
+
" <tr>\n",
|
| 93 |
+
" <th>1</th>\n",
|
| 94 |
+
" <td>622877</td>\n",
|
| 95 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 96 |
+
" <td>&lt;p&gt;Suppose I have a data set that contai...</td>\n",
|
| 97 |
+
" <td>|regression|poisson-distribution|poisson-proce...</td>\n",
|
| 98 |
+
" <td>1</td>\n",
|
| 99 |
+
" <td>2023-08-01T15:57:49.950</td>\n",
|
| 100 |
+
" <td>314344</td>\n",
|
| 101 |
+
" <td>NaN</td>\n",
|
| 102 |
+
" </tr>\n",
|
| 103 |
+
" <tr>\n",
|
| 104 |
+
" <th>5</th>\n",
|
| 105 |
+
" <td>517792</td>\n",
|
| 106 |
+
" <td>Did I correctly apply the factorisation theore...</td>\n",
|
| 107 |
+
" <td>&lt;p&gt;Suppose that we have a density &lt;sp...</td>\n",
|
| 108 |
+
" <td>|probability|estimation|inference|estimators|s...</td>\n",
|
| 109 |
+
" <td>1</td>\n",
|
| 110 |
+
" <td>2021-04-01T18:01:50.420</td>\n",
|
| 111 |
+
" <td>310650</td>\n",
|
| 112 |
+
" <td>NaN</td>\n",
|
| 113 |
+
" </tr>\n",
|
| 114 |
+
" <tr>\n",
|
| 115 |
+
" <th>6</th>\n",
|
| 116 |
+
" <td>344644</td>\n",
|
| 117 |
+
" <td>IBM SPSS Damped Trend time series analysis met...</td>\n",
|
| 118 |
+
" <td>&lt;p&gt;I have been doing a time series analy...</td>\n",
|
| 119 |
+
" <td>|time-series|spss|trend|</td>\n",
|
| 120 |
+
" <td>1</td>\n",
|
| 121 |
+
" <td>2018-05-05T13:34:35.617</td>\n",
|
| 122 |
+
" <td>207140</td>\n",
|
| 123 |
+
" <td>NaN</td>\n",
|
| 124 |
+
" </tr>\n",
|
| 125 |
+
" <tr>\n",
|
| 126 |
+
" <th>7</th>\n",
|
| 127 |
+
" <td>620838</td>\n",
|
| 128 |
+
" <td>Mixed model development for repeated measures ...</td>\n",
|
| 129 |
+
" <td>&lt;p&gt;I have longitudinal data for multiple...</td>\n",
|
| 130 |
+
" <td>|mixed-model|lme4-nlme|repeated-measures|multi...</td>\n",
|
| 131 |
+
" <td>1</td>\n",
|
| 132 |
+
" <td>2023-07-07T23:34:22.930</td>\n",
|
| 133 |
+
" <td>391974</td>\n",
|
| 134 |
+
" <td>NaN</td>\n",
|
| 135 |
+
" </tr>\n",
|
| 136 |
+
" </tbody>\n",
|
| 137 |
+
"</table>\n",
|
| 138 |
+
"</div>"
|
| 139 |
+
],
|
| 140 |
+
"text/plain": [
|
| 141 |
+
" Id Title \\\n",
|
| 142 |
+
"0 437734 Effect of sex at specific point with confidenc... \n",
|
| 143 |
+
"1 622877 Poisson process for small sample size \n",
|
| 144 |
+
"5 517792 Did I correctly apply the factorisation theore... \n",
|
| 145 |
+
"6 344644 IBM SPSS Damped Trend time series analysis met... \n",
|
| 146 |
+
"7 620838 Mixed model development for repeated measures ... \n",
|
| 147 |
+
"\n",
|
| 148 |
+
" Body \\\n",
|
| 149 |
+
"0 <p>Assume I model PEFR (related to lung ... \n",
|
| 150 |
+
"1 <p>Suppose I have a data set that contai... \n",
|
| 151 |
+
"5 <p>Suppose that we have a density <sp... \n",
|
| 152 |
+
"6 <p>I have been doing a time series analy... \n",
|
| 153 |
+
"7 <p>I have longitudinal data for multiple... \n",
|
| 154 |
+
"\n",
|
| 155 |
+
" Tags PostTypeId \\\n",
|
| 156 |
+
"0 |r|regression|confidence-interval| 1 \n",
|
| 157 |
+
"1 |regression|poisson-distribution|poisson-proce... 1 \n",
|
| 158 |
+
"5 |probability|estimation|inference|estimators|s... 1 \n",
|
| 159 |
+
"6 |time-series|spss|trend| 1 \n",
|
| 160 |
+
"7 |mixed-model|lme4-nlme|repeated-measures|multi... 1 \n",
|
| 161 |
+
"\n",
|
| 162 |
+
" CreationDate OwnerUserId ParentId \n",
|
| 163 |
+
"0 2019-11-24T19:50:42.807 266724 NaN \n",
|
| 164 |
+
"1 2023-08-01T15:57:49.950 314344 NaN \n",
|
| 165 |
+
"5 2021-04-01T18:01:50.420 310650 NaN \n",
|
| 166 |
+
"6 2018-05-05T13:34:35.617 207140 NaN \n",
|
| 167 |
+
"7 2023-07-07T23:34:22.930 391974 NaN "
|
| 168 |
+
]
|
| 169 |
+
},
|
| 170 |
+
"execution_count": 2,
|
| 171 |
+
"metadata": {},
|
| 172 |
+
"output_type": "execute_result"
|
| 173 |
+
}
|
| 174 |
+
],
|
| 175 |
+
"source": [
|
| 176 |
+
"posts = pd.read_csv('csvs/Posts.csv')\n",
|
| 177 |
+
"posts.dropna(subset=['Body', 'OwnerUserId'], how='any', inplace=True)\n",
|
| 178 |
+
"\n",
|
| 179 |
+
"# Shuffle\n",
|
| 180 |
+
"posts = posts.sample(frac=1, random_state=42, replace=False, ignore_index=True)\n",
|
| 181 |
+
"\n",
|
| 182 |
+
"questions = posts[posts['PostTypeId']==1]\n",
|
| 183 |
+
"answers = posts[posts['PostTypeId']==2]\n",
|
| 184 |
+
"\n",
|
| 185 |
+
"print('Question Counts', len(questions))\n",
|
| 186 |
+
"print('Answers Counts', len(answers))\n",
|
| 187 |
+
"questions.head()"
|
| 188 |
+
]
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"cell_type": "code",
|
| 192 |
+
"execution_count": 3,
|
| 193 |
+
"id": "1f48885a95573c3",
|
| 194 |
+
"metadata": {
|
| 195 |
+
"ExecuteTime": {
|
| 196 |
+
"end_time": "2024-12-02T15:09:16.092779Z",
|
| 197 |
+
"start_time": "2024-12-02T15:09:15.257949Z"
|
| 198 |
+
}
|
| 199 |
+
},
|
| 200 |
+
"outputs": [
|
| 201 |
+
{
|
| 202 |
+
"data": {
|
| 203 |
+
"text/html": [
|
| 204 |
+
"<div>\n",
|
| 205 |
+
"<style scoped>\n",
|
| 206 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 207 |
+
" vertical-align: middle;\n",
|
| 208 |
+
" }\n",
|
| 209 |
+
"\n",
|
| 210 |
+
" .dataframe tbody tr th {\n",
|
| 211 |
+
" vertical-align: top;\n",
|
| 212 |
+
" }\n",
|
| 213 |
+
"\n",
|
| 214 |
+
" .dataframe thead th {\n",
|
| 215 |
+
" text-align: right;\n",
|
| 216 |
+
" }\n",
|
| 217 |
+
"</style>\n",
|
| 218 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 219 |
+
" <thead>\n",
|
| 220 |
+
" <tr style=\"text-align: right;\">\n",
|
| 221 |
+
" <th></th>\n",
|
| 222 |
+
" <th>Id</th>\n",
|
| 223 |
+
" <th>Title</th>\n",
|
| 224 |
+
" <th>Body</th>\n",
|
| 225 |
+
" <th>Tags</th>\n",
|
| 226 |
+
" <th>PostTypeId</th>\n",
|
| 227 |
+
" <th>CreationDate</th>\n",
|
| 228 |
+
" <th>OwnerUserId</th>\n",
|
| 229 |
+
" <th>ParentId</th>\n",
|
| 230 |
+
" </tr>\n",
|
| 231 |
+
" </thead>\n",
|
| 232 |
+
" <tbody>\n",
|
| 233 |
+
" <tr>\n",
|
| 234 |
+
" <th>0</th>\n",
|
| 235 |
+
" <td>437734</td>\n",
|
| 236 |
+
" <td>Effect of sex at specific point with confidenc...</td>\n",
|
| 237 |
+
" <td>&lt;p&gt;Assume I model PEFR (related to lung ...</td>\n",
|
| 238 |
+
" <td>[r, regression, confidence-interval]</td>\n",
|
| 239 |
+
" <td>1</td>\n",
|
| 240 |
+
" <td>2019-11-24T19:50:42.807</td>\n",
|
| 241 |
+
" <td>266724</td>\n",
|
| 242 |
+
" <td>NaN</td>\n",
|
| 243 |
+
" </tr>\n",
|
| 244 |
+
" <tr>\n",
|
| 245 |
+
" <th>1</th>\n",
|
| 246 |
+
" <td>622877</td>\n",
|
| 247 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 248 |
+
" <td>&lt;p&gt;Suppose I have a data set that contai...</td>\n",
|
| 249 |
+
" <td>[regression, poisson-distribution, poisson-pro...</td>\n",
|
| 250 |
+
" <td>1</td>\n",
|
| 251 |
+
" <td>2023-08-01T15:57:49.950</td>\n",
|
| 252 |
+
" <td>314344</td>\n",
|
| 253 |
+
" <td>NaN</td>\n",
|
| 254 |
+
" </tr>\n",
|
| 255 |
+
" <tr>\n",
|
| 256 |
+
" <th>5</th>\n",
|
| 257 |
+
" <td>517792</td>\n",
|
| 258 |
+
" <td>Did I correctly apply the factorisation theore...</td>\n",
|
| 259 |
+
" <td>&lt;p&gt;Suppose that we have a density &lt;sp...</td>\n",
|
| 260 |
+
" <td>[probability, estimation, inference, estimator...</td>\n",
|
| 261 |
+
" <td>1</td>\n",
|
| 262 |
+
" <td>2021-04-01T18:01:50.420</td>\n",
|
| 263 |
+
" <td>310650</td>\n",
|
| 264 |
+
" <td>NaN</td>\n",
|
| 265 |
+
" </tr>\n",
|
| 266 |
+
" <tr>\n",
|
| 267 |
+
" <th>6</th>\n",
|
| 268 |
+
" <td>344644</td>\n",
|
| 269 |
+
" <td>IBM SPSS Damped Trend time series analysis met...</td>\n",
|
| 270 |
+
" <td>&lt;p&gt;I have been doing a time series analy...</td>\n",
|
| 271 |
+
" <td>[time-series, spss, trend]</td>\n",
|
| 272 |
+
" <td>1</td>\n",
|
| 273 |
+
" <td>2018-05-05T13:34:35.617</td>\n",
|
| 274 |
+
" <td>207140</td>\n",
|
| 275 |
+
" <td>NaN</td>\n",
|
| 276 |
+
" </tr>\n",
|
| 277 |
+
" <tr>\n",
|
| 278 |
+
" <th>7</th>\n",
|
| 279 |
+
" <td>620838</td>\n",
|
| 280 |
+
" <td>Mixed model development for repeated measures ...</td>\n",
|
| 281 |
+
" <td>&lt;p&gt;I have longitudinal data for multiple...</td>\n",
|
| 282 |
+
" <td>[mixed-model, lme4-nlme, repeated-measures, mu...</td>\n",
|
| 283 |
+
" <td>1</td>\n",
|
| 284 |
+
" <td>2023-07-07T23:34:22.930</td>\n",
|
| 285 |
+
" <td>391974</td>\n",
|
| 286 |
+
" <td>NaN</td>\n",
|
| 287 |
+
" </tr>\n",
|
| 288 |
+
" </tbody>\n",
|
| 289 |
+
"</table>\n",
|
| 290 |
+
"</div>"
|
| 291 |
+
],
|
| 292 |
+
"text/plain": [
|
| 293 |
+
" Id Title \\\n",
|
| 294 |
+
"0 437734 Effect of sex at specific point with confidenc... \n",
|
| 295 |
+
"1 622877 Poisson process for small sample size \n",
|
| 296 |
+
"5 517792 Did I correctly apply the factorisation theore... \n",
|
| 297 |
+
"6 344644 IBM SPSS Damped Trend time series analysis met... \n",
|
| 298 |
+
"7 620838 Mixed model development for repeated measures ... \n",
|
| 299 |
+
"\n",
|
| 300 |
+
" Body \\\n",
|
| 301 |
+
"0 <p>Assume I model PEFR (related to lung ... \n",
|
| 302 |
+
"1 <p>Suppose I have a data set that contai... \n",
|
| 303 |
+
"5 <p>Suppose that we have a density <sp... \n",
|
| 304 |
+
"6 <p>I have been doing a time series analy... \n",
|
| 305 |
+
"7 <p>I have longitudinal data for multiple... \n",
|
| 306 |
+
"\n",
|
| 307 |
+
" Tags PostTypeId \\\n",
|
| 308 |
+
"0 [r, regression, confidence-interval] 1 \n",
|
| 309 |
+
"1 [regression, poisson-distribution, poisson-pro... 1 \n",
|
| 310 |
+
"5 [probability, estimation, inference, estimator... 1 \n",
|
| 311 |
+
"6 [time-series, spss, trend] 1 \n",
|
| 312 |
+
"7 [mixed-model, lme4-nlme, repeated-measures, mu... 1 \n",
|
| 313 |
+
"\n",
|
| 314 |
+
" CreationDate OwnerUserId ParentId \n",
|
| 315 |
+
"0 2019-11-24T19:50:42.807 266724 NaN \n",
|
| 316 |
+
"1 2023-08-01T15:57:49.950 314344 NaN \n",
|
| 317 |
+
"5 2021-04-01T18:01:50.420 310650 NaN \n",
|
| 318 |
+
"6 2018-05-05T13:34:35.617 207140 NaN \n",
|
| 319 |
+
"7 2023-07-07T23:34:22.930 391974 NaN "
|
| 320 |
+
]
|
| 321 |
+
},
|
| 322 |
+
"execution_count": 3,
|
| 323 |
+
"metadata": {},
|
| 324 |
+
"output_type": "execute_result"
|
| 325 |
+
}
|
| 326 |
+
],
|
| 327 |
+
"source": [
|
| 328 |
+
"questions.loc[:, 'Tags'] = questions['Tags'].str.split('|').apply(lambda x: x[1:-1])\n",
|
| 329 |
+
"questions.head()"
|
| 330 |
+
]
|
| 331 |
+
},
|
| 332 |
+
{
|
| 333 |
+
"cell_type": "code",
|
| 334 |
+
"execution_count": 4,
|
| 335 |
+
"id": "42a4b75299719d52",
|
| 336 |
+
"metadata": {
|
| 337 |
+
"ExecuteTime": {
|
| 338 |
+
"end_time": "2024-12-02T15:09:16.870012Z",
|
| 339 |
+
"start_time": "2024-12-02T15:09:16.184978Z"
|
| 340 |
+
}
|
| 341 |
+
},
|
| 342 |
+
"outputs": [],
|
| 343 |
+
"source": [
|
| 344 |
+
"questions_ids = np.concatenate([np.full(count, i) \n",
|
| 345 |
+
" for i, count in enumerate(questions['Tags'].apply(len).values)])\n",
|
| 346 |
+
"all_tags = list(itertools.chain(*(questions['Tags'].values)))"
|
| 347 |
+
]
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"cell_type": "code",
|
| 351 |
+
"execution_count": 5,
|
| 352 |
+
"id": "9b790352a2990970",
|
| 353 |
+
"metadata": {
|
| 354 |
+
"ExecuteTime": {
|
| 355 |
+
"end_time": "2024-12-02T15:09:17.991099Z",
|
| 356 |
+
"start_time": "2024-12-02T15:09:16.947033Z"
|
| 357 |
+
}
|
| 358 |
+
},
|
| 359 |
+
"outputs": [
|
| 360 |
+
{
|
| 361 |
+
"data": {
|
| 362 |
+
"text/plain": [
|
| 363 |
+
"(652198,)"
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
"execution_count": 5,
|
| 367 |
+
"metadata": {},
|
| 368 |
+
"output_type": "execute_result"
|
| 369 |
+
}
|
| 370 |
+
],
|
| 371 |
+
"source": [
|
| 372 |
+
"tag_label_encoder1 = LabelEncoder()\n",
|
| 373 |
+
"all_tag_ids = tag_label_encoder1.fit_transform(all_tags)\n",
|
| 374 |
+
"all_tag_ids.shape"
|
| 375 |
+
]
|
| 376 |
+
},
|
| 377 |
+
{
|
| 378 |
+
"cell_type": "code",
|
| 379 |
+
"execution_count": 6,
|
| 380 |
+
"id": "a7b6eb11f97145df",
|
| 381 |
+
"metadata": {
|
| 382 |
+
"ExecuteTime": {
|
| 383 |
+
"end_time": "2024-12-02T15:09:18.064642Z",
|
| 384 |
+
"start_time": "2024-12-02T15:09:18.055165Z"
|
| 385 |
+
}
|
| 386 |
+
},
|
| 387 |
+
"outputs": [],
|
| 388 |
+
"source": [
|
| 389 |
+
"selected_tags = ['regression', 'hypothesis-testing', 'distributions', 'neural-networks', 'classification', 'clustering']\n",
|
| 390 |
+
"selected_tag_ids = tag_label_encoder1.transform(selected_tags)"
|
| 391 |
+
]
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"cell_type": "code",
|
| 395 |
+
"execution_count": 7,
|
| 396 |
+
"id": "6612b2e89985b151",
|
| 397 |
+
"metadata": {
|
| 398 |
+
"ExecuteTime": {
|
| 399 |
+
"end_time": "2024-12-02T15:09:18.146649Z",
|
| 400 |
+
"start_time": "2024-12-02T15:09:18.114610Z"
|
| 401 |
+
}
|
| 402 |
+
},
|
| 403 |
+
"outputs": [
|
| 404 |
+
{
|
| 405 |
+
"name": "stdout",
|
| 406 |
+
"output_type": "stream",
|
| 407 |
+
"text": [
|
| 408 |
+
"67940\n"
|
| 409 |
+
]
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"data": {
|
| 413 |
+
"text/plain": [
|
| 414 |
+
"(60783,)"
|
| 415 |
+
]
|
| 416 |
+
},
|
| 417 |
+
"execution_count": 7,
|
| 418 |
+
"metadata": {},
|
| 419 |
+
"output_type": "execute_result"
|
| 420 |
+
}
|
| 421 |
+
],
|
| 422 |
+
"source": [
|
| 423 |
+
"# Select questions with only one of selected_tags\n",
|
| 424 |
+
"mask = np.isin(all_tag_ids, selected_tag_ids)\n",
|
| 425 |
+
"print(mask.sum())\n",
|
| 426 |
+
"questions_with_selected_tags, counts = np.unique(questions_ids[mask], return_counts=True)\n",
|
| 427 |
+
"questions_with_selected_tags = questions_with_selected_tags[counts==1]\n",
|
| 428 |
+
"questions_with_selected_tags.shape"
|
| 429 |
+
]
|
| 430 |
+
},
|
| 431 |
+
{
|
| 432 |
+
"cell_type": "code",
|
| 433 |
+
"execution_count": 8,
|
| 434 |
+
"id": "f8335fdbad91449e",
|
| 435 |
+
"metadata": {
|
| 436 |
+
"ExecuteTime": {
|
| 437 |
+
"end_time": "2024-12-02T15:09:18.279119Z",
|
| 438 |
+
"start_time": "2024-12-02T15:09:18.248060Z"
|
| 439 |
+
}
|
| 440 |
+
},
|
| 441 |
+
"outputs": [],
|
| 442 |
+
"source": [
|
| 443 |
+
"mask = np.isin(questions_ids, questions_with_selected_tags)\n",
|
| 444 |
+
"questions_ids = questions_ids[mask]\n",
|
| 445 |
+
"all_tag_ids = all_tag_ids[mask]\n",
|
| 446 |
+
"mask = np.isin(all_tag_ids, selected_tag_ids)\n",
|
| 447 |
+
"questions_ids = questions_ids[mask]\n",
|
| 448 |
+
"all_tag_ids = all_tag_ids[mask]"
|
| 449 |
+
]
|
| 450 |
+
},
|
| 451 |
+
{
|
| 452 |
+
"cell_type": "code",
|
| 453 |
+
"execution_count": 9,
|
| 454 |
+
"id": "acc2ccdc88ca5ebb",
|
| 455 |
+
"metadata": {
|
| 456 |
+
"ExecuteTime": {
|
| 457 |
+
"end_time": "2024-12-02T15:09:18.328543Z",
|
| 458 |
+
"start_time": "2024-12-02T15:09:18.319728Z"
|
| 459 |
+
}
|
| 460 |
+
},
|
| 461 |
+
"outputs": [
|
| 462 |
+
{
|
| 463 |
+
"data": {
|
| 464 |
+
"text/plain": [
|
| 465 |
+
"(array([ 185, 193, 386, 635, 973, 1237]),\n",
|
| 466 |
+
" array([ 5365, 3541, 8514, 9210, 6904, 27249]))"
|
| 467 |
+
]
|
| 468 |
+
},
|
| 469 |
+
"execution_count": 9,
|
| 470 |
+
"metadata": {},
|
| 471 |
+
"output_type": "execute_result"
|
| 472 |
+
}
|
| 473 |
+
],
|
| 474 |
+
"source": [
|
| 475 |
+
"np.unique(all_tag_ids, return_counts=True)"
|
| 476 |
+
]
|
| 477 |
+
},
|
| 478 |
+
{
|
| 479 |
+
"cell_type": "code",
|
| 480 |
+
"execution_count": 10,
|
| 481 |
+
"id": "6dfaf5e25aee9ed5",
|
| 482 |
+
"metadata": {
|
| 483 |
+
"ExecuteTime": {
|
| 484 |
+
"end_time": "2024-12-02T15:09:18.424326Z",
|
| 485 |
+
"start_time": "2024-12-02T15:09:18.381400Z"
|
| 486 |
+
}
|
| 487 |
+
},
|
| 488 |
+
"outputs": [
|
| 489 |
+
{
|
| 490 |
+
"name": "stdout",
|
| 491 |
+
"output_type": "stream",
|
| 492 |
+
"text": [
|
| 493 |
+
"(60783, 9)\n"
|
| 494 |
+
]
|
| 495 |
+
},
|
| 496 |
+
{
|
| 497 |
+
"data": {
|
| 498 |
+
"text/html": [
|
| 499 |
+
"<div>\n",
|
| 500 |
+
"<style scoped>\n",
|
| 501 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 502 |
+
" vertical-align: middle;\n",
|
| 503 |
+
" }\n",
|
| 504 |
+
"\n",
|
| 505 |
+
" .dataframe tbody tr th {\n",
|
| 506 |
+
" vertical-align: top;\n",
|
| 507 |
+
" }\n",
|
| 508 |
+
"\n",
|
| 509 |
+
" .dataframe thead th {\n",
|
| 510 |
+
" text-align: right;\n",
|
| 511 |
+
" }\n",
|
| 512 |
+
"</style>\n",
|
| 513 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 514 |
+
" <thead>\n",
|
| 515 |
+
" <tr style=\"text-align: right;\">\n",
|
| 516 |
+
" <th></th>\n",
|
| 517 |
+
" <th>Id</th>\n",
|
| 518 |
+
" <th>Title</th>\n",
|
| 519 |
+
" <th>Body</th>\n",
|
| 520 |
+
" <th>Tags</th>\n",
|
| 521 |
+
" <th>PostTypeId</th>\n",
|
| 522 |
+
" <th>CreationDate</th>\n",
|
| 523 |
+
" <th>OwnerUserId</th>\n",
|
| 524 |
+
" <th>ParentId</th>\n",
|
| 525 |
+
" <th>Tag</th>\n",
|
| 526 |
+
" </tr>\n",
|
| 527 |
+
" </thead>\n",
|
| 528 |
+
" <tbody>\n",
|
| 529 |
+
" <tr>\n",
|
| 530 |
+
" <th>0</th>\n",
|
| 531 |
+
" <td>437734</td>\n",
|
| 532 |
+
" <td>Effect of sex at specific point with confidenc...</td>\n",
|
| 533 |
+
" <td>&lt;p&gt;Assume I model PEFR (related to lung ...</td>\n",
|
| 534 |
+
" <td>[r, regression, confidence-interval]</td>\n",
|
| 535 |
+
" <td>1</td>\n",
|
| 536 |
+
" <td>2019-11-24T19:50:42.807</td>\n",
|
| 537 |
+
" <td>266724</td>\n",
|
| 538 |
+
" <td>NaN</td>\n",
|
| 539 |
+
" <td>regression</td>\n",
|
| 540 |
+
" </tr>\n",
|
| 541 |
+
" <tr>\n",
|
| 542 |
+
" <th>1</th>\n",
|
| 543 |
+
" <td>622877</td>\n",
|
| 544 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 545 |
+
" <td>&lt;p&gt;Suppose I have a data set that contai...</td>\n",
|
| 546 |
+
" <td>[regression, poisson-distribution, poisson-pro...</td>\n",
|
| 547 |
+
" <td>1</td>\n",
|
| 548 |
+
" <td>2023-08-01T15:57:49.950</td>\n",
|
| 549 |
+
" <td>314344</td>\n",
|
| 550 |
+
" <td>NaN</td>\n",
|
| 551 |
+
" <td>regression</td>\n",
|
| 552 |
+
" </tr>\n",
|
| 553 |
+
" <tr>\n",
|
| 554 |
+
" <th>11</th>\n",
|
| 555 |
+
" <td>178240</td>\n",
|
| 556 |
+
" <td>linear regression accounting for standard erro...</td>\n",
|
| 557 |
+
" <td>&lt;p&gt;I am trying to figure out what is the...</td>\n",
|
| 558 |
+
" <td>[regression, errors-in-variables]</td>\n",
|
| 559 |
+
" <td>1</td>\n",
|
| 560 |
+
" <td>2015-10-22T20:46:44.137</td>\n",
|
| 561 |
+
" <td>19758</td>\n",
|
| 562 |
+
" <td>NaN</td>\n",
|
| 563 |
+
" <td>regression</td>\n",
|
| 564 |
+
" </tr>\n",
|
| 565 |
+
" <tr>\n",
|
| 566 |
+
" <th>14</th>\n",
|
| 567 |
+
" <td>600361</td>\n",
|
| 568 |
+
" <td>Problematic Residual plot</td>\n",
|
| 569 |
+
" <td>&lt;p&gt;&lt;a href=&quot;https://i.stack.imgu...</td>\n",
|
| 570 |
+
" <td>[regression, residuals]</td>\n",
|
| 571 |
+
" <td>1</td>\n",
|
| 572 |
+
" <td>2022-12-29T16:21:35.377</td>\n",
|
| 573 |
+
" <td>376392</td>\n",
|
| 574 |
+
" <td>NaN</td>\n",
|
| 575 |
+
" <td>regression</td>\n",
|
| 576 |
+
" </tr>\n",
|
| 577 |
+
" <tr>\n",
|
| 578 |
+
" <th>17</th>\n",
|
| 579 |
+
" <td>625541</td>\n",
|
| 580 |
+
" <td>Does skipgram model uses backpropagation?</td>\n",
|
| 581 |
+
" <td>&lt;p&gt;I just started to get interested in n...</td>\n",
|
| 582 |
+
" <td>[machine-learning, neural-networks, natural-la...</td>\n",
|
| 583 |
+
" <td>1</td>\n",
|
| 584 |
+
" <td>2023-08-30T06:56:57.460</td>\n",
|
| 585 |
+
" <td>302098</td>\n",
|
| 586 |
+
" <td>NaN</td>\n",
|
| 587 |
+
" <td>neural-networks</td>\n",
|
| 588 |
+
" </tr>\n",
|
| 589 |
+
" </tbody>\n",
|
| 590 |
+
"</table>\n",
|
| 591 |
+
"</div>"
|
| 592 |
+
],
|
| 593 |
+
"text/plain": [
|
| 594 |
+
" Id Title \\\n",
|
| 595 |
+
"0 437734 Effect of sex at specific point with confidenc... \n",
|
| 596 |
+
"1 622877 Poisson process for small sample size \n",
|
| 597 |
+
"11 178240 linear regression accounting for standard erro... \n",
|
| 598 |
+
"14 600361 Problematic Residual plot \n",
|
| 599 |
+
"17 625541 Does skipgram model uses backpropagation? \n",
|
| 600 |
+
"\n",
|
| 601 |
+
" Body \\\n",
|
| 602 |
+
"0 <p>Assume I model PEFR (related to lung ... \n",
|
| 603 |
+
"1 <p>Suppose I have a data set that contai... \n",
|
| 604 |
+
"11 <p>I am trying to figure out what is the... \n",
|
| 605 |
+
"14 <p><a href="https://i.stack.imgu... \n",
|
| 606 |
+
"17 <p>I just started to get interested in n... \n",
|
| 607 |
+
"\n",
|
| 608 |
+
" Tags PostTypeId \\\n",
|
| 609 |
+
"0 [r, regression, confidence-interval] 1 \n",
|
| 610 |
+
"1 [regression, poisson-distribution, poisson-pro... 1 \n",
|
| 611 |
+
"11 [regression, errors-in-variables] 1 \n",
|
| 612 |
+
"14 [regression, residuals] 1 \n",
|
| 613 |
+
"17 [machine-learning, neural-networks, natural-la... 1 \n",
|
| 614 |
+
"\n",
|
| 615 |
+
" CreationDate OwnerUserId ParentId Tag \n",
|
| 616 |
+
"0 2019-11-24T19:50:42.807 266724 NaN regression \n",
|
| 617 |
+
"1 2023-08-01T15:57:49.950 314344 NaN regression \n",
|
| 618 |
+
"11 2015-10-22T20:46:44.137 19758 NaN regression \n",
|
| 619 |
+
"14 2022-12-29T16:21:35.377 376392 NaN regression \n",
|
| 620 |
+
"17 2023-08-30T06:56:57.460 302098 NaN neural-networks "
|
| 621 |
+
]
|
| 622 |
+
},
|
| 623 |
+
"execution_count": 10,
|
| 624 |
+
"metadata": {},
|
| 625 |
+
"output_type": "execute_result"
|
| 626 |
+
}
|
| 627 |
+
],
|
| 628 |
+
"source": [
|
| 629 |
+
"questions = questions.iloc[questions_ids]\n",
|
| 630 |
+
"questions['Tag'] = tag_label_encoder1.inverse_transform(all_tag_ids)\n",
|
| 631 |
+
"\n",
|
| 632 |
+
"print(questions.shape)\n",
|
| 633 |
+
"questions.head()"
|
| 634 |
+
]
|
| 635 |
+
},
|
| 636 |
+
{
|
| 637 |
+
"cell_type": "code",
|
| 638 |
+
"execution_count": 11,
|
| 639 |
+
"id": "b78a91701107f9cd",
|
| 640 |
+
"metadata": {
|
| 641 |
+
"ExecuteTime": {
|
| 642 |
+
"end_time": "2024-12-02T15:09:18.554427Z",
|
| 643 |
+
"start_time": "2024-12-02T15:09:18.536519Z"
|
| 644 |
+
}
|
| 645 |
+
},
|
| 646 |
+
"outputs": [
|
| 647 |
+
{
|
| 648 |
+
"name": "stdout",
|
| 649 |
+
"output_type": "stream",
|
| 650 |
+
"text": [
|
| 651 |
+
"(60783, 9)\n"
|
| 652 |
+
]
|
| 653 |
+
},
|
| 654 |
+
{
|
| 655 |
+
"data": {
|
| 656 |
+
"text/html": [
|
| 657 |
+
"<div>\n",
|
| 658 |
+
"<style scoped>\n",
|
| 659 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 660 |
+
" vertical-align: middle;\n",
|
| 661 |
+
" }\n",
|
| 662 |
+
"\n",
|
| 663 |
+
" .dataframe tbody tr th {\n",
|
| 664 |
+
" vertical-align: top;\n",
|
| 665 |
+
" }\n",
|
| 666 |
+
"\n",
|
| 667 |
+
" .dataframe thead th {\n",
|
| 668 |
+
" text-align: right;\n",
|
| 669 |
+
" }\n",
|
| 670 |
+
"</style>\n",
|
| 671 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 672 |
+
" <thead>\n",
|
| 673 |
+
" <tr style=\"text-align: right;\">\n",
|
| 674 |
+
" <th></th>\n",
|
| 675 |
+
" <th>Id</th>\n",
|
| 676 |
+
" <th>Title</th>\n",
|
| 677 |
+
" <th>Body</th>\n",
|
| 678 |
+
" <th>Tags</th>\n",
|
| 679 |
+
" <th>PostTypeId</th>\n",
|
| 680 |
+
" <th>CreationDate</th>\n",
|
| 681 |
+
" <th>OwnerUserId</th>\n",
|
| 682 |
+
" <th>ParentId</th>\n",
|
| 683 |
+
" <th>Tag</th>\n",
|
| 684 |
+
" </tr>\n",
|
| 685 |
+
" </thead>\n",
|
| 686 |
+
" <tbody>\n",
|
| 687 |
+
" <tr>\n",
|
| 688 |
+
" <th>0</th>\n",
|
| 689 |
+
" <td>437734</td>\n",
|
| 690 |
+
" <td>Effect of sex at specific point with confidenc...</td>\n",
|
| 691 |
+
" <td>&lt;p&gt;Assume I model PEFR (related to lung ...</td>\n",
|
| 692 |
+
" <td>[r, regression, confidence-interval]</td>\n",
|
| 693 |
+
" <td>1</td>\n",
|
| 694 |
+
" <td>2019-11-24T19:50:42.807</td>\n",
|
| 695 |
+
" <td>266724</td>\n",
|
| 696 |
+
" <td>NaN</td>\n",
|
| 697 |
+
" <td>regression</td>\n",
|
| 698 |
+
" </tr>\n",
|
| 699 |
+
" <tr>\n",
|
| 700 |
+
" <th>1</th>\n",
|
| 701 |
+
" <td>622877</td>\n",
|
| 702 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 703 |
+
" <td>&lt;p&gt;Suppose I have a data set that contai...</td>\n",
|
| 704 |
+
" <td>[regression, poisson-distribution, poisson-pro...</td>\n",
|
| 705 |
+
" <td>1</td>\n",
|
| 706 |
+
" <td>2023-08-01T15:57:49.950</td>\n",
|
| 707 |
+
" <td>314344</td>\n",
|
| 708 |
+
" <td>NaN</td>\n",
|
| 709 |
+
" <td>regression</td>\n",
|
| 710 |
+
" </tr>\n",
|
| 711 |
+
" <tr>\n",
|
| 712 |
+
" <th>11</th>\n",
|
| 713 |
+
" <td>178240</td>\n",
|
| 714 |
+
" <td>linear regression accounting for standard erro...</td>\n",
|
| 715 |
+
" <td>&lt;p&gt;I am trying to figure out what is the...</td>\n",
|
| 716 |
+
" <td>[regression, errors-in-variables]</td>\n",
|
| 717 |
+
" <td>1</td>\n",
|
| 718 |
+
" <td>2015-10-22T20:46:44.137</td>\n",
|
| 719 |
+
" <td>19758</td>\n",
|
| 720 |
+
" <td>NaN</td>\n",
|
| 721 |
+
" <td>regression</td>\n",
|
| 722 |
+
" </tr>\n",
|
| 723 |
+
" <tr>\n",
|
| 724 |
+
" <th>14</th>\n",
|
| 725 |
+
" <td>600361</td>\n",
|
| 726 |
+
" <td>Problematic Residual plot</td>\n",
|
| 727 |
+
" <td>&lt;p&gt;&lt;a href=&quot;https://i.stack.imgu...</td>\n",
|
| 728 |
+
" <td>[regression, residuals]</td>\n",
|
| 729 |
+
" <td>1</td>\n",
|
| 730 |
+
" <td>2022-12-29T16:21:35.377</td>\n",
|
| 731 |
+
" <td>376392</td>\n",
|
| 732 |
+
" <td>NaN</td>\n",
|
| 733 |
+
" <td>regression</td>\n",
|
| 734 |
+
" </tr>\n",
|
| 735 |
+
" <tr>\n",
|
| 736 |
+
" <th>17</th>\n",
|
| 737 |
+
" <td>625541</td>\n",
|
| 738 |
+
" <td>Does skipgram model uses backpropagation?</td>\n",
|
| 739 |
+
" <td>&lt;p&gt;I just started to get interested in n...</td>\n",
|
| 740 |
+
" <td>[machine-learning, neural-networks, natural-la...</td>\n",
|
| 741 |
+
" <td>1</td>\n",
|
| 742 |
+
" <td>2023-08-30T06:56:57.460</td>\n",
|
| 743 |
+
" <td>302098</td>\n",
|
| 744 |
+
" <td>NaN</td>\n",
|
| 745 |
+
" <td>neural-networks</td>\n",
|
| 746 |
+
" </tr>\n",
|
| 747 |
+
" </tbody>\n",
|
| 748 |
+
"</table>\n",
|
| 749 |
+
"</div>"
|
| 750 |
+
],
|
| 751 |
+
"text/plain": [
|
| 752 |
+
" Id Title \\\n",
|
| 753 |
+
"0 437734 Effect of sex at specific point with confidenc... \n",
|
| 754 |
+
"1 622877 Poisson process for small sample size \n",
|
| 755 |
+
"11 178240 linear regression accounting for standard erro... \n",
|
| 756 |
+
"14 600361 Problematic Residual plot \n",
|
| 757 |
+
"17 625541 Does skipgram model uses backpropagation? \n",
|
| 758 |
+
"\n",
|
| 759 |
+
" Body \\\n",
|
| 760 |
+
"0 <p>Assume I model PEFR (related to lung ... \n",
|
| 761 |
+
"1 <p>Suppose I have a data set that contai... \n",
|
| 762 |
+
"11 <p>I am trying to figure out what is the... \n",
|
| 763 |
+
"14 <p><a href="https://i.stack.imgu... \n",
|
| 764 |
+
"17 <p>I just started to get interested in n... \n",
|
| 765 |
+
"\n",
|
| 766 |
+
" Tags PostTypeId \\\n",
|
| 767 |
+
"0 [r, regression, confidence-interval] 1 \n",
|
| 768 |
+
"1 [regression, poisson-distribution, poisson-pro... 1 \n",
|
| 769 |
+
"11 [regression, errors-in-variables] 1 \n",
|
| 770 |
+
"14 [regression, residuals] 1 \n",
|
| 771 |
+
"17 [machine-learning, neural-networks, natural-la... 1 \n",
|
| 772 |
+
"\n",
|
| 773 |
+
" CreationDate OwnerUserId ParentId Tag \n",
|
| 774 |
+
"0 2019-11-24T19:50:42.807 266724 NaN regression \n",
|
| 775 |
+
"1 2023-08-01T15:57:49.950 314344 NaN regression \n",
|
| 776 |
+
"11 2015-10-22T20:46:44.137 19758 NaN regression \n",
|
| 777 |
+
"14 2022-12-29T16:21:35.377 376392 NaN regression \n",
|
| 778 |
+
"17 2023-08-30T06:56:57.460 302098 NaN neural-networks "
|
| 779 |
+
]
|
| 780 |
+
},
|
| 781 |
+
"execution_count": 11,
|
| 782 |
+
"metadata": {},
|
| 783 |
+
"output_type": "execute_result"
|
| 784 |
+
}
|
| 785 |
+
],
|
| 786 |
+
"source": [
|
| 787 |
+
"print(questions.shape)\n",
|
| 788 |
+
"questions.head()"
|
| 789 |
+
]
|
| 790 |
+
},
|
| 791 |
+
{
|
| 792 |
+
"cell_type": "code",
|
| 793 |
+
"execution_count": 12,
|
| 794 |
+
"id": "a8c894ecef5eba68",
|
| 795 |
+
"metadata": {
|
| 796 |
+
"ExecuteTime": {
|
| 797 |
+
"end_time": "2024-12-02T15:09:18.819935Z",
|
| 798 |
+
"start_time": "2024-12-02T15:09:18.805296Z"
|
| 799 |
+
}
|
| 800 |
+
},
|
| 801 |
+
"outputs": [
|
| 802 |
+
{
|
| 803 |
+
"data": {
|
| 804 |
+
"text/plain": [
|
| 805 |
+
"OwnerUserId\n",
|
| 806 |
+
"408603 222\n",
|
| 807 |
+
"247274 106\n",
|
| 808 |
+
"28986 99\n",
|
| 809 |
+
"1005 95\n",
|
| 810 |
+
"108150 84\n",
|
| 811 |
+
"Name: count, dtype: int64"
|
| 812 |
+
]
|
| 813 |
+
},
|
| 814 |
+
"execution_count": 12,
|
| 815 |
+
"metadata": {},
|
| 816 |
+
"output_type": "execute_result"
|
| 817 |
+
}
|
| 818 |
+
],
|
| 819 |
+
"source": [
|
| 820 |
+
"user_ask_counts = questions['OwnerUserId'].value_counts()\n",
|
| 821 |
+
"user_ask_counts.head()"
|
| 822 |
+
]
|
| 823 |
+
},
|
| 824 |
+
{
|
| 825 |
+
"cell_type": "code",
|
| 826 |
+
"execution_count": 13,
|
| 827 |
+
"id": "29e54f2c7af6e472",
|
| 828 |
+
"metadata": {
|
| 829 |
+
"ExecuteTime": {
|
| 830 |
+
"end_time": "2024-12-02T15:09:19.139229Z",
|
| 831 |
+
"start_time": "2024-12-02T15:09:19.023915Z"
|
| 832 |
+
}
|
| 833 |
+
},
|
| 834 |
+
"outputs": [
|
| 835 |
+
{
|
| 836 |
+
"data": {
|
| 837 |
+
"text/plain": [
|
| 838 |
+
"(34153, 9)"
|
| 839 |
+
]
|
| 840 |
+
},
|
| 841 |
+
"execution_count": 13,
|
| 842 |
+
"metadata": {},
|
| 843 |
+
"output_type": "execute_result"
|
| 844 |
+
}
|
| 845 |
+
],
|
| 846 |
+
"source": [
|
| 847 |
+
"user_id_with_counts_gt_1 = user_ask_counts.index[user_ask_counts > 1]\n",
|
| 848 |
+
"selected_question_idx = []\n",
|
| 849 |
+
"for idx, owner_user_id in zip(questions.index, questions['OwnerUserId']):\n",
|
| 850 |
+
" if owner_user_id in user_id_with_counts_gt_1:\n",
|
| 851 |
+
" selected_question_idx.append(idx)\n",
|
| 852 |
+
"questions = questions.loc[selected_question_idx]\n",
|
| 853 |
+
"questions.shape"
|
| 854 |
+
]
|
| 855 |
+
},
|
| 856 |
+
{
|
| 857 |
+
"cell_type": "code",
|
| 858 |
+
"execution_count": 14,
|
| 859 |
+
"id": "3e2dd2b2022619c6",
|
| 860 |
+
"metadata": {
|
| 861 |
+
"ExecuteTime": {
|
| 862 |
+
"end_time": "2024-12-02T15:09:19.313893Z",
|
| 863 |
+
"start_time": "2024-12-02T15:09:19.299332Z"
|
| 864 |
+
}
|
| 865 |
+
},
|
| 866 |
+
"outputs": [
|
| 867 |
+
{
|
| 868 |
+
"data": {
|
| 869 |
+
"text/plain": [
|
| 870 |
+
"Tag\n",
|
| 871 |
+
"regression 15530\n",
|
| 872 |
+
"hypothesis-testing 4858\n",
|
| 873 |
+
"distributions 4697\n",
|
| 874 |
+
"neural-networks 4103\n",
|
| 875 |
+
"classification 3042\n",
|
| 876 |
+
"clustering 1923\n",
|
| 877 |
+
"Name: count, dtype: int64"
|
| 878 |
+
]
|
| 879 |
+
},
|
| 880 |
+
"execution_count": 14,
|
| 881 |
+
"metadata": {},
|
| 882 |
+
"output_type": "execute_result"
|
| 883 |
+
}
|
| 884 |
+
],
|
| 885 |
+
"source": [
|
| 886 |
+
"questions['Tag'].value_counts()"
|
| 887 |
+
]
|
| 888 |
+
},
|
| 889 |
+
{
|
| 890 |
+
"cell_type": "code",
|
| 891 |
+
"execution_count": 15,
|
| 892 |
+
"id": "dfaaf16f245957ea",
|
| 893 |
+
"metadata": {
|
| 894 |
+
"ExecuteTime": {
|
| 895 |
+
"end_time": "2024-12-02T15:09:19.475081Z",
|
| 896 |
+
"start_time": "2024-12-02T15:09:19.469247Z"
|
| 897 |
+
}
|
| 898 |
+
},
|
| 899 |
+
"outputs": [],
|
| 900 |
+
"source": [
|
| 901 |
+
"import re\n",
|
| 902 |
+
"\n",
|
| 903 |
+
"def clean_text_html(raw_text: str):\n",
|
| 904 |
+
" text = re.sub(r'<.*?>', '', raw_text)\n",
|
| 905 |
+
" text = text.replace('
', ' ')\n",
|
| 906 |
+
" text = re.sub(r'\\s+', ' ', text)\n",
|
| 907 |
+
" return text.rstrip()"
|
| 908 |
+
]
|
| 909 |
+
},
|
| 910 |
+
{
|
| 911 |
+
"cell_type": "code",
|
| 912 |
+
"execution_count": 16,
|
| 913 |
+
"id": "ff094f35b736db56",
|
| 914 |
+
"metadata": {
|
| 915 |
+
"ExecuteTime": {
|
| 916 |
+
"end_time": "2024-12-02T15:09:22.591039Z",
|
| 917 |
+
"start_time": "2024-12-02T15:09:19.558750Z"
|
| 918 |
+
}
|
| 919 |
+
},
|
| 920 |
+
"outputs": [],
|
| 921 |
+
"source": [
|
| 922 |
+
"questions['Body'] = questions['Body'].apply(clean_text_html)"
|
| 923 |
+
]
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"cell_type": "code",
|
| 927 |
+
"execution_count": 17,
|
| 928 |
+
"id": "10921285f215489f",
|
| 929 |
+
"metadata": {
|
| 930 |
+
"ExecuteTime": {
|
| 931 |
+
"end_time": "2024-12-02T15:09:22.618084Z",
|
| 932 |
+
"start_time": "2024-12-02T15:09:22.605847Z"
|
| 933 |
+
}
|
| 934 |
+
},
|
| 935 |
+
"outputs": [
|
| 936 |
+
{
|
| 937 |
+
"data": {
|
| 938 |
+
"text/html": [
|
| 939 |
+
"<div>\n",
|
| 940 |
+
"<style scoped>\n",
|
| 941 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 942 |
+
" vertical-align: middle;\n",
|
| 943 |
+
" }\n",
|
| 944 |
+
"\n",
|
| 945 |
+
" .dataframe tbody tr th {\n",
|
| 946 |
+
" vertical-align: top;\n",
|
| 947 |
+
" }\n",
|
| 948 |
+
"\n",
|
| 949 |
+
" .dataframe thead th {\n",
|
| 950 |
+
" text-align: right;\n",
|
| 951 |
+
" }\n",
|
| 952 |
+
"</style>\n",
|
| 953 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 954 |
+
" <thead>\n",
|
| 955 |
+
" <tr style=\"text-align: right;\">\n",
|
| 956 |
+
" <th></th>\n",
|
| 957 |
+
" <th>Id</th>\n",
|
| 958 |
+
" <th>Title</th>\n",
|
| 959 |
+
" <th>Body</th>\n",
|
| 960 |
+
" <th>Tags</th>\n",
|
| 961 |
+
" <th>PostTypeId</th>\n",
|
| 962 |
+
" <th>CreationDate</th>\n",
|
| 963 |
+
" <th>OwnerUserId</th>\n",
|
| 964 |
+
" <th>ParentId</th>\n",
|
| 965 |
+
" <th>Tag</th>\n",
|
| 966 |
+
" </tr>\n",
|
| 967 |
+
" </thead>\n",
|
| 968 |
+
" <tbody>\n",
|
| 969 |
+
" <tr>\n",
|
| 970 |
+
" <th>1</th>\n",
|
| 971 |
+
" <td>622877</td>\n",
|
| 972 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 973 |
+
" <td>Suppose I have a data set that contains insura...</td>\n",
|
| 974 |
+
" <td>[regression, poisson-distribution, poisson-pro...</td>\n",
|
| 975 |
+
" <td>1</td>\n",
|
| 976 |
+
" <td>2023-08-01T15:57:49.950</td>\n",
|
| 977 |
+
" <td>314344</td>\n",
|
| 978 |
+
" <td>NaN</td>\n",
|
| 979 |
+
" <td>regression</td>\n",
|
| 980 |
+
" </tr>\n",
|
| 981 |
+
" <tr>\n",
|
| 982 |
+
" <th>17</th>\n",
|
| 983 |
+
" <td>625541</td>\n",
|
| 984 |
+
" <td>Does skipgram model uses backpropagation?</td>\n",
|
| 985 |
+
" <td>I just started to get interested in natural la...</td>\n",
|
| 986 |
+
" <td>[machine-learning, neural-networks, natural-la...</td>\n",
|
| 987 |
+
" <td>1</td>\n",
|
| 988 |
+
" <td>2023-08-30T06:56:57.460</td>\n",
|
| 989 |
+
" <td>302098</td>\n",
|
| 990 |
+
" <td>NaN</td>\n",
|
| 991 |
+
" <td>neural-networks</td>\n",
|
| 992 |
+
" </tr>\n",
|
| 993 |
+
" <tr>\n",
|
| 994 |
+
" <th>46</th>\n",
|
| 995 |
+
" <td>501441</td>\n",
|
| 996 |
+
" <td>Inference in a system in which (almost) all re...</td>\n",
|
| 997 |
+
" <td>We conducted a number of tests on individual s...</td>\n",
|
| 998 |
+
" <td>[regression, correlation, inference, least-squ...</td>\n",
|
| 999 |
+
" <td>1</td>\n",
|
| 1000 |
+
" <td>2020-12-18T10:53:32.023</td>\n",
|
| 1001 |
+
" <td>107859</td>\n",
|
| 1002 |
+
" <td>NaN</td>\n",
|
| 1003 |
+
" <td>regression</td>\n",
|
| 1004 |
+
" </tr>\n",
|
| 1005 |
+
" <tr>\n",
|
| 1006 |
+
" <th>50</th>\n",
|
| 1007 |
+
" <td>572092</td>\n",
|
| 1008 |
+
" <td>A faster way of finding unbiased estimators fo...</td>\n",
|
| 1009 |
+
" <td>No access to computers or calculators is avail...</td>\n",
|
| 1010 |
+
" <td>[regression, self-study, multiple-regression, ...</td>\n",
|
| 1011 |
+
" <td>1</td>\n",
|
| 1012 |
+
" <td>2022-04-19T05:43:00.277</td>\n",
|
| 1013 |
+
" <td>347256</td>\n",
|
| 1014 |
+
" <td>NaN</td>\n",
|
| 1015 |
+
" <td>regression</td>\n",
|
| 1016 |
+
" </tr>\n",
|
| 1017 |
+
" <tr>\n",
|
| 1018 |
+
" <th>73</th>\n",
|
| 1019 |
+
" <td>533957</td>\n",
|
| 1020 |
+
" <td>Would it be wrong if I picked a model with les...</td>\n",
|
| 1021 |
+
" <td>I have some data containing a list of 2000 que...</td>\n",
|
| 1022 |
+
" <td>[machine-learning, classification, accuracy]</td>\n",
|
| 1023 |
+
" <td>1</td>\n",
|
| 1024 |
+
" <td>2021-07-09T11:49:29.693</td>\n",
|
| 1025 |
+
" <td>327301</td>\n",
|
| 1026 |
+
" <td>NaN</td>\n",
|
| 1027 |
+
" <td>classification</td>\n",
|
| 1028 |
+
" </tr>\n",
|
| 1029 |
+
" </tbody>\n",
|
| 1030 |
+
"</table>\n",
|
| 1031 |
+
"</div>"
|
| 1032 |
+
],
|
| 1033 |
+
"text/plain": [
|
| 1034 |
+
" Id Title \\\n",
|
| 1035 |
+
"1 622877 Poisson process for small sample size \n",
|
| 1036 |
+
"17 625541 Does skipgram model uses backpropagation? \n",
|
| 1037 |
+
"46 501441 Inference in a system in which (almost) all re... \n",
|
| 1038 |
+
"50 572092 A faster way of finding unbiased estimators fo... \n",
|
| 1039 |
+
"73 533957 Would it be wrong if I picked a model with les... \n",
|
| 1040 |
+
"\n",
|
| 1041 |
+
" Body \\\n",
|
| 1042 |
+
"1 Suppose I have a data set that contains insura... \n",
|
| 1043 |
+
"17 I just started to get interested in natural la... \n",
|
| 1044 |
+
"46 We conducted a number of tests on individual s... \n",
|
| 1045 |
+
"50 No access to computers or calculators is avail... \n",
|
| 1046 |
+
"73 I have some data containing a list of 2000 que... \n",
|
| 1047 |
+
"\n",
|
| 1048 |
+
" Tags PostTypeId \\\n",
|
| 1049 |
+
"1 [regression, poisson-distribution, poisson-pro... 1 \n",
|
| 1050 |
+
"17 [machine-learning, neural-networks, natural-la... 1 \n",
|
| 1051 |
+
"46 [regression, correlation, inference, least-squ... 1 \n",
|
| 1052 |
+
"50 [regression, self-study, multiple-regression, ... 1 \n",
|
| 1053 |
+
"73 [machine-learning, classification, accuracy] 1 \n",
|
| 1054 |
+
"\n",
|
| 1055 |
+
" CreationDate OwnerUserId ParentId Tag \n",
|
| 1056 |
+
"1 2023-08-01T15:57:49.950 314344 NaN regression \n",
|
| 1057 |
+
"17 2023-08-30T06:56:57.460 302098 NaN neural-networks \n",
|
| 1058 |
+
"46 2020-12-18T10:53:32.023 107859 NaN regression \n",
|
| 1059 |
+
"50 2022-04-19T05:43:00.277 347256 NaN regression \n",
|
| 1060 |
+
"73 2021-07-09T11:49:29.693 327301 NaN classification "
|
| 1061 |
+
]
|
| 1062 |
+
},
|
| 1063 |
+
"execution_count": 17,
|
| 1064 |
+
"metadata": {},
|
| 1065 |
+
"output_type": "execute_result"
|
| 1066 |
+
}
|
| 1067 |
+
],
|
| 1068 |
+
"source": [
|
| 1069 |
+
"questions.head()"
|
| 1070 |
+
]
|
| 1071 |
+
},
|
| 1072 |
+
{
|
| 1073 |
+
"cell_type": "code",
|
| 1074 |
+
"execution_count": 18,
|
| 1075 |
+
"id": "9c8b5d859adf2fe7",
|
| 1076 |
+
"metadata": {
|
| 1077 |
+
"ExecuteTime": {
|
| 1078 |
+
"end_time": "2024-12-02T15:09:22.739984Z",
|
| 1079 |
+
"start_time": "2024-12-02T15:09:22.695937Z"
|
| 1080 |
+
}
|
| 1081 |
+
},
|
| 1082 |
+
"outputs": [
|
| 1083 |
+
{
|
| 1084 |
+
"data": {
|
| 1085 |
+
"text/html": [
|
| 1086 |
+
"<div>\n",
|
| 1087 |
+
"<style scoped>\n",
|
| 1088 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 1089 |
+
" vertical-align: middle;\n",
|
| 1090 |
+
" }\n",
|
| 1091 |
+
"\n",
|
| 1092 |
+
" .dataframe tbody tr th {\n",
|
| 1093 |
+
" vertical-align: top;\n",
|
| 1094 |
+
" }\n",
|
| 1095 |
+
"\n",
|
| 1096 |
+
" .dataframe thead th {\n",
|
| 1097 |
+
" text-align: right;\n",
|
| 1098 |
+
" }\n",
|
| 1099 |
+
"</style>\n",
|
| 1100 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 1101 |
+
" <thead>\n",
|
| 1102 |
+
" <tr style=\"text-align: right;\">\n",
|
| 1103 |
+
" <th></th>\n",
|
| 1104 |
+
" <th>Id</th>\n",
|
| 1105 |
+
" <th>Title</th>\n",
|
| 1106 |
+
" <th>Body</th>\n",
|
| 1107 |
+
" <th>Tag</th>\n",
|
| 1108 |
+
" <th>Year</th>\n",
|
| 1109 |
+
" <th>OwnerUserId</th>\n",
|
| 1110 |
+
" <th>Tags</th>\n",
|
| 1111 |
+
" </tr>\n",
|
| 1112 |
+
" </thead>\n",
|
| 1113 |
+
" <tbody>\n",
|
| 1114 |
+
" <tr>\n",
|
| 1115 |
+
" <th>0</th>\n",
|
| 1116 |
+
" <td>622877</td>\n",
|
| 1117 |
+
" <td>Poisson process for small sample size</td>\n",
|
| 1118 |
+
" <td>Suppose I have a data set that contains insura...</td>\n",
|
| 1119 |
+
" <td>regression</td>\n",
|
| 1120 |
+
" <td>2023</td>\n",
|
| 1121 |
+
" <td>314344</td>\n",
|
| 1122 |
+
" <td>[regression, poisson-distribution, poisson-pro...</td>\n",
|
| 1123 |
+
" </tr>\n",
|
| 1124 |
+
" <tr>\n",
|
| 1125 |
+
" <th>1</th>\n",
|
| 1126 |
+
" <td>625541</td>\n",
|
| 1127 |
+
" <td>Does skipgram model uses backpropagation?</td>\n",
|
| 1128 |
+
" <td>I just started to get interested in natural la...</td>\n",
|
| 1129 |
+
" <td>neural-networks</td>\n",
|
| 1130 |
+
" <td>2023</td>\n",
|
| 1131 |
+
" <td>302098</td>\n",
|
| 1132 |
+
" <td>[machine-learning, neural-networks, natural-la...</td>\n",
|
| 1133 |
+
" </tr>\n",
|
| 1134 |
+
" <tr>\n",
|
| 1135 |
+
" <th>2</th>\n",
|
| 1136 |
+
" <td>501441</td>\n",
|
| 1137 |
+
" <td>Inference in a system in which (almost) all re...</td>\n",
|
| 1138 |
+
" <td>We conducted a number of tests on individual s...</td>\n",
|
| 1139 |
+
" <td>regression</td>\n",
|
| 1140 |
+
" <td>2020</td>\n",
|
| 1141 |
+
" <td>107859</td>\n",
|
| 1142 |
+
" <td>[regression, correlation, inference, least-squ...</td>\n",
|
| 1143 |
+
" </tr>\n",
|
| 1144 |
+
" <tr>\n",
|
| 1145 |
+
" <th>3</th>\n",
|
| 1146 |
+
" <td>572092</td>\n",
|
| 1147 |
+
" <td>A faster way of finding unbiased estimators fo...</td>\n",
|
| 1148 |
+
" <td>No access to computers or calculators is avail...</td>\n",
|
| 1149 |
+
" <td>regression</td>\n",
|
| 1150 |
+
" <td>2022</td>\n",
|
| 1151 |
+
" <td>347256</td>\n",
|
| 1152 |
+
" <td>[regression, self-study, multiple-regression, ...</td>\n",
|
| 1153 |
+
" </tr>\n",
|
| 1154 |
+
" <tr>\n",
|
| 1155 |
+
" <th>4</th>\n",
|
| 1156 |
+
" <td>533957</td>\n",
|
| 1157 |
+
" <td>Would it be wrong if I picked a model with les...</td>\n",
|
| 1158 |
+
" <td>I have some data containing a list of 2000 que...</td>\n",
|
| 1159 |
+
" <td>classification</td>\n",
|
| 1160 |
+
" <td>2021</td>\n",
|
| 1161 |
+
" <td>327301</td>\n",
|
| 1162 |
+
" <td>[machine-learning, classification, accuracy]</td>\n",
|
| 1163 |
+
" </tr>\n",
|
| 1164 |
+
" </tbody>\n",
|
| 1165 |
+
"</table>\n",
|
| 1166 |
+
"</div>"
|
| 1167 |
+
],
|
| 1168 |
+
"text/plain": [
|
| 1169 |
+
" Id Title \\\n",
|
| 1170 |
+
"0 622877 Poisson process for small sample size \n",
|
| 1171 |
+
"1 625541 Does skipgram model uses backpropagation? \n",
|
| 1172 |
+
"2 501441 Inference in a system in which (almost) all re... \n",
|
| 1173 |
+
"3 572092 A faster way of finding unbiased estimators fo... \n",
|
| 1174 |
+
"4 533957 Would it be wrong if I picked a model with les... \n",
|
| 1175 |
+
"\n",
|
| 1176 |
+
" Body Tag Year \\\n",
|
| 1177 |
+
"0 Suppose I have a data set that contains insura... regression 2023 \n",
|
| 1178 |
+
"1 I just started to get interested in natural la... neural-networks 2023 \n",
|
| 1179 |
+
"2 We conducted a number of tests on individual s... regression 2020 \n",
|
| 1180 |
+
"3 No access to computers or calculators is avail... regression 2022 \n",
|
| 1181 |
+
"4 I have some data containing a list of 2000 que... classification 2021 \n",
|
| 1182 |
+
"\n",
|
| 1183 |
+
" OwnerUserId Tags \n",
|
| 1184 |
+
"0 314344 [regression, poisson-distribution, poisson-pro... \n",
|
| 1185 |
+
"1 302098 [machine-learning, neural-networks, natural-la... \n",
|
| 1186 |
+
"2 107859 [regression, correlation, inference, least-squ... \n",
|
| 1187 |
+
"3 347256 [regression, self-study, multiple-regression, ... \n",
|
| 1188 |
+
"4 327301 [machine-learning, classification, accuracy] "
|
| 1189 |
+
]
|
| 1190 |
+
},
|
| 1191 |
+
"execution_count": 18,
|
| 1192 |
+
"metadata": {},
|
| 1193 |
+
"output_type": "execute_result"
|
| 1194 |
+
}
|
| 1195 |
+
],
|
| 1196 |
+
"source": [
|
| 1197 |
+
"questions['Year'] = questions['CreationDate'].apply(lambda x: int(x[:4]))\n",
|
| 1198 |
+
"questions = questions[['Id', 'Title', 'Body', 'Tag', 'Year', 'OwnerUserId', 'Tags']]\n",
|
| 1199 |
+
"questions.reset_index(drop=True, inplace=True)\n",
|
| 1200 |
+
"questions.head()"
|
| 1201 |
+
]
|
| 1202 |
+
},
|
| 1203 |
+
{
|
| 1204 |
+
"cell_type": "code",
|
| 1205 |
+
"execution_count": 19,
|
| 1206 |
+
"id": "9d04f49d17dfc1a8",
|
| 1207 |
+
"metadata": {
|
| 1208 |
+
"ExecuteTime": {
|
| 1209 |
+
"end_time": "2024-12-02T15:09:24.689251Z",
|
| 1210 |
+
"start_time": "2024-12-02T15:09:22.797595Z"
|
| 1211 |
+
}
|
| 1212 |
+
},
|
| 1213 |
+
"outputs": [],
|
| 1214 |
+
"source": [
|
| 1215 |
+
"questions.to_csv('CroVal.csv', index=False)"
|
| 1216 |
+
]
|
| 1217 |
+
},
|
| 1218 |
+
{
|
| 1219 |
+
"cell_type": "markdown",
|
| 1220 |
+
"id": "b3f1e9a5f85e7914",
|
| 1221 |
+
"metadata": {},
|
| 1222 |
+
"source": [
|
| 1223 |
+
"## Question-User Links"
|
| 1224 |
+
]
|
| 1225 |
+
},
|
| 1226 |
+
{
|
| 1227 |
+
"cell_type": "code",
|
| 1228 |
+
"execution_count": 20,
|
| 1229 |
+
"id": "380cc31c31d492ed",
|
| 1230 |
+
"metadata": {
|
| 1231 |
+
"ExecuteTime": {
|
| 1232 |
+
"end_time": "2024-12-02T15:09:24.999097Z",
|
| 1233 |
+
"start_time": "2024-12-02T15:09:24.991021Z"
|
| 1234 |
+
}
|
| 1235 |
+
},
|
| 1236 |
+
"outputs": [],
|
| 1237 |
+
"source": [
|
| 1238 |
+
"data = {}"
|
| 1239 |
+
]
|
| 1240 |
+
},
|
| 1241 |
+
{
|
| 1242 |
+
"cell_type": "code",
|
| 1243 |
+
"execution_count": 21,
|
| 1244 |
+
"id": "b006f380b608da92",
|
| 1245 |
+
"metadata": {
|
| 1246 |
+
"ExecuteTime": {
|
| 1247 |
+
"end_time": "2024-12-02T15:09:25.147540Z",
|
| 1248 |
+
"start_time": "2024-12-02T15:09:25.131782Z"
|
| 1249 |
+
}
|
| 1250 |
+
},
|
| 1251 |
+
"outputs": [
|
| 1252 |
+
{
|
| 1253 |
+
"name": "stdout",
|
| 1254 |
+
"output_type": "stream",
|
| 1255 |
+
"text": [
|
| 1256 |
+
"Number of question-user links: 34153\n"
|
| 1257 |
+
]
|
| 1258 |
+
}
|
| 1259 |
+
],
|
| 1260 |
+
"source": [
|
| 1261 |
+
"question_ids = np.arange(questions.shape[0], dtype=np.uint16)\n",
|
| 1262 |
+
"\n",
|
| 1263 |
+
"user_id_encoder = LabelEncoder()\n",
|
| 1264 |
+
"user_ids = user_id_encoder.fit_transform(questions['OwnerUserId'].values).astype(np.uint16)\n",
|
| 1265 |
+
"assert len(user_ids) == len(question_ids)\n",
|
| 1266 |
+
"print('Number of question-user links:', len(question_ids))\n",
|
| 1267 |
+
"\n",
|
| 1268 |
+
"data['question-user'] = (question_ids, user_ids)"
|
| 1269 |
+
]
|
| 1270 |
+
},
|
| 1271 |
+
{
|
| 1272 |
+
"cell_type": "markdown",
|
| 1273 |
+
"id": "7b938fec4998c22",
|
| 1274 |
+
"metadata": {},
|
| 1275 |
+
"source": [
|
| 1276 |
+
"## Question-Tag Links"
|
| 1277 |
+
]
|
| 1278 |
+
},
|
| 1279 |
+
{
|
| 1280 |
+
"cell_type": "code",
|
| 1281 |
+
"execution_count": 22,
|
| 1282 |
+
"id": "3e8613f44eb40ece",
|
| 1283 |
+
"metadata": {
|
| 1284 |
+
"ExecuteTime": {
|
| 1285 |
+
"end_time": "2024-12-02T15:09:25.315143Z",
|
| 1286 |
+
"start_time": "2024-12-02T15:09:25.182811Z"
|
| 1287 |
+
}
|
| 1288 |
+
},
|
| 1289 |
+
"outputs": [],
|
| 1290 |
+
"source": [
|
| 1291 |
+
"question_ids = np.concatenate([np.full(count, i)\n",
|
| 1292 |
+
" for i, count in enumerate(questions['Tags'].apply(len).values)])\n",
|
| 1293 |
+
"all_tags = list(itertools.chain(*(questions['Tags'].values)))"
|
| 1294 |
+
]
|
| 1295 |
+
},
|
| 1296 |
+
{
|
| 1297 |
+
"cell_type": "code",
|
| 1298 |
+
"execution_count": 23,
|
| 1299 |
+
"id": "37e8f87c035aa8fe",
|
| 1300 |
+
"metadata": {
|
| 1301 |
+
"ExecuteTime": {
|
| 1302 |
+
"end_time": "2024-12-02T15:09:25.490973Z",
|
| 1303 |
+
"start_time": "2024-12-02T15:09:25.350607Z"
|
| 1304 |
+
}
|
| 1305 |
+
},
|
| 1306 |
+
"outputs": [
|
| 1307 |
+
{
|
| 1308 |
+
"data": {
|
| 1309 |
+
"text/plain": [
|
| 1310 |
+
"(118712,)"
|
| 1311 |
+
]
|
| 1312 |
+
},
|
| 1313 |
+
"execution_count": 23,
|
| 1314 |
+
"metadata": {},
|
| 1315 |
+
"output_type": "execute_result"
|
| 1316 |
+
}
|
| 1317 |
+
],
|
| 1318 |
+
"source": [
|
| 1319 |
+
"tag_label_encoder = LabelEncoder()\n",
|
| 1320 |
+
"all_tag_ids = tag_label_encoder.fit_transform(all_tags)\n",
|
| 1321 |
+
"all_tag_ids.shape"
|
| 1322 |
+
]
|
| 1323 |
+
},
|
| 1324 |
+
{
|
| 1325 |
+
"cell_type": "code",
|
| 1326 |
+
"execution_count": 24,
|
| 1327 |
+
"id": "e0774b0351720c1e",
|
| 1328 |
+
"metadata": {
|
| 1329 |
+
"ExecuteTime": {
|
| 1330 |
+
"end_time": "2024-12-02T15:09:25.571892Z",
|
| 1331 |
+
"start_time": "2024-12-02T15:09:25.526063Z"
|
| 1332 |
+
}
|
| 1333 |
+
},
|
| 1334 |
+
"outputs": [],
|
| 1335 |
+
"source": [
|
| 1336 |
+
"selected_tags = np.unique(questions['Tag'])\n",
|
| 1337 |
+
"selected_tag_ids = tag_label_encoder.transform(selected_tags)"
|
| 1338 |
+
]
|
| 1339 |
+
},
|
| 1340 |
+
{
|
| 1341 |
+
"cell_type": "code",
|
| 1342 |
+
"execution_count": 25,
|
| 1343 |
+
"id": "9cdff6755217f598",
|
| 1344 |
+
"metadata": {
|
| 1345 |
+
"ExecuteTime": {
|
| 1346 |
+
"end_time": "2024-12-02T15:09:25.618365Z",
|
| 1347 |
+
"start_time": "2024-12-02T15:09:25.605755Z"
|
| 1348 |
+
}
|
| 1349 |
+
},
|
| 1350 |
+
"outputs": [
|
| 1351 |
+
{
|
| 1352 |
+
"name": "stdout",
|
| 1353 |
+
"output_type": "stream",
|
| 1354 |
+
"text": [
|
| 1355 |
+
"Number of tags: 1335\n",
|
| 1356 |
+
"Number of question-tag links: 84559\n"
|
| 1357 |
+
]
|
| 1358 |
+
}
|
| 1359 |
+
],
|
| 1360 |
+
"source": [
|
| 1361 |
+
"mask = ~np.isin(all_tag_ids, selected_tag_ids)\n",
|
| 1362 |
+
"question_ids = question_ids[mask]\n",
|
| 1363 |
+
"all_tag_ids = all_tag_ids[mask]\n",
|
| 1364 |
+
"\n",
|
| 1365 |
+
"tag_label_encoder = LabelEncoder()\n",
|
| 1366 |
+
"all_tag_ids = tag_label_encoder.fit_transform(all_tag_ids)\n",
|
| 1367 |
+
"print('Number of tags:', len(tag_label_encoder.classes_))\n",
|
| 1368 |
+
"\n",
|
| 1369 |
+
"print('Number of question-tag links:', len(question_ids))\n",
|
| 1370 |
+
"data['question-tag'] = (question_ids, all_tag_ids)"
|
| 1371 |
+
]
|
| 1372 |
+
},
|
| 1373 |
+
{
|
| 1374 |
+
"cell_type": "code",
|
| 1375 |
+
"execution_count": null,
|
| 1376 |
+
"id": "b9da239efcbdf395",
|
| 1377 |
+
"metadata": {
|
| 1378 |
+
"ExecuteTime": {
|
| 1379 |
+
"end_time": "2024-12-02T15:09:25.661530Z",
|
| 1380 |
+
"start_time": "2024-12-02T15:09:25.657476Z"
|
| 1381 |
+
}
|
| 1382 |
+
},
|
| 1383 |
+
"outputs": [],
|
| 1384 |
+
"source": []
|
| 1385 |
+
},
|
| 1386 |
+
{
|
| 1387 |
+
"cell_type": "markdown",
|
| 1388 |
+
"id": "58734f48c8c4dcfd",
|
| 1389 |
+
"metadata": {},
|
| 1390 |
+
"source": [
|
| 1391 |
+
"## Question-Question Links"
|
| 1392 |
+
]
|
| 1393 |
+
},
|
| 1394 |
+
{
|
| 1395 |
+
"cell_type": "code",
|
| 1396 |
+
"execution_count": 26,
|
| 1397 |
+
"id": "353f026c274f42ed",
|
| 1398 |
+
"metadata": {
|
| 1399 |
+
"ExecuteTime": {
|
| 1400 |
+
"end_time": "2024-12-02T15:09:25.848989Z",
|
| 1401 |
+
"start_time": "2024-12-02T15:09:25.727095Z"
|
| 1402 |
+
}
|
| 1403 |
+
},
|
| 1404 |
+
"outputs": [
|
| 1405 |
+
{
|
| 1406 |
+
"data": {
|
| 1407 |
+
"text/html": [
|
| 1408 |
+
"<div>\n",
|
| 1409 |
+
"<style scoped>\n",
|
| 1410 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 1411 |
+
" vertical-align: middle;\n",
|
| 1412 |
+
" }\n",
|
| 1413 |
+
"\n",
|
| 1414 |
+
" .dataframe tbody tr th {\n",
|
| 1415 |
+
" vertical-align: top;\n",
|
| 1416 |
+
" }\n",
|
| 1417 |
+
"\n",
|
| 1418 |
+
" .dataframe thead th {\n",
|
| 1419 |
+
" text-align: right;\n",
|
| 1420 |
+
" }\n",
|
| 1421 |
+
"</style>\n",
|
| 1422 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 1423 |
+
" <thead>\n",
|
| 1424 |
+
" <tr style=\"text-align: right;\">\n",
|
| 1425 |
+
" <th></th>\n",
|
| 1426 |
+
" <th>Id</th>\n",
|
| 1427 |
+
" <th>CreationDate</th>\n",
|
| 1428 |
+
" <th>PostId</th>\n",
|
| 1429 |
+
" <th>RelatedPostId</th>\n",
|
| 1430 |
+
" <th>LinkTypeId</th>\n",
|
| 1431 |
+
" </tr>\n",
|
| 1432 |
+
" </thead>\n",
|
| 1433 |
+
" <tbody>\n",
|
| 1434 |
+
" <tr>\n",
|
| 1435 |
+
" <th>0</th>\n",
|
| 1436 |
+
" <td>6140526</td>\n",
|
| 1437 |
+
" <td>2017-02-10T08:09:54.907</td>\n",
|
| 1438 |
+
" <td>261056</td>\n",
|
| 1439 |
+
" <td>82664</td>\n",
|
| 1440 |
+
" <td>1</td>\n",
|
| 1441 |
+
" </tr>\n",
|
| 1442 |
+
" <tr>\n",
|
| 1443 |
+
" <th>1</th>\n",
|
| 1444 |
+
" <td>13300159</td>\n",
|
| 1445 |
+
" <td>2020-02-24T03:34:51.287</td>\n",
|
| 1446 |
+
" <td>448097</td>\n",
|
| 1447 |
+
" <td>441156</td>\n",
|
| 1448 |
+
" <td>1</td>\n",
|
| 1449 |
+
" </tr>\n",
|
| 1450 |
+
" <tr>\n",
|
| 1451 |
+
" <th>2</th>\n",
|
| 1452 |
+
" <td>3805280</td>\n",
|
| 1453 |
+
" <td>2015-03-04T21:44:24.393</td>\n",
|
| 1454 |
+
" <td>140369</td>\n",
|
| 1455 |
+
" <td>140163</td>\n",
|
| 1456 |
+
" <td>1</td>\n",
|
| 1457 |
+
" </tr>\n",
|
| 1458 |
+
" <tr>\n",
|
| 1459 |
+
" <th>3</th>\n",
|
| 1460 |
+
" <td>3953036</td>\n",
|
| 1461 |
+
" <td>2015-04-30T14:11:47.800</td>\n",
|
| 1462 |
+
" <td>149074</td>\n",
|
| 1463 |
+
" <td>35019</td>\n",
|
| 1464 |
+
" <td>1</td>\n",
|
| 1465 |
+
" </tr>\n",
|
| 1466 |
+
" <tr>\n",
|
| 1467 |
+
" <th>4</th>\n",
|
| 1468 |
+
" <td>11264471</td>\n",
|
| 1469 |
+
" <td>2018-11-25T16:21:16.053</td>\n",
|
| 1470 |
+
" <td>378611</td>\n",
|
| 1471 |
+
" <td>377444</td>\n",
|
| 1472 |
+
" <td>3</td>\n",
|
| 1473 |
+
" </tr>\n",
|
| 1474 |
+
" </tbody>\n",
|
| 1475 |
+
"</table>\n",
|
| 1476 |
+
"</div>"
|
| 1477 |
+
],
|
| 1478 |
+
"text/plain": [
|
| 1479 |
+
" Id CreationDate PostId RelatedPostId LinkTypeId\n",
|
| 1480 |
+
"0 6140526 2017-02-10T08:09:54.907 261056 82664 1\n",
|
| 1481 |
+
"1 13300159 2020-02-24T03:34:51.287 448097 441156 1\n",
|
| 1482 |
+
"2 3805280 2015-03-04T21:44:24.393 140369 140163 1\n",
|
| 1483 |
+
"3 3953036 2015-04-30T14:11:47.800 149074 35019 1\n",
|
| 1484 |
+
"4 11264471 2018-11-25T16:21:16.053 378611 377444 3"
|
| 1485 |
+
]
|
| 1486 |
+
},
|
| 1487 |
+
"execution_count": 26,
|
| 1488 |
+
"metadata": {},
|
| 1489 |
+
"output_type": "execute_result"
|
| 1490 |
+
}
|
| 1491 |
+
],
|
| 1492 |
+
"source": [
|
| 1493 |
+
"post_links = pd.read_csv('csvs/PostLinks.csv')\n",
|
| 1494 |
+
"post_links.head()"
|
| 1495 |
+
]
|
| 1496 |
+
},
|
| 1497 |
+
{
|
| 1498 |
+
"cell_type": "code",
|
| 1499 |
+
"execution_count": 27,
|
| 1500 |
+
"id": "92aa15c1433a2dbf",
|
| 1501 |
+
"metadata": {
|
| 1502 |
+
"ExecuteTime": {
|
| 1503 |
+
"end_time": "2024-12-02T15:09:25.919007Z",
|
| 1504 |
+
"start_time": "2024-12-02T15:09:25.908831Z"
|
| 1505 |
+
}
|
| 1506 |
+
},
|
| 1507 |
+
"outputs": [],
|
| 1508 |
+
"source": [
|
| 1509 |
+
"src_post_ids = post_links['PostId'].values\n",
|
| 1510 |
+
"dst_post_ids = post_links['RelatedPostId'].values\n",
|
| 1511 |
+
"mask = (np.isin(src_post_ids, questions['Id'].values) & \n",
|
| 1512 |
+
" np.isin(dst_post_ids, questions['Id'].values))\n",
|
| 1513 |
+
"src_post_ids = src_post_ids[mask]\n",
|
| 1514 |
+
"dst_post_ids = dst_post_ids[mask]"
|
| 1515 |
+
]
|
| 1516 |
+
},
|
| 1517 |
+
{
|
| 1518 |
+
"cell_type": "code",
|
| 1519 |
+
"execution_count": 28,
|
| 1520 |
+
"id": "c74c23bb7d5eecbb",
|
| 1521 |
+
"metadata": {
|
| 1522 |
+
"ExecuteTime": {
|
| 1523 |
+
"end_time": "2024-12-02T15:09:26.015226Z",
|
| 1524 |
+
"start_time": "2024-12-02T15:09:25.987311Z"
|
| 1525 |
+
}
|
| 1526 |
+
},
|
| 1527 |
+
"outputs": [],
|
| 1528 |
+
"source": [
|
| 1529 |
+
"post_id_map = dict(zip(questions['Id'].values, range(len(questions))))\n",
|
| 1530 |
+
"src_post_ids = np.array([post_id_map[_] for _ in src_post_ids], dtype=np.uint16)\n",
|
| 1531 |
+
"post_id_map = dict(zip(questions['Id'].values, range(len(questions))))\n",
|
| 1532 |
+
"dst_post_ids = np.array([post_id_map[_] for _ in dst_post_ids], dtype=np.uint16)"
|
| 1533 |
+
]
|
| 1534 |
+
},
|
| 1535 |
+
{
|
| 1536 |
+
"cell_type": "code",
|
| 1537 |
+
"execution_count": 29,
|
| 1538 |
+
"id": "bd61cd75abb0ceab",
|
| 1539 |
+
"metadata": {
|
| 1540 |
+
"ExecuteTime": {
|
| 1541 |
+
"end_time": "2024-12-02T15:09:26.045364Z",
|
| 1542 |
+
"start_time": "2024-12-02T15:09:26.037949Z"
|
| 1543 |
+
}
|
| 1544 |
+
},
|
| 1545 |
+
"outputs": [
|
| 1546 |
+
{
|
| 1547 |
+
"name": "stdout",
|
| 1548 |
+
"output_type": "stream",
|
| 1549 |
+
"text": [
|
| 1550 |
+
"Number of question-question links: 6743\n"
|
| 1551 |
+
]
|
| 1552 |
+
}
|
| 1553 |
+
],
|
| 1554 |
+
"source": [
|
| 1555 |
+
"print('Number of question-question links:', src_post_ids.shape[0])\n",
|
| 1556 |
+
"data['question-question'] = (src_post_ids, dst_post_ids)"
|
| 1557 |
+
]
|
| 1558 |
+
},
|
| 1559 |
+
{
|
| 1560 |
+
"cell_type": "markdown",
|
| 1561 |
+
"id": "e38c5a9bbae43870",
|
| 1562 |
+
"metadata": {},
|
| 1563 |
+
"source": [
|
| 1564 |
+
"## Labels and Years"
|
| 1565 |
+
]
|
| 1566 |
+
},
|
| 1567 |
+
{
|
| 1568 |
+
"cell_type": "code",
|
| 1569 |
+
"execution_count": 30,
|
| 1570 |
+
"id": "cbd4f798db752644",
|
| 1571 |
+
"metadata": {
|
| 1572 |
+
"ExecuteTime": {
|
| 1573 |
+
"end_time": "2024-12-02T15:11:02.198886Z",
|
| 1574 |
+
"start_time": "2024-12-02T15:11:02.194669Z"
|
| 1575 |
+
}
|
| 1576 |
+
},
|
| 1577 |
+
"outputs": [],
|
| 1578 |
+
"source": [
|
| 1579 |
+
"question_years = questions['Year'].values.astype(np.int16)\n",
|
| 1580 |
+
"\n",
|
| 1581 |
+
"label_encoder = LabelEncoder()\n",
|
| 1582 |
+
"question_labels = label_encoder.fit_transform(questions['Tag']).astype(np.int8)\n",
|
| 1583 |
+
"\n",
|
| 1584 |
+
"data['question_years'] = question_years\n",
|
| 1585 |
+
"data['question_labels'] = question_labels"
|
| 1586 |
+
]
|
| 1587 |
+
},
|
| 1588 |
+
{
|
| 1589 |
+
"cell_type": "markdown",
|
| 1590 |
+
"id": "5b96baa7b9600d32",
|
| 1591 |
+
"metadata": {},
|
| 1592 |
+
"source": [
|
| 1593 |
+
"### Node Features\n",
|
| 1594 |
+
"\n",
|
| 1595 |
+
"We generate embeddings as features for each node in the graph. Node embeddings are generated by passing the title and body through a Sentence-BERT model and obtaining a 384-embedding vector for each movie node.\n",
|
| 1596 |
+
"\n",
|
| 1597 |
+
"\n",
|
| 1598 |
+
"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",
|
| 1599 |
+
"\n",
|
| 1600 |
+
"all-MiniLM-L6-v2\n",
|
| 1601 |
+
"\n",
|
| 1602 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 1603 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 1604 |
+
"Max Sequence Length:\t256\n",
|
| 1605 |
+
"Dimensions:\t384\n",
|
| 1606 |
+
"Normalized Embeddings:\ttrue\n",
|
| 1607 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 1608 |
+
"Size:\t80 MB\n",
|
| 1609 |
+
"Pooling:\tMean Pooling\n",
|
| 1610 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 1611 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 1612 |
+
]
|
| 1613 |
+
},
|
| 1614 |
+
{
|
| 1615 |
+
"cell_type": "code",
|
| 1616 |
+
"execution_count": 31,
|
| 1617 |
+
"id": "65607ae67568281d",
|
| 1618 |
+
"metadata": {},
|
| 1619 |
+
"outputs": [
|
| 1620 |
+
{
|
| 1621 |
+
"name": "stderr",
|
| 1622 |
+
"output_type": "stream",
|
| 1623 |
+
"text": [
|
| 1624 |
+
"/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",
|
| 1625 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 1626 |
+
]
|
| 1627 |
+
},
|
| 1628 |
+
{
|
| 1629 |
+
"data": {
|
| 1630 |
+
"text/plain": [
|
| 1631 |
+
"SentenceTransformer(\n",
|
| 1632 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 1633 |
+
" (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",
|
| 1634 |
+
" (2): Normalize()\n",
|
| 1635 |
+
")"
|
| 1636 |
+
]
|
| 1637 |
+
},
|
| 1638 |
+
"execution_count": 31,
|
| 1639 |
+
"metadata": {},
|
| 1640 |
+
"output_type": "execute_result"
|
| 1641 |
+
}
|
| 1642 |
+
],
|
| 1643 |
+
"source": [
|
| 1644 |
+
"import torch\n",
|
| 1645 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 1646 |
+
"\n",
|
| 1647 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 1648 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 1649 |
+
"model"
|
| 1650 |
+
]
|
| 1651 |
+
},
|
| 1652 |
+
{
|
| 1653 |
+
"cell_type": "code",
|
| 1654 |
+
"execution_count": 32,
|
| 1655 |
+
"id": "d13d815aaee99d99",
|
| 1656 |
+
"metadata": {},
|
| 1657 |
+
"outputs": [],
|
| 1658 |
+
"source": [
|
| 1659 |
+
"text = questions['Title'] + ' ' + questions['Body']"
|
| 1660 |
+
]
|
| 1661 |
+
},
|
| 1662 |
+
{
|
| 1663 |
+
"cell_type": "code",
|
| 1664 |
+
"execution_count": 33,
|
| 1665 |
+
"id": "1e482784",
|
| 1666 |
+
"metadata": {},
|
| 1667 |
+
"outputs": [
|
| 1668 |
+
{
|
| 1669 |
+
"name": "stderr",
|
| 1670 |
+
"output_type": "stream",
|
| 1671 |
+
"text": [
|
| 1672 |
+
"Batches: 100%|██████████| 9/9 [00:31<00:00, 3.49s/it]\n"
|
| 1673 |
+
]
|
| 1674 |
+
}
|
| 1675 |
+
],
|
| 1676 |
+
"source": [
|
| 1677 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
|
| 1678 |
+
]
|
| 1679 |
+
},
|
| 1680 |
+
{
|
| 1681 |
+
"cell_type": "code",
|
| 1682 |
+
"execution_count": 34,
|
| 1683 |
+
"id": "96bac537",
|
| 1684 |
+
"metadata": {},
|
| 1685 |
+
"outputs": [
|
| 1686 |
+
{
|
| 1687 |
+
"data": {
|
| 1688 |
+
"text/plain": [
|
| 1689 |
+
"{'question-user': (array([ 0, 1, 2, ..., 34150, 34151, 34152], dtype=uint16),\n",
|
| 1690 |
+
" array([7927, 7752, 3986, ..., 67, 3988, 4143], dtype=uint16)),\n",
|
| 1691 |
+
" 'question-tag': (array([ 0, 0, 0, ..., 34150, 34150, 34152]),\n",
|
| 1692 |
+
" array([920, 921, 397, ..., 981, 419, 331])),\n",
|
| 1693 |
+
" 'question-question': (array([8581, 678, 5604, ..., 4463, 4463, 4053], dtype=uint16),\n",
|
| 1694 |
+
" array([11735, 9756, 18156, ..., 19652, 19652, 19002], dtype=uint16)),\n",
|
| 1695 |
+
" 'question_years': array([2023, 2023, 2020, ..., 2010, 2017, 2016], dtype=int16),\n",
|
| 1696 |
+
" 'question_labels': array([5, 4, 5, ..., 2, 5, 4], dtype=int8),\n",
|
| 1697 |
+
" 'question_feats': array([[-0.02393158, 0.06053483, 0.03126719, ..., -0.10800511,\n",
|
| 1698 |
+
" -0.00546587, 0.03609833],\n",
|
| 1699 |
+
" [-0.05885282, -0.11182664, 0.02024328, ..., 0.07537424,\n",
|
| 1700 |
+
" 0.05215778, -0.04128488],\n",
|
| 1701 |
+
" [-0.06636419, -0.0513887 , -0.01564158, ..., -0.00976081,\n",
|
| 1702 |
+
" 0.01578866, -0.04567946],\n",
|
| 1703 |
+
" ...,\n",
|
| 1704 |
+
" [-0.12249381, -0.03751755, 0.03033727, ..., -0.03496004,\n",
|
| 1705 |
+
" -0.04555019, 0.03692898],\n",
|
| 1706 |
+
" [ 0.00232019, 0.0414363 , 0.06341822, ..., -0.0623777 ,\n",
|
| 1707 |
+
" 0.07806651, -0.00320921],\n",
|
| 1708 |
+
" [-0.05833942, -0.08774115, 0.02993867, ..., -0.00308282,\n",
|
| 1709 |
+
" 0.06190689, -0.04922426]], dtype=float32)}"
|
| 1710 |
+
]
|
| 1711 |
+
},
|
| 1712 |
+
"execution_count": 34,
|
| 1713 |
+
"metadata": {},
|
| 1714 |
+
"output_type": "execute_result"
|
| 1715 |
+
}
|
| 1716 |
+
],
|
| 1717 |
+
"source": [
|
| 1718 |
+
"data['question_feats'] = feats\n",
|
| 1719 |
+
"data"
|
| 1720 |
+
]
|
| 1721 |
+
},
|
| 1722 |
+
{
|
| 1723 |
+
"cell_type": "code",
|
| 1724 |
+
"execution_count": 35,
|
| 1725 |
+
"id": "8d0053d6",
|
| 1726 |
+
"metadata": {},
|
| 1727 |
+
"outputs": [],
|
| 1728 |
+
"source": [
|
| 1729 |
+
"import pickle\n",
|
| 1730 |
+
"\n",
|
| 1731 |
+
"with open('croval.pkl', 'wb') as f:\n",
|
| 1732 |
+
" pickle.dump(data, f)"
|
| 1733 |
+
]
|
| 1734 |
+
}
|
| 1735 |
+
],
|
| 1736 |
+
"metadata": {
|
| 1737 |
+
"kernelspec": {
|
| 1738 |
+
"display_name": "Python 3",
|
| 1739 |
+
"language": "python",
|
| 1740 |
+
"name": "python3"
|
| 1741 |
+
},
|
| 1742 |
+
"language_info": {
|
| 1743 |
+
"codemirror_mode": {
|
| 1744 |
+
"name": "ipython",
|
| 1745 |
+
"version": 3
|
| 1746 |
+
},
|
| 1747 |
+
"file_extension": ".py",
|
| 1748 |
+
"mimetype": "text/x-python",
|
| 1749 |
+
"name": "python",
|
| 1750 |
+
"nbconvert_exporter": "python",
|
| 1751 |
+
"pygments_lexer": "ipython3",
|
| 1752 |
+
"version": "3.10.12"
|
| 1753 |
+
}
|
| 1754 |
+
},
|
| 1755 |
+
"nbformat": 4,
|
| 1756 |
+
"nbformat_minor": 5
|
| 1757 |
+
}
|
dblp/DBLP.csv.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:131b3f1588ab8b7ca3e9d23f2f403889ba98a2686372b6818ca4bc21fed15967
|
| 3 |
+
size 521602357
|
dblp/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DBLP: Academic Network
|
| 2 |
+
|
| 3 |
+
The DBLP dataset is a heterogeneous academic network constructed from the [Digital Bibliography \& Library Project](https://dblp.org) a comprehensive, freely accessible online database of bibliographic information related to computer science research. We construct our HTAG based on the source data provided by [Aminer](https://originalstatic.aminer.cn/misc/dblp.v12.7z) [1]. After processing, it contains three types of entities—papers (964,350 nodes), authors (958,961 nodes), and fields of study (FoS, 65,699 nodes)—as well as three types of directed relations connecting three types of entities—a paper "cites" another paper, an author "writes" a paper, and a paper "has a topic of" a field of study. Papers are associated with their titles and abstracts, and all the other types of entities are textless. We concatenate the paper title and abstract and pass it to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each paper node. Based on the publication venue, each paper is assigned one of [nine topics](https://numbda.cs.tsinghua.edu.cn/~yuwj/TH-CPL.pdf): "high-performance computing", "computer networks", "network and information security", "theoretical computer science", "system software and software engineering", "database and data mining", "artificial intelligence and pattern recognition", "computer graphics and multimedia", "human-computer interaction and pervasive computing". Additionally, each paper is associated with its year of publication.
|
| 4 |
+
|
| 5 |
+
**Prediction task.**
|
| 6 |
+
The task is to predict the topic of each paper based on its content, references, authors, and fields of study. To evaluate performance, we use both Micro-F1 and Macro-F1 scores.
|
| 7 |
+
|
| 8 |
+
**Dataset splitting.**
|
| 9 |
+
We use the time-based strategy to split the paper nodes in the heterogeneous graph, i.e., models are trained on papers published before 2010, validated on papers published from 2011 to 2013, and tested on papers published from 2014 onwards.
|
| 10 |
+
|
| 11 |
+
**Dataset statistics.**
|
| 12 |
+
|
| 13 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 14 |
+
| -------------- | ----------------------- | --------- | -------------- |
|
| 15 |
+
| **1,989,010** | **29,830,033** | 9 | Train: 508,464 |
|
| 16 |
+
| Paper: 964350 | Paper-Paper: 16,679,526 | | Valid: 158,891 |
|
| 17 |
+
| Author: 958961 | Paper-Author: 3,070,343 | | Test: 296,995 |
|
| 18 |
+
| FoS: 65699 | Paper-FoS: 10,080,164 | | |
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
[1] Zhang, F., Shi, S., Zhu, Y., Chen, B., Cen, Y., Yu, J., ... & Tang, J. (2024, August). Oag-bench: a human-curated benchmark for academic graph mining. In *Proceedings of the 30th ACM SIGKDD Conference on Knowledge Discovery and Data Mining* (pp. 6214-6225).
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Dataset Construction
|
| 27 |
+
|
| 28 |
+
1. Download `dblp.v12.7z` from [AMiner](https://originalstatic.aminer.cn/misc/dblp.v12.7z)
|
| 29 |
+
2. Download `aminer_name_cluster_edit.txt` from [Aliyun](https://open-data-set.oss-cn-beijing.aliyuncs.com/oag-benchmark/entity-tagging/aminer_name_cluster_edit.txt)
|
| 30 |
+
3. Run `extract_from_dblp.py`
|
| 31 |
+
4. Run `graph_builder.ipynb`
|
dblp/dblp.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf28e0b18572b410a6b60dc4435c3f92b9fa0dd3dfd47321190f80b1fc883626
|
| 3 |
+
size 1652405214
|
dblp/extract_from_dblp.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import json
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
start_time = time.time()
|
| 6 |
+
|
| 7 |
+
ven_label_map = {}
|
| 8 |
+
labels = {'0': 0, '3': 1, '4': 2, '5': 3, '6': 4, '7': 5, '8': 6, '10': 7, '11': 8}
|
| 9 |
+
|
| 10 |
+
with open('aminer_name_cluster_edit.txt', 'r', encoding='utf-8') as f:
|
| 11 |
+
for line in f:
|
| 12 |
+
item = line.strip().split('\t')
|
| 13 |
+
if item[-1] in labels:
|
| 14 |
+
ven_label_map[int(item[0])] = labels[item[-1]]
|
| 15 |
+
print('Number of venues:', len(ven_label_map))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
print('Extract...')
|
| 19 |
+
with open(f'dblp.v12.json', 'r', encoding='utf-8') as f_in:
|
| 20 |
+
with open(f'dblp.v12.csv', 'w', encoding='utf-8', newline='') as f_out:
|
| 21 |
+
writer = csv.writer(f_out)
|
| 22 |
+
heads = ['id', 'title', 'abstract', 'year', 'label', 'authors', 'references', 'fos']
|
| 23 |
+
writer.writerow(heads)
|
| 24 |
+
|
| 25 |
+
num = 0
|
| 26 |
+
rows = []
|
| 27 |
+
for line in f_in:
|
| 28 |
+
if line[0] == ',' or line[0] == '{':
|
| 29 |
+
line = line.strip(',')
|
| 30 |
+
paper = json.loads(line)
|
| 31 |
+
row = []
|
| 32 |
+
try:
|
| 33 |
+
if paper['venue']['id'] in ven_label_map:
|
| 34 |
+
# get abstract
|
| 35 |
+
abs_length = paper['indexed_abstract']['IndexLength']
|
| 36 |
+
abs_dic = paper['indexed_abstract']['InvertedIndex']
|
| 37 |
+
abstract = [None for _ in range(abs_length)]
|
| 38 |
+
for key, values in abs_dic.items():
|
| 39 |
+
for i in values:
|
| 40 |
+
abstract[i] = key
|
| 41 |
+
str_abs = ''
|
| 42 |
+
for i in abstract:
|
| 43 |
+
str_abs += (i + ' ')
|
| 44 |
+
str_abs = str_abs.strip(' ')
|
| 45 |
+
id = paper['id']
|
| 46 |
+
title = paper['title']
|
| 47 |
+
year = paper['year']
|
| 48 |
+
label = ven_label_map[paper['venue']['id']]
|
| 49 |
+
authors = [author['id'] for author in paper['authors']]
|
| 50 |
+
fos = [fos_item['name'].lower() for fos_item in paper['fos']]
|
| 51 |
+
row = [id, title, str_abs, year, label, authors, paper['references'], fos]
|
| 52 |
+
rows.append(row)
|
| 53 |
+
num += 1
|
| 54 |
+
if num % 5000 == 0:
|
| 55 |
+
writer.writerows(rows)
|
| 56 |
+
rows = []
|
| 57 |
+
print(num)
|
| 58 |
+
except:
|
| 59 |
+
continue
|
| 60 |
+
if len(rows) > 0:
|
| 61 |
+
writer.writerows(rows)
|
| 62 |
+
print(num, f'{time.time() - start_time}s', 'Done!')
|
dblp/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,944 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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": "initial_id",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"collapsed": true
|
| 9 |
+
},
|
| 10 |
+
"outputs": [],
|
| 11 |
+
"source": [
|
| 12 |
+
"import itertools\n",
|
| 13 |
+
"import numpy as np\n",
|
| 14 |
+
"import pandas as pd\n",
|
| 15 |
+
"from sklearn.preprocessing import LabelEncoder"
|
| 16 |
+
]
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"cell_type": "code",
|
| 20 |
+
"execution_count": 2,
|
| 21 |
+
"id": "775d8173",
|
| 22 |
+
"metadata": {},
|
| 23 |
+
"outputs": [
|
| 24 |
+
{
|
| 25 |
+
"name": "stdout",
|
| 26 |
+
"output_type": "stream",
|
| 27 |
+
"text": [
|
| 28 |
+
"(1002355, 8)\n"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"data": {
|
| 33 |
+
"text/html": [
|
| 34 |
+
"<div>\n",
|
| 35 |
+
"<style scoped>\n",
|
| 36 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 37 |
+
" vertical-align: middle;\n",
|
| 38 |
+
" }\n",
|
| 39 |
+
"\n",
|
| 40 |
+
" .dataframe tbody tr th {\n",
|
| 41 |
+
" vertical-align: top;\n",
|
| 42 |
+
" }\n",
|
| 43 |
+
"\n",
|
| 44 |
+
" .dataframe thead th {\n",
|
| 45 |
+
" text-align: right;\n",
|
| 46 |
+
" }\n",
|
| 47 |
+
"</style>\n",
|
| 48 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 49 |
+
" <thead>\n",
|
| 50 |
+
" <tr style=\"text-align: right;\">\n",
|
| 51 |
+
" <th></th>\n",
|
| 52 |
+
" <th>id</th>\n",
|
| 53 |
+
" <th>title</th>\n",
|
| 54 |
+
" <th>abstract</th>\n",
|
| 55 |
+
" <th>year</th>\n",
|
| 56 |
+
" <th>label</th>\n",
|
| 57 |
+
" <th>authors</th>\n",
|
| 58 |
+
" <th>references</th>\n",
|
| 59 |
+
" <th>fos</th>\n",
|
| 60 |
+
" </tr>\n",
|
| 61 |
+
" </thead>\n",
|
| 62 |
+
" <tbody>\n",
|
| 63 |
+
" <tr>\n",
|
| 64 |
+
" <th>0</th>\n",
|
| 65 |
+
" <td>1091</td>\n",
|
| 66 |
+
" <td>Preliminary Design of a Network Protocol Learn...</td>\n",
|
| 67 |
+
" <td>The purpose of this study is to develop a lear...</td>\n",
|
| 68 |
+
" <td>2013</td>\n",
|
| 69 |
+
" <td>6</td>\n",
|
| 70 |
+
" <td>[2312688602, 2482909946, 2128134587, 210178269...</td>\n",
|
| 71 |
+
" <td>[2005687710, 2018037215]</td>\n",
|
| 72 |
+
" <td>[telecommunications network, computer science,...</td>\n",
|
| 73 |
+
" </tr>\n",
|
| 74 |
+
" <tr>\n",
|
| 75 |
+
" <th>1</th>\n",
|
| 76 |
+
" <td>15883</td>\n",
|
| 77 |
+
" <td>Leveraging legacy code to deploy desktop appli...</td>\n",
|
| 78 |
+
" <td>Xax is a browser plugin model that enables dev...</td>\n",
|
| 79 |
+
" <td>2008</td>\n",
|
| 80 |
+
" <td>4</td>\n",
|
| 81 |
+
" <td>[135218249, 2120803867, 2128381254, 2150137935]</td>\n",
|
| 82 |
+
" <td>[114793137, 186343359, 205258527, 1516211918, ...</td>\n",
|
| 83 |
+
" <td>[world wide web, computer science, machine cod...</td>\n",
|
| 84 |
+
" </tr>\n",
|
| 85 |
+
" <tr>\n",
|
| 86 |
+
" <th>2</th>\n",
|
| 87 |
+
" <td>15901</td>\n",
|
| 88 |
+
" <td>A pedestrian navigation method for user's safe...</td>\n",
|
| 89 |
+
" <td>In recent years, most of mobile phones have a ...</td>\n",
|
| 90 |
+
" <td>2013</td>\n",
|
| 91 |
+
" <td>6</td>\n",
|
| 92 |
+
" <td>[2789599552, 2935910818]</td>\n",
|
| 93 |
+
" <td>[2055819696, 2167564737, 2169528473]</td>\n",
|
| 94 |
+
" <td>[visibility, route planning, computer science,...</td>\n",
|
| 95 |
+
" </tr>\n",
|
| 96 |
+
" <tr>\n",
|
| 97 |
+
" <th>3</th>\n",
|
| 98 |
+
" <td>38917</td>\n",
|
| 99 |
+
" <td>Automated Object Identification and Position E...</td>\n",
|
| 100 |
+
" <td>The development of an automated system for the...</td>\n",
|
| 101 |
+
" <td>2008</td>\n",
|
| 102 |
+
" <td>0</td>\n",
|
| 103 |
+
" <td>[2068146743, 2252543171, 1278895136, 2171534607]</td>\n",
|
| 104 |
+
" <td>[96589161, 2138661420, 2157641950, 2163004336,...</td>\n",
|
| 105 |
+
" <td>[computer vision, aerodrome, image sensor, com...</td>\n",
|
| 106 |
+
" </tr>\n",
|
| 107 |
+
" <tr>\n",
|
| 108 |
+
" <th>4</th>\n",
|
| 109 |
+
" <td>58261</td>\n",
|
| 110 |
+
" <td>A general semantic analyser for data base access</td>\n",
|
| 111 |
+
" <td>The paper discusses the design principles and ...</td>\n",
|
| 112 |
+
" <td>1981</td>\n",
|
| 113 |
+
" <td>0</td>\n",
|
| 114 |
+
" <td>[2316496857, 2169254595]</td>\n",
|
| 115 |
+
" <td>[1997320166, 2042008249, 2043794661, 2061141062]</td>\n",
|
| 116 |
+
" <td>[front and back ends, design elements and prin...</td>\n",
|
| 117 |
+
" </tr>\n",
|
| 118 |
+
" </tbody>\n",
|
| 119 |
+
"</table>\n",
|
| 120 |
+
"</div>"
|
| 121 |
+
],
|
| 122 |
+
"text/plain": [
|
| 123 |
+
" id title \\\n",
|
| 124 |
+
"0 1091 Preliminary Design of a Network Protocol Learn... \n",
|
| 125 |
+
"1 15883 Leveraging legacy code to deploy desktop appli... \n",
|
| 126 |
+
"2 15901 A pedestrian navigation method for user's safe... \n",
|
| 127 |
+
"3 38917 Automated Object Identification and Position E... \n",
|
| 128 |
+
"4 58261 A general semantic analyser for data base access \n",
|
| 129 |
+
"\n",
|
| 130 |
+
" abstract year label \\\n",
|
| 131 |
+
"0 The purpose of this study is to develop a lear... 2013 6 \n",
|
| 132 |
+
"1 Xax is a browser plugin model that enables dev... 2008 4 \n",
|
| 133 |
+
"2 In recent years, most of mobile phones have a ... 2013 6 \n",
|
| 134 |
+
"3 The development of an automated system for the... 2008 0 \n",
|
| 135 |
+
"4 The paper discusses the design principles and ... 1981 0 \n",
|
| 136 |
+
"\n",
|
| 137 |
+
" authors \\\n",
|
| 138 |
+
"0 [2312688602, 2482909946, 2128134587, 210178269... \n",
|
| 139 |
+
"1 [135218249, 2120803867, 2128381254, 2150137935] \n",
|
| 140 |
+
"2 [2789599552, 2935910818] \n",
|
| 141 |
+
"3 [2068146743, 2252543171, 1278895136, 2171534607] \n",
|
| 142 |
+
"4 [2316496857, 2169254595] \n",
|
| 143 |
+
"\n",
|
| 144 |
+
" references \\\n",
|
| 145 |
+
"0 [2005687710, 2018037215] \n",
|
| 146 |
+
"1 [114793137, 186343359, 205258527, 1516211918, ... \n",
|
| 147 |
+
"2 [2055819696, 2167564737, 2169528473] \n",
|
| 148 |
+
"3 [96589161, 2138661420, 2157641950, 2163004336,... \n",
|
| 149 |
+
"4 [1997320166, 2042008249, 2043794661, 2061141062] \n",
|
| 150 |
+
"\n",
|
| 151 |
+
" fos \n",
|
| 152 |
+
"0 [telecommunications network, computer science,... \n",
|
| 153 |
+
"1 [world wide web, computer science, machine cod... \n",
|
| 154 |
+
"2 [visibility, route planning, computer science,... \n",
|
| 155 |
+
"3 [computer vision, aerodrome, image sensor, com... \n",
|
| 156 |
+
"4 [front and back ends, design elements and prin... "
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
"execution_count": 2,
|
| 160 |
+
"metadata": {},
|
| 161 |
+
"output_type": "execute_result"
|
| 162 |
+
}
|
| 163 |
+
],
|
| 164 |
+
"source": [
|
| 165 |
+
"papers = pd.read_csv('dblp.v12.csv')\n",
|
| 166 |
+
"papers['authors'] = papers['authors'].apply(eval)\n",
|
| 167 |
+
"papers['references'] = papers['references'].apply(eval)\n",
|
| 168 |
+
"papers['fos'] = papers['fos'].apply(eval)\n",
|
| 169 |
+
"print(papers.shape)\n",
|
| 170 |
+
"papers.head()"
|
| 171 |
+
]
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
"cell_type": "code",
|
| 175 |
+
"execution_count": 3,
|
| 176 |
+
"id": "add9f8dc",
|
| 177 |
+
"metadata": {},
|
| 178 |
+
"outputs": [
|
| 179 |
+
{
|
| 180 |
+
"data": {
|
| 181 |
+
"text/plain": [
|
| 182 |
+
"(14072159, np.int64(7876504))"
|
| 183 |
+
]
|
| 184 |
+
},
|
| 185 |
+
"execution_count": 3,
|
| 186 |
+
"metadata": {},
|
| 187 |
+
"output_type": "execute_result"
|
| 188 |
+
}
|
| 189 |
+
],
|
| 190 |
+
"source": [
|
| 191 |
+
"# Extend the `references` column to a List[2005687710, 2018037215, 114793137, ...]\n",
|
| 192 |
+
"all_references = np.array(list(itertools.chain(*(papers['references'].values))))\n",
|
| 193 |
+
"\n",
|
| 194 |
+
"# Construct a list containing the `id` corresponding to the above references list\n",
|
| 195 |
+
"paper_ids = np.concatenate([np.full(count, i) \n",
|
| 196 |
+
" for i, count in zip(papers['id'].values, papers['references'].apply(len))])\n",
|
| 197 |
+
"\n",
|
| 198 |
+
"assert len(all_references) == len(paper_ids)\n",
|
| 199 |
+
"\n",
|
| 200 |
+
"# Wether a reference is in the `id` column\n",
|
| 201 |
+
"in_paperids = np.isin(all_references, papers['id'].values)\n",
|
| 202 |
+
"len(in_paperids), in_paperids.sum() "
|
| 203 |
+
]
|
| 204 |
+
},
|
| 205 |
+
{
|
| 206 |
+
"cell_type": "code",
|
| 207 |
+
"execution_count": 4,
|
| 208 |
+
"id": "98a23d01",
|
| 209 |
+
"metadata": {},
|
| 210 |
+
"outputs": [],
|
| 211 |
+
"source": [
|
| 212 |
+
"# Filter the references list\n",
|
| 213 |
+
"all_references = all_references[in_paperids]\n",
|
| 214 |
+
"paper_ids = paper_ids[in_paperids]"
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"cell_type": "code",
|
| 219 |
+
"execution_count": 5,
|
| 220 |
+
"id": "a35ac7fd",
|
| 221 |
+
"metadata": {},
|
| 222 |
+
"outputs": [
|
| 223 |
+
{
|
| 224 |
+
"name": "stdout",
|
| 225 |
+
"output_type": "stream",
|
| 226 |
+
"text": [
|
| 227 |
+
"Number of papers that refer or are referred 964350\n"
|
| 228 |
+
]
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"data": {
|
| 232 |
+
"text/html": [
|
| 233 |
+
"<div>\n",
|
| 234 |
+
"<style scoped>\n",
|
| 235 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 236 |
+
" vertical-align: middle;\n",
|
| 237 |
+
" }\n",
|
| 238 |
+
"\n",
|
| 239 |
+
" .dataframe tbody tr th {\n",
|
| 240 |
+
" vertical-align: top;\n",
|
| 241 |
+
" }\n",
|
| 242 |
+
"\n",
|
| 243 |
+
" .dataframe thead th {\n",
|
| 244 |
+
" text-align: right;\n",
|
| 245 |
+
" }\n",
|
| 246 |
+
"</style>\n",
|
| 247 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 248 |
+
" <thead>\n",
|
| 249 |
+
" <tr style=\"text-align: right;\">\n",
|
| 250 |
+
" <th></th>\n",
|
| 251 |
+
" <th>id</th>\n",
|
| 252 |
+
" <th>title</th>\n",
|
| 253 |
+
" <th>abstract</th>\n",
|
| 254 |
+
" <th>year</th>\n",
|
| 255 |
+
" <th>label</th>\n",
|
| 256 |
+
" <th>authors</th>\n",
|
| 257 |
+
" <th>references</th>\n",
|
| 258 |
+
" <th>fos</th>\n",
|
| 259 |
+
" </tr>\n",
|
| 260 |
+
" </thead>\n",
|
| 261 |
+
" <tbody>\n",
|
| 262 |
+
" <tr>\n",
|
| 263 |
+
" <th>1</th>\n",
|
| 264 |
+
" <td>15883</td>\n",
|
| 265 |
+
" <td>Leveraging legacy code to deploy desktop appli...</td>\n",
|
| 266 |
+
" <td>Xax is a browser plugin model that enables dev...</td>\n",
|
| 267 |
+
" <td>2008</td>\n",
|
| 268 |
+
" <td>4</td>\n",
|
| 269 |
+
" <td>[135218249, 2120803867, 2128381254, 2150137935]</td>\n",
|
| 270 |
+
" <td>[114793137, 186343359, 205258527, 1516211918, ...</td>\n",
|
| 271 |
+
" <td>[world wide web, computer science, machine cod...</td>\n",
|
| 272 |
+
" </tr>\n",
|
| 273 |
+
" <tr>\n",
|
| 274 |
+
" <th>2</th>\n",
|
| 275 |
+
" <td>15901</td>\n",
|
| 276 |
+
" <td>A pedestrian navigation method for user's safe...</td>\n",
|
| 277 |
+
" <td>In recent years, most of mobile phones have a ...</td>\n",
|
| 278 |
+
" <td>2013</td>\n",
|
| 279 |
+
" <td>6</td>\n",
|
| 280 |
+
" <td>[2789599552, 2935910818]</td>\n",
|
| 281 |
+
" <td>[2055819696, 2167564737, 2169528473]</td>\n",
|
| 282 |
+
" <td>[visibility, route planning, computer science,...</td>\n",
|
| 283 |
+
" </tr>\n",
|
| 284 |
+
" <tr>\n",
|
| 285 |
+
" <th>3</th>\n",
|
| 286 |
+
" <td>38917</td>\n",
|
| 287 |
+
" <td>Automated Object Identification and Position E...</td>\n",
|
| 288 |
+
" <td>The development of an automated system for the...</td>\n",
|
| 289 |
+
" <td>2008</td>\n",
|
| 290 |
+
" <td>0</td>\n",
|
| 291 |
+
" <td>[2068146743, 2252543171, 1278895136, 2171534607]</td>\n",
|
| 292 |
+
" <td>[96589161, 2138661420, 2157641950, 2163004336,...</td>\n",
|
| 293 |
+
" <td>[computer vision, aerodrome, image sensor, com...</td>\n",
|
| 294 |
+
" </tr>\n",
|
| 295 |
+
" <tr>\n",
|
| 296 |
+
" <th>4</th>\n",
|
| 297 |
+
" <td>58261</td>\n",
|
| 298 |
+
" <td>A general semantic analyser for data base access</td>\n",
|
| 299 |
+
" <td>The paper discusses the design principles and ...</td>\n",
|
| 300 |
+
" <td>1981</td>\n",
|
| 301 |
+
" <td>0</td>\n",
|
| 302 |
+
" <td>[2316496857, 2169254595]</td>\n",
|
| 303 |
+
" <td>[1997320166, 2042008249, 2043794661, 2061141062]</td>\n",
|
| 304 |
+
" <td>[front and back ends, design elements and prin...</td>\n",
|
| 305 |
+
" </tr>\n",
|
| 306 |
+
" <tr>\n",
|
| 307 |
+
" <th>5</th>\n",
|
| 308 |
+
" <td>65220</td>\n",
|
| 309 |
+
" <td>Two notes from experimental study on image ste...</td>\n",
|
| 310 |
+
" <td>In recent years, several advanced methods for ...</td>\n",
|
| 311 |
+
" <td>2013</td>\n",
|
| 312 |
+
" <td>0</td>\n",
|
| 313 |
+
" <td>[2304723528, 2676058149, 2120394816]</td>\n",
|
| 314 |
+
" <td>[22271197, 29798142, 1713630528, 1955882805, 2...</td>\n",
|
| 315 |
+
" <td>[steganography, steganography tools, pattern r...</td>\n",
|
| 316 |
+
" </tr>\n",
|
| 317 |
+
" </tbody>\n",
|
| 318 |
+
"</table>\n",
|
| 319 |
+
"</div>"
|
| 320 |
+
],
|
| 321 |
+
"text/plain": [
|
| 322 |
+
" id title \\\n",
|
| 323 |
+
"1 15883 Leveraging legacy code to deploy desktop appli... \n",
|
| 324 |
+
"2 15901 A pedestrian navigation method for user's safe... \n",
|
| 325 |
+
"3 38917 Automated Object Identification and Position E... \n",
|
| 326 |
+
"4 58261 A general semantic analyser for data base access \n",
|
| 327 |
+
"5 65220 Two notes from experimental study on image ste... \n",
|
| 328 |
+
"\n",
|
| 329 |
+
" abstract year label \\\n",
|
| 330 |
+
"1 Xax is a browser plugin model that enables dev... 2008 4 \n",
|
| 331 |
+
"2 In recent years, most of mobile phones have a ... 2013 6 \n",
|
| 332 |
+
"3 The development of an automated system for the... 2008 0 \n",
|
| 333 |
+
"4 The paper discusses the design principles and ... 1981 0 \n",
|
| 334 |
+
"5 In recent years, several advanced methods for ... 2013 0 \n",
|
| 335 |
+
"\n",
|
| 336 |
+
" authors \\\n",
|
| 337 |
+
"1 [135218249, 2120803867, 2128381254, 2150137935] \n",
|
| 338 |
+
"2 [2789599552, 2935910818] \n",
|
| 339 |
+
"3 [2068146743, 2252543171, 1278895136, 2171534607] \n",
|
| 340 |
+
"4 [2316496857, 2169254595] \n",
|
| 341 |
+
"5 [2304723528, 2676058149, 2120394816] \n",
|
| 342 |
+
"\n",
|
| 343 |
+
" references \\\n",
|
| 344 |
+
"1 [114793137, 186343359, 205258527, 1516211918, ... \n",
|
| 345 |
+
"2 [2055819696, 2167564737, 2169528473] \n",
|
| 346 |
+
"3 [96589161, 2138661420, 2157641950, 2163004336,... \n",
|
| 347 |
+
"4 [1997320166, 2042008249, 2043794661, 2061141062] \n",
|
| 348 |
+
"5 [22271197, 29798142, 1713630528, 1955882805, 2... \n",
|
| 349 |
+
"\n",
|
| 350 |
+
" fos \n",
|
| 351 |
+
"1 [world wide web, computer science, machine cod... \n",
|
| 352 |
+
"2 [visibility, route planning, computer science,... \n",
|
| 353 |
+
"3 [computer vision, aerodrome, image sensor, com... \n",
|
| 354 |
+
"4 [front and back ends, design elements and prin... \n",
|
| 355 |
+
"5 [steganography, steganography tools, pattern r... "
|
| 356 |
+
]
|
| 357 |
+
},
|
| 358 |
+
"execution_count": 5,
|
| 359 |
+
"metadata": {},
|
| 360 |
+
"output_type": "execute_result"
|
| 361 |
+
}
|
| 362 |
+
],
|
| 363 |
+
"source": [
|
| 364 |
+
"has_reference1 = np.isin(papers['id'].values, paper_ids)\n",
|
| 365 |
+
"has_reference2 = np.isin(papers['id'].values, all_references)\n",
|
| 366 |
+
"has_reference = has_reference1 | has_reference2\n",
|
| 367 |
+
"papers = papers[has_reference]\n",
|
| 368 |
+
"print('Number of papers that refer or are referred', papers.shape[0])\n",
|
| 369 |
+
"papers.head()"
|
| 370 |
+
]
|
| 371 |
+
},
|
| 372 |
+
{
|
| 373 |
+
"cell_type": "markdown",
|
| 374 |
+
"id": "140f3a6b",
|
| 375 |
+
"metadata": {},
|
| 376 |
+
"source": [
|
| 377 |
+
"## Paper-Paper Links"
|
| 378 |
+
]
|
| 379 |
+
},
|
| 380 |
+
{
|
| 381 |
+
"cell_type": "code",
|
| 382 |
+
"execution_count": 6,
|
| 383 |
+
"id": "58bc2147",
|
| 384 |
+
"metadata": {},
|
| 385 |
+
"outputs": [],
|
| 386 |
+
"source": [
|
| 387 |
+
"data = {}"
|
| 388 |
+
]
|
| 389 |
+
},
|
| 390 |
+
{
|
| 391 |
+
"cell_type": "code",
|
| 392 |
+
"execution_count": 7,
|
| 393 |
+
"id": "8c8a2b26",
|
| 394 |
+
"metadata": {},
|
| 395 |
+
"outputs": [],
|
| 396 |
+
"source": [
|
| 397 |
+
"paper_id_encoder = LabelEncoder()\n",
|
| 398 |
+
"paper_id_encoder.fit(papers['id'].values)\n",
|
| 399 |
+
"all_references = paper_id_encoder.transform(all_references).astype(np.int32)\n",
|
| 400 |
+
"paper_ids = paper_id_encoder.transform(paper_ids).astype(np.int32)"
|
| 401 |
+
]
|
| 402 |
+
},
|
| 403 |
+
{
|
| 404 |
+
"cell_type": "code",
|
| 405 |
+
"execution_count": 8,
|
| 406 |
+
"id": "e59e8efe",
|
| 407 |
+
"metadata": {},
|
| 408 |
+
"outputs": [
|
| 409 |
+
{
|
| 410 |
+
"name": "stdout",
|
| 411 |
+
"output_type": "stream",
|
| 412 |
+
"text": [
|
| 413 |
+
"Number of paper-paper links: 7876504\n"
|
| 414 |
+
]
|
| 415 |
+
}
|
| 416 |
+
],
|
| 417 |
+
"source": [
|
| 418 |
+
"src = np.concatenate((paper_ids, all_references))\n",
|
| 419 |
+
"dst = np.concatenate((all_references, paper_ids))\n",
|
| 420 |
+
"mask = src < dst\n",
|
| 421 |
+
"src = src[mask]\n",
|
| 422 |
+
"dst = dst[mask]\n",
|
| 423 |
+
"\n",
|
| 424 |
+
"print('Number of paper-paper links:', src.shape[0])\n",
|
| 425 |
+
"data['paper-paper'] = (src, dst)"
|
| 426 |
+
]
|
| 427 |
+
},
|
| 428 |
+
{
|
| 429 |
+
"cell_type": "markdown",
|
| 430 |
+
"id": "c6ea40b9",
|
| 431 |
+
"metadata": {},
|
| 432 |
+
"source": [
|
| 433 |
+
"## Paper-Author Links"
|
| 434 |
+
]
|
| 435 |
+
},
|
| 436 |
+
{
|
| 437 |
+
"cell_type": "code",
|
| 438 |
+
"execution_count": 9,
|
| 439 |
+
"id": "7ac95935",
|
| 440 |
+
"metadata": {},
|
| 441 |
+
"outputs": [],
|
| 442 |
+
"source": [
|
| 443 |
+
"paper_ids = np.concatenate([np.full(count, i) \n",
|
| 444 |
+
" for i, count in zip(papers['id'].values, papers['authors'].apply(len))])\n",
|
| 445 |
+
"authors = list(itertools.chain(*(papers['authors'].values)))"
|
| 446 |
+
]
|
| 447 |
+
},
|
| 448 |
+
{
|
| 449 |
+
"cell_type": "code",
|
| 450 |
+
"execution_count": 10,
|
| 451 |
+
"id": "a18d2f9c",
|
| 452 |
+
"metadata": {},
|
| 453 |
+
"outputs": [
|
| 454 |
+
{
|
| 455 |
+
"name": "stdout",
|
| 456 |
+
"output_type": "stream",
|
| 457 |
+
"text": [
|
| 458 |
+
"Number of authors: 958961\n"
|
| 459 |
+
]
|
| 460 |
+
}
|
| 461 |
+
],
|
| 462 |
+
"source": [
|
| 463 |
+
"author_id_encoder = LabelEncoder()\n",
|
| 464 |
+
"author_ids = author_id_encoder.fit_transform(authors).astype(np.int32)\n",
|
| 465 |
+
"print('Number of authors:', len(author_id_encoder.classes_))"
|
| 466 |
+
]
|
| 467 |
+
},
|
| 468 |
+
{
|
| 469 |
+
"cell_type": "code",
|
| 470 |
+
"execution_count": 11,
|
| 471 |
+
"id": "c26050f6",
|
| 472 |
+
"metadata": {},
|
| 473 |
+
"outputs": [
|
| 474 |
+
{
|
| 475 |
+
"name": "stdout",
|
| 476 |
+
"output_type": "stream",
|
| 477 |
+
"text": [
|
| 478 |
+
"Number of paper-author links: 3070343\n"
|
| 479 |
+
]
|
| 480 |
+
}
|
| 481 |
+
],
|
| 482 |
+
"source": [
|
| 483 |
+
"paper_ids = paper_id_encoder.transform(paper_ids).astype(np.int32)\n",
|
| 484 |
+
"assert len(author_ids) == len(paper_ids)\n",
|
| 485 |
+
"print('Number of paper-author links:', paper_ids.shape[0])\n",
|
| 486 |
+
"data['paper-author'] = (paper_ids, author_ids)"
|
| 487 |
+
]
|
| 488 |
+
},
|
| 489 |
+
{
|
| 490 |
+
"cell_type": "markdown",
|
| 491 |
+
"id": "dac2cf56",
|
| 492 |
+
"metadata": {},
|
| 493 |
+
"source": [
|
| 494 |
+
"## Paper-FoS Links"
|
| 495 |
+
]
|
| 496 |
+
},
|
| 497 |
+
{
|
| 498 |
+
"cell_type": "code",
|
| 499 |
+
"execution_count": 12,
|
| 500 |
+
"id": "84c81398",
|
| 501 |
+
"metadata": {},
|
| 502 |
+
"outputs": [],
|
| 503 |
+
"source": [
|
| 504 |
+
"paper_ids = np.concatenate([np.full(count, i) \n",
|
| 505 |
+
" for i, count in zip(papers['id'].values, papers['fos'].apply(len))])\n",
|
| 506 |
+
"foss = list(itertools.chain(*(papers['fos'].values)))"
|
| 507 |
+
]
|
| 508 |
+
},
|
| 509 |
+
{
|
| 510 |
+
"cell_type": "code",
|
| 511 |
+
"execution_count": 13,
|
| 512 |
+
"id": "4b01e746",
|
| 513 |
+
"metadata": {},
|
| 514 |
+
"outputs": [
|
| 515 |
+
{
|
| 516 |
+
"name": "stdout",
|
| 517 |
+
"output_type": "stream",
|
| 518 |
+
"text": [
|
| 519 |
+
"Number of FoS: 65699\n"
|
| 520 |
+
]
|
| 521 |
+
}
|
| 522 |
+
],
|
| 523 |
+
"source": [
|
| 524 |
+
"fos_id_encoder = LabelEncoder()\n",
|
| 525 |
+
"fos_ids = fos_id_encoder.fit_transform(foss).astype(np.int32)\n",
|
| 526 |
+
"print('Number of FoS:', len(fos_id_encoder.classes_))"
|
| 527 |
+
]
|
| 528 |
+
},
|
| 529 |
+
{
|
| 530 |
+
"cell_type": "code",
|
| 531 |
+
"execution_count": 14,
|
| 532 |
+
"id": "db87e8fe",
|
| 533 |
+
"metadata": {},
|
| 534 |
+
"outputs": [
|
| 535 |
+
{
|
| 536 |
+
"name": "stdout",
|
| 537 |
+
"output_type": "stream",
|
| 538 |
+
"text": [
|
| 539 |
+
"Number of paper-fos links: 10086883\n"
|
| 540 |
+
]
|
| 541 |
+
}
|
| 542 |
+
],
|
| 543 |
+
"source": [
|
| 544 |
+
"paper_ids = paper_id_encoder.transform(paper_ids).astype(np.int32)\n",
|
| 545 |
+
"\n",
|
| 546 |
+
"assert len(fos_ids) == len(paper_ids)\n",
|
| 547 |
+
"print('Number of paper-fos links:', fos_ids.shape[0])\n",
|
| 548 |
+
"data['paper-fos'] = (paper_ids, fos_ids)"
|
| 549 |
+
]
|
| 550 |
+
},
|
| 551 |
+
{
|
| 552 |
+
"cell_type": "code",
|
| 553 |
+
"execution_count": null,
|
| 554 |
+
"id": "bfe4abd3",
|
| 555 |
+
"metadata": {},
|
| 556 |
+
"outputs": [],
|
| 557 |
+
"source": []
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"cell_type": "markdown",
|
| 561 |
+
"id": "59b8e0bf",
|
| 562 |
+
"metadata": {},
|
| 563 |
+
"source": [
|
| 564 |
+
"## Labels and Years"
|
| 565 |
+
]
|
| 566 |
+
},
|
| 567 |
+
{
|
| 568 |
+
"cell_type": "code",
|
| 569 |
+
"execution_count": 15,
|
| 570 |
+
"id": "2f2e6972",
|
| 571 |
+
"metadata": {},
|
| 572 |
+
"outputs": [
|
| 573 |
+
{
|
| 574 |
+
"data": {
|
| 575 |
+
"text/html": [
|
| 576 |
+
"<div>\n",
|
| 577 |
+
"<style scoped>\n",
|
| 578 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 579 |
+
" vertical-align: middle;\n",
|
| 580 |
+
" }\n",
|
| 581 |
+
"\n",
|
| 582 |
+
" .dataframe tbody tr th {\n",
|
| 583 |
+
" vertical-align: top;\n",
|
| 584 |
+
" }\n",
|
| 585 |
+
"\n",
|
| 586 |
+
" .dataframe thead th {\n",
|
| 587 |
+
" text-align: right;\n",
|
| 588 |
+
" }\n",
|
| 589 |
+
"</style>\n",
|
| 590 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 591 |
+
" <thead>\n",
|
| 592 |
+
" <tr style=\"text-align: right;\">\n",
|
| 593 |
+
" <th></th>\n",
|
| 594 |
+
" <th>id</th>\n",
|
| 595 |
+
" <th>title</th>\n",
|
| 596 |
+
" <th>abstract</th>\n",
|
| 597 |
+
" <th>year</th>\n",
|
| 598 |
+
" <th>label</th>\n",
|
| 599 |
+
" <th>authors</th>\n",
|
| 600 |
+
" <th>references</th>\n",
|
| 601 |
+
" <th>fos</th>\n",
|
| 602 |
+
" </tr>\n",
|
| 603 |
+
" </thead>\n",
|
| 604 |
+
" <tbody>\n",
|
| 605 |
+
" <tr>\n",
|
| 606 |
+
" <th>964345</th>\n",
|
| 607 |
+
" <td>3008425973</td>\n",
|
| 608 |
+
" <td>A Simulation Model Demonstrating the Impact of...</td>\n",
|
| 609 |
+
" <td>In addition to seamless connectivity and smart...</td>\n",
|
| 610 |
+
" <td>2020</td>\n",
|
| 611 |
+
" <td>0</td>\n",
|
| 612 |
+
" <td>[3008013535]</td>\n",
|
| 613 |
+
" <td>[1969595988, 2024456547, 2106660896, 240927666...</td>\n",
|
| 614 |
+
" <td>[social objects, computer science, cooperative...</td>\n",
|
| 615 |
+
" </tr>\n",
|
| 616 |
+
" <tr>\n",
|
| 617 |
+
" <th>964346</th>\n",
|
| 618 |
+
" <td>3008480875</td>\n",
|
| 619 |
+
" <td>Scaling Blockchains to Support Electronic Heal...</td>\n",
|
| 620 |
+
" <td>Electronic Health Records (EHRs) have improved...</td>\n",
|
| 621 |
+
" <td>2020</td>\n",
|
| 622 |
+
" <td>2</td>\n",
|
| 623 |
+
" <td>[3000482756, 2560842277, 2096420846]</td>\n",
|
| 624 |
+
" <td>[1593596963, 2038708100, 2071551483, 216457208...</td>\n",
|
| 625 |
+
" <td>[health care, architecture, computer science, ...</td>\n",
|
| 626 |
+
" </tr>\n",
|
| 627 |
+
" <tr>\n",
|
| 628 |
+
" <th>964347</th>\n",
|
| 629 |
+
" <td>3008559546</td>\n",
|
| 630 |
+
" <td>How Good Is a Strategy in a Game with Nature</td>\n",
|
| 631 |
+
" <td>We consider games with two antagonistic player...</td>\n",
|
| 632 |
+
" <td>2020</td>\n",
|
| 633 |
+
" <td>7</td>\n",
|
| 634 |
+
" <td>[2083017933, 2033699461]</td>\n",
|
| 635 |
+
" <td>[157185084, 744920664, 1502459210, 1513485037,...</td>\n",
|
| 636 |
+
" <td>[discrete mathematics, graph, infinite game, d...</td>\n",
|
| 637 |
+
" </tr>\n",
|
| 638 |
+
" <tr>\n",
|
| 639 |
+
" <th>964348</th>\n",
|
| 640 |
+
" <td>3008721399</td>\n",
|
| 641 |
+
" <td>Chunking in Soar: The Anatomy of a General Lea...</td>\n",
|
| 642 |
+
" <td>In this article we describe an approach to the...</td>\n",
|
| 643 |
+
" <td>1986</td>\n",
|
| 644 |
+
" <td>0</td>\n",
|
| 645 |
+
" <td>[2098086841, 237745248, 2126658068]</td>\n",
|
| 646 |
+
" <td>[10646503, 38913427, 86408651, 152570004, 1597...</td>\n",
|
| 647 |
+
" <td>[anatomy, architecture, chunking (psychology),...</td>\n",
|
| 648 |
+
" </tr>\n",
|
| 649 |
+
" <tr>\n",
|
| 650 |
+
" <th>964349</th>\n",
|
| 651 |
+
" <td>3008773848</td>\n",
|
| 652 |
+
" <td>Shorter identifier names take longer to compre...</td>\n",
|
| 653 |
+
" <td>Developers spend the majority of their time co...</td>\n",
|
| 654 |
+
" <td>2017</td>\n",
|
| 655 |
+
" <td>4</td>\n",
|
| 656 |
+
" <td>[2576839772, 2145688174, 2166709612]</td>\n",
|
| 657 |
+
" <td>[1490674333, 1842503650, 1967931023, 203468809...</td>\n",
|
| 658 |
+
" <td>[identifier, computer science, artificial inte...</td>\n",
|
| 659 |
+
" </tr>\n",
|
| 660 |
+
" </tbody>\n",
|
| 661 |
+
"</table>\n",
|
| 662 |
+
"</div>"
|
| 663 |
+
],
|
| 664 |
+
"text/plain": [
|
| 665 |
+
" id title \\\n",
|
| 666 |
+
"964345 3008425973 A Simulation Model Demonstrating the Impact of... \n",
|
| 667 |
+
"964346 3008480875 Scaling Blockchains to Support Electronic Heal... \n",
|
| 668 |
+
"964347 3008559546 How Good Is a Strategy in a Game with Nature \n",
|
| 669 |
+
"964348 3008721399 Chunking in Soar: The Anatomy of a General Lea... \n",
|
| 670 |
+
"964349 3008773848 Shorter identifier names take longer to compre... \n",
|
| 671 |
+
"\n",
|
| 672 |
+
" abstract year label \\\n",
|
| 673 |
+
"964345 In addition to seamless connectivity and smart... 2020 0 \n",
|
| 674 |
+
"964346 Electronic Health Records (EHRs) have improved... 2020 2 \n",
|
| 675 |
+
"964347 We consider games with two antagonistic player... 2020 7 \n",
|
| 676 |
+
"964348 In this article we describe an approach to the... 1986 0 \n",
|
| 677 |
+
"964349 Developers spend the majority of their time co... 2017 4 \n",
|
| 678 |
+
"\n",
|
| 679 |
+
" authors \\\n",
|
| 680 |
+
"964345 [3008013535] \n",
|
| 681 |
+
"964346 [3000482756, 2560842277, 2096420846] \n",
|
| 682 |
+
"964347 [2083017933, 2033699461] \n",
|
| 683 |
+
"964348 [2098086841, 237745248, 2126658068] \n",
|
| 684 |
+
"964349 [2576839772, 2145688174, 2166709612] \n",
|
| 685 |
+
"\n",
|
| 686 |
+
" references \\\n",
|
| 687 |
+
"964345 [1969595988, 2024456547, 2106660896, 240927666... \n",
|
| 688 |
+
"964346 [1593596963, 2038708100, 2071551483, 216457208... \n",
|
| 689 |
+
"964347 [157185084, 744920664, 1502459210, 1513485037,... \n",
|
| 690 |
+
"964348 [10646503, 38913427, 86408651, 152570004, 1597... \n",
|
| 691 |
+
"964349 [1490674333, 1842503650, 1967931023, 203468809... \n",
|
| 692 |
+
"\n",
|
| 693 |
+
" fos \n",
|
| 694 |
+
"964345 [social objects, computer science, cooperative... \n",
|
| 695 |
+
"964346 [health care, architecture, computer science, ... \n",
|
| 696 |
+
"964347 [discrete mathematics, graph, infinite game, d... \n",
|
| 697 |
+
"964348 [anatomy, architecture, chunking (psychology),... \n",
|
| 698 |
+
"964349 [identifier, computer science, artificial inte... "
|
| 699 |
+
]
|
| 700 |
+
},
|
| 701 |
+
"execution_count": 15,
|
| 702 |
+
"metadata": {},
|
| 703 |
+
"output_type": "execute_result"
|
| 704 |
+
}
|
| 705 |
+
],
|
| 706 |
+
"source": [
|
| 707 |
+
"# Reorder papers\n",
|
| 708 |
+
"\n",
|
| 709 |
+
"papers.set_index('id', inplace=True)\n",
|
| 710 |
+
"papers = papers.loc[paper_id_encoder.classes_]\n",
|
| 711 |
+
"papers.reset_index(inplace=True)\n",
|
| 712 |
+
"papers.tail()\n"
|
| 713 |
+
]
|
| 714 |
+
},
|
| 715 |
+
{
|
| 716 |
+
"cell_type": "code",
|
| 717 |
+
"execution_count": 16,
|
| 718 |
+
"id": "316ae0b2",
|
| 719 |
+
"metadata": {},
|
| 720 |
+
"outputs": [],
|
| 721 |
+
"source": [
|
| 722 |
+
"paper_years = papers['year'].values.astype(np.int16)\n",
|
| 723 |
+
"data['paper_years'] = paper_years"
|
| 724 |
+
]
|
| 725 |
+
},
|
| 726 |
+
{
|
| 727 |
+
"cell_type": "code",
|
| 728 |
+
"execution_count": 17,
|
| 729 |
+
"id": "64536f16",
|
| 730 |
+
"metadata": {},
|
| 731 |
+
"outputs": [],
|
| 732 |
+
"source": [
|
| 733 |
+
"paper_labels = papers['label'].values.astype(np.int8)\n",
|
| 734 |
+
"data['paper_labels'] = paper_labels"
|
| 735 |
+
]
|
| 736 |
+
},
|
| 737 |
+
{
|
| 738 |
+
"cell_type": "code",
|
| 739 |
+
"execution_count": 18,
|
| 740 |
+
"id": "e0333a3d",
|
| 741 |
+
"metadata": {},
|
| 742 |
+
"outputs": [
|
| 743 |
+
{
|
| 744 |
+
"data": {
|
| 745 |
+
"text/plain": [
|
| 746 |
+
"{'paper-paper': (array([ 0, 0, 0, ..., 16345, 732, 7251], dtype=int32),\n",
|
| 747 |
+
" array([13858, 61018, 81249, ..., 19830, 744, 19890], dtype=int32)),\n",
|
| 748 |
+
" 'paper-author': (array([ 0, 0, 0, ..., 19890, 19890, 19882], dtype=int32),\n",
|
| 749 |
+
" array([ 10439, 196586, 212053, ..., 685977, 455354, 510243], dtype=int32)),\n",
|
| 750 |
+
" 'paper-fos': (array([ 0, 0, 0, ..., 19882, 19882, 19882], dtype=int32),\n",
|
| 751 |
+
" array([65253, 10791, 33819, ..., 43792, 2953, 38524], dtype=int32)),\n",
|
| 752 |
+
" 'paper_years': array([2008, 2013, 2008, ..., 2020, 1986, 2017], dtype=int16),\n",
|
| 753 |
+
" 'paper_labels': array([4, 6, 0, ..., 7, 0, 4], dtype=int8)}"
|
| 754 |
+
]
|
| 755 |
+
},
|
| 756 |
+
"execution_count": 18,
|
| 757 |
+
"metadata": {},
|
| 758 |
+
"output_type": "execute_result"
|
| 759 |
+
}
|
| 760 |
+
],
|
| 761 |
+
"source": [
|
| 762 |
+
"data"
|
| 763 |
+
]
|
| 764 |
+
},
|
| 765 |
+
{
|
| 766 |
+
"cell_type": "code",
|
| 767 |
+
"execution_count": 19,
|
| 768 |
+
"id": "fce3faf6",
|
| 769 |
+
"metadata": {},
|
| 770 |
+
"outputs": [],
|
| 771 |
+
"source": [
|
| 772 |
+
"papers.to_csv('DBLP.csv', index=False)"
|
| 773 |
+
]
|
| 774 |
+
},
|
| 775 |
+
{
|
| 776 |
+
"cell_type": "markdown",
|
| 777 |
+
"id": "32d3dd5f",
|
| 778 |
+
"metadata": {},
|
| 779 |
+
"source": [
|
| 780 |
+
"### Node Features\n",
|
| 781 |
+
"\n",
|
| 782 |
+
"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",
|
| 783 |
+
"\n",
|
| 784 |
+
"\n",
|
| 785 |
+
"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",
|
| 786 |
+
"\n",
|
| 787 |
+
"all-MiniLM-L6-v2\n",
|
| 788 |
+
"\n",
|
| 789 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 790 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 791 |
+
"Max Sequence Length:\t256\n",
|
| 792 |
+
"Dimensions:\t384\n",
|
| 793 |
+
"Normalized Embeddings:\ttrue\n",
|
| 794 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 795 |
+
"Size:\t80 MB\n",
|
| 796 |
+
"Pooling:\tMean Pooling\n",
|
| 797 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 798 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 799 |
+
]
|
| 800 |
+
},
|
| 801 |
+
{
|
| 802 |
+
"cell_type": "code",
|
| 803 |
+
"execution_count": 20,
|
| 804 |
+
"id": "1b3b9b1d",
|
| 805 |
+
"metadata": {},
|
| 806 |
+
"outputs": [
|
| 807 |
+
{
|
| 808 |
+
"name": "stderr",
|
| 809 |
+
"output_type": "stream",
|
| 810 |
+
"text": [
|
| 811 |
+
"/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",
|
| 812 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 813 |
+
]
|
| 814 |
+
},
|
| 815 |
+
{
|
| 816 |
+
"data": {
|
| 817 |
+
"text/plain": [
|
| 818 |
+
"SentenceTransformer(\n",
|
| 819 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 820 |
+
" (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",
|
| 821 |
+
" (2): Normalize()\n",
|
| 822 |
+
")"
|
| 823 |
+
]
|
| 824 |
+
},
|
| 825 |
+
"execution_count": 20,
|
| 826 |
+
"metadata": {},
|
| 827 |
+
"output_type": "execute_result"
|
| 828 |
+
}
|
| 829 |
+
],
|
| 830 |
+
"source": [
|
| 831 |
+
"import torch\n",
|
| 832 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 833 |
+
"\n",
|
| 834 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 835 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 836 |
+
"model"
|
| 837 |
+
]
|
| 838 |
+
},
|
| 839 |
+
{
|
| 840 |
+
"cell_type": "code",
|
| 841 |
+
"execution_count": 21,
|
| 842 |
+
"id": "346dc6fa",
|
| 843 |
+
"metadata": {},
|
| 844 |
+
"outputs": [],
|
| 845 |
+
"source": [
|
| 846 |
+
"text = papers['title'] + ' ' + papers['abstract']"
|
| 847 |
+
]
|
| 848 |
+
},
|
| 849 |
+
{
|
| 850 |
+
"cell_type": "code",
|
| 851 |
+
"execution_count": 22,
|
| 852 |
+
"id": "cfcef3f2",
|
| 853 |
+
"metadata": {},
|
| 854 |
+
"outputs": [
|
| 855 |
+
{
|
| 856 |
+
"name": "stderr",
|
| 857 |
+
"output_type": "stream",
|
| 858 |
+
"text": [
|
| 859 |
+
"Batches: 100%|██████████| 236/236 [12:22<00:00, 3.15s/it]\n"
|
| 860 |
+
]
|
| 861 |
+
}
|
| 862 |
+
],
|
| 863 |
+
"source": [
|
| 864 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
|
| 865 |
+
]
|
| 866 |
+
},
|
| 867 |
+
{
|
| 868 |
+
"cell_type": "code",
|
| 869 |
+
"execution_count": 23,
|
| 870 |
+
"id": "ba74f1f9",
|
| 871 |
+
"metadata": {},
|
| 872 |
+
"outputs": [
|
| 873 |
+
{
|
| 874 |
+
"data": {
|
| 875 |
+
"text/plain": [
|
| 876 |
+
"{'paper-paper': (array([ 0, 0, 0, ..., 16345, 732, 7251], dtype=int32),\n",
|
| 877 |
+
" array([13858, 61018, 81249, ..., 19830, 744, 19890], dtype=int32)),\n",
|
| 878 |
+
" 'paper-author': (array([ 0, 0, 0, ..., 19890, 19890, 19882], dtype=int32),\n",
|
| 879 |
+
" array([ 10439, 196586, 212053, ..., 685977, 455354, 510243], dtype=int32)),\n",
|
| 880 |
+
" 'paper-fos': (array([ 0, 0, 0, ..., 19882, 19882, 19882], dtype=int32),\n",
|
| 881 |
+
" array([65253, 10791, 33819, ..., 43792, 2953, 38524], dtype=int32)),\n",
|
| 882 |
+
" 'paper_years': array([2008, 2013, 2008, ..., 2020, 1986, 2017], dtype=int16),\n",
|
| 883 |
+
" 'paper_labels': array([4, 6, 0, ..., 7, 0, 4], dtype=int8),\n",
|
| 884 |
+
" 'paper_feats': array([[-0.09045218, -0.04914903, -0.00183934, ..., -0.02621997,\n",
|
| 885 |
+
" 0.10682236, 0.03757928],\n",
|
| 886 |
+
" [ 0.05457439, -0.03537758, -0.00981656, ..., 0.02816821,\n",
|
| 887 |
+
" -0.08244677, 0.05598091],\n",
|
| 888 |
+
" [ 0.05163385, -0.00435178, 0.00543169, ..., 0.04312224,\n",
|
| 889 |
+
" -0.08650234, 0.02618632],\n",
|
| 890 |
+
" ...,\n",
|
| 891 |
+
" [ 0.00644145, -0.02942889, -0.03935754, ..., 0.00694911,\n",
|
| 892 |
+
" 0.04468951, -0.01565437],\n",
|
| 893 |
+
" [-0.00039966, 0.06023127, -0.01369713, ..., 0.05656872,\n",
|
| 894 |
+
" -0.0026328 , 0.03119653],\n",
|
| 895 |
+
" [-0.02327097, 0.01399295, 0.02802348, ..., 0.07121975,\n",
|
| 896 |
+
" 0.03597061, -0.01132829]], dtype=float32)}"
|
| 897 |
+
]
|
| 898 |
+
},
|
| 899 |
+
"execution_count": 23,
|
| 900 |
+
"metadata": {},
|
| 901 |
+
"output_type": "execute_result"
|
| 902 |
+
}
|
| 903 |
+
],
|
| 904 |
+
"source": [
|
| 905 |
+
"data['paper_feats'] = feats\n",
|
| 906 |
+
"data"
|
| 907 |
+
]
|
| 908 |
+
},
|
| 909 |
+
{
|
| 910 |
+
"cell_type": "code",
|
| 911 |
+
"execution_count": 24,
|
| 912 |
+
"id": "6a123fee",
|
| 913 |
+
"metadata": {},
|
| 914 |
+
"outputs": [],
|
| 915 |
+
"source": [
|
| 916 |
+
"import pickle\n",
|
| 917 |
+
"\n",
|
| 918 |
+
"with open('dblp.pkl', 'wb') as f:\n",
|
| 919 |
+
" pickle.dump(data, f)"
|
| 920 |
+
]
|
| 921 |
+
}
|
| 922 |
+
],
|
| 923 |
+
"metadata": {
|
| 924 |
+
"kernelspec": {
|
| 925 |
+
"display_name": "Python 3",
|
| 926 |
+
"language": "python",
|
| 927 |
+
"name": "python3"
|
| 928 |
+
},
|
| 929 |
+
"language_info": {
|
| 930 |
+
"codemirror_mode": {
|
| 931 |
+
"name": "ipython",
|
| 932 |
+
"version": 3
|
| 933 |
+
},
|
| 934 |
+
"file_extension": ".py",
|
| 935 |
+
"mimetype": "text/x-python",
|
| 936 |
+
"name": "python",
|
| 937 |
+
"nbconvert_exporter": "python",
|
| 938 |
+
"pygments_lexer": "ipython3",
|
| 939 |
+
"version": "3.10.12"
|
| 940 |
+
}
|
| 941 |
+
},
|
| 942 |
+
"nbformat": 4,
|
| 943 |
+
"nbformat_minor": 5
|
| 944 |
+
}
|
patent/Patent.csv.zip
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79ee5fb5aad5cc6414ebe707c2b3955486e772ecc41e80014f1ad2b212b869cc
|
| 3 |
+
size 834116899
|
patent/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Patent: Patent Application Network
|
| 2 |
+
|
| 3 |
+
The Patent dataset is a heterogeneous graph constructed from the [United States Patent and Trademark Office](https://www.uspto.gov). Our HTAG is constructed using source data provided by the [Harvard USPTO Patent Dataset](https://patentdataset.org) [1], covering the period from 2010 to 2018. After processing, it contains three types of entities—patents (2,762,187 nodes), inventors (2,873,311 nodes), and examiners (10,641 nodes)—as well as two types of directed relations connecting three types of entities—an inventor “invents” a patent, and an examiner “examines” a patent. Patents are associated with their titles and abstracts, and all the other types of entities are textless. We concatenate the patent title and abstract and pass it to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each patent node. Additionally, each patent is assigned a primary [International Patent Classification (IPC) code](https://www.wipo.int/classifications/ipc), and the patent application date is included as metadata.
|
| 4 |
+
|
| 5 |
+
**Prediction task.**
|
| 6 |
+
The task is to predict the main IPC codes of patent applications at the class level. There are 120 IPC codes at the class level in our dataset. We also use both Micro-F1 and Macro-F1 scores as classification metrics.
|
| 7 |
+
|
| 8 |
+
**Dataset splitting.**
|
| 9 |
+
The splitting strategy is the time-based split. Specifically, we train on patents published up to 2014, validate on patents published in 2015, and test on patents published since 2016.
|
| 10 |
+
|
| 11 |
+
**Dataset statistics.**
|
| 12 |
+
|
| 13 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 14 |
+
| ------------------- | -------------------------- | --------- | ---------------- |
|
| 15 |
+
| **5,646,139** | **8,833,738** | 120 | Train: 1,705,155 |
|
| 16 |
+
| Patent: 2,762,187 | Patent-Inventor: 6,071,551 | | Valid: 374,275 |
|
| 17 |
+
| Inventor: 2,873,311 | Patent-Examiner: 2,762,187 | | Test: 682,757 |
|
| 18 |
+
| Examiner: 10,641 | | | |
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
[1] Suzgun, M., Melas-Kyriazi, L., Sarkar, S., Kominers, S. D., & Shieber, S. (2023). The harvard uspto patent dataset: A large-scale, well-structured, and multi-purpose corpus of patent applications. Advances in neural information processing systems, 36, 57908-57946.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## Dataset Construction
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
1. Download patent data (2010-2018) from [Harvard USPTO Patent Dataset](https://huggingface.co/datasets/HUPD/hupd/tree/main/data) to `./raw/`
|
| 30 |
+
2. Run `extract_from_hupd.py`
|
| 31 |
+
3. Run `graph_builder.ipynb`
|
patent/extract_from_hupd.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import json
|
| 3 |
+
import time
|
| 4 |
+
import tarfile
|
| 5 |
+
import argparse
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def extract(year):
|
| 9 |
+
start_time = time.time()
|
| 10 |
+
|
| 11 |
+
tar = tarfile.open(f'./raw/{year}.tar.gz', 'r')
|
| 12 |
+
|
| 13 |
+
print('Extract...')
|
| 14 |
+
with open(f'csvs/{year}.csv', 'w', encoding='utf-8', newline='') as f:
|
| 15 |
+
writer = csv.writer(f)
|
| 16 |
+
heads = ['application_number', 'title', 'abstract', 'main_ipcr_label', 'filing_date', 'examiner_id',
|
| 17 |
+
'inventor_list']
|
| 18 |
+
writer.writerow(heads)
|
| 19 |
+
|
| 20 |
+
num = 0
|
| 21 |
+
rows = []
|
| 22 |
+
for member in tar.getmembers():
|
| 23 |
+
if member.name.endswith('.json'):
|
| 24 |
+
with tar.extractfile(member) as file:
|
| 25 |
+
content = json.load(file)
|
| 26 |
+
row = [content[head] for head in heads[:-1]]
|
| 27 |
+
inventor_list = ['|'.join(inventor_infos.values())
|
| 28 |
+
for inventor_infos in content['inventor_list']]
|
| 29 |
+
row.append(inventor_list)
|
| 30 |
+
rows.append(row)
|
| 31 |
+
num += 1
|
| 32 |
+
if num % 5000 == 0:
|
| 33 |
+
writer.writerows(rows)
|
| 34 |
+
rows = []
|
| 35 |
+
print(num)
|
| 36 |
+
if len(rows) > 0:
|
| 37 |
+
writer.writerows(rows)
|
| 38 |
+
|
| 39 |
+
tar.close()
|
| 40 |
+
print(num, f'{time.time()-start_time}s','Done!')
|
| 41 |
+
|
| 42 |
+
parser = argparse.ArgumentParser()
|
| 43 |
+
parser.add_argument('--year', type=str, default='2020')
|
| 44 |
+
args = parser.parse_args()
|
| 45 |
+
|
| 46 |
+
extract(args.year)
|
patent/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,1065 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"id": "initial_id",
|
| 7 |
+
"metadata": {
|
| 8 |
+
"ExecuteTime": {
|
| 9 |
+
"end_time": "2024-12-01T08:32:19.372004Z",
|
| 10 |
+
"start_time": "2024-12-01T08:32:18.179932Z"
|
| 11 |
+
},
|
| 12 |
+
"collapsed": true
|
| 13 |
+
},
|
| 14 |
+
"outputs": [],
|
| 15 |
+
"source": [
|
| 16 |
+
"import itertools\n",
|
| 17 |
+
"import numpy as np\n",
|
| 18 |
+
"import pandas as pd\n",
|
| 19 |
+
"from collections import Counter\n",
|
| 20 |
+
"from sklearn.preprocessing import LabelEncoder"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": 2,
|
| 26 |
+
"id": "f47b9b42a2c1db6b",
|
| 27 |
+
"metadata": {
|
| 28 |
+
"ExecuteTime": {
|
| 29 |
+
"end_time": "2024-12-01T08:33:13.881724Z",
|
| 30 |
+
"start_time": "2024-12-01T08:32:19.390239Z"
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
"outputs": [
|
| 34 |
+
{
|
| 35 |
+
"name": "stdout",
|
| 36 |
+
"output_type": "stream",
|
| 37 |
+
"text": [
|
| 38 |
+
"(2762354, 7)\n"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"data": {
|
| 43 |
+
"text/html": [
|
| 44 |
+
"<div>\n",
|
| 45 |
+
"<style scoped>\n",
|
| 46 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 47 |
+
" vertical-align: middle;\n",
|
| 48 |
+
" }\n",
|
| 49 |
+
"\n",
|
| 50 |
+
" .dataframe tbody tr th {\n",
|
| 51 |
+
" vertical-align: top;\n",
|
| 52 |
+
" }\n",
|
| 53 |
+
"\n",
|
| 54 |
+
" .dataframe thead th {\n",
|
| 55 |
+
" text-align: right;\n",
|
| 56 |
+
" }\n",
|
| 57 |
+
"</style>\n",
|
| 58 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 59 |
+
" <thead>\n",
|
| 60 |
+
" <tr style=\"text-align: right;\">\n",
|
| 61 |
+
" <th></th>\n",
|
| 62 |
+
" <th>application_number</th>\n",
|
| 63 |
+
" <th>title</th>\n",
|
| 64 |
+
" <th>abstract</th>\n",
|
| 65 |
+
" <th>main_ipcr_label</th>\n",
|
| 66 |
+
" <th>filing_date</th>\n",
|
| 67 |
+
" <th>examiner_id</th>\n",
|
| 68 |
+
" <th>inventor_list</th>\n",
|
| 69 |
+
" </tr>\n",
|
| 70 |
+
" </thead>\n",
|
| 71 |
+
" <tbody>\n",
|
| 72 |
+
" <tr>\n",
|
| 73 |
+
" <th>0</th>\n",
|
| 74 |
+
" <td>12745329</td>\n",
|
| 75 |
+
" <td>PROCESS AND PRODUCT</td>\n",
|
| 76 |
+
" <td>Process for producing a chocolate or chocolate...</td>\n",
|
| 77 |
+
" <td>A23G150</td>\n",
|
| 78 |
+
" <td>20100907</td>\n",
|
| 79 |
+
" <td>95893</td>\n",
|
| 80 |
+
" <td>[Rumbaut|Luc Joseph Paul Antoine Marie|Lebbeke...</td>\n",
|
| 81 |
+
" </tr>\n",
|
| 82 |
+
" <tr>\n",
|
| 83 |
+
" <th>1</th>\n",
|
| 84 |
+
" <td>12658202</td>\n",
|
| 85 |
+
" <td>Stabilized pharmaceutical compositions contain...</td>\n",
|
| 86 |
+
" <td>The present invention provides a pharmaceutica...</td>\n",
|
| 87 |
+
" <td>A61K31397</td>\n",
|
| 88 |
+
" <td>20100203</td>\n",
|
| 89 |
+
" <td>70017</td>\n",
|
| 90 |
+
" <td>[Wakiyama|Naoki|Yokohama-shi||JP, Usui|Fusao|Y...</td>\n",
|
| 91 |
+
" </tr>\n",
|
| 92 |
+
" <tr>\n",
|
| 93 |
+
" <th>2</th>\n",
|
| 94 |
+
" <td>12746833</td>\n",
|
| 95 |
+
" <td>MEDICAL APPLIANCE WITH A CONNECTION AND DISCON...</td>\n",
|
| 96 |
+
" <td>A medical appliance including a medical instru...</td>\n",
|
| 97 |
+
" <td>A61B100</td>\n",
|
| 98 |
+
" <td>20100825</td>\n",
|
| 99 |
+
" <td>94236</td>\n",
|
| 100 |
+
" <td>[Mathieu|Nicolas|Ecully||FR]</td>\n",
|
| 101 |
+
" </tr>\n",
|
| 102 |
+
" <tr>\n",
|
| 103 |
+
" <th>3</th>\n",
|
| 104 |
+
" <td>12843590</td>\n",
|
| 105 |
+
" <td>SAWHORSE BRACKET SYSTEM AND METHOD</td>\n",
|
| 106 |
+
" <td>Embodiments of sawhorse systems are shown and ...</td>\n",
|
| 107 |
+
" <td>B25H106</td>\n",
|
| 108 |
+
" <td>20100726</td>\n",
|
| 109 |
+
" <td>85438</td>\n",
|
| 110 |
+
" <td>[Johnson|Michael|Waterville|WA|US, Johnson|Phi...</td>\n",
|
| 111 |
+
" </tr>\n",
|
| 112 |
+
" <tr>\n",
|
| 113 |
+
" <th>4</th>\n",
|
| 114 |
+
" <td>12748977</td>\n",
|
| 115 |
+
" <td>One Piece Hip and Ridge Shingle</td>\n",
|
| 116 |
+
" <td>The invention provides a one piece shingle for...</td>\n",
|
| 117 |
+
" <td>E04D120</td>\n",
|
| 118 |
+
" <td>20100329</td>\n",
|
| 119 |
+
" <td>70726</td>\n",
|
| 120 |
+
" <td>[Ward|Bryan|Olathe|KS|US, Rosewall|Ray|Blue Sp...</td>\n",
|
| 121 |
+
" </tr>\n",
|
| 122 |
+
" </tbody>\n",
|
| 123 |
+
"</table>\n",
|
| 124 |
+
"</div>"
|
| 125 |
+
],
|
| 126 |
+
"text/plain": [
|
| 127 |
+
" application_number title \\\n",
|
| 128 |
+
"0 12745329 PROCESS AND PRODUCT \n",
|
| 129 |
+
"1 12658202 Stabilized pharmaceutical compositions contain... \n",
|
| 130 |
+
"2 12746833 MEDICAL APPLIANCE WITH A CONNECTION AND DISCON... \n",
|
| 131 |
+
"3 12843590 SAWHORSE BRACKET SYSTEM AND METHOD \n",
|
| 132 |
+
"4 12748977 One Piece Hip and Ridge Shingle \n",
|
| 133 |
+
"\n",
|
| 134 |
+
" abstract main_ipcr_label \\\n",
|
| 135 |
+
"0 Process for producing a chocolate or chocolate... A23G150 \n",
|
| 136 |
+
"1 The present invention provides a pharmaceutica... A61K31397 \n",
|
| 137 |
+
"2 A medical appliance including a medical instru... A61B100 \n",
|
| 138 |
+
"3 Embodiments of sawhorse systems are shown and ... B25H106 \n",
|
| 139 |
+
"4 The invention provides a one piece shingle for... E04D120 \n",
|
| 140 |
+
"\n",
|
| 141 |
+
" filing_date examiner_id inventor_list \n",
|
| 142 |
+
"0 20100907 95893 [Rumbaut|Luc Joseph Paul Antoine Marie|Lebbeke... \n",
|
| 143 |
+
"1 20100203 70017 [Wakiyama|Naoki|Yokohama-shi||JP, Usui|Fusao|Y... \n",
|
| 144 |
+
"2 20100825 94236 [Mathieu|Nicolas|Ecully||FR] \n",
|
| 145 |
+
"3 20100726 85438 [Johnson|Michael|Waterville|WA|US, Johnson|Phi... \n",
|
| 146 |
+
"4 20100329 70726 [Ward|Bryan|Olathe|KS|US, Rosewall|Ray|Blue Sp... "
|
| 147 |
+
]
|
| 148 |
+
},
|
| 149 |
+
"execution_count": 2,
|
| 150 |
+
"metadata": {},
|
| 151 |
+
"output_type": "execute_result"
|
| 152 |
+
}
|
| 153 |
+
],
|
| 154 |
+
"source": [
|
| 155 |
+
"names = range(2010, 2019)\n",
|
| 156 |
+
"df = [pd.read_csv(f'csvs/{name}.csv') for name in names]\n",
|
| 157 |
+
"df = pd.concat(df, ignore_index=True, copy=False)\n",
|
| 158 |
+
"df = df[~df['examiner_id'].isna()]\n",
|
| 159 |
+
"df['examiner_id'] = df['examiner_id'].astype(np.int32)\n",
|
| 160 |
+
"df['inventor_list'] =df['inventor_list'].apply(eval)\n",
|
| 161 |
+
"print(df.shape)\n",
|
| 162 |
+
"df.head()"
|
| 163 |
+
]
|
| 164 |
+
},
|
| 165 |
+
{
|
| 166 |
+
"cell_type": "code",
|
| 167 |
+
"execution_count": 3,
|
| 168 |
+
"id": "d67ebb41b21a1cb0",
|
| 169 |
+
"metadata": {
|
| 170 |
+
"ExecuteTime": {
|
| 171 |
+
"end_time": "2024-12-01T08:33:14.752740Z",
|
| 172 |
+
"start_time": "2024-12-01T08:33:14.008339Z"
|
| 173 |
+
}
|
| 174 |
+
},
|
| 175 |
+
"outputs": [],
|
| 176 |
+
"source": [
|
| 177 |
+
"# Shuffle\n",
|
| 178 |
+
"df = df.sample(frac=1, random_state=42, replace=False, ignore_index=True)"
|
| 179 |
+
]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"cell_type": "code",
|
| 183 |
+
"execution_count": 5,
|
| 184 |
+
"id": "dacbae2e86c8fe24",
|
| 185 |
+
"metadata": {
|
| 186 |
+
"ExecuteTime": {
|
| 187 |
+
"end_time": "2024-12-01T08:33:14.803083Z",
|
| 188 |
+
"start_time": "2024-12-01T08:33:14.798397Z"
|
| 189 |
+
}
|
| 190 |
+
},
|
| 191 |
+
"outputs": [],
|
| 192 |
+
"source": [
|
| 193 |
+
"data = {}"
|
| 194 |
+
]
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"cell_type": "markdown",
|
| 198 |
+
"id": "ccfa8be0912a9d60",
|
| 199 |
+
"metadata": {},
|
| 200 |
+
"source": [
|
| 201 |
+
"## Labels\n",
|
| 202 |
+
"\n",
|
| 203 |
+
"The International Patent Classification (IPC) system has 4 levels of categorization, which are as follows:\n",
|
| 204 |
+
"\n",
|
| 205 |
+
"1. Section: There are 8 main sections, represented by the letters A to H (e.g., Section A, Section B, etc.), each covering a broad field of technology.\n",
|
| 206 |
+
"2. Class: Each section is subdivided into multiple classes, typically represented by two-digit numbers. For example, A01 refers to agriculture; B01 refers to apparatus for physical or chemical processes.\n",
|
| 207 |
+
"3. Subclass: Each class is further divided into subclasses, which are denoted by three-digit numbers. For example, A01B refers to agricultural machines; B01D refers to separation processes.\n",
|
| 208 |
+
"4. Group: Subclasses are further divided into groups, typically indicated by more detailed numeric codes. These groups provide a more precise classification of specific technological aspects. For example, A01B1 refers to a specific type of agricultural machinery.\n",
|
| 209 |
+
"\n",
|
| 210 |
+
"Summary:\n",
|
| 211 |
+
"\n",
|
| 212 |
+
"- Section → Class → Subclass → Group\n",
|
| 213 |
+
"\n",
|
| 214 |
+
"Each level progresses from broad categories to more specific and detailed classifications, enabling a precise and organized system for patent description and retrieval."
|
| 215 |
+
]
|
| 216 |
+
},
|
| 217 |
+
{
|
| 218 |
+
"cell_type": "code",
|
| 219 |
+
"execution_count": 6,
|
| 220 |
+
"id": "8a631e26df8a6c05",
|
| 221 |
+
"metadata": {
|
| 222 |
+
"ExecuteTime": {
|
| 223 |
+
"end_time": "2024-12-01T08:33:16.312660Z",
|
| 224 |
+
"start_time": "2024-12-01T08:33:14.845137Z"
|
| 225 |
+
}
|
| 226 |
+
},
|
| 227 |
+
"outputs": [
|
| 228 |
+
{
|
| 229 |
+
"data": {
|
| 230 |
+
"text/plain": [
|
| 231 |
+
"main_ipcr_label\n",
|
| 232 |
+
"D07 183\n",
|
| 233 |
+
"C14 135\n",
|
| 234 |
+
"B82 64\n",
|
| 235 |
+
"B33 57\n",
|
| 236 |
+
"G12 39\n",
|
| 237 |
+
"H99 2\n",
|
| 238 |
+
"F99 1\n",
|
| 239 |
+
"E99 1\n",
|
| 240 |
+
"Name: count, dtype: int64"
|
| 241 |
+
]
|
| 242 |
+
},
|
| 243 |
+
"execution_count": 6,
|
| 244 |
+
"metadata": {},
|
| 245 |
+
"output_type": "execute_result"
|
| 246 |
+
}
|
| 247 |
+
],
|
| 248 |
+
"source": [
|
| 249 |
+
"# We use level 2. (e.g., A01, B01,...)\n",
|
| 250 |
+
"labels = df['main_ipcr_label'].str[:3]\n",
|
| 251 |
+
"label_counts = df['main_ipcr_label'].str[:3].value_counts()\n",
|
| 252 |
+
"label_counts.tail(8)"
|
| 253 |
+
]
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"cell_type": "code",
|
| 257 |
+
"execution_count": 7,
|
| 258 |
+
"id": "7220b0221929bb56",
|
| 259 |
+
"metadata": {
|
| 260 |
+
"ExecuteTime": {
|
| 261 |
+
"end_time": "2024-12-01T08:33:17.198111Z",
|
| 262 |
+
"start_time": "2024-12-01T08:33:16.355816Z"
|
| 263 |
+
}
|
| 264 |
+
},
|
| 265 |
+
"outputs": [
|
| 266 |
+
{
|
| 267 |
+
"data": {
|
| 268 |
+
"text/plain": [
|
| 269 |
+
"(2762187, 7)"
|
| 270 |
+
]
|
| 271 |
+
},
|
| 272 |
+
"execution_count": 7,
|
| 273 |
+
"metadata": {},
|
| 274 |
+
"output_type": "execute_result"
|
| 275 |
+
}
|
| 276 |
+
],
|
| 277 |
+
"source": [
|
| 278 |
+
"# Select labels with counts >= 100\n",
|
| 279 |
+
"min_counts = 100\n",
|
| 280 |
+
"labels_deleted = label_counts[label_counts >= min_counts].index\n",
|
| 281 |
+
"df = df[labels.isin(labels_deleted)]\n",
|
| 282 |
+
"df.shape"
|
| 283 |
+
]
|
| 284 |
+
},
|
| 285 |
+
{
|
| 286 |
+
"cell_type": "code",
|
| 287 |
+
"execution_count": 8,
|
| 288 |
+
"id": "9c4921ddef95b225",
|
| 289 |
+
"metadata": {
|
| 290 |
+
"ExecuteTime": {
|
| 291 |
+
"end_time": "2024-12-01T08:33:18.266008Z",
|
| 292 |
+
"start_time": "2024-12-01T08:33:17.286145Z"
|
| 293 |
+
}
|
| 294 |
+
},
|
| 295 |
+
"outputs": [],
|
| 296 |
+
"source": [
|
| 297 |
+
"df.loc[:, 'label'] = df['main_ipcr_label'].str[:3]"
|
| 298 |
+
]
|
| 299 |
+
},
|
| 300 |
+
{
|
| 301 |
+
"cell_type": "code",
|
| 302 |
+
"execution_count": 9,
|
| 303 |
+
"id": "5e68241068153a03",
|
| 304 |
+
"metadata": {
|
| 305 |
+
"ExecuteTime": {
|
| 306 |
+
"end_time": "2024-12-01T08:33:18.786890Z",
|
| 307 |
+
"start_time": "2024-12-01T08:33:18.279976Z"
|
| 308 |
+
}
|
| 309 |
+
},
|
| 310 |
+
"outputs": [
|
| 311 |
+
{
|
| 312 |
+
"name": "stdout",
|
| 313 |
+
"output_type": "stream",
|
| 314 |
+
"text": [
|
| 315 |
+
"Number of classes 120\n"
|
| 316 |
+
]
|
| 317 |
+
}
|
| 318 |
+
],
|
| 319 |
+
"source": [
|
| 320 |
+
"label_encoder = LabelEncoder()\n",
|
| 321 |
+
"labels = label_encoder.fit_transform(df['label'])\n",
|
| 322 |
+
"print('Number of classes', len(label_encoder.classes_))"
|
| 323 |
+
]
|
| 324 |
+
},
|
| 325 |
+
{
|
| 326 |
+
"cell_type": "code",
|
| 327 |
+
"execution_count": 10,
|
| 328 |
+
"id": "84a7a7a63e001349",
|
| 329 |
+
"metadata": {
|
| 330 |
+
"ExecuteTime": {
|
| 331 |
+
"end_time": "2024-12-01T08:33:18.820476Z",
|
| 332 |
+
"start_time": "2024-12-01T08:33:18.813927Z"
|
| 333 |
+
}
|
| 334 |
+
},
|
| 335 |
+
"outputs": [],
|
| 336 |
+
"source": [
|
| 337 |
+
"labels = labels.astype(np.int8)"
|
| 338 |
+
]
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"cell_type": "code",
|
| 342 |
+
"execution_count": 11,
|
| 343 |
+
"id": "eeaa8e4a1b2bdc07",
|
| 344 |
+
"metadata": {
|
| 345 |
+
"ExecuteTime": {
|
| 346 |
+
"end_time": "2024-12-01T08:33:18.840571Z",
|
| 347 |
+
"start_time": "2024-12-01T08:33:18.834743Z"
|
| 348 |
+
}
|
| 349 |
+
},
|
| 350 |
+
"outputs": [],
|
| 351 |
+
"source": [
|
| 352 |
+
"data['patent_labels'] = labels"
|
| 353 |
+
]
|
| 354 |
+
},
|
| 355 |
+
{
|
| 356 |
+
"cell_type": "markdown",
|
| 357 |
+
"id": "e99f2439ad2a7ba",
|
| 358 |
+
"metadata": {},
|
| 359 |
+
"source": [
|
| 360 |
+
"## Patent-Examiner Links"
|
| 361 |
+
]
|
| 362 |
+
},
|
| 363 |
+
{
|
| 364 |
+
"cell_type": "code",
|
| 365 |
+
"execution_count": 12,
|
| 366 |
+
"id": "3a967c0916bf30ed",
|
| 367 |
+
"metadata": {
|
| 368 |
+
"ExecuteTime": {
|
| 369 |
+
"end_time": "2024-12-01T08:33:18.868401Z",
|
| 370 |
+
"start_time": "2024-12-01T08:33:18.857137Z"
|
| 371 |
+
}
|
| 372 |
+
},
|
| 373 |
+
"outputs": [],
|
| 374 |
+
"source": [
|
| 375 |
+
"patent_ids = np.arange(df.shape[0])"
|
| 376 |
+
]
|
| 377 |
+
},
|
| 378 |
+
{
|
| 379 |
+
"cell_type": "code",
|
| 380 |
+
"execution_count": 13,
|
| 381 |
+
"id": "42fdbf6230aaa6bb",
|
| 382 |
+
"metadata": {
|
| 383 |
+
"ExecuteTime": {
|
| 384 |
+
"end_time": "2024-12-01T08:33:19.400626Z",
|
| 385 |
+
"start_time": "2024-12-01T08:33:18.885300Z"
|
| 386 |
+
}
|
| 387 |
+
},
|
| 388 |
+
"outputs": [
|
| 389 |
+
{
|
| 390 |
+
"data": {
|
| 391 |
+
"text/plain": [
|
| 392 |
+
"np.int64(10641)"
|
| 393 |
+
]
|
| 394 |
+
},
|
| 395 |
+
"execution_count": 13,
|
| 396 |
+
"metadata": {},
|
| 397 |
+
"output_type": "execute_result"
|
| 398 |
+
}
|
| 399 |
+
],
|
| 400 |
+
"source": [
|
| 401 |
+
"examiner_id_encoder = LabelEncoder()\n",
|
| 402 |
+
"examiner_ids = examiner_id_encoder.fit_transform(df['examiner_id'])\n",
|
| 403 |
+
"examiner_ids.max()+1"
|
| 404 |
+
]
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"cell_type": "code",
|
| 408 |
+
"execution_count": 14,
|
| 409 |
+
"id": "b690c62d181e327c",
|
| 410 |
+
"metadata": {
|
| 411 |
+
"ExecuteTime": {
|
| 412 |
+
"end_time": "2024-12-01T08:33:19.435167Z",
|
| 413 |
+
"start_time": "2024-12-01T08:33:19.425590Z"
|
| 414 |
+
}
|
| 415 |
+
},
|
| 416 |
+
"outputs": [],
|
| 417 |
+
"source": [
|
| 418 |
+
"examiner_ids = examiner_ids.astype(np.int16)"
|
| 419 |
+
]
|
| 420 |
+
},
|
| 421 |
+
{
|
| 422 |
+
"cell_type": "code",
|
| 423 |
+
"execution_count": 15,
|
| 424 |
+
"id": "7ebb6da22eca4769",
|
| 425 |
+
"metadata": {
|
| 426 |
+
"ExecuteTime": {
|
| 427 |
+
"end_time": "2024-12-01T08:33:19.457826Z",
|
| 428 |
+
"start_time": "2024-12-01T08:33:19.452414Z"
|
| 429 |
+
}
|
| 430 |
+
},
|
| 431 |
+
"outputs": [
|
| 432 |
+
{
|
| 433 |
+
"name": "stdout",
|
| 434 |
+
"output_type": "stream",
|
| 435 |
+
"text": [
|
| 436 |
+
"Number of patent-examiner links: 2762187\n"
|
| 437 |
+
]
|
| 438 |
+
}
|
| 439 |
+
],
|
| 440 |
+
"source": [
|
| 441 |
+
"print('Number of patent-examiner links:', examiner_ids.shape[0])"
|
| 442 |
+
]
|
| 443 |
+
},
|
| 444 |
+
{
|
| 445 |
+
"cell_type": "code",
|
| 446 |
+
"execution_count": 16,
|
| 447 |
+
"id": "f3c172c40a4ffb1d",
|
| 448 |
+
"metadata": {
|
| 449 |
+
"ExecuteTime": {
|
| 450 |
+
"end_time": "2024-12-01T08:33:19.577174Z",
|
| 451 |
+
"start_time": "2024-12-01T08:33:19.572744Z"
|
| 452 |
+
}
|
| 453 |
+
},
|
| 454 |
+
"outputs": [],
|
| 455 |
+
"source": [
|
| 456 |
+
"data['patent-examiner'] = (patent_ids, examiner_ids)"
|
| 457 |
+
]
|
| 458 |
+
},
|
| 459 |
+
{
|
| 460 |
+
"cell_type": "markdown",
|
| 461 |
+
"id": "1ff6515cc5b109ec",
|
| 462 |
+
"metadata": {},
|
| 463 |
+
"source": [
|
| 464 |
+
"## Patent-Inventor Links"
|
| 465 |
+
]
|
| 466 |
+
},
|
| 467 |
+
{
|
| 468 |
+
"cell_type": "code",
|
| 469 |
+
"execution_count": 17,
|
| 470 |
+
"id": "fc7f29576fff34a3",
|
| 471 |
+
"metadata": {
|
| 472 |
+
"ExecuteTime": {
|
| 473 |
+
"end_time": "2024-12-01T08:33:24.237691Z",
|
| 474 |
+
"start_time": "2024-12-01T08:33:19.615209Z"
|
| 475 |
+
}
|
| 476 |
+
},
|
| 477 |
+
"outputs": [],
|
| 478 |
+
"source": [
|
| 479 |
+
"df.loc[:, 'inventor_list'] = df['inventor_list'].apply(lambda xx: [x.lower() for x in xx])"
|
| 480 |
+
]
|
| 481 |
+
},
|
| 482 |
+
{
|
| 483 |
+
"cell_type": "code",
|
| 484 |
+
"execution_count": 18,
|
| 485 |
+
"id": "d27fb011526e4c76",
|
| 486 |
+
"metadata": {
|
| 487 |
+
"ExecuteTime": {
|
| 488 |
+
"end_time": "2024-12-01T08:33:46.322969Z",
|
| 489 |
+
"start_time": "2024-12-01T08:33:42.585328Z"
|
| 490 |
+
}
|
| 491 |
+
},
|
| 492 |
+
"outputs": [],
|
| 493 |
+
"source": [
|
| 494 |
+
"inventors = list(itertools.chain(*(df['inventor_list'].values)))\n",
|
| 495 |
+
"inventor_count_dict = Counter(inventors)"
|
| 496 |
+
]
|
| 497 |
+
},
|
| 498 |
+
{
|
| 499 |
+
"cell_type": "code",
|
| 500 |
+
"execution_count": 19,
|
| 501 |
+
"id": "11caff034b1389b4",
|
| 502 |
+
"metadata": {
|
| 503 |
+
"ExecuteTime": {
|
| 504 |
+
"end_time": "2024-12-01T08:33:54.138803Z",
|
| 505 |
+
"start_time": "2024-12-01T08:33:53.358330Z"
|
| 506 |
+
}
|
| 507 |
+
},
|
| 508 |
+
"outputs": [
|
| 509 |
+
{
|
| 510 |
+
"data": {
|
| 511 |
+
"text/html": [
|
| 512 |
+
"<div>\n",
|
| 513 |
+
"<style scoped>\n",
|
| 514 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 515 |
+
" vertical-align: middle;\n",
|
| 516 |
+
" }\n",
|
| 517 |
+
"\n",
|
| 518 |
+
" .dataframe tbody tr th {\n",
|
| 519 |
+
" vertical-align: top;\n",
|
| 520 |
+
" }\n",
|
| 521 |
+
"\n",
|
| 522 |
+
" .dataframe thead th {\n",
|
| 523 |
+
" text-align: right;\n",
|
| 524 |
+
" }\n",
|
| 525 |
+
"</style>\n",
|
| 526 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 527 |
+
" <thead>\n",
|
| 528 |
+
" <tr style=\"text-align: right;\">\n",
|
| 529 |
+
" <th></th>\n",
|
| 530 |
+
" <th>inventor</th>\n",
|
| 531 |
+
" <th>count</th>\n",
|
| 532 |
+
" </tr>\n",
|
| 533 |
+
" </thead>\n",
|
| 534 |
+
" <tbody>\n",
|
| 535 |
+
" <tr>\n",
|
| 536 |
+
" <th>0</th>\n",
|
| 537 |
+
" <td>bower|christopher|raleigh|nc|us</td>\n",
|
| 538 |
+
" <td>99</td>\n",
|
| 539 |
+
" </tr>\n",
|
| 540 |
+
" <tr>\n",
|
| 541 |
+
" <th>1</th>\n",
|
| 542 |
+
" <td>menard|etienne|limonges||fr</td>\n",
|
| 543 |
+
" <td>2</td>\n",
|
| 544 |
+
" </tr>\n",
|
| 545 |
+
" <tr>\n",
|
| 546 |
+
" <th>2</th>\n",
|
| 547 |
+
" <td>meitl|matthew|durham|nc|us</td>\n",
|
| 548 |
+
" <td>112</td>\n",
|
| 549 |
+
" </tr>\n",
|
| 550 |
+
" <tr>\n",
|
| 551 |
+
" <th>3</th>\n",
|
| 552 |
+
" <td>carr|joseph|chapel hill|nc|us</td>\n",
|
| 553 |
+
" <td>12</td>\n",
|
| 554 |
+
" </tr>\n",
|
| 555 |
+
" <tr>\n",
|
| 556 |
+
" <th>4</th>\n",
|
| 557 |
+
" <td>tsai|jui-yi|newtown|pa|us</td>\n",
|
| 558 |
+
" <td>33</td>\n",
|
| 559 |
+
" </tr>\n",
|
| 560 |
+
" </tbody>\n",
|
| 561 |
+
"</table>\n",
|
| 562 |
+
"</div>"
|
| 563 |
+
],
|
| 564 |
+
"text/plain": [
|
| 565 |
+
" inventor count\n",
|
| 566 |
+
"0 bower|christopher|raleigh|nc|us 99\n",
|
| 567 |
+
"1 menard|etienne|limonges||fr 2\n",
|
| 568 |
+
"2 meitl|matthew|durham|nc|us 112\n",
|
| 569 |
+
"3 carr|joseph|chapel hill|nc|us 12\n",
|
| 570 |
+
"4 tsai|jui-yi|newtown|pa|us 33"
|
| 571 |
+
]
|
| 572 |
+
},
|
| 573 |
+
"execution_count": 19,
|
| 574 |
+
"metadata": {},
|
| 575 |
+
"output_type": "execute_result"
|
| 576 |
+
}
|
| 577 |
+
],
|
| 578 |
+
"source": [
|
| 579 |
+
"inventor_count_df = pd.DataFrame(list(inventor_count_dict.items()), columns=['inventor', 'count'])\n",
|
| 580 |
+
"inventor_count_df.head()"
|
| 581 |
+
]
|
| 582 |
+
},
|
| 583 |
+
{
|
| 584 |
+
"cell_type": "code",
|
| 585 |
+
"execution_count": 20,
|
| 586 |
+
"id": "b59f081244865ae1",
|
| 587 |
+
"metadata": {
|
| 588 |
+
"ExecuteTime": {
|
| 589 |
+
"end_time": "2024-12-01T08:34:10.565550Z",
|
| 590 |
+
"start_time": "2024-12-01T08:34:10.547799Z"
|
| 591 |
+
}
|
| 592 |
+
},
|
| 593 |
+
"outputs": [
|
| 594 |
+
{
|
| 595 |
+
"data": {
|
| 596 |
+
"text/plain": [
|
| 597 |
+
"count\n",
|
| 598 |
+
"1 1683797\n",
|
| 599 |
+
"2 494218\n",
|
| 600 |
+
"3 224304\n",
|
| 601 |
+
"4 126584\n",
|
| 602 |
+
"5 79738\n",
|
| 603 |
+
"Name: count, dtype: int64"
|
| 604 |
+
]
|
| 605 |
+
},
|
| 606 |
+
"execution_count": 20,
|
| 607 |
+
"metadata": {},
|
| 608 |
+
"output_type": "execute_result"
|
| 609 |
+
}
|
| 610 |
+
],
|
| 611 |
+
"source": [
|
| 612 |
+
"inventor_count_df['count'].value_counts().head()"
|
| 613 |
+
]
|
| 614 |
+
},
|
| 615 |
+
{
|
| 616 |
+
"cell_type": "code",
|
| 617 |
+
"execution_count": 21,
|
| 618 |
+
"id": "8770afdd302ada4c",
|
| 619 |
+
"metadata": {
|
| 620 |
+
"ExecuteTime": {
|
| 621 |
+
"end_time": "2024-12-01T08:35:09.567262Z",
|
| 622 |
+
"start_time": "2024-12-01T08:35:09.521929Z"
|
| 623 |
+
}
|
| 624 |
+
},
|
| 625 |
+
"outputs": [],
|
| 626 |
+
"source": [
|
| 627 |
+
"# Select inventors with at least 2 patents\n",
|
| 628 |
+
"selected_inventors = inventor_count_df['inventor'][inventor_count_df['count']>=2].values"
|
| 629 |
+
]
|
| 630 |
+
},
|
| 631 |
+
{
|
| 632 |
+
"cell_type": "code",
|
| 633 |
+
"execution_count": 22,
|
| 634 |
+
"id": "fb911b678227e9ac",
|
| 635 |
+
"metadata": {
|
| 636 |
+
"ExecuteTime": {
|
| 637 |
+
"end_time": "2024-12-01T08:35:51.176432Z",
|
| 638 |
+
"start_time": "2024-12-01T08:35:15.823056Z"
|
| 639 |
+
}
|
| 640 |
+
},
|
| 641 |
+
"outputs": [],
|
| 642 |
+
"source": [
|
| 643 |
+
"inventor_id_encoder_all = LabelEncoder()\n",
|
| 644 |
+
"inventor_ids_all = inventor_id_encoder_all.fit_transform(inventors)\n",
|
| 645 |
+
"patent_ids_all = np.concatenate([np.full(count, i) \n",
|
| 646 |
+
" for i, count in enumerate(df['inventor_list'].apply(len))])\n",
|
| 647 |
+
"selected_inventor_ids = inventor_id_encoder_all.transform(selected_inventors)\n",
|
| 648 |
+
"masks = np.isin(inventor_ids_all, selected_inventor_ids) "
|
| 649 |
+
]
|
| 650 |
+
},
|
| 651 |
+
{
|
| 652 |
+
"cell_type": "code",
|
| 653 |
+
"execution_count": 23,
|
| 654 |
+
"id": "fc5a14d92342af4d",
|
| 655 |
+
"metadata": {
|
| 656 |
+
"ExecuteTime": {
|
| 657 |
+
"end_time": "2024-12-01T08:35:54.794539Z",
|
| 658 |
+
"start_time": "2024-12-01T08:35:54.680524Z"
|
| 659 |
+
}
|
| 660 |
+
},
|
| 661 |
+
"outputs": [
|
| 662 |
+
{
|
| 663 |
+
"name": "stdout",
|
| 664 |
+
"output_type": "stream",
|
| 665 |
+
"text": [
|
| 666 |
+
"Number of patent-inventor links: 6071805\n"
|
| 667 |
+
]
|
| 668 |
+
}
|
| 669 |
+
],
|
| 670 |
+
"source": [
|
| 671 |
+
"inventor_ids = inventor_ids_all[masks].astype(np.int32)\n",
|
| 672 |
+
"patent_ids = patent_ids_all[masks]\n",
|
| 673 |
+
"print('Number of patent-inventor links:', len(inventor_ids))"
|
| 674 |
+
]
|
| 675 |
+
},
|
| 676 |
+
{
|
| 677 |
+
"cell_type": "code",
|
| 678 |
+
"execution_count": 24,
|
| 679 |
+
"id": "b17d7ccb6baeabe8",
|
| 680 |
+
"metadata": {
|
| 681 |
+
"ExecuteTime": {
|
| 682 |
+
"end_time": "2024-12-01T08:36:02.947198Z",
|
| 683 |
+
"start_time": "2024-12-01T08:36:02.943592Z"
|
| 684 |
+
}
|
| 685 |
+
},
|
| 686 |
+
"outputs": [],
|
| 687 |
+
"source": [
|
| 688 |
+
"data['patent-inventor'] = (patent_ids, inventor_ids)"
|
| 689 |
+
]
|
| 690 |
+
},
|
| 691 |
+
{
|
| 692 |
+
"cell_type": "code",
|
| 693 |
+
"execution_count": 29,
|
| 694 |
+
"id": "003311a6",
|
| 695 |
+
"metadata": {},
|
| 696 |
+
"outputs": [],
|
| 697 |
+
"source": [
|
| 698 |
+
"patent_years = (df['filing_date'] // 10000).values.astype(np.int16)\n",
|
| 699 |
+
"data['patent_years'] = patent_years"
|
| 700 |
+
]
|
| 701 |
+
},
|
| 702 |
+
{
|
| 703 |
+
"cell_type": "code",
|
| 704 |
+
"execution_count": 30,
|
| 705 |
+
"id": "2c3ad5b8",
|
| 706 |
+
"metadata": {},
|
| 707 |
+
"outputs": [
|
| 708 |
+
{
|
| 709 |
+
"data": {
|
| 710 |
+
"text/plain": [
|
| 711 |
+
"{'patent_labels': array([115, 56, 11, ..., 115, 58, 51], dtype=int8),\n",
|
| 712 |
+
" 'patent-examiner': (array([ 0, 1, 2, ..., 2762184, 2762185, 2762186]),\n",
|
| 713 |
+
" array([5875, 1162, 5676, ..., 6876, 5808, 7515], dtype=int16)),\n",
|
| 714 |
+
" 'patent-inventor': (array([ 0, 0, 0, ..., 2762184, 2762185, 2762186]),\n",
|
| 715 |
+
" array([ 218391, 1633817, 1630717, ..., 2301356, 766552, 1247700],\n",
|
| 716 |
+
" dtype=int32)),\n",
|
| 717 |
+
" 'patent_years': array([2016, 2011, 2011, ..., 2016, 2016, 2016], dtype=int16)}"
|
| 718 |
+
]
|
| 719 |
+
},
|
| 720 |
+
"execution_count": 30,
|
| 721 |
+
"metadata": {},
|
| 722 |
+
"output_type": "execute_result"
|
| 723 |
+
}
|
| 724 |
+
],
|
| 725 |
+
"source": [
|
| 726 |
+
"data"
|
| 727 |
+
]
|
| 728 |
+
},
|
| 729 |
+
{
|
| 730 |
+
"cell_type": "code",
|
| 731 |
+
"execution_count": null,
|
| 732 |
+
"id": "96ff79e4",
|
| 733 |
+
"metadata": {},
|
| 734 |
+
"outputs": [],
|
| 735 |
+
"source": [
|
| 736 |
+
"import pickle\n",
|
| 737 |
+
"\n",
|
| 738 |
+
"with open('patent.pkl', 'wb') as f:\n",
|
| 739 |
+
" pickle.dump(data, f)"
|
| 740 |
+
]
|
| 741 |
+
},
|
| 742 |
+
{
|
| 743 |
+
"cell_type": "code",
|
| 744 |
+
"execution_count": 32,
|
| 745 |
+
"id": "c12b35e2",
|
| 746 |
+
"metadata": {},
|
| 747 |
+
"outputs": [],
|
| 748 |
+
"source": [
|
| 749 |
+
"df.to_csv('Patent.csv', index=False)"
|
| 750 |
+
]
|
| 751 |
+
},
|
| 752 |
+
{
|
| 753 |
+
"cell_type": "code",
|
| 754 |
+
"execution_count": null,
|
| 755 |
+
"id": "964ff612",
|
| 756 |
+
"metadata": {},
|
| 757 |
+
"outputs": [],
|
| 758 |
+
"source": []
|
| 759 |
+
},
|
| 760 |
+
{
|
| 761 |
+
"cell_type": "markdown",
|
| 762 |
+
"id": "cbf19f89927467f1",
|
| 763 |
+
"metadata": {},
|
| 764 |
+
"source": [
|
| 765 |
+
"### Node Features\n",
|
| 766 |
+
"\n",
|
| 767 |
+
"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",
|
| 768 |
+
"\n",
|
| 769 |
+
"\n",
|
| 770 |
+
"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",
|
| 771 |
+
"\n",
|
| 772 |
+
"all-MiniLM-L6-v2\n",
|
| 773 |
+
"\n",
|
| 774 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 775 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 776 |
+
"Max Sequence Length:\t256\n",
|
| 777 |
+
"Dimensions:\t384\n",
|
| 778 |
+
"Normalized Embeddings:\ttrue\n",
|
| 779 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 780 |
+
"Size:\t80 MB\n",
|
| 781 |
+
"Pooling:\tMean Pooling\n",
|
| 782 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 783 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 784 |
+
]
|
| 785 |
+
},
|
| 786 |
+
{
|
| 787 |
+
"cell_type": "code",
|
| 788 |
+
"execution_count": 1,
|
| 789 |
+
"id": "4c2278bf",
|
| 790 |
+
"metadata": {},
|
| 791 |
+
"outputs": [
|
| 792 |
+
{
|
| 793 |
+
"data": {
|
| 794 |
+
"text/html": [
|
| 795 |
+
"<div>\n",
|
| 796 |
+
"<style scoped>\n",
|
| 797 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 798 |
+
" vertical-align: middle;\n",
|
| 799 |
+
" }\n",
|
| 800 |
+
"\n",
|
| 801 |
+
" .dataframe tbody tr th {\n",
|
| 802 |
+
" vertical-align: top;\n",
|
| 803 |
+
" }\n",
|
| 804 |
+
"\n",
|
| 805 |
+
" .dataframe thead th {\n",
|
| 806 |
+
" text-align: right;\n",
|
| 807 |
+
" }\n",
|
| 808 |
+
"</style>\n",
|
| 809 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 810 |
+
" <thead>\n",
|
| 811 |
+
" <tr style=\"text-align: right;\">\n",
|
| 812 |
+
" <th></th>\n",
|
| 813 |
+
" <th>application_number</th>\n",
|
| 814 |
+
" <th>title</th>\n",
|
| 815 |
+
" <th>abstract</th>\n",
|
| 816 |
+
" <th>main_ipcr_label</th>\n",
|
| 817 |
+
" <th>filing_date</th>\n",
|
| 818 |
+
" <th>examiner_id</th>\n",
|
| 819 |
+
" <th>inventor_list</th>\n",
|
| 820 |
+
" <th>label</th>\n",
|
| 821 |
+
" </tr>\n",
|
| 822 |
+
" </thead>\n",
|
| 823 |
+
" <tbody>\n",
|
| 824 |
+
" <tr>\n",
|
| 825 |
+
" <th>0</th>\n",
|
| 826 |
+
" <td>15243228</td>\n",
|
| 827 |
+
" <td>METHODS OF FORMING PRINTABLE INTEGRATED CIRCUI...</td>\n",
|
| 828 |
+
" <td>Methods of forming integrated circuit devices ...</td>\n",
|
| 829 |
+
" <td>H01L2712</td>\n",
|
| 830 |
+
" <td>20160822</td>\n",
|
| 831 |
+
" <td>75592</td>\n",
|
| 832 |
+
" <td>['bower|christopher|raleigh|nc|us', 'menard|et...</td>\n",
|
| 833 |
+
" <td>H01</td>\n",
|
| 834 |
+
" </tr>\n",
|
| 835 |
+
" <tr>\n",
|
| 836 |
+
" <th>1</th>\n",
|
| 837 |
+
" <td>13033229</td>\n",
|
| 838 |
+
" <td>RUTHENIUM CARBENE COMPLEXES FOR OLED MATERIAL</td>\n",
|
| 839 |
+
" <td>Neutral ruthenium(II) complexes having at leas...</td>\n",
|
| 840 |
+
" <td>C07F1500</td>\n",
|
| 841 |
+
" <td>20110223</td>\n",
|
| 842 |
+
" <td>60315</td>\n",
|
| 843 |
+
" <td>['tsai|jui-yi|newtown|pa|us']</td>\n",
|
| 844 |
+
" <td>C07</td>\n",
|
| 845 |
+
" </tr>\n",
|
| 846 |
+
" <tr>\n",
|
| 847 |
+
" <th>2</th>\n",
|
| 848 |
+
" <td>13218612</td>\n",
|
| 849 |
+
" <td>BED INSERT</td>\n",
|
| 850 |
+
" <td>An insert for a bed facilitates use of a mattr...</td>\n",
|
| 851 |
+
" <td>A47C2100</td>\n",
|
| 852 |
+
" <td>20110826</td>\n",
|
| 853 |
+
" <td>74819</td>\n",
|
| 854 |
+
" <td>[\"o'reagan|james r.|greer|sc|us\"]</td>\n",
|
| 855 |
+
" <td>A47</td>\n",
|
| 856 |
+
" </tr>\n",
|
| 857 |
+
" <tr>\n",
|
| 858 |
+
" <th>3</th>\n",
|
| 859 |
+
" <td>13828921</td>\n",
|
| 860 |
+
" <td>IMAGE DISPLAY APPARATUS AND METHOD FOR OPERATI...</td>\n",
|
| 861 |
+
" <td>An image display apparatus and a method for op...</td>\n",
|
| 862 |
+
" <td>G06F301</td>\n",
|
| 863 |
+
" <td>20130314</td>\n",
|
| 864 |
+
" <td>66365</td>\n",
|
| 865 |
+
" <td>['choi|eunjung|seoul||kr', 'choi|kwangsoo|seou...</td>\n",
|
| 866 |
+
" <td>G06</td>\n",
|
| 867 |
+
" </tr>\n",
|
| 868 |
+
" <tr>\n",
|
| 869 |
+
" <th>4</th>\n",
|
| 870 |
+
" <td>15373712</td>\n",
|
| 871 |
+
" <td>BI-DIRECTIONAL ROLLER ASSEMBLY</td>\n",
|
| 872 |
+
" <td>Disclosed is a method of assembling a roller a...</td>\n",
|
| 873 |
+
" <td>F16L318</td>\n",
|
| 874 |
+
" <td>20161209</td>\n",
|
| 875 |
+
" <td>58099</td>\n",
|
| 876 |
+
" <td>['costa|carlos|somerset|ma|us']</td>\n",
|
| 877 |
+
" <td>F16</td>\n",
|
| 878 |
+
" </tr>\n",
|
| 879 |
+
" </tbody>\n",
|
| 880 |
+
"</table>\n",
|
| 881 |
+
"</div>"
|
| 882 |
+
],
|
| 883 |
+
"text/plain": [
|
| 884 |
+
" application_number title \\\n",
|
| 885 |
+
"0 15243228 METHODS OF FORMING PRINTABLE INTEGRATED CIRCUI... \n",
|
| 886 |
+
"1 13033229 RUTHENIUM CARBENE COMPLEXES FOR OLED MATERIAL \n",
|
| 887 |
+
"2 13218612 BED INSERT \n",
|
| 888 |
+
"3 13828921 IMAGE DISPLAY APPARATUS AND METHOD FOR OPERATI... \n",
|
| 889 |
+
"4 15373712 BI-DIRECTIONAL ROLLER ASSEMBLY \n",
|
| 890 |
+
"\n",
|
| 891 |
+
" abstract main_ipcr_label \\\n",
|
| 892 |
+
"0 Methods of forming integrated circuit devices ... H01L2712 \n",
|
| 893 |
+
"1 Neutral ruthenium(II) complexes having at leas... C07F1500 \n",
|
| 894 |
+
"2 An insert for a bed facilitates use of a mattr... A47C2100 \n",
|
| 895 |
+
"3 An image display apparatus and a method for op... G06F301 \n",
|
| 896 |
+
"4 Disclosed is a method of assembling a roller a... F16L318 \n",
|
| 897 |
+
"\n",
|
| 898 |
+
" filing_date examiner_id \\\n",
|
| 899 |
+
"0 20160822 75592 \n",
|
| 900 |
+
"1 20110223 60315 \n",
|
| 901 |
+
"2 20110826 74819 \n",
|
| 902 |
+
"3 20130314 66365 \n",
|
| 903 |
+
"4 20161209 58099 \n",
|
| 904 |
+
"\n",
|
| 905 |
+
" inventor_list label \n",
|
| 906 |
+
"0 ['bower|christopher|raleigh|nc|us', 'menard|et... H01 \n",
|
| 907 |
+
"1 ['tsai|jui-yi|newtown|pa|us'] C07 \n",
|
| 908 |
+
"2 [\"o'reagan|james r.|greer|sc|us\"] A47 \n",
|
| 909 |
+
"3 ['choi|eunjung|seoul||kr', 'choi|kwangsoo|seou... G06 \n",
|
| 910 |
+
"4 ['costa|carlos|somerset|ma|us'] F16 "
|
| 911 |
+
]
|
| 912 |
+
},
|
| 913 |
+
"execution_count": 1,
|
| 914 |
+
"metadata": {},
|
| 915 |
+
"output_type": "execute_result"
|
| 916 |
+
}
|
| 917 |
+
],
|
| 918 |
+
"source": [
|
| 919 |
+
"import pandas as pd\n",
|
| 920 |
+
"\n",
|
| 921 |
+
"df = pd.read_csv('Patent.csv')\n",
|
| 922 |
+
"df.head()"
|
| 923 |
+
]
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"cell_type": "code",
|
| 927 |
+
"execution_count": 3,
|
| 928 |
+
"id": "22d32b65",
|
| 929 |
+
"metadata": {},
|
| 930 |
+
"outputs": [
|
| 931 |
+
{
|
| 932 |
+
"data": {
|
| 933 |
+
"text/plain": [
|
| 934 |
+
"{'patent_labels': array([115, 56, 11, ..., 115, 58, 51], dtype=int8),\n",
|
| 935 |
+
" 'patent-examiner': (array([ 0, 1, 2, ..., 2762184, 2762185, 2762186]),\n",
|
| 936 |
+
" array([5875, 1162, 5676, ..., 6876, 5808, 7515], dtype=int16)),\n",
|
| 937 |
+
" 'patent-inventor': (array([ 0, 0, 0, ..., 2762184, 2762185, 2762186]),\n",
|
| 938 |
+
" array([ 218391, 1633817, 1630717, ..., 2301356, 766552, 1247700],\n",
|
| 939 |
+
" dtype=int32)),\n",
|
| 940 |
+
" 'patent_years': array([2016, 2011, 2011, ..., 2016, 2016, 2016], dtype=int16)}"
|
| 941 |
+
]
|
| 942 |
+
},
|
| 943 |
+
"execution_count": 3,
|
| 944 |
+
"metadata": {},
|
| 945 |
+
"output_type": "execute_result"
|
| 946 |
+
}
|
| 947 |
+
],
|
| 948 |
+
"source": [
|
| 949 |
+
"import pickle\n",
|
| 950 |
+
"\n",
|
| 951 |
+
"with open('patent.pkl', 'rb') as f:\n",
|
| 952 |
+
" data = pickle.load(f)\n",
|
| 953 |
+
"data"
|
| 954 |
+
]
|
| 955 |
+
},
|
| 956 |
+
{
|
| 957 |
+
"cell_type": "code",
|
| 958 |
+
"execution_count": 4,
|
| 959 |
+
"id": "cbf8349f28ec104",
|
| 960 |
+
"metadata": {},
|
| 961 |
+
"outputs": [
|
| 962 |
+
{
|
| 963 |
+
"name": "stderr",
|
| 964 |
+
"output_type": "stream",
|
| 965 |
+
"text": [
|
| 966 |
+
"/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",
|
| 967 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 968 |
+
]
|
| 969 |
+
},
|
| 970 |
+
{
|
| 971 |
+
"data": {
|
| 972 |
+
"text/plain": [
|
| 973 |
+
"SentenceTransformer(\n",
|
| 974 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 975 |
+
" (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",
|
| 976 |
+
" (2): Normalize()\n",
|
| 977 |
+
")"
|
| 978 |
+
]
|
| 979 |
+
},
|
| 980 |
+
"execution_count": 4,
|
| 981 |
+
"metadata": {},
|
| 982 |
+
"output_type": "execute_result"
|
| 983 |
+
}
|
| 984 |
+
],
|
| 985 |
+
"source": [
|
| 986 |
+
"import torch\n",
|
| 987 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 988 |
+
"\n",
|
| 989 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 990 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 991 |
+
"model"
|
| 992 |
+
]
|
| 993 |
+
},
|
| 994 |
+
{
|
| 995 |
+
"cell_type": "code",
|
| 996 |
+
"execution_count": 5,
|
| 997 |
+
"id": "6c1a927b",
|
| 998 |
+
"metadata": {},
|
| 999 |
+
"outputs": [],
|
| 1000 |
+
"source": [
|
| 1001 |
+
"text = df['title'] + ' ' + df['abstract']"
|
| 1002 |
+
]
|
| 1003 |
+
},
|
| 1004 |
+
{
|
| 1005 |
+
"cell_type": "code",
|
| 1006 |
+
"execution_count": 18,
|
| 1007 |
+
"id": "c419b9b4",
|
| 1008 |
+
"metadata": {},
|
| 1009 |
+
"outputs": [
|
| 1010 |
+
{
|
| 1011 |
+
"name": "stderr",
|
| 1012 |
+
"output_type": "stream",
|
| 1013 |
+
"text": [
|
| 1014 |
+
"Batches: 100%|██████████| 675/675 [33:12<00:00, 2.95s/it]\n"
|
| 1015 |
+
]
|
| 1016 |
+
}
|
| 1017 |
+
],
|
| 1018 |
+
"source": [
|
| 1019 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)"
|
| 1020 |
+
]
|
| 1021 |
+
},
|
| 1022 |
+
{
|
| 1023 |
+
"cell_type": "code",
|
| 1024 |
+
"execution_count": 22,
|
| 1025 |
+
"id": "f3e6cfd3",
|
| 1026 |
+
"metadata": {},
|
| 1027 |
+
"outputs": [],
|
| 1028 |
+
"source": [
|
| 1029 |
+
"data['patent_feats'] = feats"
|
| 1030 |
+
]
|
| 1031 |
+
},
|
| 1032 |
+
{
|
| 1033 |
+
"cell_type": "code",
|
| 1034 |
+
"execution_count": 25,
|
| 1035 |
+
"id": "1c132a42",
|
| 1036 |
+
"metadata": {},
|
| 1037 |
+
"outputs": [],
|
| 1038 |
+
"source": [
|
| 1039 |
+
"with open('patent.pkl', 'wb') as f:\n",
|
| 1040 |
+
" pickle.dump(data, f)"
|
| 1041 |
+
]
|
| 1042 |
+
}
|
| 1043 |
+
],
|
| 1044 |
+
"metadata": {
|
| 1045 |
+
"kernelspec": {
|
| 1046 |
+
"display_name": "Python 3",
|
| 1047 |
+
"language": "python",
|
| 1048 |
+
"name": "python3"
|
| 1049 |
+
},
|
| 1050 |
+
"language_info": {
|
| 1051 |
+
"codemirror_mode": {
|
| 1052 |
+
"name": "ipython",
|
| 1053 |
+
"version": 3
|
| 1054 |
+
},
|
| 1055 |
+
"file_extension": ".py",
|
| 1056 |
+
"mimetype": "text/x-python",
|
| 1057 |
+
"name": "python",
|
| 1058 |
+
"nbconvert_exporter": "python",
|
| 1059 |
+
"pygments_lexer": "ipython3",
|
| 1060 |
+
"version": "3.10.12"
|
| 1061 |
+
}
|
| 1062 |
+
},
|
| 1063 |
+
"nbformat": 4,
|
| 1064 |
+
"nbformat_minor": 5
|
| 1065 |
+
}
|
patent/patent.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1db46a7225ca5996a235da63fd95934c6d0223303335a10fa130e3d1e901081a
|
| 3 |
+
size 4351489987
|
tmdb/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# TMDB: Movie Collaboration Network
|
| 2 |
+
|
| 3 |
+
## Dataset Description
|
| 4 |
+
|
| 5 |
+
The TMDB dataset is a heterogeneous network composed of a subset of [The Movie Database](https://www.themoviedb.org), a popular online database and community platform that provides a vast collection of information about movies, TV shows, and other related content. We collected metadata of the most popular movies via the platform's public [API](https://developer.themoviedb.org/docs) on May 31, 2024. After processing, it contains three types of entities—movies (7,505 nodes), actors (13,016 nodes), and directors (3,891 nodes)—as well as two types of directed relations connecting two types of entities—an actor "performs" a movie, and a director "directs" a movie. Movies are associated with their overviews, and all the other types of entities are textless. We pass the movie overview to a [MiniLM](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) sentence encoder, generating a 384-dimensional feature vector for each movie node. All movies are labeled as one of four classes ("action", "romance", "thriller", and "animation") based on their genre. On the movie nodes, we attach the release date as meta information.
|
| 6 |
+
|
| 7 |
+
**Prediction task.**
|
| 8 |
+
Given the heterogeneous TMDB data, the task is to predict the genre of each movie, given its content, actors, and directors. We use the Micro-F1 and Macro-F1 scores to evaluate this multi-class classification performance.
|
| 9 |
+
|
| 10 |
+
**Dataset splitting.**
|
| 11 |
+
We consider a realistic and challenging data split based on the release dates of the movies instead of a random split. In this setup, machine learning models are trained on existing movies and then used to predict the genres of newly-released movies, which supports the direct application of them into real-world scenarios, such as helping the TMDB moderators. Specifically, we train on movies released up to 2015, validate on those released from 2016 to 2018, and test on those released since 2019.
|
| 12 |
+
|
| 13 |
+
**Dataset statistics.**
|
| 14 |
+
|
| 15 |
+
| # Nodes | # Edges | # Classes | # Splits |
|
| 16 |
+
| --------------- | ---------------------- | --------- | ------------ |
|
| 17 |
+
| 24,412 | 104,858 | 4 | Train: 5,698 |
|
| 18 |
+
| Movie: 7,505 | Movie-Actor: 86,517 | | Valid: 711 |
|
| 19 |
+
| Actor: 13,016 | Movie-Director: 18,341 | | Test: 1,096 |
|
| 20 |
+
| Director: 3,891 | | | |
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
## Dataset Construction
|
| 25 |
+
|
| 26 |
+
1. Run `graph_builder.ipynb`
|
| 27 |
+
|
| 28 |
+
Details about data collection are in `tmdb_fetcher.ipynb`.
|
| 29 |
+
|
| 30 |
+
|
tmdb/TMDB.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tmdb/graph_builder.ipynb
ADDED
|
@@ -0,0 +1,641 @@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "dd3a9f32-3b8c-46b5-9165-b243049d2f81",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# TMDB Network\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"This notebook contains recipe to construct a heterogeneous network based on the fetched TMDB dataset."
|
| 11 |
+
]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"cell_type": "code",
|
| 15 |
+
"execution_count": 1,
|
| 16 |
+
"id": "412ba4a1-7f05-4a65-97ae-9a235c30dae5",
|
| 17 |
+
"metadata": {
|
| 18 |
+
"ExecuteTime": {
|
| 19 |
+
"end_time": "2024-12-02T15:41:05.965764Z",
|
| 20 |
+
"start_time": "2024-12-02T15:41:05.188819Z"
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"outputs": [],
|
| 24 |
+
"source": [
|
| 25 |
+
"import pickle\n",
|
| 26 |
+
"import numpy as np\n",
|
| 27 |
+
"import pandas as pd\n",
|
| 28 |
+
"import matplotlib.pyplot as plt"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"cell_type": "markdown",
|
| 33 |
+
"id": "e3ab0c46-271e-4cae-adf4-f5de94f011bf",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"## Input Data\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"[The Movie Database (TMDB)](https://www.themoviedb.org/) is a popular online database and community platform that provides a vast collection of information about movies, TV shows, and other related content. We collected metadata about more than 7500 of the most popular action, romance, thriller and animation English movies from [TMDB's public API](https://developer.themoviedb.org/docs) on May 31, 2024. After meticulous data cleaning, we finally obtain 7,505 movies, 13,016 actors, and 3,891 directors.\n"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"cell_type": "code",
|
| 43 |
+
"execution_count": 2,
|
| 44 |
+
"id": "262e4aa2-3566-476f-a79f-29609a88139a",
|
| 45 |
+
"metadata": {
|
| 46 |
+
"ExecuteTime": {
|
| 47 |
+
"end_time": "2024-12-02T15:41:07.133497Z",
|
| 48 |
+
"start_time": "2024-12-02T15:41:06.904795Z"
|
| 49 |
+
}
|
| 50 |
+
},
|
| 51 |
+
"outputs": [
|
| 52 |
+
{
|
| 53 |
+
"name": "stdout",
|
| 54 |
+
"output_type": "stream",
|
| 55 |
+
"text": [
|
| 56 |
+
"Number of movies: 7505\n"
|
| 57 |
+
]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"data": {
|
| 61 |
+
"text/html": [
|
| 62 |
+
"<div>\n",
|
| 63 |
+
"<style scoped>\n",
|
| 64 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 65 |
+
" vertical-align: middle;\n",
|
| 66 |
+
" }\n",
|
| 67 |
+
"\n",
|
| 68 |
+
" .dataframe tbody tr th {\n",
|
| 69 |
+
" vertical-align: top;\n",
|
| 70 |
+
" }\n",
|
| 71 |
+
"\n",
|
| 72 |
+
" .dataframe thead th {\n",
|
| 73 |
+
" text-align: right;\n",
|
| 74 |
+
" }\n",
|
| 75 |
+
"</style>\n",
|
| 76 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 77 |
+
" <thead>\n",
|
| 78 |
+
" <tr style=\"text-align: right;\">\n",
|
| 79 |
+
" <th></th>\n",
|
| 80 |
+
" <th>id</th>\n",
|
| 81 |
+
" <th>title</th>\n",
|
| 82 |
+
" <th>overview</th>\n",
|
| 83 |
+
" <th>genre</th>\n",
|
| 84 |
+
" <th>release_date</th>\n",
|
| 85 |
+
" <th>actor</th>\n",
|
| 86 |
+
" <th>director</th>\n",
|
| 87 |
+
" </tr>\n",
|
| 88 |
+
" </thead>\n",
|
| 89 |
+
" <tbody>\n",
|
| 90 |
+
" <tr>\n",
|
| 91 |
+
" <th>0</th>\n",
|
| 92 |
+
" <td>199753</td>\n",
|
| 93 |
+
" <td>Tom and Jerry's Giant Adventure</td>\n",
|
| 94 |
+
" <td>Tom And Jerry are among the last animals livin...</td>\n",
|
| 95 |
+
" <td>Animation</td>\n",
|
| 96 |
+
" <td>2013-08-04</td>\n",
|
| 97 |
+
" <td>[80416, 86434, 60739, 5129, 1065, 31531, 11444...</td>\n",
|
| 98 |
+
" <td>[23683, 1447452, 92317]</td>\n",
|
| 99 |
+
" </tr>\n",
|
| 100 |
+
" <tr>\n",
|
| 101 |
+
" <th>1</th>\n",
|
| 102 |
+
" <td>9560</td>\n",
|
| 103 |
+
" <td>A Walk in the Clouds</td>\n",
|
| 104 |
+
" <td>World War II vet Paul Sutton falls for a pregn...</td>\n",
|
| 105 |
+
" <td>Romance</td>\n",
|
| 106 |
+
" <td>1995-05-27</td>\n",
|
| 107 |
+
" <td>[7353, 62595, 3753, 85869, 6862, 152943, 6384,...</td>\n",
|
| 108 |
+
" <td>[77162, 1377239]</td>\n",
|
| 109 |
+
" </tr>\n",
|
| 110 |
+
" <tr>\n",
|
| 111 |
+
" <th>2</th>\n",
|
| 112 |
+
" <td>10875</td>\n",
|
| 113 |
+
" <td>The Fabulous Baker Boys</td>\n",
|
| 114 |
+
" <td>The lives of two struggling musicians, who hap...</td>\n",
|
| 115 |
+
" <td>Romance</td>\n",
|
| 116 |
+
" <td>1989-10-13</td>\n",
|
| 117 |
+
" <td>[7906, 8354, 43364, 152963, 1160, 57992, 1229,...</td>\n",
|
| 118 |
+
" <td>[2226, 2571810, 1966431]</td>\n",
|
| 119 |
+
" </tr>\n",
|
| 120 |
+
" <tr>\n",
|
| 121 |
+
" <th>3</th>\n",
|
| 122 |
+
" <td>67609</td>\n",
|
| 123 |
+
" <td>Three Blind Mouseketeers</td>\n",
|
| 124 |
+
" <td>As the title implies, the three blind mice are...</td>\n",
|
| 125 |
+
" <td>Animation</td>\n",
|
| 126 |
+
" <td>1936-09-26</td>\n",
|
| 127 |
+
" <td>[31771, 5462]</td>\n",
|
| 128 |
+
" <td>[564041, 5446]</td>\n",
|
| 129 |
+
" </tr>\n",
|
| 130 |
+
" <tr>\n",
|
| 131 |
+
" <th>4</th>\n",
|
| 132 |
+
" <td>24021</td>\n",
|
| 133 |
+
" <td>The Twilight Saga: Eclipse</td>\n",
|
| 134 |
+
" <td>Bella once again finds herself surrounded by d...</td>\n",
|
| 135 |
+
" <td>Romance</td>\n",
|
| 136 |
+
" <td>2010-06-23</td>\n",
|
| 137 |
+
" <td>[84224, 84225, 45827, 121868, 87310, 1475835, ...</td>\n",
|
| 138 |
+
" <td>[2045537, 1393423, 27571, 2476949, 113019]</td>\n",
|
| 139 |
+
" </tr>\n",
|
| 140 |
+
" </tbody>\n",
|
| 141 |
+
"</table>\n",
|
| 142 |
+
"</div>"
|
| 143 |
+
],
|
| 144 |
+
"text/plain": [
|
| 145 |
+
" id title \\\n",
|
| 146 |
+
"0 199753 Tom and Jerry's Giant Adventure \n",
|
| 147 |
+
"1 9560 A Walk in the Clouds \n",
|
| 148 |
+
"2 10875 The Fabulous Baker Boys \n",
|
| 149 |
+
"3 67609 Three Blind Mouseketeers \n",
|
| 150 |
+
"4 24021 The Twilight Saga: Eclipse \n",
|
| 151 |
+
"\n",
|
| 152 |
+
" overview genre release_date \\\n",
|
| 153 |
+
"0 Tom And Jerry are among the last animals livin... Animation 2013-08-04 \n",
|
| 154 |
+
"1 World War II vet Paul Sutton falls for a pregn... Romance 1995-05-27 \n",
|
| 155 |
+
"2 The lives of two struggling musicians, who hap... Romance 1989-10-13 \n",
|
| 156 |
+
"3 As the title implies, the three blind mice are... Animation 1936-09-26 \n",
|
| 157 |
+
"4 Bella once again finds herself surrounded by d... Romance 2010-06-23 \n",
|
| 158 |
+
"\n",
|
| 159 |
+
" actor \\\n",
|
| 160 |
+
"0 [80416, 86434, 60739, 5129, 1065, 31531, 11444... \n",
|
| 161 |
+
"1 [7353, 62595, 3753, 85869, 6862, 152943, 6384,... \n",
|
| 162 |
+
"2 [7906, 8354, 43364, 152963, 1160, 57992, 1229,... \n",
|
| 163 |
+
"3 [31771, 5462] \n",
|
| 164 |
+
"4 [84224, 84225, 45827, 121868, 87310, 1475835, ... \n",
|
| 165 |
+
"\n",
|
| 166 |
+
" director \n",
|
| 167 |
+
"0 [23683, 1447452, 92317] \n",
|
| 168 |
+
"1 [77162, 1377239] \n",
|
| 169 |
+
"2 [2226, 2571810, 1966431] \n",
|
| 170 |
+
"3 [564041, 5446] \n",
|
| 171 |
+
"4 [2045537, 1393423, 27571, 2476949, 113019] "
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
"execution_count": 2,
|
| 175 |
+
"metadata": {},
|
| 176 |
+
"output_type": "execute_result"
|
| 177 |
+
}
|
| 178 |
+
],
|
| 179 |
+
"source": [
|
| 180 |
+
"movies = pd.read_csv('TMDB.csv')\n",
|
| 181 |
+
"movies['actor'] = movies['actor'].apply(eval)\n",
|
| 182 |
+
"movies['director'] = movies['director'].apply(eval)\n",
|
| 183 |
+
"print('Number of movies:', movies.shape[0])\n",
|
| 184 |
+
"movies.head()"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
{
|
| 188 |
+
"cell_type": "code",
|
| 189 |
+
"execution_count": 3,
|
| 190 |
+
"id": "92ae38e6-98cb-4c6a-b66f-7187208c9e30",
|
| 191 |
+
"metadata": {
|
| 192 |
+
"ExecuteTime": {
|
| 193 |
+
"end_time": "2024-12-02T15:41:08.778301Z",
|
| 194 |
+
"start_time": "2024-12-02T15:41:08.763644Z"
|
| 195 |
+
}
|
| 196 |
+
},
|
| 197 |
+
"outputs": [
|
| 198 |
+
{
|
| 199 |
+
"data": {
|
| 200 |
+
"text/plain": [
|
| 201 |
+
"13016"
|
| 202 |
+
]
|
| 203 |
+
},
|
| 204 |
+
"execution_count": 3,
|
| 205 |
+
"metadata": {},
|
| 206 |
+
"output_type": "execute_result"
|
| 207 |
+
}
|
| 208 |
+
],
|
| 209 |
+
"source": [
|
| 210 |
+
"actor_id_map = {}\n",
|
| 211 |
+
"idx = 0\n",
|
| 212 |
+
"for actors in movies['actor']:\n",
|
| 213 |
+
" for actor in actors:\n",
|
| 214 |
+
" if actor not in actor_id_map:\n",
|
| 215 |
+
" actor_id_map[actor] = idx\n",
|
| 216 |
+
" idx += 1\n",
|
| 217 |
+
"len(actor_id_map)"
|
| 218 |
+
]
|
| 219 |
+
},
|
| 220 |
+
{
|
| 221 |
+
"cell_type": "code",
|
| 222 |
+
"execution_count": 4,
|
| 223 |
+
"id": "fec3f109-45dd-43a5-a35f-6679339a756d",
|
| 224 |
+
"metadata": {
|
| 225 |
+
"ExecuteTime": {
|
| 226 |
+
"end_time": "2024-12-02T15:41:10.396138Z",
|
| 227 |
+
"start_time": "2024-12-02T15:41:10.388693Z"
|
| 228 |
+
}
|
| 229 |
+
},
|
| 230 |
+
"outputs": [
|
| 231 |
+
{
|
| 232 |
+
"data": {
|
| 233 |
+
"text/plain": [
|
| 234 |
+
"3891"
|
| 235 |
+
]
|
| 236 |
+
},
|
| 237 |
+
"execution_count": 4,
|
| 238 |
+
"metadata": {},
|
| 239 |
+
"output_type": "execute_result"
|
| 240 |
+
}
|
| 241 |
+
],
|
| 242 |
+
"source": [
|
| 243 |
+
"director_id_map = {}\n",
|
| 244 |
+
"idx = 0\n",
|
| 245 |
+
"for directors in movies['director']:\n",
|
| 246 |
+
" for director in directors:\n",
|
| 247 |
+
" if director not in director_id_map:\n",
|
| 248 |
+
" director_id_map[director] = idx\n",
|
| 249 |
+
" idx += 1\n",
|
| 250 |
+
"len(director_id_map)"
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"cell_type": "markdown",
|
| 255 |
+
"id": "7c3f9713-edbc-4bad-859c-1431177aa617",
|
| 256 |
+
"metadata": {},
|
| 257 |
+
"source": [
|
| 258 |
+
"## Graph Construction\n",
|
| 259 |
+
"\n",
|
| 260 |
+
"```mermaid\n",
|
| 261 |
+
"---\n",
|
| 262 |
+
"title: The TMDB HIN\n",
|
| 263 |
+
"---\n",
|
| 264 |
+
"flowchart LR\n",
|
| 265 |
+
" Movie[\"<b>Movie</b><br>7,505 nodes<br>4 labels\"]\n",
|
| 266 |
+
" Actor[\"<b>Actor</b><br>13,016 nodes\"]\n",
|
| 267 |
+
" Director[\"<b>Director</b><br>3,891 nodes\"]\n",
|
| 268 |
+
" Actor --\"<b>performs</b><br>86,517 edges\"--- Movie\n",
|
| 269 |
+
" Director --\"<b>directs</b><br>18,341 edges\"--- Movie\n",
|
| 270 |
+
"```"
|
| 271 |
+
]
|
| 272 |
+
},
|
| 273 |
+
{
|
| 274 |
+
"cell_type": "code",
|
| 275 |
+
"execution_count": 5,
|
| 276 |
+
"id": "a01c16ab-1ba7-4ea5-a5c8-0d78e40fe400",
|
| 277 |
+
"metadata": {
|
| 278 |
+
"ExecuteTime": {
|
| 279 |
+
"end_time": "2024-12-02T15:41:12.596227Z",
|
| 280 |
+
"start_time": "2024-12-02T15:41:12.592281Z"
|
| 281 |
+
}
|
| 282 |
+
},
|
| 283 |
+
"outputs": [],
|
| 284 |
+
"source": [
|
| 285 |
+
"data = {}"
|
| 286 |
+
]
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"cell_type": "markdown",
|
| 290 |
+
"id": "02713230-25d4-4554-bd0c-6aaa34602bc0",
|
| 291 |
+
"metadata": {},
|
| 292 |
+
"source": [
|
| 293 |
+
"### Movie-Actor Links"
|
| 294 |
+
]
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"cell_type": "code",
|
| 298 |
+
"execution_count": 6,
|
| 299 |
+
"id": "76c1a5df-c091-49be-b6f6-2569235d4115",
|
| 300 |
+
"metadata": {
|
| 301 |
+
"ExecuteTime": {
|
| 302 |
+
"end_time": "2024-12-02T15:41:14.498387Z",
|
| 303 |
+
"start_time": "2024-12-02T15:41:14.322988Z"
|
| 304 |
+
}
|
| 305 |
+
},
|
| 306 |
+
"outputs": [
|
| 307 |
+
{
|
| 308 |
+
"name": "stdout",
|
| 309 |
+
"output_type": "stream",
|
| 310 |
+
"text": [
|
| 311 |
+
"Number of movie-actor links: 86517\n"
|
| 312 |
+
]
|
| 313 |
+
}
|
| 314 |
+
],
|
| 315 |
+
"source": [
|
| 316 |
+
"movie_ids = []\n",
|
| 317 |
+
"actor_ids = []\n",
|
| 318 |
+
"for movie_id in range(len(movies)):\n",
|
| 319 |
+
" actors = movies.iloc[movie_id]['actor']\n",
|
| 320 |
+
" for actor in actors:\n",
|
| 321 |
+
" movie_ids.append(movie_id)\n",
|
| 322 |
+
" actor_ids.append(actor_id_map[actor])\n",
|
| 323 |
+
" \n",
|
| 324 |
+
"movie_ids = np.array(movie_ids, dtype=np.int16)\n",
|
| 325 |
+
"actor_ids = np.array(actor_ids, dtype=np.int16)\n",
|
| 326 |
+
"print('Number of movie-actor links:', movie_ids.shape[0])\n",
|
| 327 |
+
"data['movie-actor'] = (movie_ids, actor_ids)"
|
| 328 |
+
]
|
| 329 |
+
},
|
| 330 |
+
{
|
| 331 |
+
"cell_type": "markdown",
|
| 332 |
+
"id": "18ecde55-9e2e-4a0d-97ef-e0d1e5ebfd79",
|
| 333 |
+
"metadata": {},
|
| 334 |
+
"source": [
|
| 335 |
+
"### Movie-Director Links"
|
| 336 |
+
]
|
| 337 |
+
},
|
| 338 |
+
{
|
| 339 |
+
"cell_type": "code",
|
| 340 |
+
"execution_count": 7,
|
| 341 |
+
"id": "dc40996c-a04c-4c49-9346-c7c8b1fbc7fd",
|
| 342 |
+
"metadata": {
|
| 343 |
+
"ExecuteTime": {
|
| 344 |
+
"end_time": "2024-12-02T15:41:16.702077Z",
|
| 345 |
+
"start_time": "2024-12-02T15:41:16.550123Z"
|
| 346 |
+
}
|
| 347 |
+
},
|
| 348 |
+
"outputs": [
|
| 349 |
+
{
|
| 350 |
+
"name": "stdout",
|
| 351 |
+
"output_type": "stream",
|
| 352 |
+
"text": [
|
| 353 |
+
"Number of movie-director links: 18341\n"
|
| 354 |
+
]
|
| 355 |
+
}
|
| 356 |
+
],
|
| 357 |
+
"source": [
|
| 358 |
+
"movie_ids = []\n",
|
| 359 |
+
"director_ids = []\n",
|
| 360 |
+
"for movie_id in range(len(movies)):\n",
|
| 361 |
+
" directors = movies.iloc[movie_id]['director']\n",
|
| 362 |
+
" \n",
|
| 363 |
+
" for director in directors:\n",
|
| 364 |
+
" movie_ids.append(movie_id)\n",
|
| 365 |
+
" director_ids.append(director_id_map[director])\n",
|
| 366 |
+
" \n",
|
| 367 |
+
"movie_ids = np.array(movie_ids, dtype=np.int16)\n",
|
| 368 |
+
"director_ids = np.array(director_ids, dtype=np.int16)\n",
|
| 369 |
+
"print('Number of movie-director links:', movie_ids.shape[0])\n",
|
| 370 |
+
"data['movie-director'] = (movie_ids, director_ids)"
|
| 371 |
+
]
|
| 372 |
+
},
|
| 373 |
+
{
|
| 374 |
+
"cell_type": "markdown",
|
| 375 |
+
"id": "64fc0ee7-6dcb-406f-a98e-21214866d25d",
|
| 376 |
+
"metadata": {},
|
| 377 |
+
"source": [
|
| 378 |
+
"### Labels\n",
|
| 379 |
+
"\n",
|
| 380 |
+
"There are a total of 19 movie genres in TMDB. We selected four genres with low intercorrelation as our ground truth labels. Note that one movie usually has multiple genres. To improve label quality, we only collect movies whose genres just include one of {action, romance, thriller, animation}.\n"
|
| 381 |
+
]
|
| 382 |
+
},
|
| 383 |
+
{
|
| 384 |
+
"cell_type": "code",
|
| 385 |
+
"execution_count": 8,
|
| 386 |
+
"id": "72cb9ae1-7a8b-4231-82e2-d0ceea47b1eb",
|
| 387 |
+
"metadata": {
|
| 388 |
+
"ExecuteTime": {
|
| 389 |
+
"end_time": "2024-12-02T15:41:19.409614Z",
|
| 390 |
+
"start_time": "2024-12-02T15:41:19.298045Z"
|
| 391 |
+
}
|
| 392 |
+
},
|
| 393 |
+
"outputs": [
|
| 394 |
+
{
|
| 395 |
+
"data": {
|
| 396 |
+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnMAAAGzCAYAAABEsJEnAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/GU6VOAAAACXBIWXMAAA9hAAAPYQGoP6dpAABHVUlEQVR4nO3dd1yV9f//8edhCrIEB6C4DVeYO0dJQaKZafpJRXNlQ1NLTTOzcnwqTbMsNVsE2VL7pFlWmgO3lgtzRWqOcqYGhANB3t8//HF+HhkqgXDl4367nduNc13v631eb64D58n7GtiMMUYAAACwJKeiLgAAAAD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3Dhw9XWlqa3NzctHz5crVt21YNGzbUmDFj5OTkpNjYWN19991avXq1mjRpIknavn27WrdurTJlymjs2LHKyMjQmDFjVK5cuXzXe/z4cd1+++2y2WwaNGiQypQpo++//179+vVTSkqKhgwZ4tB+4sSJcnJy0vDhw5WcnKxJkyapR48e+vHHH+1tlixZovvuu09BQUF66qmnFBgYqN27d2vhwoV66qmn9J///EcDBw7Up59+qvr16zv0/+mnnyo8PFzly5fPteadO3fqjjvukI+Pj5555hm5urrq3XffVXh4uFauXKmmTZuqU6dO8vPz09ChQxUdHa177733ms8bi46O1ieffKKJEyfKZrPp5MmT+uGHH/Txxx9r0aJF2dqPHTtW48aNU2RkpAYMGKDExETNnDlTGzdu1Nq1a+Xq6qquXbtqxowZ+vbbb/Xggw/atz179qy++eYb9enTR87OzjnWk5mZqfvvv19r1qzRY489plq1amn79u1644039OuvvxbIRR0bN27UunXr1K1bN1WoUEEHDhzQzJkzFR4erl27dsnT09Oh/aBBg+Tn56exY8fax3vw4EF76Jekjz/+WL1791ZUVJReffVVnT17VjNnzlTLli21devWXMP1zp07dd999yksLEzjx4+Xu7u79u7dm+MfN8ANZQD8q8XGxhpJOT6MMSY+Pt5IMlWrVjVnz561b5eZmWlq1KhhoqKiTGZmpn352bNnTZUqVcw999xjX9axY0dTokQJc/DgQfuyXbt2GWdnZ3P5r5n9+/cbSSY2NjZbnZLMmDFj7M/79etngoKCzMmTJx3adevWzfj6+tprzaq/Vq1aJi0tzd7uzTffNJLM9u3bjTHGZGRkmCpVqphKlSqZv/76y6HPy8cXHR1tgoODzcWLF+3LtmzZkmvdl+vYsaNxc3Mz+/btsy87cuSI8fb2NnfeeWe278PkyZPz7O/Ktjt27DCSzOrVq40xxsyYMcN4eXmZM2fOmN69e5uSJUvatztx4oRxc3MzrVu3dhjL9OnTjSTz4Ycf2sdevnx507lzZ4fXnTt3rpFkVq1aZV/WqlUr06pVK/vzjz/+2Dg5OdnryfLOO+8YSWbt2rV5ju3KmnNy+Xsyy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nFR4enmOfX3/9tU6dOqW+ffveoFEUL0Ue5ubOnauaNWsqNDRUDz30kD788EMZYxzajB49WlOmTNGmTZvk4uKihx9+OM8+ly9friNHjmjVqlV6/fXXNWbMGN13330qVaqUfvzxR/Xv31+PP/64/vjjD/s23t7eiouL065du/Tmm2/q/fff1xtvvCFJ6tq1q55++mnVqVPHPp3btWvXbK975swZRUVFqVSpUtq4caO++OILLV26VIMGDXJoFx8fr3379ik+Pl4fffSR4uLiHELsldLS0pSSkuLwAADAiqZNm6batWurQoUKcnNzU5s2bTRjxgzdeeed9jZz585Venq6AgIC5O7urscff1zz589X9erVc+wzJiZGUVFRqlChwo0aRrFS5GEuJiZGDz30kCSpTZs2Sk5O1sqVKx3avPzyy2rVqpVq166tZ599VuvWrdP58+dz7dPf319vvfWWQkND9fDDDys0NFRnz57Vc889pxo1amjUqFFyc3PTmjVr7Ns8//zzat68uSpXrqz27dtr+PDhmjt3riTJw8NDXl5ecnFxsU/penh4ZHvdzz77TOfPn9esWbNUt25d3X333Zo+fbo+/vhjHT9+3N6uVKlSmj59umrWrKn77rtP7dq1y/O8vwkTJsjX19f+CAkJubZvLgAAxcy0adO0YcMGff3119q8ebOmTJmigQMHaunSpfY2L7zwgpKSkrR06VJt2rRJw4YNU5cuXbR9+/Zs/f3xxx9avHix+vXrdyOHUay4FOWLJyYm6qefftL8+fMvFePioq5duyomJsZhKjUsLMz+dVBQkCTpxIkTqlixYo791qlTR05O/z+nlitXTnXr1rU/d3Z2VkBAgE6cOGFfNmfOHL311lvat2+fUlNTlZGRIR8fn+saz+7du1WvXj2VLFnSvqxFixbKzMxUYmKiypUrZ6/P2dnZYUw5vUGzjBo1SsOGDbM/T0lJIdABACzn3Llzeu655zR//nz7RY9hYWFKSEjQa6+9psjISO3bt0/Tp0/Xjh07VKdOHUlSvXr1tHr1as2YMSPbla+xsbEKCAjQ/ffff8PHU1wUaZiLiYlRRkaGgoOD7cuMMXJ3d9f06dPty1xdXe1fZ53YmJmZmWu/l7fP2ianZVl9rF+/Xj169NC4ceMUFRUlX19fzZ49W1OmTMn/4PKQVy05cXd35yILAIDlpaenKz093WHCRbo0yZL1OXj27FlJyrNNFmOMYmNj1atXr2yfrTeTIgtzGRkZmjVrlqZMmeJw0qMkdezYUZ9//rlq1qx5Q2pZt26dKlWqpNGjR9uXHTx40KGNm5ubLl68mGc/tWrVUlxcnM6cOWOfnVu7dq2cnJwUGhpa8IUDAFDMpKamau/evfbn+/fvV0JCgvz9/VWxYkW1atVKI0aMkIeHhypVqqSVK1dq1qxZev311yVJNWvWVPXq1fX444/rtddeU0BAgL766istWbJECxcudHit5cuXa//+/XrkkUdu6BiLmyI7Z27hwoX666+/1K9fP9WtW9fh0blzZ8XExNywWmrUqKFDhw5p9uzZ2rdvn9566y37od8slStXtr8hT548qbS0tGz99OjRQyVKlFDv3r21Y8cOxcfHa/DgwerZs6f9ECsAAP9mmzZtUv369VW/fn1Jl+4rV79+fb344ouSpNmzZ6tx48bq0aOHateurYkTJ+rll19W//79JV06evXdd9+pTJkyat++vcLCwjRr1ix99NFHuvfeex1eKyYmRs2bN79hkz/FVZHNzMXExCgyMlK+vr7Z1nXu3FmTJk3Szz//fENquf/++zV06FANGjRIaWlpateunV544QWNHTvWoaZ58+bprrvuUlJSkmJjY9WnTx+Hfjw9PbV48WI99dRTaty4sTw9PdW5c2f7XxsAAPzbhYeHZ7srxeUCAwOz3R7sSjVq1HD4jw+5+eyzz667vn8jm8nrO45iKSUl5dJVrUPmysnds6jLAQBAByZe/39xutlkfX4nJydf90WWeSnyW5MAAAAg/whzAAAAFkaYAwAAsDDCHAAAgIUR5gAAACyMMAcAAGBhhDkAAAALI8wBAABYGGEOAADAwghzAAAAFkaYAwAAsDDCHAAAgIUR5gAAACyMMAcAAGBhhDkAAAALI8wBAABYmEtRF4D82zEuSj4+PkVdBgAAKELMzAEAAFgYYQ4AAMDCCHMAAAAWRpgDAACwMMIcAACAheU7zGVkZGjp0qV699139ffff0uSjhw5otTU1AIrDgAA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Hhrkvr165sff/zRrFmzxtSoUcPh1hZJSUmmXLlypmfPnmbHjh1m9uzZxtPT84bc2iKv8V24cMHcf//9pkKFCiYhIcHh5zHrSsB169aZN954wyQkJJh9+/aZTz75xJQpU8b06tWr2I/v77//NsOHDzfr1683+/fvN0uXLjUNGjQwNWrUMOfPn7f3YdX9lyU5Odl4enqamTNnZtu+OO+/q30WGFMwvy+zbk0yYsQIs3v3bjNjxgxuTYLiZdq0aaZixYrGzc3NNGnSxGzYsKGoS7oqSTk+YmNjjTHGHDp0yNx5553G39/fuLu7m+rVq5sRI0Y43KvMGGMOHDhg2rZtazw8PEzp0qXN008/bdLT04tgRI66du1qgoKCjJubmylfvrzp2rWr2bt3r339uXPnzBNPPGFKlSplPD09zQMPPGCOHj3q0EdxHVuWxYsXG0kmMTHRYbkV9118fHyO78fevXsbYy7dnuSFF14w5cqVM+7u7iYiIiLbuE+dOmWio6ONl5eX8fHxMX379jV///23Q5tt27aZli1bGnd3d1O+fHkzceLEIh/f/v37c/15zLpv4ObNm03Tpk2Nr6+vKVGihKlVq5Z55ZVXHMJQcR3f2bNnTevWrU2ZMmWMq6urqVSpknn00Uez/cFr1f2X5d133zUeHh4mKSkp2/bFef9d7bPAmIL7fRkfH29uu+024+bmZqpWrerwGv82NmOMKaRJPwAAABQyzpkDAACwMMIcAACAhRHmAAAALIwwBwAAYGGEOQAAAAsjzAEAAFgYYQ4AAMDCCHMAAAAWRpgDAACwMMIcAACAhRHmAAAALOz/AC/KJgjT4tLPAAAAAElFTkSuQmCC",
|
| 397 |
+
"text/plain": [
|
| 398 |
+
"<Figure size 640x480 with 1 Axes>"
|
| 399 |
+
]
|
| 400 |
+
},
|
| 401 |
+
"metadata": {},
|
| 402 |
+
"output_type": "display_data"
|
| 403 |
+
}
|
| 404 |
+
],
|
| 405 |
+
"source": [
|
| 406 |
+
"ax = movies['genre'].value_counts().plot.barh()\n",
|
| 407 |
+
"ax.bar_label(ax.containers[0])\n",
|
| 408 |
+
"plt.title('Frequency of Movie Labels')\n",
|
| 409 |
+
"plt.show()"
|
| 410 |
+
]
|
| 411 |
+
},
|
| 412 |
+
{
|
| 413 |
+
"cell_type": "code",
|
| 414 |
+
"execution_count": 9,
|
| 415 |
+
"id": "a0adb2d4-a0a1-415c-bb1a-a4c089477112",
|
| 416 |
+
"metadata": {
|
| 417 |
+
"ExecuteTime": {
|
| 418 |
+
"end_time": "2024-12-02T15:41:23.653792Z",
|
| 419 |
+
"start_time": "2024-12-02T15:41:23.647865Z"
|
| 420 |
+
}
|
| 421 |
+
},
|
| 422 |
+
"outputs": [],
|
| 423 |
+
"source": [
|
| 424 |
+
"movie_label_ids = {'Action': 0, 'Romance': 1, 'Thriller': 2, 'Animation': 3}\n",
|
| 425 |
+
"\n",
|
| 426 |
+
"movie_labels = movies['genre'].apply(lambda g: movie_label_ids[g]).values\n",
|
| 427 |
+
"movie_labels = movie_labels.astype(np.int8)\n",
|
| 428 |
+
"data['movie_labels'] = movie_labels"
|
| 429 |
+
]
|
| 430 |
+
},
|
| 431 |
+
{
|
| 432 |
+
"cell_type": "markdown",
|
| 433 |
+
"id": "970ce294-9848-4dc7-a2c9-0f3f4d6337aa",
|
| 434 |
+
"metadata": {},
|
| 435 |
+
"source": [
|
| 436 |
+
"## Node Features\n",
|
| 437 |
+
"\n",
|
| 438 |
+
"We generate embeddings as features for each node in the graph. Node embeddings are generated by passing the movie overviews through a Sentence-BERT model and obtaining a 384-embedding vector for each movie node.\n",
|
| 439 |
+
"\n",
|
| 440 |
+
"\n",
|
| 441 |
+
"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",
|
| 442 |
+
"\n",
|
| 443 |
+
"all-MiniLM-L6-v2\n",
|
| 444 |
+
"\n",
|
| 445 |
+
"Description:\tAll-round model tuned for many use-cases. Trained on a large and diverse dataset of over 1 billion training pairs.\n",
|
| 446 |
+
"Base Model:\tnreimers/MiniLM-L6-H384-uncased\n",
|
| 447 |
+
"Max Sequence Length:\t256\n",
|
| 448 |
+
"Dimensions:\t384\n",
|
| 449 |
+
"Normalized Embeddings:\ttrue\n",
|
| 450 |
+
"Suitable Score Functions:\tdot-product (util.dot_score), cosine-similarity (util.cos_sim), euclidean distance\n",
|
| 451 |
+
"Size:\t80 MB\n",
|
| 452 |
+
"Pooling:\tMean Pooling\n",
|
| 453 |
+
"Training Data:\t1B+ training pairs. For details, see model card.\n",
|
| 454 |
+
"Model Card:\thttps://huggingface.co/sentence-transformers/all-MiniLM-L6-v2\n"
|
| 455 |
+
]
|
| 456 |
+
},
|
| 457 |
+
{
|
| 458 |
+
"cell_type": "code",
|
| 459 |
+
"execution_count": 10,
|
| 460 |
+
"id": "7ee22ad2-b585-47b1-8399-3bb0b56fa4d3",
|
| 461 |
+
"metadata": {
|
| 462 |
+
"ExecuteTime": {
|
| 463 |
+
"end_time": "2024-06-01T15:04:46.716504Z",
|
| 464 |
+
"start_time": "2024-06-01T15:04:46.404836Z"
|
| 465 |
+
}
|
| 466 |
+
},
|
| 467 |
+
"outputs": [
|
| 468 |
+
{
|
| 469 |
+
"name": "stderr",
|
| 470 |
+
"output_type": "stream",
|
| 471 |
+
"text": [
|
| 472 |
+
"/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",
|
| 473 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
| 474 |
+
]
|
| 475 |
+
},
|
| 476 |
+
{
|
| 477 |
+
"data": {
|
| 478 |
+
"text/plain": [
|
| 479 |
+
"SentenceTransformer(\n",
|
| 480 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
| 481 |
+
" (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",
|
| 482 |
+
" (2): Normalize()\n",
|
| 483 |
+
")"
|
| 484 |
+
]
|
| 485 |
+
},
|
| 486 |
+
"execution_count": 10,
|
| 487 |
+
"metadata": {},
|
| 488 |
+
"output_type": "execute_result"
|
| 489 |
+
}
|
| 490 |
+
],
|
| 491 |
+
"source": [
|
| 492 |
+
"import torch\n",
|
| 493 |
+
"from sentence_transformers import SentenceTransformer\n",
|
| 494 |
+
"\n",
|
| 495 |
+
"device = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n",
|
| 496 |
+
"model = SentenceTransformer('../sentence-transformers/all-MiniLM-L6-v2', device=device)\n",
|
| 497 |
+
"model"
|
| 498 |
+
]
|
| 499 |
+
},
|
| 500 |
+
{
|
| 501 |
+
"cell_type": "code",
|
| 502 |
+
"execution_count": 11,
|
| 503 |
+
"id": "e05e1a93",
|
| 504 |
+
"metadata": {},
|
| 505 |
+
"outputs": [],
|
| 506 |
+
"source": [
|
| 507 |
+
"text = movies['overview']"
|
| 508 |
+
]
|
| 509 |
+
},
|
| 510 |
+
{
|
| 511 |
+
"cell_type": "code",
|
| 512 |
+
"execution_count": 12,
|
| 513 |
+
"id": "3faccc3a-1091-4044-8e6a-1af1e6dfa147",
|
| 514 |
+
"metadata": {
|
| 515 |
+
"ExecuteTime": {
|
| 516 |
+
"end_time": "2024-06-01T15:04:52.986932Z",
|
| 517 |
+
"start_time": "2024-06-01T15:04:49.969544Z"
|
| 518 |
+
}
|
| 519 |
+
},
|
| 520 |
+
"outputs": [
|
| 521 |
+
{
|
| 522 |
+
"name": "stderr",
|
| 523 |
+
"output_type": "stream",
|
| 524 |
+
"text": [
|
| 525 |
+
"Batches: 100%|██████████| 2/2 [00:04<00:00, 2.22s/it]\n"
|
| 526 |
+
]
|
| 527 |
+
}
|
| 528 |
+
],
|
| 529 |
+
"source": [
|
| 530 |
+
"feats = model.encode(text, batch_size=4096, show_progress_bar=True, convert_to_numpy=True)\n",
|
| 531 |
+
"data['movie_feats'] = feats"
|
| 532 |
+
]
|
| 533 |
+
},
|
| 534 |
+
{
|
| 535 |
+
"cell_type": "code",
|
| 536 |
+
"execution_count": 13,
|
| 537 |
+
"id": "bd4dc536-4581-41ea-8c2a-a7d949ee7d29",
|
| 538 |
+
"metadata": {
|
| 539 |
+
"ExecuteTime": {
|
| 540 |
+
"end_time": "2024-06-01T15:05:58.038410Z",
|
| 541 |
+
"start_time": "2024-06-01T15:05:58.031236Z"
|
| 542 |
+
}
|
| 543 |
+
},
|
| 544 |
+
"outputs": [],
|
| 545 |
+
"source": [
|
| 546 |
+
"movie_years = movies['release_date'].apply(lambda s: int(s[:4]))\n",
|
| 547 |
+
"movie_years = movie_years.values.astype(np.int16)\n",
|
| 548 |
+
"data['movie_years'] = movie_years"
|
| 549 |
+
]
|
| 550 |
+
},
|
| 551 |
+
{
|
| 552 |
+
"cell_type": "code",
|
| 553 |
+
"execution_count": 14,
|
| 554 |
+
"id": "f7334c3a1db74c5",
|
| 555 |
+
"metadata": {
|
| 556 |
+
"ExecuteTime": {
|
| 557 |
+
"end_time": "2024-06-01T15:06:10.649671Z",
|
| 558 |
+
"start_time": "2024-06-01T15:06:10.647029Z"
|
| 559 |
+
}
|
| 560 |
+
},
|
| 561 |
+
"outputs": [
|
| 562 |
+
{
|
| 563 |
+
"data": {
|
| 564 |
+
"text/plain": [
|
| 565 |
+
"{'movie-actor': (array([ 0, 0, 0, ..., 7504, 7504, 7504], dtype=int16),\n",
|
| 566 |
+
" array([ 0, 1, 2, ..., 11870, 1733, 11794], dtype=int16)),\n",
|
| 567 |
+
" 'movie-director': (array([ 0, 0, 0, ..., 7503, 7503, 7504], dtype=int16),\n",
|
| 568 |
+
" array([ 0, 1, 2, ..., 3423, 966, 2890], dtype=int16)),\n",
|
| 569 |
+
" 'movie_labels': array([3, 1, 1, ..., 1, 1, 2], dtype=int8),\n",
|
| 570 |
+
" 'movie_feats': array([[ 0.00635284, 0.00649689, 0.01250827, ..., 0.06342042,\n",
|
| 571 |
+
" -0.01747945, 0.0134356 ],\n",
|
| 572 |
+
" [-0.14075027, 0.02825641, 0.02670695, ..., -0.12270895,\n",
|
| 573 |
+
" 0.08417314, 0.02486392],\n",
|
| 574 |
+
" [ 0.00014208, -0.02286632, 0.00615967, ..., -0.03311544,\n",
|
| 575 |
+
" 0.04735276, -0.07458566],\n",
|
| 576 |
+
" ...,\n",
|
| 577 |
+
" [ 0.01835816, 0.07484645, -0.08099765, ..., -0.00150019,\n",
|
| 578 |
+
" 0.01669764, 0.00456595],\n",
|
| 579 |
+
" [-0.00821487, -0.10434289, 0.01928608, ..., -0.06343049,\n",
|
| 580 |
+
" 0.05060194, -0.04229118],\n",
|
| 581 |
+
" [-0.06465845, 0.13461556, -0.01640793, ..., -0.06274845,\n",
|
| 582 |
+
" 0.04002513, -0.00751513]], dtype=float32),\n",
|
| 583 |
+
" 'movie_years': array([2013, 1995, 1989, ..., 1939, 1941, 1965], dtype=int16)}"
|
| 584 |
+
]
|
| 585 |
+
},
|
| 586 |
+
"execution_count": 14,
|
| 587 |
+
"metadata": {},
|
| 588 |
+
"output_type": "execute_result"
|
| 589 |
+
}
|
| 590 |
+
],
|
| 591 |
+
"source": [
|
| 592 |
+
"data"
|
| 593 |
+
]
|
| 594 |
+
},
|
| 595 |
+
{
|
| 596 |
+
"cell_type": "code",
|
| 597 |
+
"execution_count": 15,
|
| 598 |
+
"id": "577568478c17d746",
|
| 599 |
+
"metadata": {
|
| 600 |
+
"ExecuteTime": {
|
| 601 |
+
"end_time": "2024-06-01T15:06:19.797438Z",
|
| 602 |
+
"start_time": "2024-06-01T15:06:19.746897Z"
|
| 603 |
+
}
|
| 604 |
+
},
|
| 605 |
+
"outputs": [],
|
| 606 |
+
"source": [
|
| 607 |
+
"with open('tmdb.pkl', 'wb') as f:\n",
|
| 608 |
+
" pickle.dump(data, f)"
|
| 609 |
+
]
|
| 610 |
+
},
|
| 611 |
+
{
|
| 612 |
+
"cell_type": "code",
|
| 613 |
+
"execution_count": null,
|
| 614 |
+
"id": "d4174a1f7a7c8da1",
|
| 615 |
+
"metadata": {},
|
| 616 |
+
"outputs": [],
|
| 617 |
+
"source": []
|
| 618 |
+
}
|
| 619 |
+
],
|
| 620 |
+
"metadata": {
|
| 621 |
+
"kernelspec": {
|
| 622 |
+
"display_name": "Python 3",
|
| 623 |
+
"language": "python",
|
| 624 |
+
"name": "python3"
|
| 625 |
+
},
|
| 626 |
+
"language_info": {
|
| 627 |
+
"codemirror_mode": {
|
| 628 |
+
"name": "ipython",
|
| 629 |
+
"version": 3
|
| 630 |
+
},
|
| 631 |
+
"file_extension": ".py",
|
| 632 |
+
"mimetype": "text/x-python",
|
| 633 |
+
"name": "python",
|
| 634 |
+
"nbconvert_exporter": "python",
|
| 635 |
+
"pygments_lexer": "ipython3",
|
| 636 |
+
"version": "3.10.12"
|
| 637 |
+
}
|
| 638 |
+
},
|
| 639 |
+
"nbformat": 4,
|
| 640 |
+
"nbformat_minor": 5
|
| 641 |
+
}
|
tmdb/tmdb.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:79bcd9cbf386c72f84757c202cdef8c723507d9228f5495784b8b14d673eac4b
|
| 3 |
+
size 11970178
|
tmdb/tmdb_fetcher.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|