{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "e4rVoXBpRMwI" }, "outputs": [], "source": [ "# If you are using Colab for free, we highly recommend you activate the T4 GPU\n", "# hardware accelerator. Our models are designed to run with at least 16GB\n", "# of RAM, activating T4 will grant the notebook 16GB of GDDR6 RAM as opposed\n", "# to the ~13GB Colab gives automatically.\n", "# To activate T4:\n", "# 1. click on the \"Runtime\" tab\n", "# 2. click on \"Change runtime type\"\n", "# 3. select T4 GPU under \"Hardware Accelerator\"\n", "# NOTE: there is a weekly usage limit on using T4 for free" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "collapsed": true, "id": "9TasXeh9ntUx", "outputId": "0673f3a8-126d-47e7-e2ec-1eb0943343de" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting llmware\n", " Downloading llmware-0.3.0-py3-none-any.whl (56.0 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.0/56.0 MB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting boto3>=1.24.53 (from llmware)\n", " Downloading boto3-1.34.124-py3-none-any.whl (139 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m139.2/139.2 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: huggingface-hub>=0.19.4 in /usr/local/lib/python3.10/dist-packages (from llmware) (0.23.2)\n", "Requirement already satisfied: numpy>=1.23.2 in /usr/local/lib/python3.10/dist-packages (from llmware) (1.25.2)\n", "Collecting pymongo>=4.7.0 (from llmware)\n", " Downloading pymongo-4.7.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (669 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m669.1/669.1 kB\u001b[0m \u001b[31m21.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: tokenizers>=0.15.0 in /usr/local/lib/python3.10/dist-packages (from llmware) (0.19.1)\n", "Collecting psycopg-binary==3.1.17 (from llmware)\n", " Downloading psycopg_binary-3.1.17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m12.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting psycopg==3.1.17 (from llmware)\n", " Downloading psycopg-3.1.17-py3-none-any.whl (178 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m178.0/178.0 kB\u001b[0m \u001b[31m24.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting pgvector==0.2.4 (from llmware)\n", " Downloading pgvector-0.2.4-py2.py3-none-any.whl (9.6 kB)\n", "Collecting colorama==0.4.6 (from llmware)\n", " Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)\n", "Requirement already satisfied: librosa>=0.10.0 in /usr/local/lib/python3.10/dist-packages (from llmware) (0.10.2.post1)\n", "Requirement already satisfied: typing-extensions>=4.1 in /usr/local/lib/python3.10/dist-packages (from psycopg==3.1.17->llmware) (4.12.1)\n", "Collecting botocore<1.35.0,>=1.34.124 (from boto3>=1.24.53->llmware)\n", " Downloading botocore-1.34.124-py3-none-any.whl (12.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.3/12.3 MB\u001b[0m \u001b[31m58.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hCollecting jmespath<2.0.0,>=0.7.1 (from boto3>=1.24.53->llmware)\n", " Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)\n", "Collecting s3transfer<0.11.0,>=0.10.0 (from boto3>=1.24.53->llmware)\n", " Downloading s3transfer-0.10.1-py3-none-any.whl (82 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m82.2/82.2 kB\u001b[0m \u001b[31m10.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (3.14.0)\n", "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (2023.6.0)\n", "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (24.0)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (6.0.1)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (2.31.0)\n", "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->llmware) (4.66.4)\n", "Requirement already satisfied: audioread>=2.1.9 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (3.0.1)\n", "Requirement already satisfied: scipy>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (1.11.4)\n", "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (1.2.2)\n", "Requirement already satisfied: joblib>=0.14 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (1.4.2)\n", "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (4.4.2)\n", "Requirement already satisfied: numba>=0.51.0 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (0.58.1)\n", "Requirement already satisfied: soundfile>=0.12.1 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (0.12.1)\n", "Requirement already satisfied: pooch>=1.1 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (1.8.1)\n", "Requirement already satisfied: soxr>=0.3.2 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (0.3.7)\n", "Requirement already satisfied: lazy-loader>=0.1 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (0.4)\n", "Requirement already satisfied: msgpack>=1.0 in /usr/local/lib/python3.10/dist-packages (from librosa>=0.10.0->llmware) (1.0.8)\n", "Collecting dnspython<3.0.0,>=1.16.0 (from pymongo>=4.7.0->llmware)\n", " Downloading dnspython-2.6.1-py3-none-any.whl (307 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m28.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/local/lib/python3.10/dist-packages (from botocore<1.35.0,>=1.34.124->boto3>=1.24.53->llmware) (2.8.2)\n", "Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /usr/local/lib/python3.10/dist-packages (from botocore<1.35.0,>=1.34.124->boto3>=1.24.53->llmware) (2.0.7)\n", "Requirement already satisfied: llvmlite<0.42,>=0.41.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba>=0.51.0->librosa>=0.10.0->llmware) (0.41.1)\n", "Requirement already satisfied: platformdirs>=2.5.0 in /usr/local/lib/python3.10/dist-packages (from pooch>=1.1->librosa>=0.10.0->llmware) (4.2.2)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.4->llmware) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.4->llmware) (3.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.4->llmware) (2024.6.2)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.20.0->librosa>=0.10.0->llmware) (3.5.0)\n", "Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.10/dist-packages (from soundfile>=0.12.1->librosa>=0.10.0->llmware) (1.16.0)\n", "Requirement already satisfied: pycparser in /usr/local/lib/python3.10/dist-packages (from cffi>=1.0->soundfile>=0.12.1->librosa>=0.10.0->llmware) (2.22)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.35.0,>=1.34.124->boto3>=1.24.53->llmware) (1.16.0)\n", "Installing collected packages: psycopg-binary, psycopg, pgvector, jmespath, dnspython, colorama, pymongo, botocore, s3transfer, boto3, llmware\n", "Successfully installed boto3-1.34.124 botocore-1.34.124 colorama-0.4.6 dnspython-2.6.1 jmespath-1.0.1 llmware-0.3.0 pgvector-0.2.4 psycopg-3.1.17 psycopg-binary-3.1.17 pymongo-4.7.3 s3transfer-0.10.1\n" ] } ], "source": [ "!pip install llmware" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "DNym3TAGnw9N" }, "outputs": [], "source": [ "from llmware.agents import LLMfx\n", "\n", "earnings_transcripts = [\n", " \"This is one of the best quarters we can remember for the industrial sector with significant growth across the \"\n", " \"board in new order volume, as well as price increases in excess of inflation. We continue to see very strong \"\n", " \"demand, especially in Asia and Europe. Accordingly, we remain bullish on the tier 1 suppliers and would be \"\n", " \"accumulating more stock on any dips. \",\n", "\n", " \"Not the worst results, but overall we view as negative signals on the direction of the economy, and the likely \"\n", " \"short-term trajectory for the telecom sector, and especially larger market leaders, including AT&T, Comcast, and\"\n", " \"Deutsche Telekom.\",\n", "\n", " \"This quarter was a disaster for Tesla, with falling order volume, increased costs and supply, and negative \"\n", " \"guidance for future growth forecasts in 2024 and beyond.\",\n", "\n", " \"On balance, this was an average result, with earnings in line with expectations and no big surprises to either \"\n", " \"the positive or the negative.\"\n", " ]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "kwIXabPGn2cK" }, "outputs": [], "source": [ "def get_one_sentiment_classification(text):\n", "\n", " \"\"\"This example shows a basic use to get a sentiment classification and use the output programmatically. \"\"\"\n", "\n", " # simple basic use to get the sentiment on a single piece of text\n", " agent = LLMfx(verbose=True)\n", " agent.load_tool(\"sentiment\")\n", " sentiment = agent.sentiment(text)\n", "\n", " # look at the output\n", " print(\"sentiment: \", sentiment)\n", " for keys, values in sentiment.items():\n", " print(f\"{keys}-{values}\")\n", "\n", " # two key attributes of the sentiment output dictionary\n", " sentiment_value = sentiment[\"llm_response\"][\"sentiment\"]\n", " confidence_level = sentiment[\"confidence_score\"]\n", "\n", " # use the sentiment classification as a 'if...then' decision point in a process\n", " if \"positive\" in sentiment_value:\n", " print(\"sentiment is positive .... will take 'positive' analysis path ...\", sentiment_value)\n", "\n", " if \"positive\" in sentiment_value and confidence_level > 0.8:\n", " print(\"sentiment is positive with high confidence ... \", sentiment_value, confidence_level)\n", "\n", " return sentiment" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "-YqsnaLBn6SK" }, "outputs": [], "source": [ "def review_batch_earning_transcripts():\n", "\n", " \"\"\" This example highlights how to review multiple earnings transcripts and iterate through a batch\n", " using the load_work mechanism. \"\"\"\n", "\n", " agent = LLMfx()\n", " agent.load_tool(\"sentiment\")\n", "\n", " # iterating through a larger list of samples\n", " # note: load_work method is a flexible input mechanism - pass a string, list, dictionary or combination, and\n", " # it will 'package' as iterable units of processing work for the agent\n", "\n", " agent.load_work(earnings_transcripts)\n", "\n", " while True:\n", " output = agent.sentiment()\n", " # print(\"update: test - output - \", output)\n", " if not agent.increment_work_iteration():\n", " break\n", "\n", " response_output = agent.response_list\n", "\n", " agent.clear_work()\n", " agent.clear_state()\n", "\n", " return response_output" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 765, "referenced_widgets": [ "5ff40e631f664081a8320d233f30c278", "11c6a51f2e694408b1ffd01f24cd480c", "6f325b890eaa4225b28fee5984da5af2", "bd38cf347b554772861222fd84d1eb62", "a3b32cf2a6964e3494b4c468c9905f91", "8f0a9b541ba04aa6975ca3250f0cf5f0", "9f5a3ef26bc244cc8bf6c7c82b44c52d", "c727c4ffc69546f5920f1ac2df86450e", "7b9f13f1baa94d2b9237e841b286f4ff", "576c52afab1b452a99b861d997361712", "f6d27b0e549d4ea9a687c5e29409c4f5", "138db0b72a4048fcb99577125aa42593", "a4436703900949eca1f49f208ba21f58", "2582d5db708e4f83af7f6ad9ac1ddedb", "46285793de634b409d860d33a5cc6ab2", "49b4352eda0641d7841a6a5de7854320", "c1cfd71b9fac4b23baec1263a6c0b2ee", "aff951e1937042a7ae732a6ba4fb6834", "e28c2a8c52294d88ad6d25ef66303b61", "e1cf2fb24424404fbc2343aa2b84ed09", "14734c0e1fbe424a963d6a52409be5f1", "6e5bb8fc2b414127814f634ffe4d3a06", "43bbba8de72443f3b0bd596c07116f20", "e0302fc8a864484bba58d20931ddc3d3", "bbb397ad4f0240b1a2e1b045935af46a", "69be4c5935624e91a67713d370043181", "6d549a7de0634184bc76dd9dbbbca5df", "9973c552e9924f4a8118fd5a3d8334b5", "39b3c03f7c4841168671573825df60d0", "f95543b9dd9f415e86b657b199ee2773", "202c8b18eb3841e4bc4ef74baecf6e33", "db41b31350cf4372a0004fdd7f2750b8", "f5b6ca2fbf6b4bcc84c73d08e6236583", "856de742380f48c5bbbfaafa771d349a", "326e861b92414e6b9c265888139db4de", "96f9579890ce4146820bd808827e58f5", "0997d67024754c73abaaf51cb3023e59", "f4973992e12449a099d566b2caccfa1e", "d97b429aa6bd4e939cf89819ef840012", "81d71923e94545878510e6d96f866b0f", "c390ba7fad2f4788aad5f0940bd379e5", "df9720767bd947c69ca5d72573159231", "1759fbfb1e4246ce811d60ca40629d88", "27016c45bd2243098ec392ad4849a05d", "dd4f12a02c154d788901054c65259844", "29f99325a510450199095285baa3d813", "99272e059aaa41aca098e57455075b58", "bd474430a72341fb8b36d39d54bbcc66", "865c4fe0f5d545f6a105532a707c801e", "2a2c9d74cd9b44289821798baa4a9975", "d598a363048644cd96fa2036b37b3508", "85c1aa2c5d6f4628b705a19d8751e64c", "377d10bd4eda48fd9821f24db6d44c0b", "1a8a40c8074f4edab43ea7cfc7606d55", "b866371e1e974218ac03b641219b1dab", "f4e99eddb6ee4329a2fa803f48c9f01c", "3821ba5ff2074c9f9101ad45c7eb26d4", "ba01810cc262488ca04cd270cbd18cc6", "116cfb137a804861b88448a7c3efa1d0", "0f11aa47a7f04f5cb22fdf535c0e13be", "24f8ad3fdc8549f69ff7af7516c586d4", "3842c82332b7496a9686ee4b90ca0a9c", "f2ed661079f748d288f3d359187abc7e", "fe5a66a1682e42018c61351bc00d6a90", "400656299c294b389d452413d1909f97", "6e705e9a55674e86b2b9276faa782a66" ] }, "id": "RK8KQ6g_n9a7", "outputId": "52f96443-5719-41dc-dea4-c7d9256ba2f4" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "update: Launching LLMfx process\n", "step - \t1 - \tcreating object - ready to start processing.\n", "step - \t2 - \tloading tool - sentiment\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_token.py:89: UserWarning: \n", "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", "You will be able to reuse this secret in all of your notebooks.\n", "Please note that authentication is recommended but still optional to access public models or datasets.\n", " warnings.warn(\n", "/usr/local/lib/python3.10/dist-packages/huggingface_hub/file_download.py:1194: UserWarning: `local_dir_use_symlinks` parameter is deprecated and will be ignored. The process to download files to a local folder has been updated and do not rely on symlinks anymore. You only need to pass a destination folder as`local_dir`.\n", "For more details, check out https://huggingface.co/docs/huggingface_hub/main/en/guides/download#download-files-to-local-folder.\n", " warnings.warn(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5ff40e631f664081a8320d233f30c278", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Fetching 4 files: 0%| | 0/4 [00:00