Gen AI PRG-5
Gen AI PRG-5
Use word embeddings to create meaningful sentences for creative tasks. Retrieve similar words
for a seed word. Create a sentence or story using these words as a starting point. Write a
program that: Takes a seed word. Generates similar words. Constructs a short paragraph using
these words.
import random
import nltk
nltk.download('punkt')
def generate_creative_paragraph(seed_word, top_n=5):
"""Generate a creative paragraph using similar words."""
similar_words = get_similar_words(seed_word, top_n)
if not similar_words:
return f"Could not generate a story, as '{seed_word}' is not in the vocabulary."
return paragraph
# Example Usage
seed_word = "adventure"
creative_paragraph = generate_creative_paragraph(seed_word, top_n=5)
print("\nGenerated Paragraph:\n")
print(creative_paragraph)