liveBook · Manning

Node

As explained in Natural Language Processing in Action, Second Edition

A node is an entity or vertex in a graph that can be connected to other nodes by edges.

A node is an entity or vertex in a graph. Edges connect nodes to represent relationships, making graphs useful for modeling social ties, ideas, and conversation flow. section 6.4.6

Graphs distinguish nodes by the relationships connecting them:

  • Undirected graphs connect nodes with reciprocal relationships, such as mutual friendship. section 6.4.6
  • Directed graphs connect nodes with one-way relationships, such as following someone on Twitter. section 6.4.6
  • In a chatbot conversation graph, a node represents the current conversation state, including relevant context and prior messages. section 12.3.2

Nodes can represent sentences rather than people or dialogue states. Sentence embeddings turn each sentence into a vector; highly similar sentences become connected nodes in an undirected graph, allowing related ideas to cluster visually. section 6.4.6

Building nodes from sentence similarity

A Python workflow loads manuscript text with spaCy, extracts sentence vectors, normalizes them, computes an affinity matrix, and adds nodes and weighted edges when similarity exceeds 0.95. NetworkX and a spring layout then display the resulting concept network. section 6.4.6

Node as a tutoring state

A counting chatbot can use nodes such as welcome, question, correct answer, and wrong answer. Each state sends messages and routes user input through triggers to the next node. section 12.3.2

Listing 6.19 Creating the undirected graph
>>> import re
>>> import networkx as nx
>>> similarity_matrix = np.triu(similarity_matrix, k=1)     #1
>>> iterator = np.nditer(similarity_matrix,
...     flags=['multi_index'], order='C')
>>> node_labels = dict()
>>> G = nx.Graph()
>>> pattern = re.compile(
...    r'[\w\s]*[\'\"]?[\w\s]+\-?[\w\s]*[\'\"]?[\w\s]*'
...    )                  #2
>>> for edge in iterator:
...     key = 0
...     value = ''
...     if edge > 0.95:                    #3
...         key = iterator.multi_index[0]
...         value = str(noun_phrases[iterator.multi_index[0]])
...         if (pattern.fullmatch(value)
...             and (value.lower().rstrip() != 'figure')):
...                 node_labels[key] = value
...         G.add_node(iterator.multi_index[0])
...         G.add_edge(iterator.multi_index[0],
...             iterator.multi_index[1], weight=edge)

Inspect executable NetworkX code that creates nodes and weighted edges from sentence-similarity scores. section 6.4.6

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines nodes through graph intuition and demonstrates construction, visualization, and chatbot-state semantics without detailing graph algorithms.
Examples
Uses social networks, sentence-similarity plots, and a counting chatbot with welcome, question, and answer states.
What it assumes
Assumes familiarity with word embeddings for the sentence-graph workflow while defining graph structure and chatbot context explicitly.
What you can do after
Build nodes in NetworkX graphs and interpret them as clustered ideas or context-dependent chatbot states.
How it connects
Connects nodes to graphs, edges, sentence embeddings, word embeddings, conversation graphs, and conversational context.

Also explained in

Compare how 19 books explain node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.