Downloads · 30 days
13
10% of all-time downloads
ajiayi/llama-3.1-8b-merged-unsloth-cot
llama-3.1-8b-merged-unsloth-cot is a machine learning model from ajiayi. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This model is a specialized fine-tuned variant of Llama 3.1 8B Instruct designed for stock price prediction using Socratic Chain-of-Thought (CoT) methodology. The model has been trained through knowledge distillation…
Downloads · 30 days
13
10% of all-time downloads
All-time downloads
124
Public
Parameters
8B
16.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors16.1 GB · 100%
From the Hugging Face model README
This model is a specialized fine-tuned variant of Llama 3.1 8B Instruct designed for stock price prediction using Socratic Chain-of-Thought (CoT) methodology. The model has been trained through knowledge distillation using GPT-4o Mini as the teacher model, emphasizing step-by-step reasoning through question-and-answer interactions to improve prediction quality.
Model ID: ajiayi/llama-3.1-8b-merged-unsloth-cot
Model Size: 8 Billion Parameters
Base Model: Meta-Llama-3.1-8B-Instruct
- r (Rank): Optimized via rank finder (tested ranks: 8, 16, 32, 64)
- lora_alpha: 16
- lora_dropout: 0
- Target Modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
- Bias: None
- Use Gradient Checkpointing: Unsloth (optimized)
train_with_qa_instruction_format.jsonlThe Socratic method teaches through guided questioning and structured reasoning. In this model, a single student model is trained end-to-end to both generate questions and provide answers, creating an integrated reasoning chain.
Note: While the original Socratic CoT approach in literature often uses two separate models (a question generator and an answer generator), this implementation uses a unified single-student architecture trained to produce both questions and answers in a single forward pass.
Unlike the two-student approach in the original paper:
The single student learns to:
Generate Contextual Questions: Creates relevant analytical questions about:
Provide Detailed Answers: Generates answers that:
Synthesize Predictions: Combines question-answer reasoning to:
During training on 8,698 examples, the single student model learns to:
Each training sample contains:
This model was trained using the Alpaca instruction-following format with question-answer pairs integrated into the output:
{
"instruction": "[System prompt describing task]",
"input": "[Market data input]",
"output": "[JSON with predicted_close, likelihood, and justification Q&A chain]"
}
The model expects inputs formatted as financial analysis prompts containing:
TICKER: [Stock Symbol]
DATE: [YYYY-MM-DD]
RECENT CLOSING PRICES (most recent last): [comma-separated prices]
TECHNICAL INDICATORS:
SMA_20=[value], SMA_50=[value],
EMA_12=[value], EMA_26=[value],
RSI_14=[value], MACD=[value], MACD_signal=[value], MACD_hist=[value],
BB_width_20_2=[value]
SENTIMENT AGGREGATES:
headline_count=[count], sent_compound_mean=[score]
HEADLINES (concise):
[News headlines if available]
You are a financial analyst with expertise in stock market forecasting.
Your task is to analyze market data and predict the next trading day stock price.
Use historical price trends, technical indicators, and sentiment analysis to provide an informed forecast.
Ensure that your predictions are well-justified, considering multiple financial factors.
• Predicted Stock Price: The forecasted close price for the next trading day.
• Price Movement Likelihood: The likelihood of the predicted stock price.
• Justification: Provide an explanation for the predicted stock price and the corresponding likelihood, considering the following:
- Historical market data (e.g., recent closing prices).
- Technical indicators (e.g., SMA, EMA, RSI, MACD, Bollinger Bands).
- Sentiment analysis (e.g., news sentiment, market sentiment).
Please weigh these signals and justify the predicted stock price.
Return STRICT JSON with keys:
- predicted_close (float, next-day close price),
- likelihood (float in [0,1]),
- justification (array of objects with question-answer pairs).
The model generates output with embedded question-answer reasoning chains:
{
"predicted_close": 27.18,
"likelihood": 0.5,
"justification": [
{
"question": "What is the significance of the recent closing prices in predicting AAPL's next trading day?",
"answer": "The closing prices show a slight downward trend, indicating selling pressure in the recent days, which could affect the predicted price."
},
{
"question": "How do technical indicators like RSI and MACD influence the prediction?",
"answer": "The RSI of 13.54 suggests that AAPL is oversold, which could lead to a potential price recovery, while the negative MACD indicates weakening momentum."
},
{
"question": "What does the sentiment analysis indicate about AAPL's stock performance?",
"answer": "The negative compound sentiment of -0.07955 from news headlines suggests bearish sentiment in the market, which could hinder any positive price movement in the short term."
},
{
"question": "Why is the predicted likelihood of the price movement set at 0.5?",
"answer": "The likelihood is set at 0.5 due to mixed signals from technical indicators and negative sentiment, indicating uncertainty about the stock's short-term performance."
}
]
}
The training data includes diverse stocks across sectors:
pip install transformers torch huggingface_hub
from transformers import AutoModelForCausalLM, AutoTokenizer
import json
model_id = "ajiayi/llama-3.1-8b-merged-unsloth-cot"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
# Prepare your input with Socratic questions
prompt = """[Your financial analysis input with Q1-Q4]"""
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Parse JSON output
try:
prediction = json.loads(response)
print(f"Question-Answer Justification: {prediction['justification']}")
print(f"Predicted Close: {prediction['predicted_close']}")
print(f"Confidence: {prediction['likelihood']:.2%}")
except json.JSONDecodeError:
print(response)
This model supports Hugging Face Inference Endpoints for production deployment:
from transformers import pipeline
pipe = pipeline("text-generation", model="ajiayi/llama-3.1-8b-merged-unsloth-cot")
results = pipe("[Your prompt with questions]", max_new_tokens=512, temperature=0.7)
print(results[0]['generated_text'])
Training data derived from:
The distillation targets (teacher model outputs) were generated using OpenAI's GPT-4o Mini API with explicit question-answer formatting.
If you use this model in research, please cite:
@model{llama_socratic_cot_distillation_2025,
title={Llama 3.1 8B Fine-tuned with Socratic Chain-of-Thought for Stock Price Prediction},
author={Jiayi Ang},
year={2025},
howpublished={Hugging Face Model Hub},
note={Knowledge distillation from GPT-4o Mini with Socratic methodology}
}
For questions or issues related to this model, please open an issue on the model repository or contact the model creator.
| Version | Date | Changes |
|---|---|---|
| 1.0 | 2025 | Initial release with merged LoRA weights and Socratic CoT training |
This model follows the license of the base Llama 3.1 8B Instruct model. Please refer to the base model's license for details.