Aditya commited on
Commit
fc72b2a
Β·
1 Parent(s): e2b3faf

Add project README with architecture, tech stack, and setup guide

Browse files
Files changed (1) hide show
  1. README.md +112 -184
README.md CHANGED
@@ -1,207 +1,135 @@
1
- ---
2
- base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
3
- library_name: peft
4
- pipeline_tag: text-generation
5
- tags:
6
- - base_model:adapter:TinyLlama/TinyLlama-1.1B-Chat-v1.0
7
- - lora
8
- - transformers
9
- ---
10
-
11
- # Model Card for Model ID
12
-
13
- <!-- Provide a quick summary of what the model is/does. -->
14
-
15
-
16
-
17
- ## Model Details
18
-
19
- ### Model Description
20
-
21
- <!-- Provide a longer summary of what this model is. -->
22
-
23
-
24
-
25
- - **Developed by:** [More Information Needed]
26
- - **Funded by [optional]:** [More Information Needed]
27
- - **Shared by [optional]:** [More Information Needed]
28
- - **Model type:** [More Information Needed]
29
- - **Language(s) (NLP):** [More Information Needed]
30
- - **License:** [More Information Needed]
31
- - **Finetuned from model [optional]:** [More Information Needed]
32
-
33
- ### Model Sources [optional]
34
-
35
- <!-- Provide the basic links for the model. -->
36
-
37
- - **Repository:** [More Information Needed]
38
- - **Paper [optional]:** [More Information Needed]
39
- - **Demo [optional]:** [More Information Needed]
40
-
41
- ## Uses
42
-
43
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
-
45
- ### Direct Use
46
-
47
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
-
49
- [More Information Needed]
50
-
51
- ### Downstream Use [optional]
52
-
53
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
-
55
- [More Information Needed]
56
-
57
- ### Out-of-Scope Use
58
-
59
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
-
61
- [More Information Needed]
62
-
63
- ## Bias, Risks, and Limitations
64
-
65
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
-
67
- [More Information Needed]
68
-
69
- ### Recommendations
70
-
71
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
-
73
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
-
75
- ## How to Get Started with the Model
76
-
77
- Use the code below to get started with the model.
78
-
79
- [More Information Needed]
80
-
81
- ## Training Details
82
-
83
- ### Training Data
84
-
85
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
-
87
- [More Information Needed]
88
-
89
- ### Training Procedure
90
-
91
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
 
93
- #### Preprocessing [optional]
94
 
95
- [More Information Needed]
96
 
 
97
 
98
- #### Training Hyperparameters
99
-
100
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
-
102
- #### Speeds, Sizes, Times [optional]
103
-
104
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
-
106
- [More Information Needed]
107
-
108
- ## Evaluation
109
-
110
- <!-- This section describes the evaluation protocols and provides the results. -->
111
-
112
- ### Testing Data, Factors & Metrics
113
-
114
- #### Testing Data
115
-
116
- <!-- This should link to a Dataset Card if possible. -->
117
-
118
- [More Information Needed]
119
-
120
- #### Factors
121
-
122
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
-
124
- [More Information Needed]
125
-
126
- #### Metrics
127
-
128
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
-
130
- [More Information Needed]
131
-
132
- ### Results
133
-
134
- [More Information Needed]
135
-
136
- #### Summary
137
-
138
-
139
-
140
- ## Model Examination [optional]
141
-
142
- <!-- Relevant interpretability work for the model goes here -->
143
-
144
- [More Information Needed]
145
-
146
- ## Environmental Impact
147
-
148
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
-
150
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
-
152
- - **Hardware Type:** [More Information Needed]
153
- - **Hours used:** [More Information Needed]
154
- - **Cloud Provider:** [More Information Needed]
155
- - **Compute Region:** [More Information Needed]
156
- - **Carbon Emitted:** [More Information Needed]
157
-
158
- ## Technical Specifications [optional]
159
-
160
- ### Model Architecture and Objective
161
-
162
- [More Information Needed]
163
-
164
- ### Compute Infrastructure
165
-
166
- [More Information Needed]
167
-
168
- #### Hardware
169
 
170
- [More Information Needed]
171
 
172
- #### Software
 
 
 
 
173
 
174
- [More Information Needed]
175
 
176
- ## Citation [optional]
177
 
178
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
 
180
- **BibTeX:**
 
 
 
 
181
 
182
- [More Information Needed]
183
 
184
- **APA:**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
- [More Information Needed]
187
 
188
- ## Glossary [optional]
189
 
190
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
 
 
 
 
 
191
 
192
- [More Information Needed]
193
 
194
- ## More Information [optional]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
- [More Information Needed]
197
 
198
- ## Model Card Authors [optional]
199
 
200
- [More Information Needed]
201
 
202
- ## Model Card Contact
203
 
204
- [More Information Needed]
205
- ### Framework versions
206
 
207
- - PEFT 0.18.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ§™ CodeSage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ **A comparative study of three LLM strategies for domain-specific question answering.**
4
 
5
+ CodeSage puts a Baseline LLM, a RAG pipeline, and a Fine-Tuned model side-by-side so you can ask the same programming question and immediately see how each approach differs in accuracy, grounding, and speed.
6
 
7
+ ---
8
 
9
+ ## Why This Project?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ When building an AI assistant for a specific domain (here: programming / DSA / web dev), you have three realistic options:
12
 
13
+ | Approach | Core idea | Trade-off |
14
+ |---|---|---|
15
+ | **Baseline LLM** | Prompt a large general-purpose model | Fast, zero setup β€” but may hallucinate or give vague answers |
16
+ | **RAG** | Retrieve relevant docs first, then generate | Grounded answers, updatable knowledge β€” retrieval adds latency |
17
+ | **Fine-Tuning** | Train a smaller model on domain data | Potentially fastest, very focused β€” expensive to update |
18
 
19
+ There is no universal winner. The goal of CodeSage is to **make that trade-off visible** with real side-by-side outputs and user-rated metrics.
20
 
21
+ ---
22
 
23
+ ## What It Does
24
 
25
+ 1. You type (or click) a programming question.
26
+ 2. All three systems answer it simultaneously.
27
+ 3. You see each answer, the RAG system's retrieved context, and response times.
28
+ 4. You rate each answer (correctness, completeness, hallucination).
29
+ 5. A live metrics table aggregates your ratings across all questions.
30
 
31
+ ---
32
 
33
+ ## Architecture
34
+
35
+ ```
36
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
37
+ β”‚ Streamlit UI β”‚
38
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
39
+ β”‚ β”‚ System 1 β”‚ β”‚ System 2 β”‚ β”‚ System 3 β”‚ β”‚
40
+ β”‚ β”‚ Baseline β”‚ β”‚ RAG β”‚ β”‚ Fine-Tunedβ”‚ β”‚
41
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β”‚
42
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
43
+ β”‚ β”‚ β”‚
44
+ β–Ό β–Ό β–Ό
45
+ Groq API FAISS index TinyLlama 1.1B
46
+ Llama 3.1 8B + HuggingFace (LoRA adapter loaded
47
+ (prompt only) embeddings locally via PEFT)
48
+ β”‚
49
+ Groq API
50
+ Llama 3.1 8B
51
+ (with context)
52
+ ```
53
+
54
+ ### System 1 β€” Baseline LLM
55
+ Sends the question directly to **Llama 3.1 8B** (via Groq) with a short system prompt. No extra knowledge. Represents what an off-the-shelf LLM can do.
56
+
57
+ ### System 2 β€” RAG (Retrieval-Augmented Generation)
58
+ 1. The question is embedded with `all-MiniLM-L6-v2` (HuggingFace Sentence Transformers).
59
+ 2. Top-3 most similar chunks are retrieved from a **FAISS** vector store built from 17 hand-written `.txt` documents covering DSA topics and web dev concepts.
60
+ 3. Those chunks are injected as context into the prompt sent to **Llama 3.1 8B** via Groq.
61
+
62
+ ### System 3 β€” Fine-Tuned Model
63
+ **TinyLlama 1.1B** fine-tuned with **LoRA (Low-Rank Adaptation)** on ~20 curated programming Q&A pairs. Training is done on Google Colab (free GPU). The resulting adapter is loaded locally via the `peft` library for inference.
64
 
65
+ ---
66
 
67
+ ## Tech Stack
68
 
69
+ | Layer | Technology |
70
+ |---|---|
71
+ | UI | Streamlit |
72
+ | LLM inference | Groq API β€” `llama-3.1-8b-instant` |
73
+ | Embeddings | `sentence-transformers/all-MiniLM-L6-v2` |
74
+ | Vector store | FAISS (CPU) via LangChain |
75
+ | Fine-tuning | HuggingFace Transformers + PEFT (LoRA) |
76
+ | Base model | TinyLlama/TinyLlama-1.1B-Chat-v1.0 |
77
+ | Training platform | Google Colab |
78
+ | Background animation | HTML5 Canvas (3D particle network via `components.html`) |
79
 
80
+ ---
81
 
82
+ ## How to Run
83
+
84
+ ### 1. Clone & install
85
+ ```bash
86
+ git clone https://github.com/Adityax-07/LLM-vs-RAG-vs-Fine-Tuning-.git
87
+ cd LLM-vs-RAG-vs-Fine-Tuning-
88
+ pip install -r requirements.txt
89
+ ```
90
+
91
+ ### 2. Set your Groq API key
92
+ Create a `.env` file:
93
+ ```
94
+ GROQ_API_KEY=your_key_here
95
+ ```
96
+ Get a free key at [console.groq.com](https://console.groq.com).
97
+
98
+ ### 3. Run the app
99
+ ```bash
100
+ streamlit run demo.py
101
+ ```
102
+ The FAISS index is built automatically on first launch.
103
+
104
+ ### 4. (Optional) Load the fine-tuned model
105
+ 1. Open `system3_finetune_colab.ipynb` in Google Colab.
106
+ 2. Run all cells β€” training takes ~10 min on a free T4 GPU.
107
+ 3. Download `finetuned_model.zip` and unzip it in the project root.
108
+ 4. Restart the Streamlit app β€” System 3 will now return real answers.
109
 
110
+ ---
111
 
112
+ ## Knowledge Base
113
 
114
+ The RAG system retrieves from 17 topic documents in `data/docs/`:
115
 
116
+ `binary_search` Β· `sorting_algorithms` Β· `dynamic_programming` Β· `graph_algorithms` Β· `trees` Β· `linked_list` Β· `stack_queue` Β· `recursion` Β· `backtracking` Β· `greedy_algorithms` Β· `hashing` Β· `string_algorithms` Β· `two_pointers` Β· `react_hooks` Β· `rest_api` Β· `javascript_promises` Β· `css_flexbox`
117
 
118
+ ---
 
119
 
120
+ ## Project Structure
121
+
122
+ ```
123
+ β”œβ”€β”€ demo.py # Streamlit app
124
+ β”œβ”€β”€ system1_baseline.py # Baseline LLM (Groq)
125
+ β”œβ”€β”€ system2_rag.py # RAG pipeline (FAISS + Groq)
126
+ β”œβ”€β”€ system3_inference.py # Fine-tuned model inference
127
+ β”œβ”€β”€ system3_finetune_colab.ipynb # LoRA training notebook
128
+ β”œβ”€β”€ data/
129
+ β”‚ β”œβ”€β”€ docs/ # 17 knowledge base documents
130
+ β”‚ β”œβ”€β”€ faiss_index/ # FAISS vector store (auto-built)
131
+ β”‚ β”œβ”€β”€ finetune_data.jsonl # Training data for fine-tuning
132
+ β”‚ └── questions.csv # Evaluation question set
133
+ β”œβ”€β”€ finetuned_model/ # LoRA adapter (after training)
134
+ └── requirements.txt
135
+ ```