[404218]: / Code / Groq / Groq_4_Models.ipynb

Download this file

420 lines (419 with data), 25.3 kB

{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "NBSeCnYd6EoK",
        "outputId": "d454cf4d-3145-4637-ea60-bcbb7afd3b0b"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Collecting groq\n",
            "  Downloading groq-0.9.0-py3-none-any.whl (103 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m103.5/103.5 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from groq) (3.7.1)\n",
            "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from groq) (1.7.0)\n",
            "Collecting httpx<1,>=0.23.0 (from groq)\n",
            "  Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m5.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from groq) (2.7.4)\n",
            "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from groq) (1.3.1)\n",
            "Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from groq) (4.12.2)\n",
            "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->groq) (3.7)\n",
            "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->groq) (1.2.1)\n",
            "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->groq) (2024.6.2)\n",
            "Collecting httpcore==1.* (from httpx<1,>=0.23.0->groq)\n",
            "  Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hCollecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->groq)\n",
            "  Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->groq) (0.7.0)\n",
            "Requirement already satisfied: pydantic-core==2.18.4 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->groq) (2.18.4)\n",
            "Installing collected packages: h11, httpcore, httpx, groq\n",
            "Successfully installed groq-0.9.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0\n"
          ]
        }
      ],
      "source": [
        "! pip install groq"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "o2UKwjeuxpsj",
        "outputId": "579e7920-ed0c-4d61-d7ac-e684bad64f20"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "**Best Generative AI Technologies for Molecular Design:**\n",
            "\n",
            "**1. Molecular Transformer (MT)**\n",
            "- Uses Transformers for sequence-to-structure prediction.\n",
            "- Can design molecules with desired properties.\n",
            "- Incorporates physicochemical constraints and user preferences.\n",
            "\n",
            "\n",
            "**2. VCTR (Variational Continuous Transformer for Chemistry)**\n",
            "- Generative model for rapid design of molecules.\n",
            "- Uses a continuous latent representation to capture molecular geometry and interactions.\n",
            "- Can generate molecules suitable for various applications.\n",
            "\n",
            "\n",
            "**3. AlphaFold**\n",
            "- Protein structure prediction model.\n",
            "- Can also generate novel protein sequences.\n",
            "- Offers high accuracy and diversity in generated molecules.\n",
            "\n",
            "\n",
            "**4. RotateNet**\n",
            "- Generative model for rotating molecular graphs.\n",
            "- Can generate diverse and complex molecules.\n",
            "- Suitable for drug discovery and material design.\n",
            "\n",
            "\n",
            "**5. Conformer Generative Model (CGM)**\n",
            "- Probabilistic model for generating molecules.\n",
            "- Considers conformational flexibility and energy landscape.\n",
            "- Useful for generating molecules with desired functionalities.\n",
            "\n",
            "\n",
            "**6. DREAM**\n",
            "- Generative model for de novo molecular design.\n",
            "- Uses a reinforcement learning approach to optimize molecule properties.\n",
            "- Can generate molecules with improved drug-likeness.\n",
            "\n",
            "\n",
            "**7. GA-Transformer**\n",
            "- Genetic Algorithm (GA) based on Transformers.\n",
            "- Can generate molecules with desired chemical features.\n",
            "- Suitable for combinatorial library design.\n",
            "\n",
            "\n",
            "**8. MoleculeTransformer**\n",
            "- Transformer-based model for molecular representation.\n",
            "- Captures molecular fingerprint and conformational flexibility.\n",
            "- Useful for molecular property prediction and design.\n",
            "\n",
            "\n",
            "**Factors to Consider When Choosing a Generative AI Technology:**\n",
            "\n",
            "- **Accuracy:** How well the model can predict accurate molecular structures/properties.\n",
            "- **Diversity:** The ability to generate a wide range of diverse molecules.\n",
            "- **Customization:** The extent to which the model can be tailored to specific design goals.\n",
            "- **Interpretability:** How well the model's reasoning process can be understood.\n",
            "- **Computational efficiency:** The time and resources required to generate molecules.\n",
            "\n",
            "\n",
            "**Note:** The best technology will depend on the specific molecular design goals and constraints.\n",
            "Tokens per second (assumes 1.3 tokens per word): 666.18\n"
          ]
        }
      ],
      "source": [
        "from groq import Groq\n",
        "import time\n",
        "\n",
        "# Initialize the client with the API key\n",
        "client = Groq(api_key=\"\")\n",
        "\n",
        "start_time = time.time()\n",
        "\n",
        "completion = client.chat.completions.create(\n",
        "    model=\"gemma-7b-it\",\n",
        "    messages=[\n",
        "        {\n",
        "            \"role\": \"user\",\n",
        "            \"content\": \"What is the best generative ai technology for molecular design?\"\n",
        "        }\n",
        "    ],\n",
        "    temperature=1,\n",
        "    max_tokens=1024,\n",
        "    top_p=1,\n",
        "    stream=True,\n",
        "    stop=None,\n",
        ")\n",
        "\n",
        "token_count = 0\n",
        "for chunk in completion:\n",
        "    content = chunk.choices[0].delta.content or \"\"\n",
        "    token_count += len(content.split())  # Assuming each word is a token\n",
        "    print(content, end=\"\")\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = end_time - start_time\n",
        "\n",
        "tokens_per_second = (token_count * 1.3) / elapsed_time\n",
        "print(f\"\\nTokens per second (assumes 1.3 tokens per word): {tokens_per_second:.2f}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "Hsz8ItXXxpqf",
        "outputId": "5eb9f66e-0d12-483b-e3a1-3d55278a0e63"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "There are several generative AI technologies that have been applied to molecular design, each with its own strengths and weaknesses. Here are a few examples:\n",
            "\n",
            "1. Generative Adversarial Networks (GANs): GANs have been used in molecular design to generate novel molecular structures with desired properties. GANs consist of two neural networks - a generator and a discriminator - that are trained together to generate new data samples that are similar to the training data.\n",
            "2. Variational Autoencoders (VAEs): VAEs are another type of neural network that have been applied to molecular design. VAEs learn a latent representation of the input data and can generate new data samples by sampling from the latent space.\n",
            "3. Reinforcement Learning (RL): RL has been used in molecular design to optimize molecular structures based on a specific property. In RL, an agent learns to take actions that maximize a reward signal. In molecular design, the agent is trained to modify a molecular structure in order to improve its properties.\n",
            "4. Graph Convolutional Neural Networks (GCNNs): GCNNs are neural networks designed to work with graph-structured data, such as molecular graphs. GCNNs have been used in molecular design to predict molecular properties and to generate new molecular structures.\n",
            "5. Genetic Algorithms (GAs): GAs are a type of optimization algorithm inspired by natural selection. GAs have been used in molecular design to generate new molecular structures by iteratively modifying and selecting the best-performing molecules.\n",
            "\n",
            "The best generative AI technology for molecular design will depend on the specific problem and the desired outcome. In general, GANs and VAEs are well-suited for generating new molecular structures, while RL and GCNNs are useful for optimizing molecular properties and predicting molecular properties, respectively. GAs can be useful for generating new molecules when there is a large pool of candidates. Ultimately, the best technology will depend on the specific problem and the expertise of the researcher.\n",
            "Tokens per second (assumes 1.3 tokens per word): 639.34\n"
          ]
        }
      ],
      "source": [
        "from groq import Groq\n",
        "import time\n",
        "\n",
        "# Initialize the client with the API key\n",
        "client = Groq(api_key=\"\")\n",
        "\n",
        "start_time = time.time()\n",
        "\n",
        "completion = client.chat.completions.create(\n",
        "    model=\"mixtral-8x7b-32768\",\n",
        "    messages=[\n",
        "        {\n",
        "            \"role\": \"user\",\n",
        "            \"content\": \"What is the best generative ai technology for molecular design?\"\n",
        "        }\n",
        "    ],\n",
        "    temperature=1,\n",
        "    max_tokens=1024,\n",
        "    top_p=1,\n",
        "    stream=True,\n",
        "    stop=None,\n",
        ")\n",
        "\n",
        "token_count = 0\n",
        "for chunk in completion:\n",
        "    content = chunk.choices[0].delta.content or \"\"\n",
        "    token_count += len(content.split())  # Assuming each word is a token\n",
        "    print(content, end=\"\")\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = end_time - start_time\n",
        "\n",
        "tokens_per_second = (token_count * 1.3) / elapsed_time\n",
        "print(f\"\\nTokens per second (assumes 1.3 tokens per word): {tokens_per_second:.2f}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "-CrzR5qS63fm",
        "outputId": "a185f27c-b888-472a-d994-3b40aaf5252b"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "What a great question!\n",
            "\n",
            "Generative AI technologies for molecular design have seen significant advancements in recent years, and several options have emerged as top contenders. The best one depends on your specific needs, goals, and preferences. Here's a rundown of popular options:\n",
            "\n",
            "1. **Deep Learning-based Generative Models**:\n",
            "\t* Graph Convolutional Networks (GCNs): GCNs are a widely used architecture for molecular design. They're particularly effective for generating novel, potentially active molecules from a training set of known molecules.\n",
            "\t* Variational Autoencoders (VAEs): VAEs are another popular choice for molecular design. They learn to compress molecular structures into lower-dimensional representations, allowing for efficient generation of new molecules.\n",
            "\t* Generative Adversarial Networks (GANs): GANs consist of two neural networks: a generator and a discriminator. The generator creates new molecules, while the discriminator evaluates their quality and realism.\n",
            "2. **Physical Chemistry-based Generative Models**:\n",
            "\t* Quantum-chemical inspired models: These models leverage quantum chemical calculations to generate molecules that are more likely to satisfy physical chemical rules and have desired properties.\n",
            "\t* Force field-based models: Force field-based models use classical physics to generate molecules that are consistent with experimental data and physical chemical principles.\n",
            "3. **Other Approaches**:\n",
            "\t* Rule-based Generative Models: These models use logical rules and patterns to generate molecules that satisfy specific criteria, such as physicochemical properties or biological activity.\n",
            "\t* Evolutionary Algorithms: Evolutionary algorithms, like Genetic Algorithm (GA) or Particle Swarm Optimization (PSO), can be used to search for optimal molecules within a defined space.\n",
            "\n",
            "Some notable tools and platforms that incorporate generative AI for molecular design include:\n",
            "\n",
            "1. **RDKit**: RDKit is an open-source cheminformatics library that includes tools for molecular generation and design.\n",
            "2. **Molecular Operating Environment (MOE)**: MOE is a commercial software platform that features a range of tools for molecular design, including generative AI algorithms.\n",
            "3. **OpenEye Scientific Software**: OpenEye offers a suite of software tools, including generative AI capabilities, for molecular design and optimization.\n",
            "4. **AI-powered molecular design platforms**: Platforms like Chemaxon, Novartis' Compound Evolver, and Predictive Design's AI-Liberty use generative AI for molecular design and optimization.\n",
            "\n",
            "When choosing the best generative AI technology for molecular design, consider the following factors:\n",
            "\n",
            "1. **Domain expertise**: Choose a technology that aligns with your domain knowledge and experience in molecular biology, chemistry, or pharmaceuticals.\n",
            "2. **Problem scope**: Determine the specific problem you're trying to solve, such as generating novel molecules with desired properties or designing new therapeutic agents.\n",
            "3. **Performance metrics**: Evaluate the technology based on its ability to generate high-quality molecules that meet your desired criteria, such as potency, selectivity, or bioavailability.\n",
            "4. **Ease of use**: Select a technology with a user-friendly interface and minimal computational requirements for efficient integration into your workflow.\n",
            "5. **Cost and scalability**: Consider the costs associated with the technology, including licensing fees, computational resources, and potential support needs.\n",
            "\n",
            "In conclusion, the best generative AI technology for molecular design depends on your specific needs, goals, and preferences. It's essential to evaluate various options, considering factors like domain expertise, problem scope, performance metrics, ease of use, and cost and scalability.\n",
            "Tokens per second (assumes 1.3 tokens per word): 983.15\n"
          ]
        }
      ],
      "source": [
        "from groq import Groq\n",
        "import time\n",
        "\n",
        "# Initialize the client with the API key\n",
        "client = Groq(api_key=\"\")\n",
        "\n",
        "start_time = time.time()\n",
        "\n",
        "completion = client.chat.completions.create(\n",
        "    model=\"llama3-8b-8192\",\n",
        "    messages=[\n",
        "        {\n",
        "            \"role\": \"user\",\n",
        "            \"content\": \"What is the best generative ai technology for molecular design?\"\n",
        "        }\n",
        "    ],\n",
        "    temperature=1,\n",
        "    max_tokens=1024,\n",
        "    top_p=1,\n",
        "    stream=True,\n",
        "    stop=None,\n",
        ")\n",
        "\n",
        "token_count = 0\n",
        "for chunk in completion:\n",
        "    content = chunk.choices[0].delta.content or \"\"\n",
        "    token_count += len(content.split())  # Assuming each word is a token\n",
        "    print(content, end=\"\")\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = end_time - start_time\n",
        "\n",
        "tokens_per_second = (token_count * 1.3) / elapsed_time\n",
        "print(f\"\\nTokens per second (assumes 1.3 tokens per word): {tokens_per_second:.2f}\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "uKuvefstxpoc",
        "outputId": "b0a2e63f-24b9-4716-fe94-87e8cb35b24e"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "What a great question!\n",
            "\n",
            "There are several generative AI technologies that have been applied to molecular design, each with their strengths and weaknesses. The \"best\" one depends on your specific goals, requirements, and the type of molecules you want to design. Here's a brief overview of some popular ones:\n",
            "\n",
            "1. **Generative Adversarial Networks (GANs)**: GANs have been widely used for molecular design due to their ability to generate novel, diverse, and realistic molecules. They consist of two neural networks: a generator and a discriminator. The generator produces molecules, and the discriminator evaluates their likelihood of being real. GANs can be used for tasks like generating novel compounds with desired properties or optimizing molecular structures for specific activities.\n",
            "2. **Variational Autoencoders (VAEs)**: VAEs are another popular choice for molecular design. They learn to compress molecular structures into a lower-dimensional latent space and then generate new molecules by sampling from this space. VAEs are useful for generating molecules with specific properties or for optimization tasks like molecular de novo design.\n",
            "3. **Recurrent Neural Networks (RNNs)**: RNNs, particularly Long Short-Term Memory (LSTM) and Gate Recurrent Unit (GRU) networks, have been used for molecular design by generating molecular structures one atom or bond at a time. They're suitable for tasks like generating molecules with specific topologies or for optimizing molecular sequences.\n",
            "4. **Graph Neural Networks (GNNs)**: GNNs are designed to work with graph-structured data, making them a natural fit for molecular design. They can learn to generate molecules by predicting the presence or absence of bonds between atoms. GNNs are useful for tasks like generating molecules with specific chemical properties or for optimization tasks like molecular docking.\n",
            "5. **Transformer-based models**: Inspired by the success of Transformers in natural language processing, researchers have adapted them for molecular design. These models, such as the Molecular Transformer, use self-attention mechanisms to generate molecules by processing sequences of atoms or bonds.\n",
            "\n",
            "Some popular open-source libraries and tools that implement these technologies for molecular design include:\n",
            "\n",
            "1. **MOSES** (Molecular Optimization using Stochastic Evolutionary Search): A Python library that uses GANs and VAEs for molecular design and optimization.\n",
            "2. **DeepChem**: A Python library that provides various AI models, including GANs, VAEs, and RNNs, for molecular design and other cheminformatics tasks.\n",
            "3. **RDKit**: A widely-used cheminformatics library that provides tools for molecular design, including a GNN-based molecular generator.\n",
            "4. **Molecular Transformer**: A PyTorch-based implementation of the Molecular Transformer architecture for molecular design.\n",
            "\n",
            "When choosing a generative AI technology for molecular design, consider the following factors:\n",
            "\n",
            "1. **Task complexity**: More complex tasks, like generating molecules with multiple properties, may require more advanced models like GANs or Transformer-based models.\n",
            "2. **Molecular size and complexity**: Larger molecules may require models that can handle longer sequences or more complex graph structures, such as RNNs or GNNs.\n",
            "3. **Desired properties**: If you need to optimize molecules for specific properties, like logP or QSAR, VAEs or GANs might be more suitable.\n",
            "4. **Computational resources**: The choice of technology may depend on the available computational resources, as some models require more powerful hardware or specialized GPU acceleration.\n",
            "\n",
            "Ultimately, the best generative AI technology for molecular design will depend on your specific needs and goals. You may want to experiment with different technologies and evaluate their performance on your specific task to determine the most suitable approach.\n",
            "Tokens per second (assumes 1.3 tokens per word): 412.57\n"
          ]
        }
      ],
      "source": [
        "from groq import Groq\n",
        "import time\n",
        "\n",
        "# Initialize the client with the API key\n",
        "client = Groq(api_key=\"\")\n",
        "\n",
        "start_time = time.time()\n",
        "\n",
        "completion = client.chat.completions.create(\n",
        "    model=\"llama3-70b-8192\",\n",
        "    messages=[\n",
        "        {\n",
        "            \"role\": \"user\",\n",
        "            \"content\": \"What is the best generative ai technology for molecular design?\"\n",
        "        }\n",
        "    ],\n",
        "    temperature=1,\n",
        "    max_tokens=1024,\n",
        "    top_p=1,\n",
        "    stream=True,\n",
        "    stop=None,\n",
        ")\n",
        "\n",
        "token_count = 0\n",
        "for chunk in completion:\n",
        "    content = chunk.choices[0].delta.content or \"\"\n",
        "    token_count += len(content.split())  # Assuming each word is a token\n",
        "    print(content, end=\"\")\n",
        "\n",
        "end_time = time.time()\n",
        "elapsed_time = end_time - start_time\n",
        "\n",
        "tokens_per_second = (token_count * 1.3) / elapsed_time\n",
        "print(f\"\\nTokens per second (assumes 1.3 tokens per word): {tokens_per_second:.2f}\")"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "machine_shape": "hm",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}