Using Existing Generative AI Models (LLMs)
Generative AI models, particularly Large Language Models (LLMs) like those powering ChatGPT, Copilot, and Gemini, are
amazing at creating human-like text. Beyond content generation, their advanced reasoning and instruction-following abilities allow them to assist powerfully with complex analytical tasks when guided through specific instructions (prompts).
The Value of Using Existing Generative Models
Why use pre-built LLMs? Training these massive models requires enormous datasets and computational power, making it impractical for most researchers. By using existing models, you leverage:
Dual Capabilities in Research
Existing generative models can support textual research workflow in multiple ways:
Prompt Engineering
Effectively using generative models relies on prompt engineering. This is the process of crafting clear, detailed, and context-rich instructions (prompts) to guide the AI toward your desired output. Achieving optimal results often involves experimenting and refining prompts.
Common Ways to Access Models
Critical Considerations (Important!)
Finding the Right Generative Model, Platform, or API
A growing number of powerful generative models (LLMs) are available, each with different strengths, weaknesses, access methods (web interface vs. API), and costs. This section helps you navigate the landscape to find models and services suitable for your research needs, whether for content creation or analysis assistance (particularly via APIs).
Major AI Providers & Platforms (Web UI & API)
These companies offer leading proprietary models, usually accessible via both polished web interfaces and APIs crucial for programmatic use. While there may exist free tiers for testing models, leveraging these models typically requires pay-as-you-go funding.
Prominent Open & Open-Weight Models
These models often have their weights (or full details) released publicly, offering potential for transparency, customization, or local hosting (hardware permitting). They are frequently accessed via platforms like Hugging Face or specific APIs.
Aggregator Tools & Platforms
These tools provide access to or comparisons of multiple models.
How to Choose: Key Selection Criteria
Programmatic Analysis with Leading Commercial APIs
This section details how to leverage leading commercial LLMs (like OpenAI's GPT models, Anthropic's Claude, Google's Gemini) for sophisticated textual analysis by interacting directly with their Application Programming Interfaces (APIs) using Python. While web interfaces are great for exploration, using APIs allows researchers to:
The Core Python API Workflow - A General Pattern
Although specifics vary, interacting with most modern LLM APIs via Python generally involves these steps:
Simple Example Python Script to Work with OpenAI's ChatGPT via API
|
# Conceptual Example - Check OpenAI Docs for current syntax & best practices! from openai import OpenAI # Replace "YOUR_OPENAI_API_KEY" with your actual key string try: |
Running Open Generative Models For Analysis Locally
Introduction - The Local Approach
Beyond cloud-based web interfaces and APIs, you can run many powerful generative models (LLMs) directly on your own computer. Applications like Jan.ai, Ollama, LM Studio, and GPT4All make this possible. This approach offers significant benefits for data privacy (your text never leaves your machine), eliminates API costs, and allows for offline use. This section focuses on using Jan.ai due to its user-friendly interface on Mac, Windows, and Linux, while also mentioning alternatives.
Why Consider Running Models Locally?
Chat & API Access Locally
To run a Generative LLM on a local computer requires software to serve as the interface between the LLM and the researcher. Free applications such as Jan.ai, Ollama, LM Studio, and GPT4All all serve this purpose and provide support for local chat (similar to chatting with LLMs online) and also local APIs. A local API, unlike web APIs, is accessible only on the local computer.
Jan.ai Example: Working with a Local API
Jan.ai supports unlimited, private, and free local API support when working with open GenAI models.See here for documentation on the Local API Server.
Here is a sample Python template you can use to construct your API script.
|
# -*- coding: utf-8 -*- import requests # --- Configuration --- # 1. Server URL: Get this from Jan's Settings -> Server section. # 2. Model ID: Get this from Jan's model list or server settings. # --- Request Details --- # Headers: Typically just Content-Type is needed for local servers. # Prompt: Use the standard OpenAI messages format. # Parameters: Control the model's output. # --- Send Request & Process Response --- print(f"--- Sending request to Jan server at {SERVER_URL} for model {MODEL_ID} ---") try: # Check for HTTP errors (like 404 Not Found, 500 Internal Server Error) # Parse the JSON response body # Extract the main content (following OpenAI structure) # Optional: Display token usage if provided else: except json.JSONDecodeError: except requests.exceptions.ConnectionError as e:
|
What Your Computer Needs to Run Generative Models Locally
Running generative models (LLMs) directly on a computer using tools like Jan.ai or Ollama offers great benefits for privacy and cost, but it depends heavily on your hardware. Performance and feasibility vary significantly based on your system's specifications and the specific model you choose. This section outlines the key hardware components to consider.
Key Factor - Model Size & Quantization
Essential Hardware Components
Using Existing Analytical & Predictive AI Models for Text Analysis
These AI tools are designed to analyze text content, helping to uncover patterns, classify content based on specific criteria, extract key information, or discover patterns and structures within your data. Unlike Generative models, their primary function is interpretation and analysis of existing text, not the creation of new content.
Leveraging pre-trained analytical or predictive models offers significant advantages for researchers. These advantages can include:
Existing analytical models are commonly used for such tasks as:
This section focuses on using these powerful pre-existing tools. Use the tabs above to guide you through:
Finding the Right Analytical/Predictive Model for Your Task
This section highlights key platforms and considerations for discovering pre-trained analytical and predictive models relevant to textual research. Remember that models can vary in their capabilities, languages covered, performance, and ease of use.
Central Model Repositories
Models within Specific Libraries & Frameworks
Some programming libraries come with their own sets of pre-trained models optimized for that framework.
How to Choose: Key Selection Criteria
Importance of Model Cards
Most models on Hugging Face have a Model Card. These cards are amazingly useful as they typically contain:
Applying Pre-trained Analytical/Predictive Models to Your Text
You've identified promising pre-trained models for your analysis task. Now, how do you actually use it with your text data? The process generally involves loading the model and applying it to your input. The specific steps vary depending on whether you use a dedicated tool/platform or a programming library.
Using Tools with Graphical User Interfaces (GUIs)
Many platforms, including web-based tools and some library-licensed resources (e.g., Gale Digital Scholar Lab), offer point-and-click interfaces to run common analyses using underlying pre-trained models. This is often the easiest way to get started.
Typical workflow:
Using Programming Libraries (focus on Python)
For greater flexibility, batch processing large datasets, or integrating analysis into custom scripts, using programming libraries like Hugging Face transformers or spaCy is common. This requires some coding, often in Python. Tools like Google Colab or Jupyter Notebooks provide accessible environments.
Typical Workflow
Workflow Examples:
Computing Resources for Analytical/Predictive AI Models
Running pre-trained analytical or predictive AI models can range from computationally trivial to very demanding. Understanding the potential hardware needs before you start can save time and frustration. Key factors include the model itself, the size of your dataset, and the complexity of your analysis.
Factors Influencing Resource Needs
Hardware Components Explained
Where to Run Your Analysis - Options at Baylor
Recommendation
Evaluate your specific model and data needs. Start with your local machine or Google Colab for exploration. If your analysis is slow, runs out of memory, or involves very large data, the Design & Data Lab or Baylor's HPC resources may be your best option.
Copyright © Baylor® University. All rights reserved.
Report It | Title IX | Mental Health Resources | Anonymous Reporting | Legal Disclosures