DSP Unit 5
DSP Unit 5
Graph is the mathematical term used to refer to a network. Thus, the field that
studies networks is called graph theory and it provides the tools necessary to analyze
networks. Leonhard Euler defined the first graph in 1735, as an abstraction of one
of the problems posed by mathematicians of the time regarding Konigsberg, a city
withtwo islands created by the River Pregel, which was crossed by seven bridges.
The problem was: is it possible to walk through the town of Konigsberg crossing
each bridge once and only once? Euler represented the land areas as nodes and the
bridges connecting them as edges of a graph and proved that the walk was not
possible forthis particular graph.
A graph is defined as a set of nodes, which are an abstraction of any entities
(parts of a city, persons, etc.), and the connecting links between pairs of nodes called
edges or relationships. The edge between two nodes can be directed or undirected.A
directed edge means that the edge points from one node to the other and not the
other way round. An example of a directed relationship is “a person knows another
person”. An edge has a direction when person A knows person B, and not the reverse
direction
Basic
Definitions in Graphs 143
if B does not know A (which is usual for many fans and celebrities). An undirected
edge means that there is a symmetric relationship. An example is “a person
shook hands with another person”; in this case, the relationship, unavoidably,
involves both persons and there is no directionality. Depending on whether the edges
of a graph are directed or undirected, the graph is called a directed graph or an
undirected graph,respectively.
The degree of a node is the number of edges that connect to it. Figure 8.1
shows an example of an undirected graph with 5 nodes and 5 edges. The degree
of node Cis 1, while the degree of nodes A, D and E is 2 and for node B it is 3. If a
network is directed, then nodes have two different degrees, the in-degree, which
is the number of incoming edges, and the out-degree, which is the number of
outgoing edges.
In some cases, there is information we would like to add to graphs to model
properties of the entities that the nodes represent or their relationships. We could
add strengths or weights to the links between the nodes, to represent some real-
world measure. For instance, the length of the highways connecting the cities in a
network.In this case, the graph is called a weighted graph.
Some other elementary concepts that are useful in graph analysis are those
weexplain in what follows. We define a path in a network to be a sequence of
nodesconnected by edges. Moreover, many applications of graphs require
shortest pathsto be computed. The shortest path problem is the problem of
finding a path betweentwo nodes in a graph such that the length of the path or
the sum of the weights ofedges in the path is minimized. In the example in Fig. 8.1,
the paths (C, A, B, E) and(C, A, B, D, E) are those between nodes C and E. This
graph is unweighted, so theshortest path between C and E is the one that follows
the fewer edges: (C, A, B, E).A graph is said to be connected if for every pair of
nodes, there is a path between them. A graph is fully connected or complete if
each pair of nodes is connected byan edge. A connected component or simply a
component of a graph is a subset of itsnodes such that every node in the subset has
a path to every other one. In the exampleof Fig. 8.1, the graph has one connected
component. A subgraph is a subset of thenodes of a graph and all the edges
linking those nodes. Any group of nodes can form
a subgraph.
Social Network Analysis
Social network analysis processes social data structured in graphs. It involves the
extraction of several characteristics and graphics to describe the main properties
of the network. Some general properties of networks, such as the shape of the
network degree distribution (defined bellow) or the average path length,
determine the type of network, such as a small-world network or a scale-free
network. A small-world network is a type of graph in which most nodes are not
neighbors of one another, butmost nodes can be reached from every other node
in a small number of steps. This is the so-called small-world phenomenon which
can be interpreted by the fact that strangers are linked by a short chain of
acquaintances. In a small-world network, people usually form communities or
small groups where everyone knows every- one else. Such communities can be
seen as complete graphs. In addition, most the community members have a few
relationships with people outside that community. However, some people are
connected to a large number of communities. These may be celebrities and such
people are considered as the hubs that are responsible for the small-world
phenomenon. Many small-world networks are also scale-free net- = works. In a
scale-free network the node degree distribution follows a power law (a
relationship function between two quantities x and y defined as y x n , where n
is a constant). The name scale-free comes from the fact that power laws have the
same functional form at all scales, i.e., their shape does not change on
multiplication by a scale factor. Thus, by definition, a scale-free network has many
nodes with a very few connections and a small number of nodes with many
connections. This structure is typical of the World Wide Web and other social
networks. In the following sections, we illustrate this and other graph properties
that are useful in social network analysis.
In [1]:
Basics in NetworkX
NetworkX1 is a Python toolbox for the creation, manipulation and study of the
struc- ture, dynamics and functions of complex networks. After importing the
toolbox, wecan create an undirected graph with 5 nodes by adding the edges, as
is done in the following code. The output is the graph in Fig. 8.1.
import ne two rk x as nx
G = nx . Graph ()
G. add _ed ge ( ’A ’, ’B ’);
G. add _ed ge ( ’A ’, ’C ’);
G. add _ed ge ( ’B ’, ’D ’);
G. add _ed ge ( ’B ’, ’E ’);
G. add _ed ge ( ’D ’, ’E ’);
nx . d r aw _n et w or kx ( G)
For our practical case we consider data from the Facebook network. In particular, we
use the data Social circles: Facebook2 from the Stanford Large Network Dataset3
(SNAP) collection. The SNAP collection has links to a great variety of networks
such as Facebook-style social networks, citation networks, Twitter networks or
open communities like Live Journal. The Facebook dataset consists of a network
repre- senting friendship between Facebook users. The Facebook data was
anonymized by replacing the internal Facebook identifiers for each user with a
new value.
The network corresponds to an undirected and unweighted graph that
contains users of Facebook (nodes) and their friendship relations (edges). The
Facebook dataset is defined by an edge list in a plain text file with one edge per
line.
Let us load the Facebook network and start extracting the basic information
In [2]:
from the graph, including the numbers of nodes and edges, and the average
degree:
fb = nx . read_ edgel ist (" files / ch08 / fa ce boo k_ com bi n ed . txt ")
fb_n , fb_k = fb . order () , fb . size ()
fb_avg_ deg = fb_k / fb_n
print ’ Nodes : ’, fb_n
print ’ Edges : ’, fb_k
print ’ Average degree : ’, fb_av g_de g
The graph in Fig. 8.2 is a power-law distribution. Thus, we can say that the Face-
book network is a scale-free network.
Next, let us find out if the Facebook dataset contains more than one
connectedcomponent (previously defined in Sect. 8.2):
As it can be seen, there is only one connected component in the Facebook network.
Thus, the Facebook network is a connected graph (see definition in Sect. 8.2). We can
try to divide the graph into different connected components, which can be
potential communities (see Sect. 8.6). To do that, we can remove one node from
the graph (this operation also involves removing the edges linking the node) and
see if the number of connected components of the graph changes. In the
following code, we prune the graph by removing node ‘0’ (arbitrarily selected) and
compute the number of connected components of the pruned version of the
graph:
In [5]:
fb_prun = nx . read_ edge list (
" files / ch08 / f ac eb o ok _c om bi ne d . txt ")
fb_prun . r emove _node ( ’0 ’)
print ’ Rem ain ing nodes : ’, f b_prun . nu mb er _o f _n od es ()
print ’ New # c onn ect ed com pon ent s : ’,
nx . nu m b er _ c on n e ct e d _c o mp o n en t s ( fb_pru n )
Centrality
The centrality of a node measures its relative importance within the graph. In this
section we focus on undirected graphs. Centrality concepts were first developed
in social network analysis. The first studies indicated that central nodes are
probably more influential, have greater access to information, and can
communicate their opinions to others more efficiently [1]. Thus, the applications
of centrality concepts in a social network include identifying the most influential
people, the most informed people, or the most communicative people. In practice,
what centrality means will depend on the application and the meaning of the
entities represented as nodes in the data and the connections between those
nodes. Various measures of the centrality of a node have been proposed. We
present four of the best-known measures: degree centrality, betweenness
centrality, closeness centrality, and eigenvector centrality.
Degree centrality is defined as the number of edges of the node. So the more
ties a node has, the more central the node is. To achieve a normalized degree
centrality of a node, the measure is divided by the total number of graph nodes (n)
without counting this − particular one (n 1). The normalized measure provides
proportions and allowsus to compare it among graphs. Degree centrality is related
to the capacity of a node to capture any information that is floating through the
network. In social networks,connections are associated with positive aspects such
as knowledge or friendship.
Betweenness centrality quantifies the number of times a node is crossed along
the shortest path/s between any other pair of nodes. For the normalized
measure this number is divided by the total number of shortest paths for every
pair of nodes. Intuitively, if we think of a public bus transportation network, the
bus stop (node) with the highest betweenness has the most traffic. In social
networks, a person with high betweenness has more power in the sense that
more people depend on him/her to make connections with other people or to
access information from other people. Comparing this measure with degree
centrality, we can say that degree centrality depends only on the node’s
neighbors; thus, it is more local than the betweenness centrality, which depends
on the connection properties of every pair of nodes in thegraph, except pairs with
the node in question itself. The equivalent measure exists for edges. The
betweenness centrality of an edge is the proportion of the shortest paths
between all node pairs which pass through it.
Closeness centrality tries to quantify the position a node occupies in the
networkbased on a distance calculation. The distance metric used between a pair
of nodes is defined by the length of its shortest path. The closeness of a node is
inversely proportional to the length of the average shortest path between that
node and all the
other nodes in the graph. In this case, we interpret a central node as being close
to,and able to communicate quickly with, the other nodes in a social network.
Eigenvector centrality defines a relative score for a node based on its
connections and considering that connections from high centrality nodes
contribute more to the score of the node than connections from low centrality
nodes. It is a measure of the influence of a node in a network, in the following
sense: it measures the extent to which a node is connected to influential nodes.
Accordingly, an important node is connected to important neighbors.
Let us illustrate the centrality measures with an example. In Fig. 8.3, we
showan undirected star graph with= n 8 nodes. Node C is obviously important,
since it can exchange information with more nodes than the others. The degree
centrality measures this idea. In this star network, node C has a degree
centrality of 7 or 1 if we consider the normalized measure, whereas all other
nodes have a degree of 1 or 1/7 if we consider the normalized measure. Another
reason why node C is moreimportant than the others in this star network is that it
lies between each of the other pairs of nodes, and no other node lies between C
and any other node. If node C wants to contact F, C can do it directly; whereas if
node F wants to contact B, it must go through C. This gives node C the capacity to
broke/prevent contact amongother nodes and to isolate nodes from information.
The betweenness centrality is underneath this idea. In this example, the
— −
betweenness centrality of the node C is 28, computed as (n 1)(n 2)/2, while the
rest of nodes have a betweenness of 0. The final reason why we can say node C is
superior in the star network is because C is closer to more nodes than any other
node is. In the example, node C is at a distanceof 1 from all other 7 nodes and each
other node is at a distance 2 from all other nodes, except C. So, node − C has
closeness centrality of 1/7, while the rest of nodes have a closeness of 1/13. The
normalized measures, computed by dividing by n 1, are 1 for C and 7/13 for the
other nodes.
An important concept in social network analysis is that of a hub node, which is
defined as a node with high degree centrality and betweenness centrality. When
a hub governs a very centralized network, the network can be easily fragmented
by removing that hub.
Coming back to the Facebook example, let us compute the degree centrality of
Facebook graph nodes. In the code below we show the user identifier of the 10
mostcentral nodes together with their normalized degree centrality measure. We
also show the degree histogram to extract some more information from the
shape of the distribution. It might be useful to represent distributions using
logarithmic scale. We
do that with the matplotlib.loglog() function. Figure 8.4 shows the degree
centrality histogram in linear and logarithmic scales as computed in the box
bellow.
In [7]: degree_ cent_ fb = nx . deg re e_ cen tr ali ty ( fb )
print ’ Facebook degree cent ralit y : ’,
sorted ( de gree_ cent_ fb . items () ,
key = lambda x: x [1] ,
reverse = True ) [:10]
degree_ hist = plt . hist ( list ( d egree _cent _fb . values () ) , 100)
plt . loglog ( degre e_his t [1][1:] ,
degree_ hist [0] , ’b ’, marker = ’o ’)
Fig. 8.4 Degree centrality histogram shown using a linear scale (left) and a log scale for both the
x- and y-axis (right)
150 8 Network Analysis
pose the question: What happen if we only consider the graph nodes with more
than the average degree of the network (21)? We can trim the graph using degree
centrality values. To do this, in the next code, we define a function to trim the
graph based on the degree centrality of the graph nodes. We set the threshold to
21 connections:
In [9]: def t r im _ de gr e e_ c en tr a li t y ( graph , degree = 0.01) :
g = graph . copy ()
d = nx . d eg re e_ ce nt ra l it y ( g)
for n in g. nodes () :
if d[ n] <= degree :
g. r emove _nod e ( n)
return g
thr = 21.0/( fb . order () - 1.0)
The new graph is much smaller; we have removed almost half of the nodes
(we have moved from 4,039 to 2,226 nodes).
The current flow betweenness centrality measure needs connected graphs, as
does any betweenness centrality measure, so we should first extract a connected
compo- nent from the trimmed Facebook network and then compute the
measure:
In [10]: fb_subg raph = list ( nx . co nn e ct e d_ co m po n en t_ s ub g ra p hs (
fb_trim ed ))
print ’# s ubgr aphs found : ’, size ( fb_s ubgra ph )
print ’# nodes in the first s ubgraph : ’,
len ( fb _subg raph [0])
between ness = nx . b et w ee n ne ss _ ce n tr al i ty ( fb_ subgr a ph [0])
print ’ Trimmed FB betw eenne ss : ’,
sorted ( betw eenne ss . items () , key = lambda x: x [1] ,
reverse = True ) [:10]
current _flow = nx . c u rr e nt _f l ow _ be tw e en n es s_ c en t ra li ty (
fb_subg raph [0])
print ’ Trim med FB cur rent flow be twee nne ss : ’,
sorted ( curr ent_f low . items () , key = lambda x: x [1] ,
reverse = True ) [:10]
152 8 Network Analysis
In this section we focus on graph visualization, which can help in the network
dataunderstanding and usability.
The visualization of a network with a large amount of nodes is a complex task.
Different layouts can be used to try to build a proper visualization. For instance,
we can draw the Facebook graph using the random layout (nx.random_layout),
but this is a bad option, as can be seen in Fig. 8.5. Other alternatives can be more
useful. In the box below, we use the Spring layout, as it is used in the default function
(nx.draw), but with more iterations. The function nx.spring_layout returns the
position of the nodes using the Fruchterman–Reingold force-directed algorithm.
8.4 Centrality 153
This algorithm distributes the graph nodes in such a way that all the edges are
more or less equally long and they cross themselves as few times as possible.
Moreover, we can change the size of the nodes to that defined by their degree
centrality. As can be seen in the code, the degree centrality is normalized to
values between 0 and 1, and multiplied by a constant to make the sizes
appropriate for the format of the figure:
In [11]: pos_fb = nx . sp ring_ layou t ( fb , it erati ons = 1000)
The resulting graph visualization is shown in Fig. 8.6. This illustration allows us
to understand the network better. Now we can distinguish several groups of nodes
or “communities” clearly in the graph. Moreover, the larger nodes are the more
centralnodes, which are highly connected of the Facebook graph.
We can also use the betweenness centrality to define the size of the nodes. In this
way, we obtain a new illustration stressing the nodes with higher betweenness, which
are those with a large influence on the transfer of information through the
network. The new graph is shown in Fig. 8.7. As expected, the central nodes are
now those connecting the different communities.
Generally different centrality metrics will be positively correlated, but when
they are not, there is probably something interesting about the network nodes. For
instance, if you can spot nodes with high betweenness but relatively low degree,
these are thenodes with few links but which are crucial for network flow. We can
also look for
154 8 Network Analysis
the opposite effect: nodes with high degree but relatively low betweenness.
These nodes are those with redundant communication.
Changing the centrality measure to closeness and eigenvector, we obtain the
graphs in Figs. 8.8 and 8.9, respectively. As can be seen, the central nodes
arealso different for these measures. With this or other visualizations you will be
able to discern different types of nodes. You can probably see nodes with high
closeness centrality but low degree; these are essential nodes linked to a few
important or active nodes. If the opposite occurs, if there are nodes with high
degree centrality but lowcloseness, these can be interpreted as nodes embedded
in a community that is far removed from the rest of the network.
In other examples of social networks, you could find nodes with high closeness
centrality but low betweenness; these are nodes near many people, but since
there may be multiple paths in the network, they are not the only ones to be
near many people. Finally, it is usually difficult to find nodes with high
betweenness but low closeness, since this would mean that the node in question
monopolized the links from a small number of people to many others.
PageRank
rank computation as a random walk through the network. We start with an initial equal
probability for each page: v0 = ( 1 ,n. . . , 1 ),nwhere n is the number of nodes. Then
we can compute the probability that each page is visited after one step by applying
the transition matrix: v1 = Mv. The probability that each page will be visited after
k steps is given by vk =M k a. After several steps, the sequence converges to a
unique probabilistic vector a∗ which is the PageRank vector. The i -th element of
this vector is the probability that at each moment the surfer visits page Pi . We need a
nonambiguous definition of the rank of a page for any directed web graph.
However,
in the Internet, we can expect to find pages that do not contain outgoing links
and this configuration can lead to certain problems to the explained procedure.
In order to overcome this problem, the algorithm fixes a positive constant p
between 0 and 1 (a typical value for p is 0.85) and redefines the transition
matrix of the graph by
R = (1 − p) M + p B, where B = 1 I , and n I is the identity matrix. Therefore, a
p
node with no outgoing edges has probability n of moving to any other node.
Let us compute the PageRank vector of the Facebook network and use it to define
the size of the nodes, as was done in box In [11].
In [12]: pr = nx . pagerank ( fb , alpha = 0.85)
nsize = np . array ([ v for v in pr . values () ])
nsize = 500*( nsize - min ( nsize )) /( max ( nsize ) - min ( nsize ))
nodes = nx . dr aw _ne tw ork x_ no des ( fb ,
pos = pos_fb ,
node _si ze = nsize )
edges = nx . d r aw _n et wo rk x_ ed g es ( fb ,
pos = pos_fb ,
alpha = . 1 )
The code above outputs the graph in Fig. 8.10, that emphasizes some of the
nodes with high PageRank. Looking the graph carefully one can realize that there
is one large node per community.
8.5 Ego-Networks
G = nx . r ead_e dgeli st (
os . path . join ( ’ files / ch08 / facebook ’,
’ {0}. edges ’. format ( ego_max )) ,
nodetype = int )
print ’ Nodes : ’, G. order ()
print ’ Edges : ’, G. size ()
print ’ Averag e degree : ’, G_k / G_n
The most densely connected ego-network is that of node ‘1912’, which has an
average degree of 40. We can also compute which is the largest (in number of nodes)
ego-network, changing the measure of sizes from G.size() by G.order(). In this case,
we obtain that the largest ego-network is that of node ‘107’, which has 1,034
nodes and an average degree of 25.
Next let us work out how much intersection exists between the ego-networks
in the Facebook network. To do this, in the code below, we add a field ‘egonet’ for
every node and store an array with the ego-networks the node belongs to. Then,
having thelength of these arrays, we compute the number of nodes that belong to
1, 2, 3, 4 andmore than 4 ego-networks:
In [16]: # Add a field ’ egonet ’ to the nodes of the whole face bo ok
network .
# Default value egonet = [] , meaning that this node does not
belong to any ego - netowrk
for i in fb . nodes () :
fb . node [ str (i) ][ ’ egonet ’] = []
In [17]: # Add a field ’eg ocolor ’ to the nodes of the whole fa cebook net w ork .
# D efa ult value eg ocolor r =0, mea ning that this node
does not belong to any ego-netow rk for i in fb. nodes () :fb.node [ str(i) ][’eg ocol or ’]
= 0
# Fill the ’eg ocol or ’ field with a dif f erent color number for each ego-netw ork in
eg o_i ds :
i dCol or = 1
for id in eg o_i ds :
G = nx.rea d_edg el i st (
os.path .join (’files /ch08 /f a cebook ’,
’{0}. edg es ’.f ormat (id)),nodet ype = int)
for n in G.nodes () :
fb.node [str(n) ][’eg ocolor ’] = idColor i dCol or += 1
nsize = np.a rray ([v for v in deg ree_cent _f b .val ues ()])
However, the graph in Fig. 8.12 does not illustrate how much overlap is there
between the ego-networks. To do that, we can visualize the intersection between
ego-networks using a Venn or an Euler diagram. Both diagrams are useful in order to
see how networks are related. Figure 8.13 shows the Venn diagram of the
Facebook network. This powerful and complex graph cannot be easily built in
Python tool-
162 8 Network Analysis
boxes like NetworkX or Matplotlib. In order to create it, we have used a JavaScript
visualization library called D3.JS.4
Community Detection
.
Community Detection 163
print("Generated Text:")
print(generated_text)
output:
1/1 [==============================] - 1s 517ms/step
1/1 [==============================] - 0s 75ms/step
1/1 [==============================] - 0s 101ms/step
1/1 [==============================] - 0s 93ms/step
1/1 [==============================] - 0s 132ms/step
1/1 [==============================] - 0s 143ms/step
1/1 [==============================] - 0s 140ms/step
details of the research methodology and dataset used in this paper. The experimental details and
results are discussed in Section 5. Finally, the paper is concluded in Section 6. 2. Related Work
GANs were first introduced by Goodfellow [7] in 2014, but Reed et al. [8] was the first to use
them for text-to-image generation in 2016. Salimans et al. [9] proposed training stabilizing
techniques for previously untrainable models and achieved better results on the MNIST, CIFAR-
10, and SVHN datasets. The attention-based recurrent neural network was developed by Zia et
al. [10]. In their model, word-to-pixel dependencies were learned by an attention-based auto-
encoder and pixel-to-pixel dependencies were learned by an autoregressive-based decoder. Liu et
al. [11] offered a diverse conditional image synthesis model and performed large-scale
experiments for different conditional generation tasks. Gao et al. [12] proposed an effective
approach known as lightweight dynamic conditional GAN (LD-CGAN), which disentangled the
text attributes and provided image features by capturing multi-scale features. Dong et al. [13]
trained a model for generating images from text in an unsupervised manner. Berrahal et al. [14]
focused on the development of textto-image conversion applications. They used deep fusion
GAN (DF-GAN) for generating human face images from textual descriptions. The cross-domain
feature fusion GAN (CFGAN) was proposed by Zhang et al. [15] for converting textual
descriptions into images with more semantic detail. In general, the existing methods of text-to-
image generation use wide-ranging parameters and heavy computations for generating high-
resolution images, which result in unstable and high-cost training.
This section describes the training details of deep learning-based generative models. Conditional
GANs were used with recurrent neural networks (RNNs) and convolutional neural networks
(CNNs) for generating meaningful images from a textual description. The dataset used consisted
of images of flowers and their relevant textual descriptions. For generating plausible images
from text using a GAN, preprocessing of textual data and image resizing was performed. We
took textual descriptions from the dataset, preprocessed these caption sentences, and created a
list of their vocabulary. Then, these captions were stored with their respective ids in the list. The
images were loaded and resized to a fixed dimension. These data were then given as input to our
proposed model. RNN was used for capturing the contextual information of text sequences by
defining the relationship between words at altered time stamps. Text-to-image mapping was
performed using an RNN and a CNN. The CNN recognized useful characteristics from the
images without the need for human intervention. An input sequence was given to the RNN,
which converted the textual descriptions into word embeddings with a size of 256. These word
embeddings were concatenated with a 512-dimensional noise vector. To train our model, we
took a batch size of 64 with gated-feedback 128 and fed the input noise and text input to a
generator. The architecture of the proposed model is presented in Figure 1. Eng. Proc. 2022, 20,
16 3 of 6 images were loaded for resizing to the same dimensions. All training images and
testing images were resized to a resolution of 128 × 128.
For training purposes, the images were converted into arrays, and both the vocabulary and
images were loaded onto the model. 4. Proposed Methodology This section describes the training
details of deep learning-based generative models. Conditional GANs were used with recurrent
neural networks (RNNs) and convolutional neural networks (CNNs) for generating meaningful
images from a textual description. The dataset used consisted of images of flowers and their
relevant textual descriptions. For generating plausible images from text using a GAN,
preprocessing of textual data and image resizing was performed. We took textual descriptions
from the dataset, preprocessed these caption sentences, and created a list of their vocabulary.
Then, these captions were stored with their respective ids in the list.
The images were loaded and resized to a fixed dimension. These data were then given as input
to our proposed model. RNN was used for capturing the contextual information of text sequences
by defining the relationship between words at altered time stamps. Text-to-image mapping was
performed using an RNN and a CNN. The CNN recognized useful characteristics from the
images without the need for human intervention. An input sequence was given to the RNN,
which converted the textual descriptions into word embeddings with a size of 256. These word
embeddings were concatenated with a 512-dimensional noise vector. To train our model, we
took a batch size of 64 with gated-feedback 128 and fed the input noise and text input to a
generator. The architecture of the proposed model is presented
Figure 1. Architecture of the proposed method, which can generate images from text
descriptions. Semantic information from the textual description was used as input in the
generator model, which converts characteristic information to pixels and generates the images.
This generated image was used as input in the discriminator along with real/wrong textual
descriptions and real sample images from the dataset. A sequence of distinct (picture and text)
pairings are then provided as input to the model to meet the goals of the discriminator: input
pairs of real images and real textual descriptions, wrong images and mismatched textual
descriptions, and generated images and real textual descriptions. The real photo and real text
combinations are provided so that the model can determine if a particular image and text
combination align. An incorrect picture and real text description indicates that the image does
not match the caption. The discriminator is trained to identify real and generated images. At the
start of training, the discriminator was good at classification of real/wrong images. Loss was
calculated to improve the weight and to provide training feedback to the generator and
discriminator model. As soon as the training proceeded, the generator produced more realistic
images and it fooled the discriminator when distinguishing between real and generated and
images
Content-based recommendation systems operate on the premise of suggesting items to users based
on the content attributes of those items and a user’s past preferences. These systems focus on
features and characteristics associated with items, such as text descriptions, genres, keywords, or
metadata.
The recommendations generated are aligned with the user’s historical interactions and
preferences. Content-based systems excel in providing recommendations that are closely related
to the user’s demonstrated interests. For example, a content-based movie recommendation system
might suggest films with similar genres or themes to those the user has previously enjoyed.
Collaborative filtering recommendation systems, on the other hand, rely on the collective
behavior and preferences of a large user base to make suggestions. This approach assumes that
users who have exhibited similar preferences in the past will continue to do so in the future.
Collaborative filtering can be further categorized into two subtypes: user-based and item-based.
User-based collaborative filtering recommends items to a user based on the preferences of users
who are similar to them. Item-based collaborative filtering suggests items similar to those the user
has shown interest in, based on the behavior of other users. These systems are effective at
suggesting items that are trending or popular among users with similar preferences.
Two-Tower Architecture
The user tower processes user data, such as profiles and historical interactions, while the item
tower encodes item features like metadata and content descriptors. By separately encoding user
and content information, the Two-Tower architecture excels in delivering highly personalized
recommendations. It is particularly adept at addressing challenges like the cold start problem,
where it must recommend to new users or new items with limited interaction data. This
architecture is highly efficient, scalable, and capable of fine-tuning recommendations based on
nuanced user preferences.
In the realm of retrieval systems, Two-Tower Neural Networks (NNs) hold a special significance.
Our retrieval approach, grounded in machine learning, harnesses the power of the Word2Vec
algorithm to create embeddings for both users and media/authors based on their unique identifiers.
The Two Towers model expands upon the Word2Vec algorithm, permitting the incorporation of
diverse user or media/author characteristics. This adaptation also facilitates concurrent learning
across multiple objectives, enhancing its utility for multi-objective retrieval tasks. Notably, this
model retains the scalability and real-time capabilities inherent in Word2Vec, making it an
excellent choice for candidate sourcing algorithms.
Here’s a high-level overview of how Two-Tower retrieval operates in conjunction with a schema:
1. The Two Tower model comprises two distinct neural networks — one for users and one for
items.
2. Each neural network exclusively processes features pertinent to its respective entity and
generates an embedding.
3. The primary objective is to predict engagement events (e.g., user likes on a post) by measuring
the similarity between user and item embeddings.
4. Following training, user embeddings are optimized to closely match embeddings of relevant
items, enabling the use of nearby item embeddings for ranking purposes.
learning using four popular machine learning algorithms namely, Random Forest Classifier,
KNN, Decision Tree Classifier, and Naive Bayes classifier. We will directly jump into
implementation step-by-step.
classification using machine learning and machine learning image classification. However,
the work demonstrated here will help serve research purposes if one desires to compare their
CNN image classifier model with some machine learning algorithms.
Learning Objective:
• Showcase how to test the trained models on custom input images and evaluate their
performance.
Table of contents
Dataset Acquisition
Source: cs.toronto
The dataset utilized in this blog is the CIFAR-10 dataset, which is a Keras dataset that can be
easily downloaded using the following code. The dataset includes ten classes: airplane,
automobile, bird, cat, deer, dog, frog, horse, ship, and truck, indicating that we will be
addressing a multi-class classification problem.