Can we actually do regression tasks with LLMs? And are they any good? Let's see...
There are two main projects here:
- 🔍 RAG-enhanced GPT-4 mini for improved contextual understanding
- 🦙 Fine-tuned Llama 3.1 with QLoRA optimization
| Rank | Model | Type | Status |
|---|---|---|---|
| 1 | Random prices | Baseline | ✅ |
| 2 | Average price of training set | Baseline | ✅ |
| 3 | Bag of Words + Linear Regression | Traditional ML | ✅ |
| 4 | Word2Vec + Linear Regression | Traditional ML | ✅ |
| 5 | Word2Vec + Linear SVR | Traditional ML | ✅ |
| 6 | GPT-4 mini | LLM | ✅ |
| 7 | GPT-4 mini with RAG | LLM + RAG | ✅ |
| 8 | Quantized Llama 3.1 | LLM | ✅ |
| 9 | Fine-tuned Llama 3.1 | LLM + Fine-tuning | ✅ |
# Install conda (if not already installed)
# Then create the environment
conda env create -f environment.yml -n llm-regression python=3.11
conda activate llm-regressionCreate your .env file with the required API keys:
OPENAI_API_KEY=sk-proj-your-openai-key-here
HF_TOKEN=hf_your-huggingface-token-here
WANDB_API_KEY=your-wandb-key-here # Optional for experiment trackingEnhance GPT-4 mini with Retrieval-Augmented Generation for better price predictions.
python -m llm_regressor.rag_regressor.create_dbThe RAG system creates a vector database of similar products to provide relevant context during inference.
python -m llm_regressor.benchmarkBoth RAG and fine-tuning successfully improved their base LLM models, demonstrating that Large Language Models can effectively handle regression tasks when properly optimized.
- RAG Enhancement: GPT-4 mini with RAG significantly outperformed the vanilla model by providing relevant context for better price predictions
- Fine-tuning Impact: Fine-tuned Llama 3.1 showed substantial improvement over its untrained quantized version
The untrained quantized Llama model performed poorly due to:
- Smaller model size compared to GPT-4 mini
- Aggressive 4-bit quantization reducing model capacity
Fine-tuning was performed using QLoRA with:
- Epochs: 1
- LoRA Alpha (α): 16
- LoRA Rank (r): 8
The fine-tuned Llama model could likely surpass the RAG approach with:
- Higher
randαvalues for increased learning capacity - Training for 2-3 additional epochs
- Reduced quantization (8-bit vs 4-bit)
Normally you DON'T need to train, you will download my trained model directly from Hugging Face, but if you wish to train follow this steps:
- Request access to the Llama 3.1 model on Hugging Face:
- Visit the Llama 3.1 8B model page
- Click "Request access to this model"
- Fill out the access request form with your intended use case
- Wait for Meta's approval (usually takes 1-2 business days)
- Once approved, your
HF_TOKENwill have access to download the model
- Select Training parameters (Optional): Change parameters like epochs, batch size, QLoRA hyper-parameters in llm_regressor/init.py.
- Then run
python -m llm_regressor.trainer
Source: Curated Amazon Reviews 2023
Location: 🤗 NEGU93/pricer-data
Auto-download: Via your HF_TOKEN 🔄
- Training examples: 400,000
- Test examples: 200,000
- Features: Item text description + price
- Price range: $1 - $1,000
- Categories: Electronics, Home & Garden, Sports, Books, and more
