Studies related to the book OpenAI GPT For Python Developers (Aymen El Amri).
Prompt Engineering is the process of designing prompts to steer the model towards generating the desired output.
Some prompt engineering techniques:
- Zero-shot learning: prompting an LLM without any examples.
- Few-shot learning: prompting an LLM with examples of task. The principle of fine-tuning is a method of enhancing few-shot learning by training on a significantly larger number of examples. Once a model has been refined and enhanced, it’s no longer necessary to supply examples when you submit a request. This approach is cost-effective and accelerates requests. Fine-tuning is applicable for the following models: GPT-3.5-Turbo-1106, GPT-3.5-Turbo-0613, Babbage-002, Davinci-002 e GPT-4-0613
- General knowledge prompting: ask the LLM to generate useful information about a given topic before generating a final response.
- Chain of Thought (CoT): Shows the LLM examples of logical reasoning to approach a solution to instruct it to follow a similar m ethod of reasoning in its response.
- Zero-shot CoT
- Auto Chain of Thought (AutoCoT)
- Self-consistency
- Transfer Learning, ReAct (Reason + Act)
- Others
Involves integrating the model with a system that retrieves information from a database or the internet.
For instance, Retrieval-Augmented Generation (RAG) that is a AI language processing method that merges retrieval and generation techniques. In the retrieval stage, RAG employs a retrieval mechanism to collect pertinent information from a vast external knowledge base. The generation stage then utilizes the information retrieved earlier to generate a response.
Involves integrating external functions into the model’s responses.
For instance, in a travel recommendation chatbot, when a user requests weather information about a place, the chatbot could invoke an external weather API to obtain current weather data and incorporate this in the response.
Embeddings represent real-world objects and relationships in the form of vectors that measures the similarity between two entities.
Text embeddings represent text strings as vectors, enabling the measurement of similarity between them with the intention of finding the most relevant results for a search query (Search), grouping text strings based on their similarity (clustering), recommending items with similar text (recommendation), identifying text strings that greatly differ from others (anomaly detector), analyzing the differences between text strings (diversity), and labeling text strings based on their closest match (classification).
“Ada” is one of the best models available on OpenAI for embedding.
https://github.com/life4/textdistance
Create an API key on https://platform.openai.com/api-keys and place it in an .env file on the src folder with the API_KEY and ORG_ID.
# Install the dependencies and the env variables
pip install --upgrade pip
pip install virtualenv
pip3 install virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bashrc
# To create the env
mkvirtualenv -p /usr/bin/python3.9 openaigptforpythondevelopers
# To activate
workon openaigptforpythondevelopers
# To deactivate
deactivate
python -m chat.chat_completion
python -m embedding.first_embedding