This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git


The following commit(s) were added to refs/heads/main by this push:
     new 9f8ba3d  fix(ml): handle pylint warning (#113)
9f8ba3d is described below

commit 9f8ba3d5195149659ab35ed0293c379a197608d5
Author: SoJ <[email protected]>
AuthorDate: Sat Nov 16 14:34:15 2024 +0800

    fix(ml): handle pylint warning (#113)
---
 .../examples/correct_and_smooth_example.py         | 25 +++++-----------
 .../src/hugegraph_ml/examples/gatne_example.py     |  2 +-
 hugegraph-ml/src/hugegraph_ml/models/agnn.py       |  8 +++---
 hugegraph-ml/src/hugegraph_ml/models/appnp.py      |  2 +-
 hugegraph-ml/src/hugegraph_ml/models/arma.py       |  2 ++
 hugegraph-ml/src/hugegraph_ml/models/bgnn.py       | 33 ++--------------------
 hugegraph-ml/src/hugegraph_ml/models/bgrl.py       | 14 ++++-----
 hugegraph-ml/src/hugegraph_ml/models/care_gnn.py   |  2 ++
 .../src/hugegraph_ml/models/cluster_gcn.py         |  6 ++--
 .../src/hugegraph_ml/models/correct_and_smooth.py  |  7 ++---
 hugegraph-ml/src/hugegraph_ml/models/dagnn.py      |  6 ++--
 hugegraph-ml/src/hugegraph_ml/models/deepergcn.py  | 17 ++---------
 hugegraph-ml/src/hugegraph_ml/models/gatne.py      |  4 ++-
 hugegraph-ml/src/hugegraph_ml/models/pgnn.py       |  4 ++-
 hugegraph-ml/src/hugegraph_ml/models/seal.py       |  2 ++
 .../hugegraph_ml/tasks/fraud_detector_caregnn.py   |  7 +++--
 .../src/tests/test_examples/test_examples.py       |  4 +--
 17 files changed, 52 insertions(+), 93 deletions(-)

diff --git 
a/hugegraph-ml/src/hugegraph_ml/examples/correct_and_smooth_example.py 
b/hugegraph-ml/src/hugegraph_ml/examples/correct_and_smooth_example.py
index 6faae7f..aa09808 100644
--- a/hugegraph-ml/src/hugegraph_ml/examples/correct_and_smooth_example.py
+++ b/hugegraph-ml/src/hugegraph_ml/examples/correct_and_smooth_example.py
@@ -24,28 +24,17 @@ import argparse
 def cs_example(n_epochs=200):
     hg2d = HugeGraph2DGL()
     graph = hg2d.convert_graph(vertex_label="CORA_vertex", 
edge_label="CORA_edge")
-    if args.model == "mlp":
-        model = MLP(
-            in_dim=graph.ndata["feat"].shape[1],
-            hid_dim=64,
-            out_dim=graph.ndata["label"].unique().shape[0],
-            num_layers=3,
-            dropout=0.4,
-        )
-    elif args.model == "linear":
-        model = MLPLinear(
-            in_dim=graph.ndata["feat"].shape[1],
-            out_dim=graph.ndata["label"].unique().shape[0],
-        )
-    else:
-        raise NotImplementedError(f"Model {args.model} is not supported.")
+    model = MLP(
+        in_dim=graph.ndata["feat"].shape[1],
+        hid_dim=64,
+        out_dim=graph.ndata["label"].unique().shape[0],
+        num_layers=3,
+        dropout=0.4,
+    )
     node_clf_task = NodeClassify(graph, model)
     node_clf_task.train(lr=0.005, weight_decay=0.0005, n_epochs=n_epochs, 
patience=200)
     print(node_clf_task.evaluate())
 
 
 if __name__ == "__main__":
-    parser = argparse.ArgumentParser(description="Base predictor(C&S)")
-    parser.add_argument("--model", type=str, default="mlp", choices=["mlp", 
"linear"])
-    args = parser.parse_args()
     cs_example()
diff --git a/hugegraph-ml/src/hugegraph_ml/examples/gatne_example.py 
b/hugegraph-ml/src/hugegraph_ml/examples/gatne_example.py
index 0c9c0c5..6a994f0 100644
--- a/hugegraph-ml/src/hugegraph_ml/examples/gatne_example.py
+++ b/hugegraph-ml/src/hugegraph_ml/examples/gatne_example.py
@@ -39,7 +39,7 @@ def gatne_example(n_epochs=200):
         20,
     )
     gatne_task = HeteroSampleEmbedGATNE(graph, model)
-    embs = gatne_task.train_and_embed(lr=0.005, n_epochs=n_epochs)
+    gatne_task.train_and_embed(lr=0.005, n_epochs=n_epochs)
 
 
 if __name__ == "__main__":
diff --git a/hugegraph-ml/src/hugegraph_ml/models/agnn.py 
b/hugegraph-ml/src/hugegraph_ml/models/agnn.py
index b3c3767..e693ddf 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/agnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/agnn.py
@@ -25,10 +25,10 @@ Author's code:
 DGL code: 
https://github.com/dmlc/dgl/blob/master/python/dgl/nn/pytorch/conv/agnnconv.py
 """
 
-import dgl
-import torch
+
+
 from dgl.nn.pytorch.conv import AGNNConv
-import torch.nn as nn
+from torch import nn
 import torch.nn.functional as F
 
 
@@ -40,7 +40,7 @@ class AGNN(nn.Module):
 
         self.attention_layers = nn.ModuleList()
         # 2-layer AGNN
-        for i in range(self.num_layers):
+        for _ in range(self.num_layers):
             self.attention_layers.append(AGNNConv())
 
         self.output_layer = nn.Linear(hid_dim, out_dim, bias=False)
diff --git a/hugegraph-ml/src/hugegraph_ml/models/appnp.py 
b/hugegraph-ml/src/hugegraph_ml/models/appnp.py
index 04cb19d..8c65daa 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/appnp.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/appnp.py
@@ -25,7 +25,7 @@ Author's code: https://github.com/klicperajo/ppnp
 DGL code: https://github.com/dmlc/dgl/tree/master/examples/pytorch/appnp
 """
 
-import torch.nn as nn
+from torch import nn
 
 from dgl.nn.pytorch.conv import APPNPConv
 
diff --git a/hugegraph-ml/src/hugegraph_ml/models/arma.py 
b/hugegraph-ml/src/hugegraph_ml/models/arma.py
index 7b07c68..76ca096 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/arma.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/arma.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.right (c) 2024 by jinsong, All Rights Reserved.
 
+# pylint: disable=E1101
+
 """
 auto-regressive moving average (ARMA)
 
diff --git a/hugegraph-ml/src/hugegraph_ml/models/bgnn.py 
b/hugegraph-ml/src/hugegraph_ml/models/bgnn.py
index 3db380d..b137043 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/bgnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/bgnn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1102,E0401,E0711,E0606,E0602
+
 """
 Boost-GNN (BGNN)
 
@@ -28,7 +30,7 @@ DGL code: 
https://github.com/dmlc/dgl/tree/master/examples/pytorch/bgnn
 import itertools
 import time
 from collections import defaultdict as ddict
-
+import dgl
 import numpy as np
 import pandas as pd
 import torch
@@ -650,35 +652,6 @@ class GNNModelDGL(torch.nn.Module):
 
         return logits
 
-
-def read_input(input_folder):
-    X = pd.read_csv(f"{input_folder}/X.csv")
-    y = pd.read_csv(f"{input_folder}/y.csv")
-
-    categorical_columns = []
-    if os.path.exists(f"{input_folder}/cat_features.txt"):
-        with open(f"{input_folder}/cat_features.txt") as f:
-            for line in f:
-                if line.strip():
-                    categorical_columns.append(line.strip())
-
-    cat_features = None
-    if categorical_columns:
-        columns = X.columns
-        cat_features = np.where(columns.isin(categorical_columns))[0]
-
-        for col in list(columns[cat_features]):
-            X[col] = X[col].astype(str)
-
-    gs, _ = load_graphs(f"{input_folder}/graph.dgl")
-    graph = gs[0]
-
-    with open(f"{input_folder}/masks.json") as f:
-        masks = json.load(f)
-
-    return graph, X, y, cat_features, masks
-
-
 def normalize_features(X, train_mask, val_mask, test_mask):
     min_max_scaler = preprocessing.MinMaxScaler()
     A = X.to_numpy(copy=True)
diff --git a/hugegraph-ml/src/hugegraph_ml/models/bgrl.py 
b/hugegraph-ml/src/hugegraph_ml/models/bgrl.py
index 6d991ee..ed87a43 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/bgrl.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/bgrl.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.right (c) 2024 by jinsong, All Rights Reserved.
 
+# pylint: disable=E1102
+
 """
 Bootstrapped Graph Latents (BGRL)
 
@@ -26,16 +28,14 @@ DGL code: 
https://github.com/dmlc/dgl/tree/master/examples/pytorch/bgrl
 """
 
 import copy
-
-import dgl
-
 import torch
-from dgl.nn.pytorch.conv import GraphConv, SAGEConv
 from torch import nn
-from torch.nn import BatchNorm1d, Parameter
-from torch.nn.init import ones_, zeros_
-from dgl.transforms import Compose, DropEdge, FeatMask
+from torch.nn import BatchNorm1d
 from torch.nn.functional import cosine_similarity
+import dgl
+from dgl.nn.pytorch.conv import GraphConv
+from dgl.transforms import Compose, DropEdge, FeatMask
+import numpy as np
 
 class MLP_Predictor(nn.Module):
     r"""MLP used for predictor. The MLP has one hidden layer.
diff --git a/hugegraph-ml/src/hugegraph_ml/models/care_gnn.py 
b/hugegraph-ml/src/hugegraph_ml/models/care_gnn.py
index 7046569..84e850f 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/care_gnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/care_gnn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1101
+
 """
 CAmouflage-REsistant GNN (CARE-GNN)
 
diff --git a/hugegraph-ml/src/hugegraph_ml/models/cluster_gcn.py 
b/hugegraph-ml/src/hugegraph_ml/models/cluster_gcn.py
index ce4fb94..09fd04a 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/cluster_gcn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/cluster_gcn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1101,E0401
+
 """
 Cluster-GCN
 
@@ -25,13 +27,9 @@ Author's code: 
https://github.com/google-research/google-research/tree/master/cl
 DGL code: https://github.com/dmlc/dgl/tree/master/examples/pytorch/cluster_gcn
 """
 
-import dgl
 import dgl.nn as dglnn
-import torch
 import torch.nn as nn
 import torch.nn.functional as F
-import torchmetrics.functional as MF
-
 
 class SAGE(nn.Module):
     def __init__(self, in_feats, n_hidden, n_classes):
diff --git a/hugegraph-ml/src/hugegraph_ml/models/correct_and_smooth.py 
b/hugegraph-ml/src/hugegraph_ml/models/correct_and_smooth.py
index 34f8ec7..70b8f9e 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/correct_and_smooth.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/correct_and_smooth.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1101,E1102
+
 """
  Correct and Smooth (C&S)
 
@@ -27,7 +29,7 @@ DGL code: 
https://github.com/dmlc/dgl/tree/master/examples/pytorch/correct_and_s
 
 import dgl.function as fn
 import torch
-import torch.nn as nn
+from torch import nn
 import torch.nn.functional as F
 
 
@@ -98,8 +100,6 @@ class LabelPropagation(nn.Module):
 
     Description
     -----------
-    Introduced in `Learning from Labeled and Unlabeled Data with Label 
Propagation 
<https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.14.3864&rep=rep1&type=pdf>`_
-
     .. math::
         \mathbf{Y}^{\prime} = \alpha \cdot \mathbf{D}^{-1/2} \mathbf{A}
         \mathbf{D}^{-1/2} \mathbf{Y} + (1 - \alpha) \mathbf{Y},
@@ -166,7 +166,6 @@ class CorrectAndSmooth(nn.Module):
 
     Description
     -----------
-    Introduced in `Combining Label Propagation and Simple Models Out-performs 
Graph Neural Networks <https://arxiv.org/abs/2010.13993>`_
 
     Parameters
     ----------
diff --git a/hugegraph-ml/src/hugegraph_ml/models/dagnn.py 
b/hugegraph-ml/src/hugegraph_ml/models/dagnn.py
index 2e9d260..8afd8db 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/dagnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/dagnn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1101
+
 """
 Deep Adaptive Graph Neural Network (DAGNN)
 
@@ -26,12 +28,10 @@ DGL code: 
https://github.com/dmlc/dgl/tree/master/examples/pytorch/dagnn
 """
 
 import dgl.function as fn
-
-import numpy as np
 import torch
 from torch import nn
 from torch.nn import functional as F, Parameter
-import random
+
 
 
 class DAGNNConv(nn.Module):
diff --git a/hugegraph-ml/src/hugegraph_ml/models/deepergcn.py 
b/hugegraph-ml/src/hugegraph_ml/models/deepergcn.py
index 03fc292..0781ded 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/deepergcn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/deepergcn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+
+
 """
 DeeperGCN
 
@@ -30,17 +32,15 @@ import torch.nn as nn
 import torch.nn.functional as F
 from dgl.nn.functional import edge_softmax
 from dgl.nn.pytorch.glob import AvgPooling
-from ogb.graphproppred.mol_encoder import AtomEncoder, BondEncoder
 import torch
 
+# pylint: disable=E1101,E0401
 
 class DeeperGCN(nn.Module):
     r"""
 
     Description
     -----------
-    Introduced in "DeeperGCN: All You Need to Train Deeper GCNs 
<https://arxiv.org/abs/2006.07739>"
-
     Parameters
     ----------
     node_feat_dim: int
@@ -137,8 +137,6 @@ class GENConv(nn.Module):
 
     Description
     -----------
-    Generalized Message Aggregator was introduced in "DeeperGCN: All You Need 
to Train Deeper GCNs <https://arxiv.org/abs/2006.07739>"
-
     Parameters
     ----------
     in_dim: int
@@ -244,13 +242,6 @@ class GENConv(nn.Module):
 
 
 class MLP(nn.Sequential):
-    r"""
-
-    Description
-    -----------
-    From equation (5) in "DeeperGCN: All You Need to Train Deeper GCNs 
<https://arxiv.org/abs/2006.07739>"
-    """
-
     def __init__(self, channels, act="relu", dropout=0.0, bias=True):
         layers = []
 
@@ -269,8 +260,6 @@ class MessageNorm(nn.Module):
 
     Description
     -----------
-    Message normalization was introduced in "DeeperGCN: All You Need to Train 
Deeper GCNs <https://arxiv.org/abs/2006.07739>"
-
     Parameters
     ----------
     learn_scale: bool
diff --git a/hugegraph-ml/src/hugegraph_ml/models/gatne.py 
b/hugegraph-ml/src/hugegraph_ml/models/gatne.py
index 794d1cc..b0fe329 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/gatne.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/gatne.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.right (c) 2024 by jinsong, All Rights Reserved.
 
+# pylint: disable=E1101
+
 """
 General Attributed Multiplex HeTerogeneous Network Embedding (GATNE)
 
@@ -33,7 +35,7 @@ from collections import defaultdict
 
 import numpy as np
 import torch
-import torch.nn as nn
+from torch import nn
 import torch.nn.functional as F
 from numpy import random
 from torch.nn.parameter import Parameter
diff --git a/hugegraph-ml/src/hugegraph_ml/models/pgnn.py 
b/hugegraph-ml/src/hugegraph_ml/models/pgnn.py
index de0f740..1c6dcb5 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/pgnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/pgnn.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E1101,E0401
+
 """
 Position-aware Graph Neural Networks (P-GNN)
 
@@ -27,7 +29,7 @@ DGL code: 
https://github.com/dmlc/dgl/tree/master/examples/pytorch/P-GNN
 
 import dgl.function as fn
 import torch
-import torch.nn as nn
+from torch import nn
 import torch.nn.functional as F
 import multiprocessing as mp
 import random
diff --git a/hugegraph-ml/src/hugegraph_ml/models/seal.py 
b/hugegraph-ml/src/hugegraph_ml/models/seal.py
index 09060ed..3c167c5 100644
--- a/hugegraph-ml/src/hugegraph_ml/models/seal.py
+++ b/hugegraph-ml/src/hugegraph_ml/models/seal.py
@@ -15,6 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E0401
+
 """
 SEAL
 
diff --git a/hugegraph-ml/src/hugegraph_ml/tasks/fraud_detector_caregnn.py 
b/hugegraph-ml/src/hugegraph_ml/tasks/fraud_detector_caregnn.py
index fe14d6d..632cfe3 100644
--- a/hugegraph-ml/src/hugegraph_ml/tasks/fraud_detector_caregnn.py
+++ b/hugegraph-ml/src/hugegraph_ml/tasks/fraud_detector_caregnn.py
@@ -15,12 +15,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
+# pylint: disable=E0401
+
 import torch
-from dgl import DGLGraph
 from torch import nn
-from sklearn.metrics import recall_score, roc_auc_score
 from torch.nn.functional import softmax
-
+from dgl import DGLGraph
+from sklearn.metrics import recall_score, roc_auc_score
 
 class DetectorCaregnn:
     def __init__(self, graph: DGLGraph, model: nn.Module):
diff --git a/hugegraph-ml/src/tests/test_examples/test_examples.py 
b/hugegraph-ml/src/tests/test_examples/test_examples.py
index 861b240..4adca94 100644
--- a/hugegraph-ml/src/tests/test_examples/test_examples.py
+++ b/hugegraph-ml/src/tests/test_examples/test_examples.py
@@ -96,13 +96,13 @@ class TestHugegraph2DGL(unittest.TestCase):
 
     def test_bgnn_example(self):
         try:
-            bgnn_example(n_epochs=self.test_n_epochs)
+            bgnn_example()
         except ValueError:
             self.fail("model bgnn example failed")
 
     def test_bgrl_example(self):
         try:
-            bgrl_example(n_epochs=self.test_n_epochs)
+            bgrl_example(n_epochs_embed=self.test_n_epochs, 
n_epochs_clf=self.test_n_epochs)
         except ValueError:
             self.fail("model bgrl example failed")
 

Reply via email to