ProjectCED / CED-LLM

Classify and Enhance Data with LLM - Project for Tampere University course Software Engineering Project. Working with Solita.
MIT License
0 stars 0 forks source link

LLM-Research #7

Closed VeriHeppi closed 1 month ago

VeriHeppi commented 2 months ago

Research into possible LLM models: Mistral, Llama (Meta), GPT@Azure, Gemini, CSC LUMI, etc.

Possible to combine multiple LLM models?

vnuotio commented 1 month ago

Asking ChatGPT with the following prompt:

"I am creating an LLM-based text classifier. The purpose of this project is to input text-based data and have the program analyse and classify themes and other things from the data. The program will run locally and will likely be created using Python, and will also use Docker or Podman. What LLM should I use for this task? My choices are Mistral, Llama, GPT@Azure, Gemini and CSC Lumi. Consider the upsides and downsides of each LLM and suggest one or more for my use case."

The answer:

For your LLM-based text classifier project, here’s a breakdown of the five LLMs you’re considering, focusing on their key strengths and weaknesses to help guide your decision. Your goal is to classify themes and analyze text data locally, likely using Python with Docker/Podman, so compatibility, ease of integration, performance, and licensing are essential considerations.

1. Mistral

2. LLaMA (Llama 2)

3. GPT@Azure (Azure OpenAI Service)

4. Gemini

5. CSC Lumi


Recommendation

For your use case of a locally-deployed text classifier, focusing on ease of integration with Python, Docker/Podman, and a preference for local execution, LLaMA 2 and Mistral are the top choices:

  1. LLaMA 2: Offers the best balance between performance, community support, and local deployment. It has strong text classification capabilities, with a wide range of tools and libraries that will make integration easier. LLaMA 2 is open-source but may have some licensing restrictions on commercial use.

  2. Mistral: A great lightweight, open-source option that could be more resource-efficient if your hardware is limited. Mistral is highly suitable if you want a more agile model that can still perform well for NLP tasks like classification, while running locally with minimal overhead.

Not Recommended:

Between LLaMA 2 and Mistral, LLaMA 2 is likely to give you stronger results for text classification if you have the hardware to support it, while Mistral is better for a resource-efficient, open-source, local solution.

vnuotio commented 1 month ago

Asking Gemini with the same prompt:

Choosing an LLM for Text Classification

Understanding your requirements:

Comparing LLMs:

  1. Mistral:

    • Pros: Open-source, customizable, and can be trained on specific datasets.
    • Cons: Might require more computational resources for fine-tuning, especially for larger models.
  2. Llama:

    • Pros: Open-source, popular, and has a large community.
    • Cons: Similar to Mistral, might need more computational resources for fine-tuning.
  3. GPT@Azure:

    • Pros: Cloud-based, scalable, and offers various APIs and services.
    • Cons: Requires an Azure subscription, might have limitations on customization, and could be more expensive for large-scale applications.
  4. Gemini:

    • Pros: Powerful, versatile, and designed for complex tasks.
    • Cons: Might be more resource-intensive, and commercial licensing might apply.
  5. CSC Lumi:

    • Pros: Access to high-performance computing resources.
    • Cons: Primarily for research purposes, might require specific expertise to use effectively.

Recommendations:

Given your requirements for local deployment, Python integration, and containerization, Mistral or Llama would be excellent choices. Both are open-source, well-supported, and can be fine-tuned for your specific text classification task.

Additional considerations:

By carefully considering these factors, you can select the LLM that best suits your text classification project and provides the desired performance and flexibility.

vnuotio commented 1 month ago

When asking Mistral:

Choosing the right Large Language Model (LLM) for your text classifier project depends on several factors, including performance, ease of use, cost, and specific requirements. Let's evaluate the options you've mentioned:

Mistral

Upsides:

Downsides:

Llama

Upsides:

Downsides:

GPT@Azure

Upsides:

Downsides:

Gemini

Upsides:

Downsides:

CSC Lumi

Upsides:

Downsides:

Recommendations

  1. For Open Source and Customization:

    • Mistral or Llama: If you have the technical expertise and want full control over the model, Mistral or Llama are excellent choices. They are open-source, allowing for extensive customization and fine-tuning.
  2. For Ease of Use and Performance:

    • GPT@Azure: If you prefer a more straightforward integration and are willing to pay for high performance and comprehensive support, GPT@Azure is a strong contender. It's backed by Microsoft's infrastructure and offers robust performance.
  3. For Specialized Needs:

    • Gemini or CSC Lumi: If you have specific performance or customization needs that are not met by the more general models, Gemini or CSC Lumi might be worth exploring. However, you should carefully evaluate their availability and costs.

Final Suggestion

Given your use case of running the program locally (with cloud solutions possible) and using Python along with Docker or Podman, Mistral or Llama would be excellent choices if you have the technical expertise to set them up and fine-tune them. They offer the flexibility and customization you need without direct costs.

If you prefer a more managed solution with high performance and are willing to pay for it, GPT@Azure is a strong option. It simplifies deployment and scaling, and you can leverage Microsoft's infrastructure and support.

Ultimately, the choice depends on your specific requirements, budget, and technical capabilities.

vnuotio commented 1 month ago

Preliminary research seems to point to Mistral, next up is more research on how to use it.

vnuotio commented 1 month ago

ChatGPT on how to set up Mistral using Python & Podman:

To create an LLM (Large Language Model) program using Python, Podman, and the Mistral LLM on Windows, you'll need to follow a series of steps to set up the environment. Here's a detailed guide on what you need and how to set it up:

1. Install Python

Ensure that Python is installed on your Windows machine. You can download the latest version of Python from the official website: Python.org. During installation, make sure to select the option to Add Python to PATH.

2. Install Podman on Windows

Podman is a containerization platform similar to Docker but designed to be daemonless. Here's how to install Podman on Windows:

Steps to Install Podman:

  1. Download Podman: Visit the official Podman Windows installation page and follow the steps to install Podman for Windows.

  2. WSL2 Installation: Podman on Windows requires Windows Subsystem for Linux 2 (WSL2). If you don’t have WSL2 installed, follow these steps:

    • Open PowerShell as Administrator and run:
      wsl --install
    • This command will install WSL2 along with the Ubuntu Linux distribution by default. After the installation, restart your computer if prompted.
  3. Set Up WSL2 for Podman:

    • Once WSL2 is installed, open PowerShell again and run:
      wsl --set-version <your-distro> 2

      Replace <your-distro> with the name of your installed WSL Linux distribution.

  4. Install Podman Desktop: Download and install Podman Desktop from Podman Desktop releases to manage containers graphically and use Podman more effectively.

  5. Run Podman: Open Podman Desktop or use the command line inside the WSL terminal to run Podman commands.

3. Install Mistral LLM in a Podman Container

Once Podman is set up, you can create and run a container with the Mistral LLM model inside it.

Steps to Run Mistral LLM on Podman:

  1. Search for Mistral LLM Image: First, search for the Mistral LLM container image, or create your own Dockerfile if no prebuilt image is available.

    • Use the Podman CLI to search for Mistral LLM:
      podman search mistral
    • If no pre-built images are available, you may need to create a Dockerfile that sets up Mistral LLM from source or another repository.
  2. Pull the Mistral Image or Build from Dockerfile:

    • Pull the image (if available):
      podman pull mistral/mistral-llm:latest
    • Or build the image from a Dockerfile (if you create one for Mistral):
      podman build -t mistral-llm .
  3. Run the Container:

    • Start a container with the Mistral LLM:
      podman run -it --rm mistral/mistral-llm:latest
    • This will download and start the Mistral model in a containerized environment.

4. Set Up Python to Interact with Mistral LLM

Now that Mistral LLM is running inside a Podman container, you'll need to set up Python on Windows to interact with the model.

Install Required Python Libraries:

  1. Install requests or another HTTP library (if you will interact with the LLM via an API):

    pip install requests
  2. Set Up a Python Script to Connect with Mistral:

    If Mistral LLM exposes an API, you can write a Python script to send requests to the Mistral instance running inside the Podman container. Here's an example:

    import requests
    
    # Replace with the correct URL for the running Mistral LLM API
    url = "http://localhost:8000/api/v1/generate"
    
    headers = {"Content-Type": "application/json"}
    data = {
       "prompt": "What is the capital of France?",
       "max_tokens": 50
    }
    
    response = requests.post(url, json=data, headers=headers)
    if response.status_code == 200:
       print(response.json())
    else:
       print(f"Error: {response.status_code}")
  3. Exposing Ports from the Podman Container: Ensure that the Mistral LLM container exposes the necessary ports so that Python on Windows can communicate with it. For example:

    podman run -it -p 8000:8000 mistral/mistral-llm:latest

5. Testing the Setup

Once everything is set up:

6. Automation with Scripts

To automate your setup, you can write a batch or PowerShell script to launch the container and your Python script in sequence.

Summary of Tools and Libraries:

With this setup, you'll have a containerized LLM (Mistral) running in Podman on your Windows machine, and you'll use Python to interact with it via an API or other interface.

Lauri-Niemela commented 1 month ago

I also had the same kind of discussion with ChatGPT as Vertti and came to the same conclusion that Mistral & LLAMA are the best options.

Since LLAMA and Gemini are developed by Meta's and Google's it is known how these companies make money. So I leaned towards Mistral on this one myself. Here is some conversation with ChatGPT about the subject.

"Mistral AI models, being open-weight and designed for use in local or private settings, do not collect user data by default. The responsibility for data privacy lies with the developer or organization using the model. Unlike larger companies like Meta or Google, Mistral AI does not operate a centralized advertising or data-sharing ecosystem, and there’s no indication that it collects or sells user data for marketing purposes."

My only question is: is mistral free to use? While researching the topic, I came across information that it would no longer be free after August 2024.

While researching LLM integration I came across several ways and wondered if, for example, a modular approach or ensemble learning techinique would be good for this project?

vnuotio commented 1 month ago

Mistral is not free. The price is $2 per 1 million tokens for input and $6 per 1 million for output for the best model and $0,15 per 1 million tokens for the new Pixtral 12B version.

Llama 3.1 price varies (https://www.llama.com/)

Running some models locally is possible but takes heavy amounts of GPU VRAM (https://ollama.com/library)

vnuotio commented 1 month ago

Results:

vnuotio commented 1 month ago

Client opinion: