from typing import Callable, Dict, List, Tupleimport dglimport dgl.function as fnimport torchdef collate(samples: List[Tuple[dgl.DGLGraph, str]]) -> Tuple[dgl.BatchedDGLGraph, torch.Tensor]:"""To form a mini-batch from a given list of graph and label pairs.Args:samples (List[Tuple[dgl.DGLGraph, str]]): A list of pairs,(graph, label).Returns:Tuple[dgl.BatchedDGLGraph, torch.Tensor]: A pair of batched graphand tensor-transformed labels."""graphs, labels = map(list, zip(*samples))batched_graph = dgl.batch(graphs)return batched_graph, torch.tensor(labels)def reduce(nodes: dgl.DGLGraph.nodes) -> Dict[str, torch.Tensor]:"""Take an average over all neighbor node features h_u and use itto overwrite the original node feature.Args:nodes (dgl.DGLGraph.nodes): Specified node to take an averageover all neighbor node features.Returns:torch.Tensor: Accumulated hidden feature (vector)."""accumulated = torch.mean(nodes.mailbox['m'], 1)return {'h': accumulated}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。