This project implements a basic text generation model using a graph-based approach, specifically a Markov Chain-like model. The code defines two classes, Vertex and Graph, representing words and their relationships in a text. The model uses the statistical relationships between words to generate new sequences of words.
- Represents a word in the text.
- Keeps track of adjacent words and their transition probabilities.
- Methods include adding edges, incrementing edge weights, getting adjacent nodes, generating a probability map for the next word, and selecting the next word.
- Represents the entire text as a graph of words.
- Manages a dictionary of vertices (words) and their relationships.
- Provides methods for adding vertices, retrieving vertices, getting the next word based on probabilities, and generating probability mappings for all vertices.
- Creating a Graph:
# Creating a graph graph = Graph()
graph.add_vertex("apple") graph.add_vertex("banana")
3.# Adding edges between vertices vertex_apple = graph.get_vertex("apple") vertex_banana = graph.get_vertex("banana") vertex_apple.add_edge_to(vertex_banana, weight=2)
graph.generate_probability_mappings()
next_word = graph.get_next_word(vertex_apple)