├── YourOwnaI.gif ├── pytho4aisecrets.png ├── README.md └── FivePythonSkills.ipynb /YourOwnaI.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fabiomatricardi/FivePythonSkills/main/YourOwnaI.gif -------------------------------------------------------------------------------- /pytho4aisecrets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fabiomatricardi/FivePythonSkills/main/pytho4aisecrets.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cracking the AI Code: 5 Python fundamentals is all you need. 2 | The 5 basic skills, the only ones required to start your AI journey. Believe me, you don't need more that these! 3 | You can be a complete beginner in Python, but this doesn't matter at all. Let's check them out together! 4 | 5 | ``` 6 | 1> Python, PIP and Hugging Face 7 | 2> Import, Load, Run Repeat 8 | 3> Data types secrets unveiled 9 | 4> Loops for human beings 10 | 5> ReadTheDocs, aka we must read the Documentation 11 | ``` 12 | 13 | 14 | 15 | 16 | 17 |

18 | 19 | The Google Colab [notebook here](https://github.com/fabiomatricardi/FivePythonSkills/blob/main/FivePythonSkills.ipynb) 20 |


21 | to build this 22 |

23 | 24 | -------------------------------------------------------------------------------- /FivePythonSkills.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyMHjGMUCppD5iExlJrSocB5", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "## 1> Python, PIP and Hugging Face" 33 | ], 34 | "metadata": { 35 | "id": "K63SZt6R5ML6" 36 | } 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "metadata": { 42 | "colab": { 43 | "base_uri": "https://localhost:8080/" 44 | }, 45 | "id": "vBwZi9vp17o7", 46 | "outputId": "30ff0c49-9491-40c5-86de-623dcfddcba4" 47 | }, 48 | "outputs": [ 49 | { 50 | "output_type": "stream", 51 | "name": "stdout", 52 | "text": [ 53 | "Collecting llama-cpp-python==0.2.85\n", 54 | " Downloading llama_cpp_python-0.2.85.tar.gz (49.3 MB)\n", 55 | "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 MB\u001b[0m \u001b[31m2.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", 56 | "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", 57 | " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", 58 | " Installing backend dependencies ... \u001b[?25l\u001b[?25hdone\n", 59 | " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", 60 | "Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python==0.2.85) (4.12.2)\n", 61 | "Requirement already satisfied: numpy>=1.20.0 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python==0.2.85) (1.26.4)\n", 62 | "Collecting diskcache>=5.6.1 (from llama-cpp-python==0.2.85)\n", 63 | " Using cached diskcache-5.6.3-py3-none-any.whl.metadata (20 kB)\n", 64 | "Requirement already satisfied: jinja2>=2.11.3 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python==0.2.85) (3.1.4)\n", 65 | "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2>=2.11.3->llama-cpp-python==0.2.85) (2.1.5)\n", 66 | "Using cached diskcache-5.6.3-py3-none-any.whl (45 kB)\n", 67 | "Building wheels for collected packages: llama-cpp-python\n", 68 | " Building wheel for llama-cpp-python (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", 69 | " Created wheel for llama-cpp-python: filename=llama_cpp_python-0.2.85-cp310-cp310-linux_x86_64.whl size=2857590 sha256=d4c566f140b9d3b26ec7589ee32ce2791982e1bf9ea63b2c645067a0c38a4723\n", 70 | " Stored in directory: /root/.cache/pip/wheels/3f/e8/4e/29a754f9175ef52b6481cd75e3af4de38bf6dfa9c2972f75d4\n", 71 | "Successfully built llama-cpp-python\n", 72 | "Installing collected packages: diskcache, llama-cpp-python\n", 73 | "Successfully installed diskcache-5.6.3 llama-cpp-python-0.2.85\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "!pip install llama-cpp-python==0.2.85" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "source": [ 84 | "!wget https://huggingface.co/Qwen/Qwen2-0.5B-Instruct-GGUF/resolve/main/qwen2-0_5b-instruct-q8_0.gguf" 85 | ], 86 | "metadata": { 87 | "colab": { 88 | "base_uri": "https://localhost:8080/" 89 | }, 90 | "id": "8qHcJJ5E2LsU", 91 | "outputId": "b3577e53-e001-44bf-fea2-1ecd6557c8c9" 92 | }, 93 | "execution_count": 3, 94 | "outputs": [ 95 | { 96 | "output_type": "stream", 97 | "name": "stdout", 98 | "text": [ 99 | "--2024-08-13 22:31:54-- https://huggingface.co/Qwen/Qwen2-0.5B-Instruct-GGUF/resolve/main/qwen2-0_5b-instruct-q8_0.gguf\n", 100 | "Resolving huggingface.co (huggingface.co)... 13.35.7.81, 13.35.7.38, 13.35.7.57, ...\n", 101 | "Connecting to huggingface.co (huggingface.co)|13.35.7.81|:443... connected.\n", 102 | "HTTP request sent, awaiting response... 302 Found\n", 103 | "Location: https://cdn-lfs-us-1.huggingface.co/repos/de/a7/dea7cb7dd91181a6289326a9659bea3ef76442ab6822ba741994f21ad9825f70/834f4115ad5a836c9f17716b1577290fda96de3deb881ba45a4d5476fd202e96?response-content-disposition=inline%3B+filename*%3DUTF-8%27%27qwen2-0_5b-instruct-q8_0.gguf%3B+filename%3D%22qwen2-0_5b-instruct-q8_0.gguf%22%3B&Expires=1723847514&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTcyMzg0NzUxNH19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy11cy0xLmh1Z2dpbmdmYWNlLmNvL3JlcG9zL2RlL2E3L2RlYTdjYjdkZDkxMTgxYTYyODkzMjZhOTY1OWJlYTNlZjc2NDQyYWI2ODIyYmE3NDE5OTRmMjFhZDk4MjVmNzAvODM0ZjQxMTVhZDVhODM2YzlmMTc3MTZiMTU3NzI5MGZkYTk2ZGUzZGViODgxYmE0NWE0ZDU0NzZmZDIwMmU5Nj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSoifV19&Signature=CirkF%7EjcVeQ9TJZLUjM9v8oJeuj01XMNb5-zSgccEys9gx5QwKTmT8gROHE78ds6jC6DuLZVrhNkcoltRUD80MdL2O5qoE5ftXVo5DzXfyMoiuYZ0mK0kztwxk9j-iZeT62pX7-4yRhY4elYjk-VYNpCOlYALopyU0Fk0X166WGlyZo0X%7Ev5DI9FywxX55Dm%7EVhaj3miGYG8guPqfi7e9ptU%7EzqOeUsUsJ6UbOC2iz-uvJblnQc7FkpsnXQTXmYqKp-u5VT0Atu4dhSJCIK-VF7UxLkd%7EPUNUCrwmRXJc5EXuLxxfpQGzXi4xAkZLf8ytMwD%7E2PLTUPUKbwFwcSVTg__&Key-Pair-Id=K24J24Z295AEI9 [following]\n", 104 | "--2024-08-13 22:31:55-- https://cdn-lfs-us-1.huggingface.co/repos/de/a7/dea7cb7dd91181a6289326a9659bea3ef76442ab6822ba741994f21ad9825f70/834f4115ad5a836c9f17716b1577290fda96de3deb881ba45a4d5476fd202e96?response-content-disposition=inline%3B+filename*%3DUTF-8%27%27qwen2-0_5b-instruct-q8_0.gguf%3B+filename%3D%22qwen2-0_5b-instruct-q8_0.gguf%22%3B&Expires=1723847514&Policy=eyJTdGF0ZW1lbnQiOlt7IkNvbmRpdGlvbiI6eyJEYXRlTGVzc1RoYW4iOnsiQVdTOkVwb2NoVGltZSI6MTcyMzg0NzUxNH19LCJSZXNvdXJjZSI6Imh0dHBzOi8vY2RuLWxmcy11cy0xLmh1Z2dpbmdmYWNlLmNvL3JlcG9zL2RlL2E3L2RlYTdjYjdkZDkxMTgxYTYyODkzMjZhOTY1OWJlYTNlZjc2NDQyYWI2ODIyYmE3NDE5OTRmMjFhZDk4MjVmNzAvODM0ZjQxMTVhZDVhODM2YzlmMTc3MTZiMTU3NzI5MGZkYTk2ZGUzZGViODgxYmE0NWE0ZDU0NzZmZDIwMmU5Nj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPSoifV19&Signature=CirkF%7EjcVeQ9TJZLUjM9v8oJeuj01XMNb5-zSgccEys9gx5QwKTmT8gROHE78ds6jC6DuLZVrhNkcoltRUD80MdL2O5qoE5ftXVo5DzXfyMoiuYZ0mK0kztwxk9j-iZeT62pX7-4yRhY4elYjk-VYNpCOlYALopyU0Fk0X166WGlyZo0X%7Ev5DI9FywxX55Dm%7EVhaj3miGYG8guPqfi7e9ptU%7EzqOeUsUsJ6UbOC2iz-uvJblnQc7FkpsnXQTXmYqKp-u5VT0Atu4dhSJCIK-VF7UxLkd%7EPUNUCrwmRXJc5EXuLxxfpQGzXi4xAkZLf8ytMwD%7E2PLTUPUKbwFwcSVTg__&Key-Pair-Id=K24J24Z295AEI9\n", 105 | "Resolving cdn-lfs-us-1.huggingface.co (cdn-lfs-us-1.huggingface.co)... 13.35.35.21, 13.35.35.125, 13.35.35.109, ...\n", 106 | "Connecting to cdn-lfs-us-1.huggingface.co (cdn-lfs-us-1.huggingface.co)|13.35.35.21|:443... connected.\n", 107 | "HTTP request sent, awaiting response... 200 OK\n", 108 | "Length: 531065536 (506M) [binary/octet-stream]\n", 109 | "Saving to: ‘qwen2-0_5b-instruct-q8_0.gguf’\n", 110 | "\n", 111 | "qwen2-0_5b-instruct 100%[===================>] 506.46M 29.3MB/s in 18s \n", 112 | "\n", 113 | "2024-08-13 22:32:13 (28.0 MB/s) - ‘qwen2-0_5b-instruct-q8_0.gguf’ saved [531065536/531065536]\n", 114 | "\n" 115 | ] 116 | } 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "source": [ 122 | "## 2> Import, Load, Run Repeat" 123 | ], 124 | "metadata": { 125 | "id": "PTXuhACY5QFo" 126 | } 127 | }, 128 | { 129 | "cell_type": "code", 130 | "source": [ 131 | "from llama_cpp import Llama" 132 | ], 133 | "metadata": { 134 | "id": "E_r-K_JA4mFS" 135 | }, 136 | "execution_count": 5, 137 | "outputs": [] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "source": [ 142 | "llm = Llama(model_path='/content/qwen2-0_5b-instruct-q8_0.gguf', n_ctx=8196)" 143 | ], 144 | "metadata": { 145 | "colab": { 146 | "base_uri": "https://localhost:8080/" 147 | }, 148 | "id": "Q0dLNWxI6ns9", 149 | "outputId": "1f8afd06-c859-491d-dee0-03bb39e23959" 150 | }, 151 | "execution_count": 6, 152 | "outputs": [ 153 | { 154 | "output_type": "stream", 155 | "name": "stderr", 156 | "text": [ 157 | "llama_model_loader: loaded meta data with 26 key-value pairs and 290 tensors from /content/qwen2-0_5b-instruct-q8_0.gguf (version GGUF V3 (latest))\n", 158 | "llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.\n", 159 | "llama_model_loader: - kv 0: general.architecture str = qwen2\n", 160 | "llama_model_loader: - kv 1: general.name str = qwen2-0_5b-instruct\n", 161 | "llama_model_loader: - kv 2: qwen2.block_count u32 = 24\n", 162 | "llama_model_loader: - kv 3: qwen2.context_length u32 = 32768\n", 163 | "llama_model_loader: - kv 4: qwen2.embedding_length u32 = 896\n", 164 | "llama_model_loader: - kv 5: qwen2.feed_forward_length u32 = 4864\n", 165 | "llama_model_loader: - kv 6: qwen2.attention.head_count u32 = 14\n", 166 | "llama_model_loader: - kv 7: qwen2.attention.head_count_kv u32 = 2\n", 167 | "llama_model_loader: - kv 8: qwen2.rope.freq_base f32 = 1000000.000000\n", 168 | "llama_model_loader: - kv 9: qwen2.attention.layer_norm_rms_epsilon f32 = 0.000001\n", 169 | "llama_model_loader: - kv 10: general.file_type u32 = 7\n", 170 | "llama_model_loader: - kv 11: tokenizer.ggml.model str = gpt2\n", 171 | "llama_model_loader: - kv 12: tokenizer.ggml.pre str = qwen2\n", 172 | "llama_model_loader: - kv 13: tokenizer.ggml.tokens arr[str,151936] = [\"!\", \"\\\"\", \"#\", \"$\", \"%\", \"&\", \"'\", ...\n", 173 | "llama_model_loader: - kv 14: tokenizer.ggml.token_type arr[i32,151936] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...\n", 174 | "llama_model_loader: - kv 15: tokenizer.ggml.merges arr[str,151387] = [\"Ġ Ġ\", \"ĠĠ ĠĠ\", \"i n\", \"Ġ t\",...\n", 175 | "llama_model_loader: - kv 16: tokenizer.ggml.eos_token_id u32 = 151645\n", 176 | "llama_model_loader: - kv 17: tokenizer.ggml.padding_token_id u32 = 151643\n", 177 | "llama_model_loader: - kv 18: tokenizer.ggml.bos_token_id u32 = 151643\n", 178 | "llama_model_loader: - kv 19: tokenizer.chat_template str = {% for message in messages %}{% if lo...\n", 179 | "llama_model_loader: - kv 20: tokenizer.ggml.add_bos_token bool = false\n", 180 | "llama_model_loader: - kv 21: general.quantization_version u32 = 2\n", 181 | "llama_model_loader: - kv 22: quantize.imatrix.file str = ../Qwen2/gguf/qwen2-0_5b-imatrix/imat...\n", 182 | "llama_model_loader: - kv 23: quantize.imatrix.dataset str = ../sft_2406.txt\n", 183 | "llama_model_loader: - kv 24: quantize.imatrix.entries_count i32 = 168\n", 184 | "llama_model_loader: - kv 25: quantize.imatrix.chunks_count i32 = 1937\n", 185 | "llama_model_loader: - type f32: 121 tensors\n", 186 | "llama_model_loader: - type q8_0: 169 tensors\n", 187 | "llm_load_vocab: special tokens cache size = 293\n", 188 | "llm_load_vocab: token to piece cache size = 0.9338 MB\n", 189 | "llm_load_print_meta: format = GGUF V3 (latest)\n", 190 | "llm_load_print_meta: arch = qwen2\n", 191 | "llm_load_print_meta: vocab type = BPE\n", 192 | "llm_load_print_meta: n_vocab = 151936\n", 193 | "llm_load_print_meta: n_merges = 151387\n", 194 | "llm_load_print_meta: vocab_only = 0\n", 195 | "llm_load_print_meta: n_ctx_train = 32768\n", 196 | "llm_load_print_meta: n_embd = 896\n", 197 | "llm_load_print_meta: n_layer = 24\n", 198 | "llm_load_print_meta: n_head = 14\n", 199 | "llm_load_print_meta: n_head_kv = 2\n", 200 | "llm_load_print_meta: n_rot = 64\n", 201 | "llm_load_print_meta: n_swa = 0\n", 202 | "llm_load_print_meta: n_embd_head_k = 64\n", 203 | "llm_load_print_meta: n_embd_head_v = 64\n", 204 | "llm_load_print_meta: n_gqa = 7\n", 205 | "llm_load_print_meta: n_embd_k_gqa = 128\n", 206 | "llm_load_print_meta: n_embd_v_gqa = 128\n", 207 | "llm_load_print_meta: f_norm_eps = 0.0e+00\n", 208 | "llm_load_print_meta: f_norm_rms_eps = 1.0e-06\n", 209 | "llm_load_print_meta: f_clamp_kqv = 0.0e+00\n", 210 | "llm_load_print_meta: f_max_alibi_bias = 0.0e+00\n", 211 | "llm_load_print_meta: f_logit_scale = 0.0e+00\n", 212 | "llm_load_print_meta: n_ff = 4864\n", 213 | "llm_load_print_meta: n_expert = 0\n", 214 | "llm_load_print_meta: n_expert_used = 0\n", 215 | "llm_load_print_meta: causal attn = 1\n", 216 | "llm_load_print_meta: pooling type = 0\n", 217 | "llm_load_print_meta: rope type = 2\n", 218 | "llm_load_print_meta: rope scaling = linear\n", 219 | "llm_load_print_meta: freq_base_train = 1000000.0\n", 220 | "llm_load_print_meta: freq_scale_train = 1\n", 221 | "llm_load_print_meta: n_ctx_orig_yarn = 32768\n", 222 | "llm_load_print_meta: rope_finetuned = unknown\n", 223 | "llm_load_print_meta: ssm_d_conv = 0\n", 224 | "llm_load_print_meta: ssm_d_inner = 0\n", 225 | "llm_load_print_meta: ssm_d_state = 0\n", 226 | "llm_load_print_meta: ssm_dt_rank = 0\n", 227 | "llm_load_print_meta: model type = 1B\n", 228 | "llm_load_print_meta: model ftype = Q8_0\n", 229 | "llm_load_print_meta: model params = 494.03 M\n", 230 | "llm_load_print_meta: model size = 500.79 MiB (8.50 BPW) \n", 231 | "llm_load_print_meta: general.name = qwen2-0_5b-instruct\n", 232 | "llm_load_print_meta: BOS token = 151643 '<|endoftext|>'\n", 233 | "llm_load_print_meta: EOS token = 151645 '<|im_end|>'\n", 234 | "llm_load_print_meta: PAD token = 151643 '<|endoftext|>'\n", 235 | "llm_load_print_meta: LF token = 148848 'ÄĬ'\n", 236 | "llm_load_print_meta: EOT token = 151645 '<|im_end|>'\n", 237 | "llm_load_print_meta: max token length = 256\n", 238 | "llm_load_tensors: ggml ctx size = 0.13 MiB\n", 239 | "llm_load_tensors: CPU buffer size = 500.79 MiB\n", 240 | "...........................................................\n", 241 | "llama_new_context_with_model: n_ctx = 8224\n", 242 | "llama_new_context_with_model: n_batch = 512\n", 243 | "llama_new_context_with_model: n_ubatch = 512\n", 244 | "llama_new_context_with_model: flash_attn = 0\n", 245 | "llama_new_context_with_model: freq_base = 1000000.0\n", 246 | "llama_new_context_with_model: freq_scale = 1\n", 247 | "llama_kv_cache_init: CPU KV buffer size = 96.38 MiB\n", 248 | "llama_new_context_with_model: KV self size = 96.38 MiB, K (f16): 48.19 MiB, V (f16): 48.19 MiB\n", 249 | "llama_new_context_with_model: CPU output buffer size = 0.58 MiB\n", 250 | "llama_new_context_with_model: CPU compute buffer size = 300.25 MiB\n", 251 | "llama_new_context_with_model: graph nodes = 846\n", 252 | "llama_new_context_with_model: graph splits = 1\n", 253 | "AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 1 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | \n", 254 | "Model metadata: {'quantize.imatrix.entries_count': '168', 'quantize.imatrix.dataset': '../sft_2406.txt', 'quantize.imatrix.chunks_count': '1937', 'quantize.imatrix.file': '../Qwen2/gguf/qwen2-0_5b-imatrix/imatrix.dat', 'tokenizer.ggml.add_bos_token': 'false', 'tokenizer.ggml.bos_token_id': '151643', 'general.architecture': 'qwen2', 'qwen2.block_count': '24', 'qwen2.context_length': '32768', 'tokenizer.chat_template': \"{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\\n' }}{% endif %}\", 'qwen2.attention.head_count_kv': '2', 'tokenizer.ggml.padding_token_id': '151643', 'qwen2.embedding_length': '896', 'qwen2.attention.layer_norm_rms_epsilon': '0.000001', 'qwen2.attention.head_count': '14', 'tokenizer.ggml.eos_token_id': '151645', 'qwen2.rope.freq_base': '1000000.000000', 'general.file_type': '7', 'general.quantization_version': '2', 'qwen2.feed_forward_length': '4864', 'tokenizer.ggml.model': 'gpt2', 'general.name': 'qwen2-0_5b-instruct', 'tokenizer.ggml.pre': 'qwen2'}\n", 255 | "Available chat formats from metadata: chat_template.default\n", 256 | "Using gguf chat template: {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\n", 257 | "You are a helpful assistant.<|im_end|>\n", 258 | "' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n", 259 | "' + message['content'] + '<|im_end|>' + '\n", 260 | "'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n", 261 | "' }}{% endif %}\n", 262 | "Using chat eos_token: <|im_end|>\n", 263 | "Using chat bos_token: <|endoftext|>\n" 264 | ] 265 | } 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "source": [ 271 | "llm('what is Science?', temperature=0.25, max_tokens=350, repeat_penalty=1.18, stop=['<|im_end|>'])" 272 | ], 273 | "metadata": { 274 | "colab": { 275 | "base_uri": "https://localhost:8080/" 276 | }, 277 | "id": "WwBOADZ06nc0", 278 | "outputId": "0abf25e9-82d5-4a98-b08e-7b782cff538e" 279 | }, 280 | "execution_count": 8, 281 | "outputs": [ 282 | { 283 | "output_type": "stream", 284 | "name": "stderr", 285 | "text": [ 286 | "Llama.generate: prefix-match hit\n", 287 | "\n", 288 | "llama_print_timings: load time = 659.51 ms\n", 289 | "llama_print_timings: sample time = 1047.54 ms / 350 runs ( 2.99 ms per token, 334.12 tokens per second)\n", 290 | "llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n", 291 | "llama_print_timings: eval time = 32762.39 ms / 350 runs ( 93.61 ms per token, 10.68 tokens per second)\n", 292 | "llama_print_timings: total time = 34610.76 ms / 350 tokens\n" 293 | ] 294 | }, 295 | { 296 | "output_type": "execute_result", 297 | "data": { 298 | "text/plain": [ 299 | "{'id': 'cmpl-5f4b09fb-47bb-4b52-a113-dc64412a22c2',\n", 300 | " 'object': 'text_completion',\n", 301 | " 'created': 1723589728,\n", 302 | " 'model': '/content/qwen2-0_5b-instruct-q8_0.gguf',\n", 303 | " 'choices': [{'text': ' What does it mean to be a scientist?\\nScience, in the broadest sense, refers to all knowledge that can be acquired through observation and experimentation. It encompasses both natural phenomena such as plants, animals, rocks, and minerals, as well as human-made objects like machines or buildings.\\nScientists are individuals who use their skills and expertise to investigate and understand complex systems of matter, energy, and information in order to make predictions about the future. They work with a wide range of tools and methods, including observation, experimentation, data analysis, theory development, and communication.\\nOne way that scientists can be considered \"scientists\" is by using their knowledge to advance scientific understanding and improve our lives. For example, they may develop new technologies or medical treatments based on the results of their research; they might help us understand how different types of plants respond to environmental stressors; or they could use their expertise in fields such as climate change science to inform policy decisions.\\nAnother way that scientists can be considered \"scientists\" is by using their knowledge to improve our understanding and appreciation for scientific inquiry. They may work with other researchers, educators, and policymakers to promote a culture of curiosity and critical thinking about the nature of reality; they might use their expertise in fields such as biology or psychology to help us better understand how people think and feel.\\nOverall, scientists are individuals who have developed an understanding of the natural world through observation and experimentation. They work with tools and methods that allow them to investigate complex systems of matter, energy, and information, and they make predictions about the future based on their knowledge. By using their expertise in fields such as biology or psychology, scientists can help us better understand how we interact with our environment and improve our lives.\\nWhat is a',\n", 304 | " 'index': 0,\n", 305 | " 'logprobs': None,\n", 306 | " 'finish_reason': 'length'}],\n", 307 | " 'usage': {'prompt_tokens': 4, 'completion_tokens': 350, 'total_tokens': 354}}" 308 | ] 309 | }, 310 | "metadata": {}, 311 | "execution_count": 8 312 | } 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "source": [ 318 | "prompt = \"\"\"<|im_start|>user\n", 319 | "What is Science?<|im_end|>\n", 320 | "<|im_start|>assistant\n", 321 | "\"\"\"" 322 | ], 323 | "metadata": { 324 | "id": "IU_uBKXV5UZI" 325 | }, 326 | "execution_count": 10, 327 | "outputs": [] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "source": [ 332 | "llm(prompt, temperature=0.25, max_tokens=350, repeat_penalty=1.18, stop=['<|im_end|>'])" 333 | ], 334 | "metadata": { 335 | "colab": { 336 | "base_uri": "https://localhost:8080/" 337 | }, 338 | "id": "ugq6_tc95UV9", 339 | "outputId": "a8f8cf20-954b-4522-d15f-7c4ea24dfbc6" 340 | }, 341 | "execution_count": 11, 342 | "outputs": [ 343 | { 344 | "output_type": "stream", 345 | "name": "stderr", 346 | "text": [ 347 | "\n", 348 | "llama_print_timings: load time = 659.51 ms\n", 349 | "llama_print_timings: sample time = 282.20 ms / 98 runs ( 2.88 ms per token, 347.28 tokens per second)\n", 350 | "llama_print_timings: prompt eval time = 293.50 ms / 12 tokens ( 24.46 ms per token, 40.89 tokens per second)\n", 351 | "llama_print_timings: eval time = 8909.84 ms / 97 runs ( 91.85 ms per token, 10.89 tokens per second)\n", 352 | "llama_print_timings: total time = 9662.28 ms / 109 tokens\n" 353 | ] 354 | }, 355 | { 356 | "output_type": "execute_result", 357 | "data": { 358 | "text/plain": [ 359 | "{'id': 'cmpl-7e0c6a43-3334-4eca-9402-db22d47c2c40',\n", 360 | " 'object': 'text_completion',\n", 361 | " 'created': 1723591678,\n", 362 | " 'model': '/content/qwen2-0_5b-instruct-q8_0.gguf',\n", 363 | " 'choices': [{'text': 'Science refers to the study of natural phenomena, including their causes and consequences. It involves a range of disciplines such as physics, chemistry, biology, geology, astronomy, mathematics, psychology, sociology, economics, linguistics, philosophy, etc., that aim at understanding how things work in the world around us.\\n\\nIn short, Science is about discovering new knowledge through observation, experimentation, reasoning and critical thinking. It aims to understand the natural world by studying its laws of cause and effect.',\n", 364 | " 'index': 0,\n", 365 | " 'logprobs': None,\n", 366 | " 'finish_reason': 'stop'}],\n", 367 | " 'usage': {'prompt_tokens': 12, 'completion_tokens': 97, 'total_tokens': 109}}" 368 | ] 369 | }, 370 | "metadata": {}, 371 | "execution_count": 11 372 | } 373 | ] 374 | }, 375 | { 376 | "cell_type": "markdown", 377 | "source": [ 378 | "## 3> Data types secrets unveiled" 379 | ], 380 | "metadata": { 381 | "id": "GGv3-nog5UuC" 382 | } 383 | }, 384 | { 385 | "cell_type": "code", 386 | "source": [ 387 | "output = llm(prompt, temperature=0.25, max_tokens=350, repeat_penalty=1.18, stop=['<|im_end|>'])" 388 | ], 389 | "metadata": { 390 | "colab": { 391 | "base_uri": "https://localhost:8080/" 392 | }, 393 | "id": "ik-ep_tZ5XGS", 394 | "outputId": "df635af8-752a-4077-ff04-fe0c58595afe" 395 | }, 396 | "execution_count": 12, 397 | "outputs": [ 398 | { 399 | "output_type": "stream", 400 | "name": "stderr", 401 | "text": [ 402 | "Llama.generate: prefix-match hit\n", 403 | "\n", 404 | "llama_print_timings: load time = 659.51 ms\n", 405 | "llama_print_timings: sample time = 220.76 ms / 77 runs ( 2.87 ms per token, 348.80 tokens per second)\n", 406 | "llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n", 407 | "llama_print_timings: eval time = 7286.45 ms / 77 runs ( 94.63 ms per token, 10.57 tokens per second)\n", 408 | "llama_print_timings: total time = 7647.65 ms / 77 tokens\n" 409 | ] 410 | } 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "source": [ 416 | "print(output)" 417 | ], 418 | "metadata": { 419 | "colab": { 420 | "base_uri": "https://localhost:8080/" 421 | }, 422 | "id": "ujYqTlL25Yv3", 423 | "outputId": "4fb0d0fa-fd25-4b13-f4d3-9d3d5356b980" 424 | }, 425 | "execution_count": 13, 426 | "outputs": [ 427 | { 428 | "output_type": "stream", 429 | "name": "stdout", 430 | "text": [ 431 | "{'id': 'cmpl-31bea99e-3ef0-4cbe-897a-5e6bc28ee21b', 'object': 'text_completion', 'created': 1723592570, 'model': '/content/qwen2-0_5b-instruct-q8_0.gguf', 'choices': [{'text': 'Science refers to the study of natural phenomena and their causes, processes, and relationships. It includes all branches of knowledge that deal with these topics: physics, chemistry, biology, geology, astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry into the nature of reality through observation, experimentation, theory development, and interpretation.', 'index': 0, 'logprobs': None, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 12, 'completion_tokens': 76, 'total_tokens': 88}}\n" 432 | ] 433 | } 434 | ] 435 | }, 436 | { 437 | "cell_type": "code", 438 | "source": [ 439 | "from rich.console import Console\n", 440 | "console = Console(width=110)" 441 | ], 442 | "metadata": { 443 | "id": "QKClON9O5YtZ" 444 | }, 445 | "execution_count": 14, 446 | "outputs": [] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "source": [ 451 | "# import\n", 452 | "from rich.console import Console\n", 453 | "# call\n", 454 | "console = Console(width=110)\n", 455 | "# run\n", 456 | "console.print(output)" 457 | ], 458 | "metadata": { 459 | "colab": { 460 | "base_uri": "https://localhost:8080/", 461 | "height": 323 462 | }, 463 | "id": "objJN3YkI0ZM", 464 | "outputId": "630fd9ab-a01a-4d5f-90b8-7bed5fad9bbd" 465 | }, 466 | "execution_count": 15, 467 | "outputs": [ 468 | { 469 | "output_type": "display_data", 470 | "data": { 471 | "text/plain": [ 472 | "\u001b[1m{\u001b[0m\n", 473 | " \u001b[32m'id'\u001b[0m: \u001b[32m'cmpl-31bea99e-3ef0-4cbe-897a-5e6bc28ee21b'\u001b[0m,\n", 474 | " \u001b[32m'object'\u001b[0m: \u001b[32m'text_completion'\u001b[0m,\n", 475 | " \u001b[32m'created'\u001b[0m: \u001b[1;36m1723592570\u001b[0m,\n", 476 | " \u001b[32m'model'\u001b[0m: \u001b[32m'/content/qwen2-0_5b-instruct-q8_0.gguf'\u001b[0m,\n", 477 | " \u001b[32m'choices'\u001b[0m: \u001b[1m[\u001b[0m\n", 478 | " \u001b[1m{\u001b[0m\n", 479 | " \u001b[32m'text'\u001b[0m: \u001b[32m'Science refers to the study of natural phenomena and their causes, processes, and \u001b[0m\n", 480 | "\u001b[32mrelationships. It includes all branches of knowledge that deal with these topics: physics, chemistry, biology,\u001b[0m\n", 481 | "\u001b[32mgeology, astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry\u001b[0m\n", 482 | "\u001b[32minto the nature of reality through observation, experimentation, theory development, and interpretation.'\u001b[0m,\n", 483 | " \u001b[32m'index'\u001b[0m: \u001b[1;36m0\u001b[0m,\n", 484 | " \u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m,\n", 485 | " \u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m\n", 486 | " \u001b[1m}\u001b[0m\n", 487 | " \u001b[1m]\u001b[0m,\n", 488 | " \u001b[32m'usage'\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m'prompt_tokens'\u001b[0m: \u001b[1;36m12\u001b[0m, \u001b[32m'completion_tokens'\u001b[0m: \u001b[1;36m76\u001b[0m, \u001b[32m'total_tokens'\u001b[0m: \u001b[1;36m88\u001b[0m\u001b[1m}\u001b[0m\n", 489 | "\u001b[1m}\u001b[0m\n" 490 | ], 491 | "text/html": [ 492 | "
{\n",
493 |               "    'id': 'cmpl-31bea99e-3ef0-4cbe-897a-5e6bc28ee21b',\n",
494 |               "    'object': 'text_completion',\n",
495 |               "    'created': 1723592570,\n",
496 |               "    'model': '/content/qwen2-0_5b-instruct-q8_0.gguf',\n",
497 |               "    'choices': [\n",
498 |               "        {\n",
499 |               "            'text': 'Science refers to the study of natural phenomena and their causes, processes, and \n",
500 |               "relationships. It includes all branches of knowledge that deal with these topics: physics, chemistry, biology,\n",
501 |               "geology, astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry\n",
502 |               "into the nature of reality through observation, experimentation, theory development, and interpretation.',\n",
503 |               "            'index': 0,\n",
504 |               "            'logprobs': None,\n",
505 |               "            'finish_reason': 'stop'\n",
506 |               "        }\n",
507 |               "    ],\n",
508 |               "    'usage': {'prompt_tokens': 12, 'completion_tokens': 76, 'total_tokens': 88}\n",
509 |               "}\n",
510 |               "
\n" 511 | ] 512 | }, 513 | "metadata": {} 514 | } 515 | ] 516 | }, 517 | { 518 | "cell_type": "code", 519 | "source": [ 520 | "type(output)" 521 | ], 522 | "metadata": { 523 | "colab": { 524 | "base_uri": "https://localhost:8080/" 525 | }, 526 | "id": "6Cqo_M01JfKG", 527 | "outputId": "a647e6bc-b359-48f5-945b-62b7d523b248" 528 | }, 529 | "execution_count": 18, 530 | "outputs": [ 531 | { 532 | "output_type": "execute_result", 533 | "data": { 534 | "text/plain": [ 535 | "dict" 536 | ] 537 | }, 538 | "metadata": {}, 539 | "execution_count": 18 540 | } 541 | ] 542 | }, 543 | { 544 | "cell_type": "code", 545 | "source": [ 546 | "console.print(output['model'])" 547 | ], 548 | "metadata": { 549 | "colab": { 550 | "base_uri": "https://localhost:8080/", 551 | "height": 34 552 | }, 553 | "id": "tLaYMQ11JfHp", 554 | "outputId": "d9bd8ce5-f7f4-4704-f083-3d8ba7a7b935" 555 | }, 556 | "execution_count": 19, 557 | "outputs": [ 558 | { 559 | "output_type": "display_data", 560 | "data": { 561 | "text/plain": [ 562 | "\u001b[35m/content/\u001b[0m\u001b[95mqwen2-0_5b-instruct-q8_0.gguf\u001b[0m\n" 563 | ], 564 | "text/html": [ 565 | "
/content/qwen2-0_5b-instruct-q8_0.gguf\n",
566 |               "
\n" 567 | ] 568 | }, 569 | "metadata": {} 570 | } 571 | ] 572 | }, 573 | { 574 | "cell_type": "code", 575 | "source": [ 576 | "console.print(output['choices'])" 577 | ], 578 | "metadata": { 579 | "colab": { 580 | "base_uri": "https://localhost:8080/", 581 | "height": 204 582 | }, 583 | "id": "9kh3Io_1JfFP", 584 | "outputId": "a3d1fb01-1f8d-4117-8989-fb611bb5dea4" 585 | }, 586 | "execution_count": 20, 587 | "outputs": [ 588 | { 589 | "output_type": "display_data", 590 | "data": { 591 | "text/plain": [ 592 | "\u001b[1m[\u001b[0m\n", 593 | " \u001b[1m{\u001b[0m\n", 594 | " \u001b[32m'text'\u001b[0m: \u001b[32m'Science refers to the study of natural phenomena and their causes, processes, and \u001b[0m\n", 595 | "\u001b[32mrelationships. It includes all branches of knowledge that deal with these topics: physics, chemistry, biology,\u001b[0m\n", 596 | "\u001b[32mgeology, astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry\u001b[0m\n", 597 | "\u001b[32minto the nature of reality through observation, experimentation, theory development, and interpretation.'\u001b[0m,\n", 598 | " \u001b[32m'index'\u001b[0m: \u001b[1;36m0\u001b[0m,\n", 599 | " \u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m,\n", 600 | " \u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m\n", 601 | " \u001b[1m}\u001b[0m\n", 602 | "\u001b[1m]\u001b[0m\n" 603 | ], 604 | "text/html": [ 605 | "
[\n",
606 |               "    {\n",
607 |               "        'text': 'Science refers to the study of natural phenomena and their causes, processes, and \n",
608 |               "relationships. It includes all branches of knowledge that deal with these topics: physics, chemistry, biology,\n",
609 |               "geology, astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry\n",
610 |               "into the nature of reality through observation, experimentation, theory development, and interpretation.',\n",
611 |               "        'index': 0,\n",
612 |               "        'logprobs': None,\n",
613 |               "        'finish_reason': 'stop'\n",
614 |               "    }\n",
615 |               "]\n",
616 |               "
\n" 617 | ] 618 | }, 619 | "metadata": {} 620 | } 621 | ] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "source": [ 626 | "console.print(output['choices'][0])" 627 | ], 628 | "metadata": { 629 | "colab": { 630 | "base_uri": "https://localhost:8080/", 631 | "height": 170 632 | }, 633 | "id": "oJT8SeYoVFvc", 634 | "outputId": "998d0491-4b9a-41d6-c2ed-e16bc91d6d8a" 635 | }, 636 | "execution_count": 21, 637 | "outputs": [ 638 | { 639 | "output_type": "display_data", 640 | "data": { 641 | "text/plain": [ 642 | "\u001b[1m{\u001b[0m\n", 643 | " \u001b[32m'text'\u001b[0m: \u001b[32m'Science refers to the study of natural phenomena and their causes, processes, and relationships. \u001b[0m\n", 644 | "\u001b[32mIt includes all branches of knowledge that deal with these topics: physics, chemistry, biology, geology, \u001b[0m\n", 645 | "\u001b[32mastronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry into the\u001b[0m\n", 646 | "\u001b[32mnature of reality through observation, experimentation, theory development, and interpretation.'\u001b[0m,\n", 647 | " \u001b[32m'index'\u001b[0m: \u001b[1;36m0\u001b[0m,\n", 648 | " \u001b[32m'logprobs'\u001b[0m: \u001b[3;35mNone\u001b[0m,\n", 649 | " \u001b[32m'finish_reason'\u001b[0m: \u001b[32m'stop'\u001b[0m\n", 650 | "\u001b[1m}\u001b[0m\n" 651 | ], 652 | "text/html": [ 653 | "
{\n",
654 |               "    'text': 'Science refers to the study of natural phenomena and their causes, processes, and relationships. \n",
655 |               "It includes all branches of knowledge that deal with these topics: physics, chemistry, biology, geology, \n",
656 |               "astronomy, meteorology, ecology, oceanography, etc.\\n\\nIn short, science is a branch of human inquiry into the\n",
657 |               "nature of reality through observation, experimentation, theory development, and interpretation.',\n",
658 |               "    'index': 0,\n",
659 |               "    'logprobs': None,\n",
660 |               "    'finish_reason': 'stop'\n",
661 |               "}\n",
662 |               "
\n" 663 | ] 664 | }, 665 | "metadata": {} 666 | } 667 | ] 668 | }, 669 | { 670 | "cell_type": "code", 671 | "source": [ 672 | "type(output['choices'][0])" 673 | ], 674 | "metadata": { 675 | "colab": { 676 | "base_uri": "https://localhost:8080/" 677 | }, 678 | "id": "tKXmp563VFkx", 679 | "outputId": "230cf461-87b1-43e2-b40d-75531953b123" 680 | }, 681 | "execution_count": 22, 682 | "outputs": [ 683 | { 684 | "output_type": "execute_result", 685 | "data": { 686 | "text/plain": [ 687 | "dict" 688 | ] 689 | }, 690 | "metadata": {}, 691 | "execution_count": 22 692 | } 693 | ] 694 | }, 695 | { 696 | "cell_type": "code", 697 | "source": [ 698 | "console.print(output['choices'][0]['text'])" 699 | ], 700 | "metadata": { 701 | "colab": { 702 | "base_uri": "https://localhost:8080/", 703 | "height": 119 704 | }, 705 | "id": "ZhPp93YKaGZt", 706 | "outputId": "54325fa7-03e1-4e19-f6ed-2bf3daeb1477" 707 | }, 708 | "execution_count": 23, 709 | "outputs": [ 710 | { 711 | "output_type": "display_data", 712 | "data": { 713 | "text/plain": [ 714 | "Science refers to the study of natural phenomena and their causes, processes, and relationships. It includes \n", 715 | "all branches of knowledge that deal with these topics: physics, chemistry, biology, geology, astronomy, \n", 716 | "meteorology, ecology, oceanography, etc.\n", 717 | "\n", 718 | "In short, science is a branch of human inquiry into the nature of reality through observation, \n", 719 | "experimentation, theory development, and interpretation.\n" 720 | ], 721 | "text/html": [ 722 | "
Science refers to the study of natural phenomena and their causes, processes, and relationships. It includes \n",
723 |               "all branches of knowledge that deal with these topics: physics, chemistry, biology, geology, astronomy, \n",
724 |               "meteorology, ecology, oceanography, etc.\n",
725 |               "\n",
726 |               "In short, science is a branch of human inquiry into the nature of reality through observation, \n",
727 |               "experimentation, theory development, and interpretation.\n",
728 |               "
\n" 729 | ] 730 | }, 731 | "metadata": {} 732 | } 733 | ] 734 | }, 735 | { 736 | "cell_type": "code", 737 | "source": [], 738 | "metadata": { 739 | "id": "cQrjusEgaGXG" 740 | }, 741 | "execution_count": null, 742 | "outputs": [] 743 | }, 744 | { 745 | "cell_type": "code", 746 | "source": [ 747 | "# put verbose=False for smooth chatbot experience\n", 748 | "llm = Llama(model_path='/content/qwen2-0_5b-instruct-q8_0.gguf', n_ctx=8196, verbose=False)" 749 | ], 750 | "metadata": { 751 | "id": "DezqquHKaGUr" 752 | }, 753 | "execution_count": 25, 754 | "outputs": [] 755 | }, 756 | { 757 | "cell_type": "markdown", 758 | "source": [ 759 | "## 4> Loops for human beings" 760 | ], 761 | "metadata": { 762 | "id": "CJ73BOhV5ZBt" 763 | } 764 | }, 765 | { 766 | "cell_type": "code", 767 | "source": [ 768 | "while True:\n", 769 | " #ask for input\n", 770 | " user = input('User> ')\n", 771 | " # check if the input is equal to 'quit!'\n", 772 | " # if yes exit the loop, if no keep going\n", 773 | " if user == 'quit!':\n", 774 | " console.print('Bye Bye!')\n", 775 | " # break the loop\n", 776 | " break\n", 777 | " else:\n", 778 | " # build the prompt with correct formatting\n", 779 | " prompt = f\"\"\"<|im_start|>user\n", 780 | "{user}<|im_end|>\n", 781 | "<|im_start|>assistant\n", 782 | "\"\"\"\n", 783 | " # give the prompt to the AI\n", 784 | " output = llm(prompt, temperature=0.25,\n", 785 | " max_tokens=350, repeat_penalty=1.18,\n", 786 | " stop=['<|im_end|>'])\n", 787 | " # print the result\n", 788 | " console.print(f\"AI> {output['choices'][0]['text']}\")" 789 | ], 790 | "metadata": { 791 | "colab": { 792 | "base_uri": "https://localhost:8080/", 793 | "height": 511 794 | }, 795 | "id": "YxAApcGC5aTN", 796 | "outputId": "99708f59-da4b-40a0-bca6-bb79e9eedc76" 797 | }, 798 | "execution_count": 29, 799 | "outputs": [ 800 | { 801 | "name": "stdout", 802 | "output_type": "stream", 803 | "text": [ 804 | "User> what is science?\n" 805 | ] 806 | }, 807 | { 808 | "output_type": "display_data", 809 | "data": { 810 | "text/plain": [ 811 | "AI> Science is the study of the natural world and its laws, phenomena, processes, and ideas. It involves the \n", 812 | "investigation of facts through observation, experimentation, reasoning, and interpretation to understand how \n", 813 | "things work in the real world.\n", 814 | "\n", 815 | "In simpler terms, scientific inquiry seeks to discover what exists or can exist by studying it scientifically.\n", 816 | "This includes fields such as physics, chemistry, biology, geology, astronomy, mathematics, engineering, \n", 817 | "medicine, psychology, sociology, linguistics, philosophy of science, and many others.\n", 818 | "\n", 819 | "Science is a fundamental part of our daily lives because we use its findings every day in everything from \n", 820 | "making decisions about where to buy groceries or how to build a house to understanding the world around us. It\n", 821 | "helps us make sense of complex phenomena that are hard for humans to explain on their own, such as climate \n", 822 | "change and artificial intelligence.\n", 823 | "\n", 824 | "Overall, science is an essential part of our collective knowledge and ability to understand the natural world.\n" 825 | ], 826 | "text/html": [ 827 | "
AI> Science is the study of the natural world and its laws, phenomena, processes, and ideas. It involves the \n",
828 |               "investigation of facts through observation, experimentation, reasoning, and interpretation to understand how \n",
829 |               "things work in the real world.\n",
830 |               "\n",
831 |               "In simpler terms, scientific inquiry seeks to discover what exists or can exist by studying it scientifically.\n",
832 |               "This includes fields such as physics, chemistry, biology, geology, astronomy, mathematics, engineering, \n",
833 |               "medicine, psychology, sociology, linguistics, philosophy of science, and many others.\n",
834 |               "\n",
835 |               "Science is a fundamental part of our daily lives because we use its findings every day in everything from \n",
836 |               "making decisions about where to buy groceries or how to build a house to understanding the world around us. It\n",
837 |               "helps us make sense of complex phenomena that are hard for humans to explain on their own, such as climate \n",
838 |               "change and artificial intelligence.\n",
839 |               "\n",
840 |               "Overall, science is an essential part of our collective knowledge and ability to understand the natural world.\n",
841 |               "
\n" 842 | ] 843 | }, 844 | "metadata": {} 845 | }, 846 | { 847 | "name": "stdout", 848 | "output_type": "stream", 849 | "text": [ 850 | "User> what is artificial intelligence?\n" 851 | ] 852 | }, 853 | { 854 | "output_type": "display_data", 855 | "data": { 856 | "text/plain": [ 857 | "AI> Artificial Intelligence \u001b[1m(\u001b[0mAI\u001b[1m)\u001b[0m refers to the simulation of human cognitive processes through algorithms and \n", 858 | "machine learning. It involves developing software that can perform tasks such as recognizing speech, playing \n", 859 | "games, or understanding language patterns.\n", 860 | "\n", 861 | "In simple terms, AI systems are designed to mimic what humans do best: thinking, reasoning, and \n", 862 | "problem-solving. They use data analysis techniques to learn from experience and improve their performance over\n", 863 | "time by adjusting the algorithms they use based on new information and feedback.\n", 864 | "\n", 865 | "AI is a rapidly growing field that has applications in many fields such as healthcare, finance, \n", 866 | "transportation, manufacturing, entertainment, and more. It's also being used for ethical considerations like \n", 867 | "bias and privacy concerns.\n" 868 | ], 869 | "text/html": [ 870 | "
AI> Artificial Intelligence (AI) refers to the simulation of human cognitive processes through algorithms and \n",
871 |               "machine learning. It involves developing software that can perform tasks such as recognizing speech, playing \n",
872 |               "games, or understanding language patterns.\n",
873 |               "\n",
874 |               "In simple terms, AI systems are designed to mimic what humans do best: thinking, reasoning, and \n",
875 |               "problem-solving. They use data analysis techniques to learn from experience and improve their performance over\n",
876 |               "time by adjusting the algorithms they use based on new information and feedback.\n",
877 |               "\n",
878 |               "AI is a rapidly growing field that has applications in many fields such as healthcare, finance, \n",
879 |               "transportation, manufacturing, entertainment, and more. It's also being used for ethical considerations like \n",
880 |               "bias and privacy concerns.\n",
881 |               "
\n" 882 | ] 883 | }, 884 | "metadata": {} 885 | }, 886 | { 887 | "name": "stdout", 888 | "output_type": "stream", 889 | "text": [ 890 | "User> quit!\n" 891 | ] 892 | }, 893 | { 894 | "output_type": "display_data", 895 | "data": { 896 | "text/plain": [ 897 | "Bye Bye!\n" 898 | ], 899 | "text/html": [ 900 | "
Bye Bye!\n",
901 |               "
\n" 902 | ] 903 | }, 904 | "metadata": {} 905 | } 906 | ] 907 | }, 908 | { 909 | "cell_type": "code", 910 | "source": [], 911 | "metadata": { 912 | "id": "anz7wJrQ5bKN" 913 | }, 914 | "execution_count": null, 915 | "outputs": [] 916 | }, 917 | { 918 | "cell_type": "markdown", 919 | "source": [ 920 | "## 5> ReadTheDocs, aka we must read the Documentation" 921 | ], 922 | "metadata": { 923 | "id": "RBohYiQF5a1c" 924 | } 925 | }, 926 | { 927 | "cell_type": "code", 928 | "source": [], 929 | "metadata": { 930 | "id": "A7fNHF725dHa" 931 | }, 932 | "execution_count": null, 933 | "outputs": [] 934 | }, 935 | { 936 | "cell_type": "code", 937 | "source": [], 938 | "metadata": { 939 | "id": "A-rxFSnq5d2S" 940 | }, 941 | "execution_count": null, 942 | "outputs": [] 943 | }, 944 | { 945 | "cell_type": "code", 946 | "source": [], 947 | "metadata": { 948 | "id": "4Gw081po5dxY" 949 | }, 950 | "execution_count": null, 951 | "outputs": [] 952 | }, 953 | { 954 | "cell_type": "code", 955 | "source": [], 956 | "metadata": { 957 | "id": "BdTmifi35dvC" 958 | }, 959 | "execution_count": null, 960 | "outputs": [] 961 | } 962 | ] 963 | } --------------------------------------------------------------------------------