GenAI

 Prompt engineering is the process of crafting input text to optimize the performance of a given model and its associated parameters. 

Python and the TextBlob library,  a popular Python library for processing textual data built on top of NLTK (Natural Language Toolkit) and Pattern, two other widely used NLP libraries in Python.

This line imports the TextBlob class from the TextBlob library.(from textblob import TextBlob)

text = "This recipe was disappointing. I would not recommend it."
This line defines a string text containing a sample piece of text. The text expresses a negative sentiment about a movie but also includes a clarification that the speaker did not like it. 
A TextBlob object called blob is created by passing the example text to the TextBlob constructor. . This object represents a text and provides various properties and methods for text analysis, including sentiment analysis.(blob = TextBlob(text))
This line uses the 'sentiment' property of the TextBlob object to calculate the sentiment polarity of the text. The 'polarity' score ranges between -1 and 1. A negative value indicates negative sentiment, a positive value indicates positive sentiment, and a value close to 0 indicates neutral sentiment.(_sentiment_polarity = blob.sentiment.polarity)
Zero-shot prompting
In zero-shot prompting, the model is trained to understand and follow instructions provided in the prompt, enabling it to generate responses based on that information. Unlike traditional training methods that require specific examples for each task, zero-shot prompting offers flexibility and efficiency. Instead of retraining models for new tasks, zero-shot prompting allows models to handle new challenges by interpreting the instructions contained in the prompt's context. few-shot prompting and one-shot prompting. In few-shot prompting, the model is trained with a small amount of data for new tasks, while one-shot prompting involves using a single example or template to generate text.Zero-shot prompting is a technique in natural language processing (NLP) where a model can generate responses without having been explicitly trained on the specific task or prompt.
Chain-of-thought (CoT) prompting is an input strategy used in language models to guide the generation of responses in a coherent and connected manner, resembling a chain of thoughts. 
Zero-shot CoT prompting incorporates the phrase "Let's think step by step" into the original prompt, guiding the language model's reasoning process. This technique is especially useful in scenarios when examples are not available for use in the prompt. 
multimodal CoT, both text and images are used in a two-step process. First, it creates reasons or explanations separately, and then it figures out the answers. This approach lets the system benefit from well-made explanations using both text and images to better understand and come up with answers.
Generated-knowledge prompting improves the knowledge and reasoning capabilities of language models by supplying them with generated or simulated data as prompts, instead of relying solely on pre-existing human-curated data.
PROMPT TUNING
Large language models like ChatGPT are flexible and can perform various tasks such as analyzing legal documents or writing poems. Previously, fine tuning was used to improve the performance of pre-trained models by gathering and labeling examples of the target task. However, a more energy-efficient technique called prompt tuning has emerged as a simpler alternative. Prompt tuning allows tailoring a massive model to a narrow task without requiring a large number of labeled examples. 

Deep learning (DL) is a group of neural networks (which are, in turn, groups of machine learning models). Deep learning can find patterns in complex data structures like images, video, and sound. Many of its models need no explicit training to find a solution, making them excellent for solving problems too big and complex for humans to engineer. Deep learning has been used to train self-driving vehicles, detect fraud, and even make “Deepfake” videos of popular celebrities.
Machine learning (ML) is the engine of an AI system. It describes machines that learn without explicit instructions on how to perform tasks. It often depends on models: trained artifacts that guide machines when interpreting new data. Models represent patterns of data and help a machine learning system make predictions without being told how to do so.
Natural language processing (NLP) is the ability of a computer program to understand human language as it is spoken. NLP can train computers to process large amounts of human text, like newspapers or conversations, comprehending the intent and meaning of that data. With NLP, a machine can then reply to humans with nuance and understanding. A common example of NLP is a customer service chatbot.

Reinforcement learning is a type of machine learning model that doesn’t give the machine any data at all, labeled or unlabeled. Instead, the machine tries different actions and receives reward signals (like cookies for a dog!) when it makes correct moves. In this way the system is trained solve a problem, with no human work required
Tokenization
Tokenization is a crucial phase in fine-tuning the LLM. Tokenization is the process of breaking down a text document or sequence of words into smaller units called tokens. Tokens can be as short as individual characters, words, or even subwords. Tokenization helps in various language-related tasks, such as text classification and sentiment analysis. In scientific or technical domains, specialized tokenization may be needed to break down complex terms. Tokenization is a fundamental step in natural language processing (NLP) because it transforms text data into a format that can be understood by machine learning models.
Tokenization algorithms

BPE builds a vocabulary of variable-length subword units based on the frequency of their occurrences in the training data. It's widely used in NLP tasks and has been employed in models like GPT-2.

WordPiece starts with individual characters as tokens and iteratively merges them based on the likelihood of their co-occurrence in the training data. BERT, for example, uses the WordPiece tokenizer.


Assuming we start with individual characters and iteratively merge based on co-occurrence:

1.'c', 'h', 'a', 't', 'b', 'o' → 'cha', 't', 'b', 'o'

2.'cha', 't', 'b', 'o' → 'chat', 'b', 'o'


The final vocabulary might include: {'c', 'h', 'a', 't', 'b', 'o', 'cha', 'chat’}.

Used by BERT, DistilBERT

Embeddings
 LLMs use embeddings to convert words into vectors that can be processed and manipulated within the model, capturing the nuances of language and its associations.An embedding is a mathematical representation of a word or sequence of words in a numerical vector space.


Transformers
Transformer refers to a specific type of neural network architecture called the "transformer model", that is designed to process sequential data, such as natural language sequences. 

The transformer model consists of two main parts: an encoder and a decoder. The encoder processes the input sequence and extracts important features from it, while the decoder takes the encoded representation produced by the encoder and generates the corresponding output sequence. 


Retrieval-augmented generation (RAG), 


Key concepts

  1. 1

    Prompt engineering is the process of crafting prompt text to best effect for a given model and parameters. 

  2. 2

    Common prompt elements include: Instruction, context, input data, and output indicator.

  3. 3

    Zero-shot prompting is a technique in natural language processing (NLP) where a model can generate responses without having been explicitly trained on the specific task or prompt.

  4. 4

    Chain-of-thought (CoT) prompting is an input strategy used in language models to guide the generation of responses in a coherent and connected manner, resembling a chain of thoughts.

  5. 5

    Generated-knowledge prompting improves the knowledge and reasoning capabilities of language models by supplying them with generated or simulated data as prompts, instead of relying solely on pre-existing human-curated data.

  6. 6

    Retrieval augmented generation (RAG) is a method introduced by researchers in Meta AI specifically tailored to handle knowledge-intensive tasks.


Comments

Popular posts from this blog

HTTP from First Principles

The Anatomy of a Backend Request: Layers, Middleware, and Context Explained

Validations and Transformations