Ticker

6/recent/ticker-posts

BAIL657C - Generative AI Lab Program 4

 

Program 4

AIM:

Use word embeddings to improve prompts for Generative AI model. Retrieve similar words using word embeddings. Use the similar words to enrich a GenAI prompt. Use the AI model to generate responses for the original and enriched prompts. Compare the outputs in terms of detail and relevance.


Theory: 

Prompt Enrichment using Word Embeddings

Word embeddings are a technique in Natural Language Processing (NLP) that represent words as numerical vectors based on their meaning and context. Words with similar meanings have similar vector representations. Popular models include Word2Vec and GloVe.

In this experiment, word embeddings are used to improve prompts given to a Generative AI model. First, a basic prompt is taken as input. Then, important words from the prompt are identified, and their semantically similar words are retrieved using a pre-trained embedding model.

These similar words are added to the original prompt to create an enriched prompt, which provides more context and detail. Both the original and enriched prompts are then given to a Generative AI model (such as FLAN-T5 or GPT-based models) to generate responses.

The outputs are compared in terms of:

       Detail (amount of information provided)

       Relevance (how well the response matches the topic)

It is observed that enriched prompts generally produce more detailed, informative, and contextually relevant responses, as the additional semantic information helps the model better understand the user’s intent.

Program

Step 1: Install Libraries

 

Step 2: Load Word Embeddings (GloVe)

 

Step 3: Get Similar Words

 

Step 4: Enrich Prompt

 

Step 5: Load Free LLM (FLAN-T5)

 

Step 6: Generate Outputs

 

Step 7: Quantitative Comparison 

1.       Length-Based Detail

 

2.       Relevance using Semantic Similarity



 

3.       Diversity (Unique Words)

 

 

Post a Comment

0 Comments