Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Keras and Tensorflow to learn graphic data

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces you how to use Keras and Tensorflow to learn graphic data, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Motivation:

There are a lot of data that can be represented in the form of charts in practical applications, such as citation networks, social networks (follower graphs, friend networks.), biological networks or telecommunications.

The features extracted by Graph can improve the performance of the prediction model by relying on the information flow between adjacent nodes. However, it is not easy to represent graphical data, especially if you do not plan to implement handmade features, because most ML models expect fixed size or linear input, which is not the case with graphical data.

In this article, we will explore some ways to deal with general graphs in order to classify nodes based on graphical representations learned directly from the data.

Dataset:

Referencing the web dataset in Keras will serve as a base for the entire implementation and experimentation of this position. Each node represents a scientific paper, and the edge between the nodes represents the citation relationship between the two papers.

Each node is represented by a set of binary features (word bags) and a set of edges that link it to other nodes.

The dataset has 2708 nodes and is divided into one of seven categories. The network has 5429 links. Each node is also represented by a binary character feature, indicating the existence of the corresponding word. Overall, each node has 1433 binary (sparse) functions. Below we only use 140 samples for training and the rest for verification / testing.

Question setting:

Problem: assign class labels to the nodes in the diagram without training samples.

Intuition / hypothesis: close nodes in the figure are more likely to have similar labels.

Solution: find a way to extract features from the graph to help classify new nodes.

Proposed method:

Baseline model:

Simple baseline model

First, try to use the simplest model, which learns to use only binary features to predict node classes and discard all graphic information. The model is a fully connected neural network, which takes binary features as input and outputs the class probability of each node.

Def get_features_only_model (n_features, n_classes):

In_ = Input ((n_features,))

X = Dense (10, activation= "relu", kernel_regularizer=l1 (0.001)) (in_)

X = Dropout (0.5) (x)

X = Dense (n_classes, activation= "softmax") (x)

Model = Model (in_, x)

Model.compile (loss= "sparse_categorical_crossentropy", metrics= ['acc'], optimizer= "adam")

Model.summary ()

Return model

Accuracy of baseline model: 53.28%

This is the initial accuracy that will be tried to improve by adding graphics-based features.

Add chart functionality:

By training the network on an auxiliary task of predicting the reciprocal of the shortest path length between two input nodes, a method of automatically learning graphic features by embedding each node in a vector, as shown in the following figure and the following code snippet:

Learn the embedding vector of each node

Def get_graph_embedding_model (n_nodes):

In_1 = Input (1,)

In_2 = Input (1,)

Emb = Embedding (n_nodes, 100, name= "node1")

X1 = emb (in_1)

X2 = emb (in_2)

X1 = Flatten () (x1)

X1 = Dropout (0.1) (x1)

X2 = Flatten () (x2)

X2 = Dropout (0.1) (x2)

X = Multiply () ([x1, x2])

X = Dropout (0.1) (x)

X = Dense (1, activation= "linear", name= "spl") (x)

Model = Model ([in_1, in_2], x)

Model.compile (loss= "mae", optimizer= "adam")

Model.summary ()

Return model

The next step is to use pre-trained node embedding as input to the classification model. An additional input is also added using the distance of the learned embedded vector, which is the average binary feature of the adjacent nodes.

The generated classification network is shown in the following figure:

Using pre-training embedding for node classification

Accuracy of graph embedded classification model: 73.06%

It can be seen that adding learning graph features as input to the classification model helps to significantly improve the classification accuracy from 53.28% to 73.06% compared with the baseline model.

Learning to improve graphics functions:

The previous model can be further improved by further promoting the pre-training and using the binary features embedded in the network, and then re-using the pre-training weights from the binary features in addition to the node embedding vectors. This leads the model to rely on a more useful representation of binary features learned from the graph structure.

The accuracy of the improved graph embedding classification model: 76.35%

Compared with the previous method, this additional improvement increases by several percentage points.

On how to use Keras and Tensorflow to learn graphics data sharing here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report