10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | # Introduction to LLMs with OpenAI API.
21 |
22 | In this first section of the course, **you will learn to work with the OpenAI API** by creating two small projects. You'll delve into OpenAI's roles and how to provide the necessary instructions to the model through the prompt to make it behave as desired.
23 |
24 | The first project is a restaurant chatbot where the model will take customer orders. Building upon this project, we will construct an SQL statement generator. Here, you'll attempt to create a secure prompt that only accepts SQL creation commands and nothing else.
25 |
26 | ### Create Your First Chatbot Using GPT 3.5, OpenAI, Python and Panel.
27 | | Description | Article | Notebook |
28 | | -------- | ---| --- |
29 | | We will be utilizing OpenAI GPT-3.5 and gpt-4o-mini to develop a straightforward Chatbot tailored for a fast food restaurant. During the article, we will explore the fundamentals of prompt engineering, including understanding the various OpenAI roles, manipulating temperature settings, and how to avoid Prompt Injections. | [article panel](https://medium.com/towards-artificial-intelligence/create-your-first-chatbot-using-gpt-3-5-openai-python-and-panel-7ec180b9d7f2) - [article gradio](https://ai.plainenglish.io/create-a-simple-chatbot-with-openai-and-gradio-202684d18f35?sk=e449515ec7a803ae828418011bbaca52)| [notebook panel](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_1-First_Chatbot_OpenAI.ipynb) - [notebook gradio](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_1-First_Chatbot_OpenAI_Gradio.ipynb) |
30 |
31 | ### How to Create a Natural Language to SQL Translator Using OpenAI API.
32 | | Description | Article | Notebook |
33 | | -------- | ---| --- |
34 | | Following the same framework utilized in the previous article to create the ChatBot, we made a few modifications to develop a Natural Language to SQL translator. In this case, the Model needs to be provided with the table structures, and adjustments were made to the prompt to ensure smooth functionality and avoid any potential malfunctions. With these modifications in place, the translator is capable of converting natural language queries into SQL queries. @fmquaglia has created a notebook using DBML to describe the tables that by far is a better aproach than the original.| [article](https://pub.towardsai.net/how-to-create-a-natural-language-to-sql-translator-using-openai-api-e1b1f72ac35a) - [article gradio](https://medium.com/towards-artificial-intelligence/first-nl2sql-chat-with-openai-and-gradio-b1de0d6541b4)| [notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_2-Easy_NL2SQL.ipynb) - [notebok Gradio](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_2-Easy_NL2SQL_Gradio.ipynb) - [notebook DBML](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_2b-Easy_NL2SQL.ipynb)|
35 |
36 | ### Brief Introduction to Prompt Engineering with OpenAI.
37 | | Description | Article | Notebook |
38 | | -------- | ---| --- |
39 | |We will explore prompt engineering techniques to improve the results we obtain from Models. Like how to format the answer and obtain a structured response using Few Shot Samples.| [Article](https://medium.com/gitconnected/influencing-a-large-language-model-response-with-in-context-learning-b212f0eaa113) | [notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/1-Introduction%20to%20LLMs%20with%20OpenAI/1_3-Intro_Prompt_Engineering.ipynb)
40 |
--------------------------------------------------------------------------------
/2-Vector Databases with LLMs/2_2-ChromaDB Sever mode.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "7e4c9601-fcb8-49e6-ae48-4de8b6cac494",
6 | "metadata": {
7 | "id": "7e4c9601-fcb8-49e6-ae48-4de8b6cac494"
8 | },
9 | "source": [
10 | "
\n",
11 | "
Large Language Models Projects
\n",
12 | "
Apply and Implement Strategies for Large Language Models
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | A brief introduction to Vector Databases, a technology that will accompany us in many lessons throughout the course. We will work on an example of Retrieval Augmented Generation using information from various news datasets stored in ChromaDB.
21 |
22 | ### Influencing Language Models with Personalized Information using a Vector Database.
23 | | Description | Article | Notebook |
24 | | -------- | --- | ---|
25 | | If there's one aspect gaining importance in the world of large language models, it's exploring how to leverage proprietary information with them. In this lesson, we explore a possible solution that involves storing information in a vector database, ChromaDB in our case, and using it to create enriched prompts. | [Article](https://pub.towardsai.net/harness-the-power-of-vector-databases-influencing-language-models-with-personalized-information-ab2f995f09ba?sk=ea2c5286fbff8430e5128b0c3588dbab) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/2-Vector%20Databases%20with%20LLMs/2_1_Vector_Databases_LLMs.ipynb)|
26 |
27 | ### Creating a ChromaDB server.
28 | | Description | Server | Client |
29 | | ------- | --- | --- |
30 | |In these two notebooks, a ChromaDB server is created from which information is served to a second notebook that contains the client. It is a small example of how to set up a local ChromaDB server that can be used by multiple clients. | [ChromaDB Server](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/2-Vector%20Databases%20with%20LLMs/2_2-ChromaDB%20Sever%20mode.ipynb) | [ChromaDB Client](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/2-Vector%20Databases%20with%20LLMs/2_3-ChromaDB%20Client.ipynb) |
31 |
32 | ### Semantic Cache for RAG systems ###
33 | | Description | Article | Notebook |
34 | | -------- | --- | ---|
35 | | We enhanced the RAG system by introducing a semantic cache layer capable of determining if a similar question has been asked before. If affirmative, it retrieves information from a cache system created with Faiss instead of accessing the Vector Database. The inspiration and base code of the semantic cache present in this notebook exist thanks to the course: https://maven.com/boring-bot/advanced-llm/1/home from Hamza Farooq.| WIP | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/2-Vector%20Databases%20with%20LLMs/semantic_cache_chroma_vector_database.ipynb) |
36 |
--------------------------------------------------------------------------------
/3-LangChain/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/3-LangChain/.DS_Store
--------------------------------------------------------------------------------
/3-LangChain/readme.md:
--------------------------------------------------------------------------------
1 |
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | LangChain has been one of the libraries in the universe of large language models that has contributed the most to this revolution.
21 | It allows us to chain calls to Models and other systems, allowing us to build applications based on large language models. In the course, we will use it several times, creating increasingly complex projects.
22 |
23 | ### Retrieval Augmented Generation (RAG). Use the Data from your DataFrames with LLMs.
24 | In this lesson, we used LangChain to enhance the notebook from the previous lesson, where we used data from two datasets to create an enriched prompt. This time, with the help of LangChain, we built a pipeline that is responsible for retrieving data from the vector database and passing it to the Language Model. The notebook is set up to work with two different datasets and two different models. One of the models is trained for Text Generation, while the other is trained for Text2Text Generation.
25 | | [Article](https://medium.com/towards-artificial-intelligence/query-your-dataframes-with-powerful-large-language-models-using-langchain-abe25782def5) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_1_RAG_langchain.ipynb) |
26 | | ------ | ------ |
27 |
28 | ### Create a Moderation system using LangChain.
29 | We will create a comment response system using a two-model pipeline built with LangChain. In this setup, the second model will be responsible for moderating the responses generated by the first model.
30 |
31 | One effective way to prevent our system from generating unwanted responses is by using a second model that has no direct interaction with users to handle response generation.
32 |
33 | This approach can reduce the risk of undesired responses generated by the first model in response to the user's entry.
34 |
35 |
36 | I will create separate notebooks for this task. One will involve models from OpenAI, and the others will utilize open-source models provided by Hugging Face. The results obtained in the three notebooks are very different. The system works much better with the OpenAI, and LLAMA2 models.
37 | | Article | Notebook |
38 | | --- | --- |
39 | | [OpenAI article](https://pub.towardsai.net/create-a-self-moderated-commentary-system-with-langchain-and-openai-406a51ce0c8d?sk=b4903b827e44642f7f7c311cebaef57f) | [OpenAI notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_2_OpenAI_Moderation_Chat.ipynb) |
40 | | [Llama2-7B Article](https://levelup.gitconnected.com/create-a-self-moderated-comment-system-with-llama-2-and-langchain-656f482a48be?sk=701ead7afb80e015ea4345943a1aeb1d) | [Llama2-7B Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_2_LLAMA2_Moderation_Chat.ipynb) |
41 | | No Article | [GPT-J Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_2_GPT_Moderation_System.ipynb) |
42 |
43 | ### Create a Data Analyst Assistant using a LLM Agent.
44 | Agents are one of the most powerful tools in the world of Large Language Models. The agent is capable of interpreting the user's request and using the tools and libraries at its disposal until it achieves the expected result.
45 |
46 | With LangChain Agents, we are going to create in just a few lines one of the simplest yet incredibly powerful agents. The agent will act as a Data Analyst Assistant and help us in analyzing data contained in any Excel file. It will be able to identify trends, use models, make forecasts. In summary, we are going to create a simple agent that we can use in our daily work to analyze our data.
47 | | [Article](https://pub.towardsai.net/create-your-own-data-analyst-assistant-with-langchain-agents-722f1cdcdd7e) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_3_Data_Analyst_Agent.ipynb) |
48 | | --- | --- |
49 |
50 | ### Create a Medical ChatBot with LangChain and ChromaDB.
51 | In this example, two technologies seen previously are combined: agents and vector databases. Medical information is stored in ChromaDB, and a LangChain Agent is created, which will fetch it only when necessary to create an enriched prompt that will be sent to the model to answer the user's question.
52 |
53 | In other words, a RAG system is created to assist a Medical ChatBot.
54 |
55 | **Attention!!! Use it only as an example. Nobody should take the boot's recommendations as those of a real doctor. I disclaim all responsibility for the use that may be given to the ChatBot. I have built it only as an example of different technologies.**
56 | | [Article](https://medium.com/towards-artificial-intelligence/how-to-create-a-medical-agent-rag-system-effd0aaacc91?sk=e348bb9e1b949ecc48b4dfeb96381f5a) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_4_Medical_Assistant_Agent.ipynb) / [Gradio Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/3-LangChain/3_4b_Medical_Assistant_Agent_Gradio.ipynb)
57 | | ------ | ------ |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/4-Evaluating LLMs/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/4-Evaluating LLMs/.DS_Store
--------------------------------------------------------------------------------
/4-Evaluating LLMs/bleu_evaluation.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "view-in-github"
8 | },
9 | "source": [
10 | ""
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {
16 | "id": "tcSolREOl8Gl"
17 | },
18 | "source": [
19 | "
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | The metrics used to measure the performance of Large Language Models are quite different from the ones we've been using in more traditional models. We're shifting away from metrics like Accuracy, F1 score, or recall, and moving towards metrics like BLEU, ROUGE, or METEOR.
21 |
22 | However, the evaluation of applications with Large Language Models goes far beyond metrics. That's why we will analyze other techniques and tools, such as LangSmith or evaluation using other language models.
23 |
24 | ## Metrics Based in n-Grams.
25 | These metrics are tailored to the specific task assigned to the language model.
26 |
27 | In this section, we'll explore examples of several of these metrics and how to use them to determine whether one model is superior to another for a given task. We'll delve into practical scenarios where these metrics help us make informed decisions about the performance of different models.
28 | ### Evaluating Translations with BLEU.
29 | Bleu is one of the first Metrics stablished to evaluate the quality of translations. In the notebook we compare the quality of a translation made by google with other from an Open Source Model from Hugging Face.
30 | | Article WIP | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_1_bleu_evaluation.ipynb) |
31 | | ------ | ------ |
32 |
33 | ### Evaluating Summarization with ROUGE.
34 | We will explore the usage of the ROUGE metric to measure the quality of summaries generated by a language model.
35 | We are going to use two T5 models, one of them being the t5-Base model and the other a t5-base fine-tuned specifically designed for creating summaries.
36 |
37 | | [Article](https://medium.com/towards-artificial-intelligence/rouge-metrics-evaluating-summaries-in-large-language-models-d200ee7ca0e6) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_1_rouge_evaluations.ipynb)
38 | | ------ | ------ |
39 |
40 | ## Monitoring, Testing and Evaluating LLMs with LangSmith.
41 | ### Monitor an Agent using LangSmith.
42 | In this initial example, you can observe how to use LangSmith to monitor the traffic between the various components that make up the Agent. The agent is a RAG system that utilizes a vectorial database to construct an enriched prompt and pass it to the model. LangSmith captures both the use of the Agent's tools and the decisions made by the model, providing information at all times about the sent/received data, consumed tokens, the duration of the query, and all of this in a truly user-friendly environment.
43 | | [Article](https://medium.com/towards-artificial-intelligence/tracing-a-llm-agent-with-langsmith-a81975634555) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_2_tracing_medical_agent.ipynb) |
44 | | ------ | ------ |
45 |
46 | ### Evaluating the quality of summaries using Embedding distance with LangSmith.
47 | Previously in the notebook, Rouge Metrics: Evaluating Summaries, we learned how to use ROUGE to evaluate which summary best approximated the one created by a human. This time, we will use embedding distance and LangSmith to verify which model produces summaries more similar to the reference ones.
48 | | [Article](https://medium.com/towards-artificial-intelligence/evaluating-llm-summaries-using-embedding-distance-with-langsmith-5fb46fdae2a5?sk=24eb18ce187d28547cebd6fd3dd1ddad) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_2_Evaluating_summaries_embeddings.ipynb) |
49 | | ------ | ------ |
50 |
51 | ## Evaluating Large Language Models with Large Language Models.
52 | In the course, you have already seen several examples of evaluation or moderation using Large Language Models. Now, you will see how a library that is based on evaluating using Large Language Models: giskard.
53 |
54 | ### Evaluating a RAG solution using Giskard.
55 | We take the agent that functions as a medical assistant and incorporate Giskard to evaluate if its responses are correct. In this way, not only the model's response is evaluated, but also the information retrieval in the vector database. Giskard is a solution that allows evaluating a complete RAG solution.
56 | | [Article](https://medium.com/towards-artificial-intelligence/evaluating-a-rag-solution-with-giskard-1bc138fa44af?sk=10811fe2953eb511fb1ffefda326f7a2) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_3_evaluating_rag_giskard.ipynb)
57 | | ------ | ------ |
58 |
59 | ## Standard rankings.
60 | ### Introduction to the lm-evaluation library from Eluther.ai.
61 | The lm-eval library by EleutherAI provides easy access to academic benchmarks that have become industry standards. It supports the evaluation of both Open Source models and APIs from providers like OpenAI, and even allows for the evaluation of adapters created using techniques such as LoRA.
62 |
63 | In this notebook, I will focus on a small but important feature of the library: evaluating models compatible with Hugging Face's Transformers library.
64 | | Article - WIP| [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/4-Evaluating%20LLMs/4_4_lm-evaluation-harness.ipynb)
65 | | ------ | ------ |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/5-Fine Tuning/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/5-Fine Tuning/.DS_Store
--------------------------------------------------------------------------------
/5-Fine Tuning/readme.md:
--------------------------------------------------------------------------------
1 |
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | In this section, we will explore different techniques such as Prompt Fine Tuning or LoRA, and we will use the Hugging Face PEFT library to efficiently fine-tune Large Language Models.
21 | Additionally, we will explore optimization techniques such as model quantization.
22 |
23 | ### Fine-Tuning with LoRA using PEFT from Hugging Face.
24 | After a brief explanation of how the fine-tuning technique LoRA works, we will fine-tune a model from the Bloom family to teach it to construct prompts that can be used to instruct large language models.
25 | | [Article](https://medium.com/gitconnected/efficient-fine-tuning-with-lora-optimal-training-for-large-language-models-266b63c973ca) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/5-Fine%20Tuning/5_2_LoRA_Tuning.ipynb) |
26 | | --- | --- |
27 |
28 | ### Fine-Tuning a 7B Model in a single 16GB GPU using QLoRA.
29 | We are going to see a brief introduction to quantization, used to reduce the size of big Large Language Models. With quantization you can load big models reducing the memory resources needed. It also applies to the fine-tunig process, you can fine-tune the model in a single GPU without consuming all the resources. After the brief explanation we see an example about how is possible to fine-tune a Bloom 7B Model ina a t4 16GB GPU on Google Colab.
30 | | [Article](https://medium.com/towards-artificial-intelligence/qlora-training-a-large-language-model-on-a-16gb-gpu-00ea965667c1) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/5-Fine%20Tuning/5_3_QLoRA_Tuning.ipynb)
31 | | --- | --- |
32 |
33 | ### Prompt tuning using PEFT Library from Hugging Face.
34 | In this notebook, two models are trained using Prompt Tuning from the PEFT library. This technique not only allows us to train by modifying the weights of very few parameters but also enables us to have different specialized models loaded in memory that use the same foundational model.
35 |
36 | Prompt tuning is an additive technique, and the weights of the pre-trained model are not modified. The weights that we modify in this case are those of virtual tokens that we add to the prompt.
37 | | [Article](https://medium.com/towards-artificial-intelligence/fine-tuning-models-using-prompt-tuning-with-hugging-faces-peft-library-998ae361ee27) | [Notebook](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/5-Fine%20Tuning/5_4_Prompt_Tuning.ipynb)|
38 | | --- | --- |
39 |
40 | # Papers used in the Chapter:
41 | [The Power of Scale for Parameter-Efficient Prompt Tuning](https://doi.org/10.48550/arXiv.2104.08691). Prompt tuning using PEFT Library from Hugging Face.
42 |
43 | [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685). Fine-Tuning with LoRA using PEFT from Hugging Face.
44 |
45 | [QLoRA: Efficient Finetuning of Quantized LLMs](https://arxiv.org/abs/2305.14314). Fine Tuning & Optimizacion Lesson. QLoRA Fine-Tuning Sample.
46 |
--------------------------------------------------------------------------------
/6-PRUNING/readme.md:
--------------------------------------------------------------------------------
1 | **disclaimer: The pruning section was created after the first edition of the book was published. They are not included in the book’s original content but are intended to supplement and expand on the topics covered.**
2 |
3 |
12 | This is the unofficial repository for the book:
13 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
14 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
15 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
16 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
17 |
18 |
19 |
20 |
21 |
22 | # Pruning Techniques for Large Language Models
23 | **This section is still under construction. The goal is to build a curriculum that will take us from the most simple pruning techniques to creating a model using the same techniques employed by leading companies in the field, such as Microsoft, Google, Nvidia, or OpenAI, to build their models.**
24 |
25 | 📢 A portion of the structured pruning work in this section was presented at the [STAC Summit 2025 in London](https://www.stacresearch.com/spring2025LON), an international event focused on AI in finance. The talk explored pruning strategies for LLMs models, with a focus on performance-efficiency trade-offs and carbon footprint reduction.
26 |
27 | Pruning is a crucial optimization technique in machine learning, particularly for large language models (LLMs). It involves reducing the size and complexity of a model by eliminating less important components—such as neurons, layers, or weights, while maintaining most of the model’s performance. Pruning helps to make models more efficient, reducing their computational and memory requirements, which is especially important when deploying models on resource-constrained environments like mobile devices or edge servers.
28 |
29 | One of the great advantages of pruning compared to other techniques like quantization is that when selecting parts of the model to remove, you can choose those that contribute less to the model’s output, depending on the intended use.
30 |
31 | ## Structured Width Pruning: Eliminating Less Important Neurons from Feedforward Layers.
32 | In this type of pruning, the neurons that contribute least to the model's output are identified and removed. It is crucial to know or have access to the model's structure, as the pruning process is not applied to all layers. Depending on the need, specific layers are selected for pruning.
33 |
34 | ### Prune a distilGPT2 model using l1 norm to determine less important neurons.
35 | In the first notebook, the pruning process will be applied to the feedforward layers of a distilGPT2 model. This means the model will have reduced weights in those specific layers. The neurons to prune are selected based on their importance scores, which we compute using the L1 norm of their weights. It is a simple aproach, for this first example, that can be used when you want to create a Pruned Model that mimics the Base model in all the areas.
36 |
37 | By altering the model's structure, a new configuration file must be created to ensure it works correctly with the `transformers` library.
38 |
39 | | [Notebook: Pruning a distilGPT2 model.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/6_1_pruning_structured_l1_diltilgpt2.ipynb) |
40 | | --- |
41 |
42 | ### Prune a Llama3.2 model.
43 | In this first notebook, we attempt to replicate the pruning process used with the distilGPT2 model but applied to a Llama model. By not taking the model's characteristics into account, the pruning process results in a completely unusable model. This notebook serves as an exercise to understand how crucial it is to know the structure of the models that will undergo pruning.
44 | | [Notebook: Pruning a Llama3.2 model INCORRECT APROACH.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/6_2_pruning_structured_llama3.2-1b_KO.ipynb) |
45 | | --- |
46 |
47 |
48 | The second notebook addresses the issues encountered when applying the same pruning process to the Llama model as was used for distilGPT2.
49 |
50 | The correct approach is to treat the MLP layers of the model as pairs rather than individual layers and to calculate neuron importance by considering both layers together. Additionally, we switch to using the maximum absolute weight to decide which neurons remain in the pruned layers.
51 |
52 | With these two simple changes, which adapt the pruning process to the structure of Llama models, we achieve a smaller model that retains a significant portion of the original model's knowledge.
53 | | [Pruning Llama3 Article](https://medium.com/towards-data-science/how-to-prune-llama-3-2-and-similar-large-language-models-cf18e9a2afb6?sk=af4c5e40e967437325050f019b3ae606) | [Notebook: Pruning a Llama3.2 model CORRECT APROACH.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/6_3_pruning_structured_llama3.2-1b_OK.ipynb) |
54 | | --- | --- |
55 |
56 | ## Structured Depth Pruning. Eliminating complete blocks from large language models.
57 | ### Depth pruning in a Llama-3.2 model.
58 | In this notebook, we will look at an example of depth pruning, which involves removing entire layers from the model.
59 | The first thing to note is that removing entire layers from a transformer model usually has a significant impact on the model's performance. This is a much more drastic architectural change compared to the simple removal of neurons from the MLP layers, as seen in the previous example.
60 | | [Notebook: Depth pruning a Llama Model.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/6_5_pruning_depth_st_llama3.2-1b_OK.ipynb) |
61 | | --- |
62 |
63 | ### Pruning Attention Layers.
64 | This notebook implements the ideas presented in the paper: [What Matters in Transformers? Not All Attention is Needed](https://arxiv.org/abs/2406.15786).
65 |
66 | In this notebook, the attention layers that contribute the least to the model are marked to be bypassed, improving inference efficiency and reducing the model's resource consumption. To identify the layers that contribute the least, a simple activation with a prompt is used, and the cosine similarity between the layer's input and output is measured. The smaller the difference, the less modification the layer introduces.
67 |
68 | The layer selection process implemented in the notebook is iterative. That is, the least contributing layer is selected, and the contribution of the remaining layers is recalculated using the same prompt. This process is repeated until the desired number of layers has been deactivated.
69 |
70 | Since this type of pruning does not alter the model's structure, it does not reduce the model's size.
71 |
72 | | Article: WIP. | [Notebook: Pruning Attention Layers.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/6_6_pruning_attention_layers.ipynb) |
73 | | --- | --- |
74 |
75 |
76 | # Knowledge distillation.
77 | Knowledge Distillation involves training a smaller "student" model to mimic a larger, well-trained "teacher" model. The student learns not just from the correct labels but also from the probability distributions (soft targets) that the teacher model produces, effectively transferring the teacher's learned knowledge into a more compact form.
78 |
79 | When combined with Pruning, you first create a pruned version of your base model by removing less important connections. During this process, some knowledge is inevitably lost. To recover this lost knowledge, you can apply Knowledge Distillation using the original base model as the teacher and the pruned model as the student, helping to restore some of the lost performance.
80 |
81 | Both techniques address the same challenge: reducing model size and computational requirements while maintaining performance, making them crucial for deploying AI in resource-constrained environments like mobile devices.
82 |
83 | ## Recovering knwoledge from the base model using KD.
84 | In this notebook, we will use Knowledge distillation to recover some of the knowledge lost during the model pruning process. Llama-3.2-1B will be used as the Teacher model, and the 40% pruned version will be used as the Student model. We will specifically improve the performance on the Lambada benchmark.
85 | | [Notebook: Knowledge Distillation Llama 3.2.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/7_1_knowledge_distillation_Llama.ipynb) |
86 | | --- |
87 |
88 | # Bias & Fairness in LLMs.
89 | This section introduces a preliminary line of work focused on detecting bias in LLMs by visualizing neural activations. While still in its early stages, these analyses pave the way for future fairness-aware pruning strategies, where structural pruning decisions also take into account the impact on different demographic or semantic groups.
90 |
91 | ### Visualizing Bias in State of the art Transformer Models.
92 | This notebook introduces techniques for visualizing neural activations in Transformer models, as a first step toward detecting and mitigating bias in language models.
93 | Techniques applied:
94 | * Dimensionality reduction with PCA
95 | * Visualization using heatmaps
96 | * Differential activation analysis between contrastive groups
97 |
98 | | [Article: From Biased to Balanced: Visualizing and Fixing Bias in Transformer Models](https://medium.com/data-science-collective/from-biased-to-balanced-visualizing-and-fixing-bias-in-transformer-models-d1a82f35393c?sk=abd12073ee311c3752da3219a5baf20f) | [Notebook: 8_1_transformer_activations_visualization.ipynb](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/6-PRUNING/8_1_transformer_activations_visualization.ipynb) |
99 | | --- | --- |
100 |
101 | Why is it in the Pruning section?
102 | While this work is thematically aligned with fairness and equity evaluation in models, it's temporarily placed here due to its direct connection with upcoming fairness-aware pruning strategies. These strategies explore activation patterns as a criterion for reducing parameters while preserving the representation of different groups.
103 |
104 | This notebook will serve as the foundation for the future section 8-Bias, which will include:
105 | * Tools for automated bias analysis
106 | * Fairness experiments in pruned models
107 | * Integration with the WizardSData library for contrastive dataset generation
108 |
109 | ### References
110 | > Saurav Muralidharan, Sharath Turuvekere Sreenivas, Raviraj Joshi, Marcin Chochowski, Mostofa Patwary, Mohammad Shoeybi, Bryan Catanzaro, Jan Kautz, Pavlo Molchanov, "Compact Language Models via Pruning and Knowledge Distillation," arXiv preprint arXiv:2407.14679, 2024. Available at: [https://doi.org/10.48550/arXiv.2407.14679](https://doi.org/10.48550/arXiv.2407.14679).
111 |
112 | > He, S., Sun, G., Shen, Z., & Li, A. (2024). What matters in transformers? not all attention is needed. arXiv preprint arXiv:2406.15786. https://doi.org/10.48550/arXiv.2406.15786
113 |
114 |
115 | > Kim, B. K., Kim, G., Kim, T. H., Castells, T., Choi, S., Shin, J., & Song, H. K. (2024). Shortened llama: A simple depth pruning for large language models. arXiv preprint arXiv:2402.02834, 11. https://doi.org/10.48550/arXiv.2402.02834
116 |
117 | > Martra, P. (2024, December 26). Exploring GLU Expansion Ratios: Structured Pruning in Llama-3.2 Models. https://doi.org/10.31219/osf.io/qgxea
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/Datasets/summaries_cnn.csv:
--------------------------------------------------------------------------------
1 | base,finetuned,reference
2 | "best died in hospice in Hickory, north Carolina, of complications from pneumonia. he played bumbling sheriff Rosco P. Coltrane on ""the Dukes of Hazzard"" he was born in Kentucky and raised in rural Indiana.","Jimmie Best was ""the most constantly creative person I have ever known,"" co-star John Schneider says. ""The Dukes of Hazzard"" ran until 1985 and spawned TV movies, an animated series and video games. ""Jimmie Best was my teacher, mentor, close friend and collaborator for 26 years,"" friend says.","James Best, who played the sheriff on ""The Dukes of Hazzard,"" died Monday at 88 .
3 | ""Hazzard"" ran from 1979 to 1985 and was among the most popular shows on TV ."
4 | """it doesn't matter what anyone says, he is presumed to be innocent,"" attorney says. cardiologist's lawyer says allegations against his client are ""completely unsubstantiated"" prosecutors say he pleaded not guilty to all charges. he faces charges in connection with a plot to take out a rival doctor.","Dr. Anthony Moschetto's attorney calls the allegations ""completely unsubstantiated"" He is accused of plotting to kill a rival doctor on Long Island.","A lawyer for Dr. Anthony Moschetto says the charges against him are baseless .
5 | Moschetto, 54, was arrested for selling drugs and weapons, prosecutors say .
6 | Authorities allege Moschetto hired accomplices to burn down the practice of former associate ."
7 | president Barack Obama took part in a roundtable discussion this week on climate change. he refocused on the issue from a public health vantage point. the average american can also do their part to reduce their own carbon footprint.,President Obama says climate change is a public health issue that affects all of us. He says the President wants the average American to take away the health impacts of climate change.,"""No challenge poses more of a public threat than climate change,"" the President says .
8 | He credits the Clean Air Act with making Americans ""a lot"" healthier ."
9 | independent channel in Russia aired Hillary Clinton's first campaign video with a rating stamp. the channel said it didn't want to break the country's anti-gay propaganda law. the video features a gay couple holding hands.,"A Russian TV channel aired Hillary Clinton's first campaign video with a rating stamp. The channel said it didn't want to break Russia's controversial anti-gay propaganda law. The law bans ""propaganda of nontraditional sexual relations around minors""","Presidential hopeful's video, featuring gay couple, gets mature rating in Russia .
10 | Russian TV channel feared airing it would break the country's anti-gay propaganda law .
11 | Clinton announced her support for same-sex marriage in 2013 ."
12 | sen. marco rubio is running for the 2016 presidential nomination. he has been his own worst enemy on immigration reform and Cuba relations. he has embraced a typical conservative approach to immigration.,Ruben Navarrette: Marco Rubio is missing a chance to set himself apart from GOP candidates. He says Rubio has been his own worst enemy on immigration and Cuba policy.,"Raul Reyes: In seeking Latino vote, Marco Rubio his own worst enemy on two key issues: immigration reform, Cuba relations .
13 | He says on health care, climate change and other issues, he breaks from Latinos' positions. Polls show they don't favor him ."
14 | """Orphan Black"" kicks off its second season on saturday. the series returns with a new subtitle, ""Washington's Spies"" and a new Monday night time slot.","The world of Westeros returns for a fifth season in one of the biggest season premieres of the year. ""Game of Thrones"" returns for a fifth season in one of the biggest premieres of the year.","Critically acclaimed series ""Orphan Black"" returns .
15 | ""Turn: Washington's Spies"" starts a second season .
16 | ""Game of Thrones"" is back for season five ."
17 | "ramp agent who fell asleep in plane's cargo hold is permanently banned from working on planes. ""we're going to come back around,"" passenger tells kcpq. ""all of a sudden we heard all this pounding underneath the plane,"" passenger says.","A ramp agent is permanently banned from working on an Alaska Airlines plane. ""I'm trapped in this plane and I called my job, but I'm in this plane,"" a passenger says.","The ramp agent fell asleep in the plane's cargo hold .
18 | He can no longer work on Alaska Airlines flights ."
19 | the Taliban released a biography of mullah Mohammed Omar. the reclusive militant is credited with founding the group in the early 1990s. he is credited with leading rebel groups against the communists.,Biography challenges rumors that Taliban leader Mohammed Omar is not alive. Omar studied at a religious school and was propelled into the arms of the Afghan opposition.,"Mullah Omar, the reclusive founder of the Afghan Taliban, is still in charge, a new biography claims .
20 | An ex-Taliban insider says there have been rumors that the one-eyed militant is dead ."
21 | "Michelle MacLaren is leaving the upcoming ""Wonder Woman"" movie. MacLaren was announced as director of the movie in November.","Michelle MacLaren was announced as director of the upcoming ""Wonder Woman"" The movie, starring Gal Gadot, is still set for release on June 23, 2017.","Michelle MacLaren is no longer set to direct the first ""Wonder Woman"" theatrical movie .
22 | MacLaren left the project over ""creative differences""
23 | Movie is currently set for 2017 ."
24 | police say they knew a burglar alarm went off but didn't respond to the call. the robbery took place over the weekend in the heart of the jewelry district. a former police official has speculated that the loss could be in the hundreds of thousands of pounds.,A burglar alarm was activated at Hatton Garden Safe Deposit Ltd. on Easter Sunday. Numerous British news organizations put the value of the loss in the hundreds of thousands of pounds.,"British tabloid releases video it says shows the robbery being carried out .
25 | British police say they didn't respond to a burglar alarm in jewelry district .
26 | Police give no value of the amount taken in the heist in London's jewelry district ."
27 |
--------------------------------------------------------------------------------
/E1-NL2SQL for big Databases/Select_hs_Tables.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "ecff8312",
6 | "metadata": {
7 | "colab_type": "text",
8 | "id": "view-in-github"
9 | },
10 | "source": [
11 | ""
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "id": "c1c0362a-d133-4a1b-8161-75b4f53e6bea",
17 | "metadata": {
18 | "id": "c1c0362a-d133-4a1b-8161-75b4f53e6bea"
19 | },
20 | "source": [
21 | "
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | # Decoding Risk: Transforming Banks with Customer Embeddings.
21 |
22 | If we were tasked with creating a system using LLM to enhance a bank's decision-making regarding risk assessment or product approval for its clients, the initial thought might be to provide the LLM with client and product information, enabling it to make decisions on whether to grant the product to the client or not.
23 |
24 | But let me tell you, this wouldn't work. We can't solve everything by providing information to an LLM and expecting it to generate an output based on the input data.
25 |
26 | What we're going to set up is a project that will integrate with the bank's other systems, aiming not only to enhance decision-making regarding risk but also to improve maintenance and streamline the overall development of the entity's information systems.
27 |
28 | We'll be altering the format in which we store customer information, and consequently, we'll also be changing how this information travels within the systems.
29 |
30 | *Before we proceed, **a disclaimer:** All diagrams and descriptions of the solutions presented here are simplified to the maximum extent. This is a project that will likely span years and requires an immense development team. Here, I'm only presenting the idea, with a brief outline of how it should be and the advantages it can bring.*
31 |
32 | # Actual Client Risk System.
33 |
34 | Let's start by looking at an example of what a current risk system for any institution might look like.
35 |
36 |
37 |
38 | I'm going to detail the flow of a request:
39 | 1. A loan request is initiated from one of the channels.
40 | 2. The operation data + customer identifier is passed.
41 | 3. The risk application collects customer data.
42 | 4. The risk application collects product data.
43 | 5. With customer, product, and operation data, a decision is made.
44 | 6. The decision is returned to the channel that initiated the request.
45 |
46 | The process doesn't seem overly complicated, but let's delve a bit deeper. What are we talking about when we refer to user data?
47 |
48 | Is it a snapshot of the moment? In other words: age, gender, account balances, committed balances, available credit cards, relationships with other entities, investments, funds, pension plans, salary, and so forth?
49 |
50 | Well, now we have a better idea about the amount of data that must be taken into account, and we are talking about just a snapshot, the current moment. But wouldn't it be better if we made decisions based on how all these variables have been changing over time? This implies considering even more data.
51 |
52 | As you can imagine, obtaining all this data involves a very high number of calls to different systems within the bank. I've simplified it by referring to "user data," but that's not a singular entity. Behind that label, there's a myriad of applications, each with its own set of data that we need to request.
53 |
54 | In summary, calculating the customer's position is typically done in a batch process that updates every X days, depending on the bank.
55 |
56 | The decision of whether to grant a loan is made by an algorithm or a traditional machine learning model that takes specific product data and precalculated risk positions as input.
57 |
58 | # How can a Large Language Model (LLM) help us improve this process and, above all, simplify it?
59 |
60 | In this project, the key lies not in the deployment of LLMs but rather in crafting embeddings to encapsulate the entirety of customer information. This is a pivotal decision requiring meticulous justification. Let's delve into some advantages of employing embeddings.
61 |
62 | * **Improved Feature Representation**: Can effectively represent complex and unstructured data sources, such as text data from customer interactions, financial reports, and social media profiles. By transforming these raw texts into numerical vectors that capture their underlying semantic meaning, embeddings enable credit risk models to incorporate richer and more informative features, leading to more accurate risk assessments.
63 | * **Similarity Analysis**: Eenable measuring similarity between different entities. This can be useful in identifying similar customer profiles or similar transactions, helping to identify potential risks based on historical patterns.
64 | * **Enhanced Risk Identification**: Can identify hidden patterns and relationships within vast amounts of data, allowing credit risk models to uncover subtle signals that may not be apparent from traditional numerical data. This improved ability to identify and understand risk factors can lead to more precise risk assessments and better-informed lending decisions.
65 | * **Handling Missing Data**: Can handle missing data more gracefully than traditional methods. The model can learn meaningful representations even when certain features are missing, providing more robust credit risk assessments.
66 | * **Reduced Dimensionality**: Exhibit reduced dimensionality compared to the original data representations. This facilitates storage, transmission, and processing of information.
67 | * **Transferability Convenience**: Given that embeddings are numerical representations, they can be easily transferred across various systems and components within the framework. This enables consistency in the utilization of data representations across different segments of the infrastructure.
68 |
69 | These are just a few of the advantages that storing customer information in embeddings can provide. Let's say I am fully convinced, and possibly, even if we haven't entirely convinced the leadership, we have certainly piqued their curiosity to inquire about how the project should be approached. In other words, a preliminary outline of the solution.
70 |
71 | ## First picture of the solution.
72 | The first step is to select a model and train it with a portion of the data we want to store as embeddings. The model selection and training process are crucial. The entity has sufficient data to train a model from scratch using only its own data, without having to resort to a pre-trained model with financial data, which are not particularly abundant.
73 |
74 | The challenge we face is not the quantity of data but rather the selection of which data to use and determining the cost we are willing to assume for training our model.
75 |
76 | From now on, let's refer to this kind of model as FMFD (Foundational Model on Financial Data). And we need to train at least thre of them, one to create the embeddings of the client, the other with the data of the product, and one trained to return the credit default rate.
77 |
78 | The latter model introduces an interesting feature to the project. Classical models are designed to solve a problem by returning a single output. That is, a traditional machine learning model might provide a binary output indicating whether to approve or deny credit, while another could indicate the likelihood of credit default. **In contrast, when using an LLM (Multi-Output Language Model), the output can be multiple, and from a single call, we could obtain various pieces of information**. We might even obtain a list of recommended products, the maximum allowable credit, or an acceptable risk-associated interest rate. It all depends on the data used to train this model.
79 |
80 |
81 |
82 | Starting from the point where we have already trained the three necessary models, we store the customer embeddings in an embeddings database. This could be a standard database or a vector database. For now, we won't delve into the advantages and disadvantages of using one type of database over another.
83 |
84 | The crucial point is that these embeddings can be continuously calculated as the customer's situation evolves, as it is a lightweight process that can be performed online. Although we also have the option of employing a batch process at regular intervals to handle multiple embeddings simultaneously and optimize resource utilization.
85 |
86 | Let's explore what happens when we receive a transaction that needs to be accepted or rejected using our system. With the transaction data, we generate embeddings for the product to be granted, employing the pre-trained model with product data. This yields specific embeddings for the transaction.
87 |
88 | To make the decision, we'll need the third model, to which we'll feed both embeddings – one for the customer and one for the transaction. There are several options for combining these embeddings:
89 |
90 | * Concatenate the two vectors.
91 | * Add them to a single vector, using, for example, vector summation.
92 | * Pass the data as two independent embeddings.
93 | * Pass the embeddings in a list.
94 |
95 | My preference is to pass them using a single concatenated vector. With this vector as input, the third model is capable of generating a response that, depending on the training performed, can provide more or less information.
96 |
97 | # Conclusion.
98 |
99 | With this solution, we have a system that utilizes nearly real-time information about the customer's position, along with all the historical data, to analyze whether they can obtain one of our financial products. We've increased the quality and quantity of information used for making decisions regarding our customers' risk operations.
100 |
101 | But that's not all; the use of embeddings also simplifies system maintenance and opens up a world of possibilities that are challenging to detail at this moment. We have a system that adapts better to changes in information because the entire system deals with embeddings of fixed length, as opposed to a multitude of fields that can vary.
102 |
103 | The compact size of the embeddings even allows them to reside on the client's device, enabling it to make decisions independently without the need to make a call to the bank's systems.
104 |
105 | ## Preparatory Steps when initiating the project.
106 | As one can imagine, we are not discussing a two-month project here. This initiative would redefine how a banking entity stores and processes information about its clients and products. It's a transformation that could span years, impacting a significant portion of its information systems department to varying degrees.
107 |
108 | A project of this magnitude necessitates a phased approach, allowing for pivots throughout its lifespan and a gradual introduction.
109 |
110 | My recommendation is start with a proof of concept, utilizing a single model but trained using QLoRA for the three identified tasks: Client Embeddings, Product Embeddings, and Decision Making.
111 |
112 | By adopting this approach, we can have three models operational swiftly, with minimal resource requirements for both training and inference. For each of these three models, decisions should be made regarding the data we want/need to use for their training, or in this case, fine-tuning.
113 | __________________________
114 | Check the FinGPT Model, it can be a good option to use as our FMFD. https://arxiv.org/abs/2306.06031
115 |
116 | This solution has been inspired by this article [The Shaky Foundations of Foundation Models in Healthcare](https://hai.stanford.edu/news/shaky-foundations-foundation-models-healthcare) at Stanford University
117 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [2023] [Pere Martra Manonelles]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/LLM_course_diagram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/LLM_course_diagram.jpg
--------------------------------------------------------------------------------
/P1-NL2SQL/6_2_Azure_NL2SQL_Client.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "view-in-github"
8 | },
9 | "source": [
10 | ""
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {
16 | "id": "Paa52inqag9w"
17 | },
18 | "source": [
19 | "
\n",
20 | "
Large Language Models Projects
\n",
21 | "
Apply and Implement Strategies for Large Language Models
\n",
22 | "
6.2-Calling Azure OpenAI Services from a Notebook.
\n",
23 | " \n",
24 | "
\n",
25 | "\n",
26 | "by [Pere Martra](https://www.linkedin.com/in/pere-martra/)\n",
27 | "___________\n",
28 | "Models:\n",
29 | "\n",
30 | "Colab Environment: CPU\n",
31 | "\n",
32 | "Keys:\n",
33 | "* Azure\n",
34 | "* NL2SQL\n",
35 | "___________\n"
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {
41 | "id": "uxFVaxlskUf-"
42 | },
43 | "source": [
44 | "In this notebook, we make a call to a GPT3.5 model that we've set up from Azure OpenAI Studio to function as a translator for SQL queries from natural language.\n",
45 | "\n",
46 | "The prompt structure has been created and explained in a [previous article](https://colab.research.google.com/drive/1mbIAv1p6nqtsngXfCG5WrozlvmoJI06F#scrollTo=uxFVaxlskUf-&line=3&uniqifier=1), part of the Large Language Models course."
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {
53 | "colab": {
54 | "base_uri": "https://localhost:8080/"
55 | },
56 | "id": "Jssm3zDHbKq-",
57 | "outputId": "8bdf2324-ef7e-4355-fb9c-29eaa8139dbb"
58 | },
59 | "outputs": [],
60 | "source": [
61 | "#Install openai\n",
62 | "!pip install -q openai==1.30.1"
63 | ]
64 | },
65 | {
66 | "cell_type": "code",
67 | "execution_count": null,
68 | "metadata": {
69 | "id": "ZQ48GZBFaaHg"
70 | },
71 | "outputs": [],
72 | "source": [
73 | "import os\n",
74 | "import openai"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {
80 | "id": "ZzKsM7pIEguo"
81 | },
82 | "source": [
83 | "\n",
84 | "You can Obtain the **prompt** the **api_base** and the **key** from the Sample Code window on Chat Playground in Azure Open Studio.\n",
85 | "\n",
86 | "\n"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {
93 | "colab": {
94 | "base_uri": "https://localhost:8080/"
95 | },
96 | "id": "_rWYcJ2gKEae",
97 | "outputId": "8031b629-a557-41dc-a7fc-876512221491"
98 | },
99 | "outputs": [],
100 | "source": [
101 | "from getpass import getpass\n",
102 | "os.environ[\"AZURE_OPENAI_KEY\"] = getpass(\"Azure AI key:\")"
103 | ]
104 | },
105 | {
106 | "cell_type": "code",
107 | "execution_count": null,
108 | "metadata": {
109 | "id": "B2C_0LNjHFo3"
110 | },
111 | "outputs": [],
112 | "source": [
113 | "\n",
114 | "client = AzureOpenAI(\n",
115 | " azure_endpoint = \"https://largelanguagemodelsprojects.openai.azure.com/\",\n",
116 | " api_key=os.getenv(\"AZURE_OPENAI_KEY\"),\n",
117 | " api_version=\"2024-02-15-preview\"\n",
118 | ")\n"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {
125 | "id": "VQeyT_dCbGND"
126 | },
127 | "outputs": [],
128 | "source": [
129 | "context = [{\"role\":\"system\",\"content\":\"create table employees( \\n ID_Usr INT primary key,\\n name VARCHAR);\\n /*3 example rows\\n select * from employees limit 3;\\n ID_Usr name\\n 1344 George StPierre\\n 2122 Jon jones\\n 1265 Anderson Silva\\n */\\n\\n create table salary(\\n ID_Usr INT,\\n year DATE,\\n salary FLOAT,\\n foreign key (ID_Usr) references employees(ID_Usr));\\n /*3 example rows\\n select * from salary limit 3\\n ID_Usr date salary\\n 1344 01/01/2023 61000\\n 1344 01/01/2022 60000\\n 1265 01/01/2023 55000\\n */\\n\\n create table studies(\\n ID_study INT,\\n ID_Usr INT,\\n educational_level INT, /* 5=phd, 4=Master, 3=Bachelor */\\n Institution VARCHAR,\\n Years DATE,\\n Speciality VARCHAR,\\n primary key (ID_study, ID_Usr),\\n foreign key(ID_Usr) references employees (ID_Usr));\\n /*3 example rows\\n select * from studies limit 3\\n ID_Study ID_Usr educational_level Institution Years Speciality\\n 2782 1344 3 UC San Diego 01/01/2010 Bachelor of Science in Marketing\\n 2334 1344 5 MIT 01/01/2023 Phd. Data Science.\\n 2782 2122 3 UC San Diego 01/01/2010 Bachelor of Science in Marketing\\n */\\n-- Maintain the SQL order simple and efficient as you can, using valid SQL Lite, answer the following questions, returning only SQL code, for the table provided above.\"},{\"role\":\"user\",\"content\":\"How Many employes we have with a salary bigger than 50000?\"},{\"role\":\"assistant\",\"content\":\"SELECT COUNT(*) AS total_employees\\nFROM employees e\\nINNER JOIN salary s ON e.ID_Usr = s.ID_Usr\\nWHERE s.salary > 50000;\"},{\"role\":\"user\",\"content\":\"Return the names of the three people who have had the highest salary increase in the last three years.\"},{\"role\":\"assistant\",\"content\":\"SELECT e.name\\nFROM employees e\\nJOIN salary s ON e.ID_usr = s.ID_usr\\nWHERE s.year >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR)\\nGROUP BY e.name\\nORDER BY (MAX(s.salary) - MIN(s.salary)) DESC\\nLIMIT 3;\"},{\"role\":\"user\",\"content\":\"Give me the name of the worst paid emploee\"},{\"role\":\"assistant\",\"content\":\"SELECT e.name\\nFROM employees e\\nJOIN salary s ON e.ID_usr = s.ID_usr\\nWHERE s.salary = (SELECT MIN(salary) FROM salary);\"}]"
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": null,
135 | "metadata": {
136 | "id": "j6M7t_pgy-CW"
137 | },
138 | "outputs": [],
139 | "source": [
140 | "context = [{\"role\":\"system\",\"content\":\"\"\"\n",
141 | " create table employees(\n",
142 | " ID_Usr INT primary key,\n",
143 | " name VARCHAR);\n",
144 | " /*3 example rows\n",
145 | " select * from employees limit 3;\n",
146 | " ID_Usr name\n",
147 | " 1344 George StPierre\n",
148 | " 2122 Jon jones\n",
149 | " 1265 Anderson Silva\n",
150 | " */\n",
151 | "\n",
152 | " create table salary(\n",
153 | " ID_Usr INT,\n",
154 | " year DATE,\n",
155 | " salary FLOAT,\n",
156 | " foreign key (ID_Usr) references employees(ID_Usr));\n",
157 | " /*3 example rows\n",
158 | " select * from salary limit 3\n",
159 | " ID_Usr date salary\n",
160 | " 1344 01/01/2023 61000\n",
161 | " 1344 01/01/2022 60000\n",
162 | " 1265 01/01/2023 55000\n",
163 | " */\n",
164 | "\n",
165 | " create table studies(\n",
166 | " ID_study INT,\n",
167 | " ID_Usr INT,\n",
168 | " educational_level INT, /* 5=phd, 4=Master, 3=Bachelor */\n",
169 | " Institution VARCHAR,\n",
170 | " Years DATE,\n",
171 | " Speciality VARCHAR,\n",
172 | " primary key (ID_study, ID_Usr),\n",
173 | " foreign key(ID_Usr) references employees (ID_Usr));\n",
174 | " /*3 example rows\n",
175 | " select * from studies limit 3\n",
176 | " ID_Study ID_Usr educational_level Institution Years Speciality\n",
177 | " 2782 1344 3 UC San Diego 01/01/2010 Bachelor of Science in Marketing\n",
178 | " 2334 1344 5 MIT 01/01/2023 Phd. Data Science.\n",
179 | " 2782 2122 3 UC San Diego 01/01/2010 Bachelor of Science in Marketing\n",
180 | " */\n",
181 | " -- Maintain the SQL order simple and efficient as you can,\n",
182 | " using valid SQL Lite, answer the following questions,\n",
183 | " returning only SQL code, for the table provided above.\"\"\"},\n",
184 | " {\"role\":\"user\",\"content\":\"\"\"How Many employes we have with a salary bigger than 50000?\"\"\"},\n",
185 | " {\"role\":\"assistant\",\"content\":\"\"\"\n",
186 | " SELECT COUNT(*) AS total_employees\n",
187 | " FROM employees e\n",
188 | " INNER JOIN salary s ON e.ID_Usr = s.ID_Usr\n",
189 | " WHERE s.salary > 50000;\"\"\"},\n",
190 | " {\"role\":\"user\",\"content\":\"Return the names of the three people who have had the highest salary increase in the last three years.\"},\n",
191 | " {\"role\":\"assistant\",\"content\":\"\"\"\n",
192 | " SELECT e.name\n",
193 | " FROM employees e\n",
194 | " JOIN salary s ON e.ID_usr = s.ID_usr\n",
195 | " WHERE s.year >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR)\n",
196 | " GROUP BY e.name\n",
197 | " ORDER BY (MAX(s.salary) - MIN(s.salary)) DESC\\nLIMIT 3;\"\"\"}]"
198 | ]
199 | },
200 | {
201 | "cell_type": "code",
202 | "execution_count": null,
203 | "metadata": {
204 | "id": "BcpmXLF1cVGb"
205 | },
206 | "outputs": [],
207 | "source": [
208 | "#Functio to call the model.\n",
209 | "def return_CCRMSQL(user_message, context):\n",
210 | "\n",
211 | " newcontext = context.copy()\n",
212 | " newcontext.append({'role':'user', 'content':\"question: \" + user_message})\n",
213 | "\n",
214 | " response = client.chat.completions.create(\n",
215 | " model=\"GPT35NL2SQL\", #Our deployment\n",
216 | " messages = newcontext,\n",
217 | " temperature=0,\n",
218 | " max_tokens=800)\n",
219 | "\n",
220 | " return (response.choices[0].message.content)"
221 | ]
222 | },
223 | {
224 | "cell_type": "code",
225 | "execution_count": null,
226 | "metadata": {
227 | "colab": {
228 | "base_uri": "https://localhost:8080/"
229 | },
230 | "id": "VmB27XTWhKOn",
231 | "outputId": "a00e7627-dcdc-4c26-837e-93631ca61bd6"
232 | },
233 | "outputs": [],
234 | "source": [
235 | "context_user = context.copy()\n",
236 | "response = return_CCRMSQL(\"What's the name of the best paid employee?\", context_user)\n",
237 | "print(response)\n"
238 | ]
239 | },
240 | {
241 | "cell_type": "code",
242 | "execution_count": null,
243 | "metadata": {
244 | "colab": {
245 | "base_uri": "https://localhost:8080/"
246 | },
247 | "id": "svMFswMghM3D",
248 | "outputId": "a2cc72a8-550d-47d7-f187-745020238263"
249 | },
250 | "outputs": [],
251 | "source": [
252 | "print(return_CCRMSQL(\"Return the Institution with a higher average salary\", context_user))"
253 | ]
254 | },
255 | {
256 | "cell_type": "markdown",
257 | "metadata": {
258 | "id": "CxcnI77oqLpl"
259 | },
260 | "source": [
261 | "#Conclusions.\n",
262 | "Once you have the prompt to use, set up the OpenAI services in Azure is straightforward.\n",
263 | "\n",
264 | "I observed some differences in the SQL from the one obtained calling directly to OpenAI API.\n"
265 | ]
266 | },
267 | {
268 | "cell_type": "code",
269 | "execution_count": null,
270 | "metadata": {
271 | "id": "YMVK994yhbnP"
272 | },
273 | "outputs": [],
274 | "source": []
275 | }
276 | ],
277 | "metadata": {
278 | "colab": {
279 | "authorship_tag": "ABX9TyPviR8piXLbY+Rsqjm1IQE7",
280 | "include_colab_link": true,
281 | "provenance": []
282 | },
283 | "kernelspec": {
284 | "display_name": "Python 3",
285 | "name": "python3"
286 | },
287 | "language_info": {
288 | "name": "python"
289 | }
290 | },
291 | "nbformat": 4,
292 | "nbformat_minor": 0
293 | }
294 |
--------------------------------------------------------------------------------
/P1-NL2SQL/6_3_AWS_Bedrock_NL2SQL_Client.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "view-in-github"
8 | },
9 | "source": [
10 | ""
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {
16 | "id": "Paa52inqag9w"
17 | },
18 | "source": [
19 | "
\n",
20 | "
Large Language Models Projects
\n",
21 | "
Apply and Implement Strategies for Large Language Models
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | In this straightforward initial project, we are going to develop a SQL generator from natural language. We'll begin by creating the prompt to implement two solutions: one using OpenAI models running on Azure, and the other with an open-source model from Hugging Face.
21 |
22 |
23 |
24 | ## Prompt Creation
25 | We will create two NL2SQL prompts that adhere to the best practices published in the paper from the University of Ohio (see below). Adapting them to the specific needs of OpenAI and SQLCoder Models. First we will create trhe OpenAI Prompt, then continue adapting the prompt created to SQLCoder, an open-source model trained by Defog from a super efficient Code Llama 7B Model, available on from Hugging Face.
26 |
27 | Although both prompts are based on the same paper, there are slight differences in the creation process.
28 |
29 | Besides creating the prompt, we conduct a few tests and observe how both models generate SQL commands correctly.
30 | | Article | Notebook |
31 | | --------- | --- |
32 | | [Create a NL2SQL prompt for OpenAI](https://pub.towardsai.net/create-a-superprompt-for-natural-language-to-sql-conversion-for-openai-9d19f0efe8f4?sk=88889b3417c97481e6a907e3aef74ca2) | [Notebook for OpenAI](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P1-NL2SQL/nl2sql_prompt_OpenAI.ipynb) |
33 | | Article WIP | [Notebook for SQLCoder](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P1-NL2SQL/nl2sql_prompt_SQLCoder.ipynb) |
34 |
35 | ## Azure Configuration.
36 | In Azure, we will configure the Open Services using the prompt created earlier for OpenAI models. This allows us to conduct tests and set up an inference endpoint to call for obtaining SQL commands.
37 | | Article | Notebook |
38 | | --------- | --- |
39 | | [How To Set up a NL2SQL System With Azure OpenAI Studio.](https://medium.com/towards-artificial-intelligence/how-to-set-up-an-nl2sql-system-with-azure-openai-studio-2fcfc7b57301) | [Using the inference point on Azure.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P1-NL2SQL/NL2SQL_OpenAI_Azure.ipynb) |
40 |
41 | # Papers used in the project:
42 | * [How to Prompt LLMs for Text-to-SQL: A Study in Zero-shot, Single-domain, and Cross-domain Settings](https://arxiv.org/abs/2305.11853)
43 |
--------------------------------------------------------------------------------
/P2-MHF/readme.md:
--------------------------------------------------------------------------------
1 |
10 | This is the unofficial repository for the book:
11 | Large Language Models: Apply and Implement Strategies for Large Language Models (Apress).
12 | The book is based on the content of this repository, but the notebooks are being updated, and I am incorporating new examples and chapters.
13 | If you are looking for the official repository for the book, with the original notebooks, you should visit the
14 | Apress repository, where you can find all the notebooks in their original format as they appear in the book. Buy it at: [Amazon][Springer]
15 |
16 |
17 |
18 |
19 |
20 | ## [Create and publish an LLM.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P2-MHF/readme.md)
21 | In this small project we will create a new model alingning a couple of models a [microsoft-phi-3-model](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) and a [gemma-2b-it](https://huggingface.co/google/gemma-2b-it) with DPO and then publish it to Hugging Face.
22 |
23 | Alignment is usually the final step taken when creating a model, after fine-tuning. Many people believe that the true revolution of GPT-3.5 was due to the alignment process that OpenAI carried out: Reinforcement Learning by Human Feedback, or RLFH.
24 |
25 | RLHF proved to be a highly efficient technique for controlling the model's responses, and at first, it seemed that it had to be the price to pay for any model that wanted to compete with GPT-3.5.
26 |
27 | Recently RLHF has been displaced by a technique that achieves the same result in a much more efficient way: DPO - Direct Preference Optimization.
28 |
29 | The implementation of DPO that we'll be using in the notebooks is the one developed by Hugging Face in their TRL library, which stands for Transformer Reinforcement Learning. DPO can be considered a reinforcement learning technique, where the model is rewarded during its training phase based on its responses.
30 |
31 | This library greatly simplifies the implementation of DPO. All you have to do is specify the model you want to fine-tune and provide it with a dataset in the necessary format.
32 |
33 | The dataset to be used should have three columns:
34 | * Prompt: The prompt used.
35 | * Chosen: The desired response.
36 | * Rejected: An undesired response.
37 |
38 | The dataset selected for this example is [argilla/distilabel-capybara-dpo-7k-binarized](https://huggingface.co/datasets/argilla/distilabel-capybara-dpo-7k-binarized)
39 |
40 | If you'd like to take a look at the models resulting from two hours of training on an A100 GPU with the Argila dataset, you can do so on its Hugging Face page.
41 | * [martra-open-gemma-2b-it-dpo](https://huggingface.co/oopere/martra-open-gemma-2b-it-dpo)
42 | * [martra-phi-3-mini-dpo](https://huggingface.co/oopere/martra-phi-3-mini-dpo)
43 |
44 |
45 | | Article | Notebook |
46 | | --- | --- |
47 | | WIP | [Aligning with DPO a phi3-3 model.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P2-MHF/7_2_Aligning_DPO_phi3.ipynb) [Aligning with DPO a Gemma model.](https://github.com/peremartra/Large-Language-Model-Notebooks-Course/blob/main/P2-MHF/Aligning_DPO_open_gemma-2b-it.ipynb)|
48 |
--------------------------------------------------------------------------------
/P3-CustomFinancialLLM/Readme.md:
--------------------------------------------------------------------------------
1 | In this project, we are going to optimize a financial model specialized in sentiment detection for financial reports.
2 |
3 | This is a clear example of a typical task one might encounter in a company. They have an LLM that works well but want to reduce its resource consumption while maintaining its performance. The reasons for this can vary—perhaps they simply want to lower usage costs, or maybe they need to deploy it on smaller devices, such as mobile phones.
4 |
5 | In this case, we will start with the FinGPT model and create a version that can perform the same tasks with the same efficiency while using fewer resources.
6 |
7 | **Steps to follow:**
8 | * Take the base model and measure its performance. We need to determine which benchmarks will provide the insights necessary to confirm that the optimized model consumes fewer resources while maintaining performance.
9 | * Decide which types of pruning can be applied:
10 | * Which part of the model? Embeddings / Attention / MLP.
11 | * Which type of pruning? Width / Depth.
12 | * Apply pruning.
13 | * Recover any lost performance using Knowledge Distillation.
14 |
15 | This is a fairly standard process in the optimization of customized models. We go beyond fine-tuning by modifying the model’s structure to better fit our needs while preserving the knowledge we want to retain.
16 |
17 | ________________________
18 |
19 |
--------------------------------------------------------------------------------
/clean_notebooks.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import os
3 | import subprocess
4 | from pathlib import Path
5 | import argparse
6 |
7 | def clear_notebook_outputs(root_dir='.'):
8 | """Find all Jupyter notebooks and clear their outputs using nbconvert."""
9 | # Find all .ipynb files recursively
10 | notebook_files = list(Path(root_dir).rglob('*.ipynb'))
11 |
12 | count = 0
13 | for nb_path in notebook_files:
14 | print(f"Processing: {nb_path}")
15 | try:
16 | # Run jupyter nbconvert command
17 | subprocess.run(['jupyter', 'nbconvert', '--clear-output', '--inplace', str(nb_path)],
18 | check=True,
19 | stdout=subprocess.PIPE,
20 | stderr=subprocess.PIPE)
21 | count += 1
22 | except subprocess.CalledProcessError as e:
23 | print(f"Error processing {nb_path}: {e}")
24 |
25 | print(f"Completed! Processed {count} notebooks.")
26 |
27 | if __name__ == "__main__":
28 | parser = argparse.ArgumentParser(description='Clear outputs from Jupyter notebooks recursively')
29 | parser.add_argument('--dir', type=str, default='.', help='Root directory to search for notebooks (default: current directory)')
30 |
31 | args = parser.parse_args()
32 | clear_notebook_outputs(args.dir)
33 |
--------------------------------------------------------------------------------
/img/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/.DS_Store
--------------------------------------------------------------------------------
/img/LLM_course_diagram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/LLM_course_diagram.jpg
--------------------------------------------------------------------------------
/img/Large_Language_Models_Projects_Book.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Large_Language_Models_Projects_Book.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_2-7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_2-7.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_1AE_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_1AE_1.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_1AE_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_1AE_2.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_1AE_3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_1AE_3.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_1AE_Final.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_1AE_Final.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_2SDL_CompareOpenAI_HF.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_2SDL_CompareOpenAI_HF.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_2SDL_CompareTestst.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_2SDL_CompareTestst.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_2SDL_Dataset.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_2SDL_Dataset.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_2SDL_Tests.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_2SDL_Tests.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_Retriever_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_Retriever_1.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_4_Retriever_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_4_Retriever_2.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_5_Prompt_Tuning.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_5_Prompt_Tuning.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_5_Quantization_Graph.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_5_Quantization_Graph.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_6-13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_6-13.jpg
--------------------------------------------------------------------------------
/img/Martra_Figure_6-18.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/Martra_Figure_6-18.jpg
--------------------------------------------------------------------------------
/img/colab.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/img/depth_rpunedvsbase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/depth_rpunedvsbase.png
--------------------------------------------------------------------------------
/img/lambada_BooQ_Accuracy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/lambada_BooQ_Accuracy.png
--------------------------------------------------------------------------------
/img/langsmith.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/langsmith.png
--------------------------------------------------------------------------------
/img/langsmith_API_KEY.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/langsmith_API_KEY.jpg
--------------------------------------------------------------------------------
/img/semantic_cache.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/peremartra/Large-Language-Model-Notebooks-Course/4c655e82cf149bfd302a0e8f32366bda4595eec4/img/semantic_cache.jpg
--------------------------------------------------------------------------------