torch-geometric
Fungsinya
Tool ini membantu membangun model graph neural network, yaitu seperti diagram yang berisi hubungan. Tool ini digunakan untuk menganalisis data di mana hubungan antar item itu penting, misalnya di jejaring sosial atau sistem rekomendasi.
Kapan dipakai
- βSaat bekerja dengan graph neural network di PyTorch.
- βUntuk mengklasifikasikan node, tautan, atau seluruh graf.
- βSaat menggunakan model seperti GCN, GAT, atau GraphSAGE.
Link skill
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/torch-geometric/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βBagaimana cara menggunakan PyTorch Geometric untuk melatih model klasifikasi node pada sebuah graf?β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Tool ini menyediakan blok pembangun (layer) dan struktur data siap pakai untuk merepresentasikan graf serta menerapkan algoritma machine learning padanya. Anda mendefinisikan cara data graf diatur, lalu menggunakan layer tersebut untuk memproses informasinya.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
PyTorch Geometric (PyG)
PyG is the standard library for Graph Neural Networks built on PyTorch. It provides data structures for graphs, 60+ GNN layer implementations, scalable mini-batch training, and support for heterogeneous graphs.
Installation
Reviewed released torch-geometric 2.8.0.post1 (2026-10-01); CPU examples tested with Python 3.13 / PyTorch 2.14.1. Rolling latest docs identify 2.9.0; check the installed release before adopting new APIs. PyG 2.8 requires PyTorch 2.9+; its original release table covers 2.9β2.12. Our 2.14.1 core tests do not establish every extension/backend combination.
# Install the PyTorch build for your platform from https://pytorch.org/get-started/locally/
uv pip install torch==2.14.1
uv pip install torch-geometric==2.8.0.post1
python -c "import torch, torch_geometric; print(torch.__version__, torch.version.cuda, torch_geometric.__version__)"
Basic tensor-based layers need no extensions. Neighbor sampling requires pyg-lib or torch-sparse; spatial k-NN operators require pyg-lib in 2.8. torch-cluster and torch-spline-conv are deprecated and ignored. Inspect the wheel index for your exact Python/OS/Torch/CUDA tuple. Never install wheels for a different Torch release merely because core imports succeed. The tested macOS ARM CPU extension is below; choose a different matching wheel for other platforms, and verify its operators:
uv pip install --only-binary=:all: "pyg-lib==0.9.0+pt214" \
-f https://data.pyg.org/whl/torch-2.14.0+cpu.html
Conda packages are no longer provided for Torch >2.5. See installation and 2.8 release changes. Optional sampling/GPU/distributed/download examples below are illustrative unless covered by the CPU checks in review notes.
Core Concepts
Graph Data: Data and HeteroData
A graph lives in a Data object. The key attributes:
from torch_geometric.data import Data
data = Data(
x=node_features, # [num_nodes, num_node_features]
edge_index=edge_index, # [2, num_edges] β COO format, dtype=torch.long
edge_attr=edge_features, # [num_edges, num_edge_features]
y=labels, # node-level [num_nodes, *] or graph-level [1, *]
pos=positions, # [num_nodes, num_dimensions] (for point clouds/spatial)
)
edge_index format is critical: it's a [2, num_edges] tensor where edge_index[0] = source nodes, edge_index[1] = target nodes. It is NOT a list of tuples. If you have edge pairs as rows, transpose and call .contiguous():
# If edges are [[src1, dst1], [src2, dst2], ...] β transpose first:
edge_index = edge_pairs.t().contiguous()
For undirected graphs, include both directions: edge (0,1) needs both [0,1] and [1,0] in edge_index.
If node features are absent, set data.num_nodes explicitly from the node table. Inferring it from edge_index.max() + 1 misses isolated nodes, which can corrupt batching offsets and outputs. Check data.validate(raise_on_error=True) after construction, including an edge-free or isolated-node case.
For heterogeneous graphs, use HeteroData β see the Heterogeneous Graphs section below.
Datasets
PyG bundles many standard datasets that auto-download and preprocess:
from torch_geometric.datasets import Planetoid, TUDataset
# Single-graph node classification (Cora, Citeseer, Pubmed)
dataset = Planetoid(root='./data/Cora', name='Cora', split='public')
data = dataset[0] # single graph with train/val/test masks
# Multi-graph classification (ENZYMES, MUTAG, IMDB-BINARY, etc.)
dataset = TUDataset(root='./data/TU', name='ENZYMES')
# dataset[0], dataset[1], ... are individual graphs
Common datasets by task:
- Node classification: Planetoid (Cora/Citeseer/Pubmed), OGB (ogbn-arxiv, ogbn-products, ogbn-mag)
- Graph classification: TUDataset (MUTAG, ENZYMES, PROTEINS, IMDB-BINARY), OGB (ogbg-molhiv)
- Link prediction: OGB (ogbl-collab, ogbl-citation2)
- Molecular: QM7b, QM9, MoleculeNet
- Point cloud/mesh: ShapeNet, ModelNet(name="10" or "40"), FAUST (manual download)
β¦
Pertanyaan umum
Apa itu graf dalam data science?
Graf adalah struktur yang merepresentasikan hubungan. Graf memiliki 'node' (item) dan 'edge' (hubungan antar item).
Apa itu graph neural network (GNN)?
Itu adalah jenis kecerdasan buatan yang belajar dari data berbentuk graf, sehingga memahami hubungan antar item.
Apa perbedaan antara `Data` dan `HeteroData`?
`Data` untuk graf sederhana di mana semua node dan edge bertipe sama. `HeteroData` untuk graf yang lebih kompleks dengan berbagai tipe node dan edge.
Detail
Deskripsi asli dari pembuat
Supports PyTorch Geometric (PyG) graph neural networks β node/link/graph classification, message passing (GCN, GAT, GraphSAGE, GIN), heterogeneous graphs, neighbor sampling, and custom datasets. Use when working with torch_geometric, not for general NetworkX analytics or non-graph PyTorch models.
Popularitas
- Bintang GitHub
- 51k
- Peringkat
- #3584
- Lisensi
- MIT
- Diperbarui
- 15/10/2026
Komentar
- β¦
Skill lain dari repositori ini
13c-metabolic-flux
51kMemperkirakan fluks metabolik menggunakan data pelacakan isotop karbon-13. Berguna untuk menganalisis metabolisme seluler dan jalur biokimia.
adaptyv
51kMerancang eksperimen karakterisasi protein menggunakan Adaptyv API. Membantu memperkirakan biaya, mengirimkan sekuens, dan memantau hasil lab.
aeon
51kMenjalankan tugas machine learning pada data time series. Berguna untuk klasifikasi, peramalan, deteksi anomali, dan menemukan pola dalam data berurutan.
alphagenome
51kMencari efek genomik yang sudah dihitung untuk varian genetik. Memberikan skor dan penjelasan untuk memahami dampak varian terhadap genom.
Skill serupa
pytorch-patterns
280kMembantu agent Anda menggunakan PyTorch untuk model machine learning. Menerapkan praktik terbaik untuk pelatihan model yang efisien dan hasil yang dapat direproduksi.
evm-token-decimals
280kMembantu agent menghindari kesalahan angka desimal di berbagai jaringan blockchain. Memastikan nilai token akurat dalam transaksi dan perhitungan.
ito-inference
280kMemungkinkan agent Anda mengecek ketersediaan model AI untuk digunakan. Menghubungkan permintaan komputasi dengan layanan model yang siap.