├── ai_lab ├── openai_llm │ └── Readme.md ├── chatbot_nlp │ ├── requirements.txt │ ├── app.py │ ├── Readme.md │ ├── templates │ │ └── index.html │ ├── ML.txt │ ├── chatbot.ipynb │ └── chatbot1.ipynb ├── Readme.md └── local_llm │ └── Readme.md ├── LICENSE ├── embedded_lab ├── Readme.md └── 7segment-Display.ino └── README.md /ai_lab/openai_llm/Readme.md: -------------------------------------------------------------------------------- 1 | ## wait 2 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==3.0.3 2 | nltk==3.9.1 3 | scikit-learn==1.5.1 4 | -------------------------------------------------------------------------------- /ai_lab/Readme.md: -------------------------------------------------------------------------------- 1 | # 🤖 AI Projects 2 | 3 | This folder contains all the AI-related demos from the ACE College Drone & Robotics Workshop. It includes NLP chatbots, OpenAI API examples, and running local LLMs. 4 | 5 | ## 📁 Contents 6 | 7 | - `chatbot_nlp/` – Basic Python chatbot using intents and NLP 8 | - `openai_llm/` – Chatbot and examples using OpenAI's GPT API 9 | - `local_llm/` – Running LLMs offline (e.g., LLaMA, Mistral, DeepSeek) 10 | 11 | ## 🛠️ Requirements 12 | 13 | - Python 3.8+ 14 | - `openai`, `google-generativeai` (for APIs) 15 | - `nltk`, `flask`, `pyttsx3` (for chatbot/voice) 16 | - `llama-cpp-python` or `ollama` (for local models) 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Nithin G, Sahil Pillai, Dani Johnson, Allwin Jacob 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /embedded_lab/Readme.md: -------------------------------------------------------------------------------- 1 | # 7-Segment Display Counter 2 | 3 | This Arduino project controls a **7-segment display** using **8 digital pins** to show numbers from 0 to 9 with a 1-second interval between each. 4 | 5 | ## 🔧 Hardware Used 6 | 7 | * Arduino Uno (or compatible board) 8 | * 7-Segment display (common cathode) 9 | * 8 x 220-ohm resistors (one per segment) 10 | * Jumper wires 11 | * Breadboard 12 | 13 | ## ⚙️ Pin Configuration 14 | 15 | Each segment of the 7-segment display is connected to one digital pin on the Arduino: 16 | 17 | | Segment | Arduino Pin | 18 | | ------- | ----------- | 19 | | A | 13 | 20 | | B | 12 | 21 | | C | 11 | 22 | | D | 10 | 23 | | E | 9 | 24 | | F | 8 | 25 | | G | 7 | 26 | | H (DP) | 6 | 27 | 28 | > Note: Segment H (Decimal Point) is unused for counting. 29 | 30 | ## 🧠 Functionality 31 | 32 | * Each number (0 to 9) is represented using specific segments lit up. 33 | * The `loop()` function calls each number function (`zero()` to `nine()`) with a 1-second delay. 34 | * Segment control is done using `digitalWrite()` calls. 35 | 36 | ## 🧾 Code Summary 37 | 38 | * `setup()` initializes all pins as `OUTPUT`. 39 | * Each digit from 0-9 has its own function (`zero()`, `one()`, ..., `nine()`) that turns on/off the required segments. 40 | * The display loops through numbers 0-9 indefinitely. 41 | 42 | ## 📦 How to Use 43 | 44 | 1. Connect each segment pin of the 7-segment display to the corresponding Arduino digital pin using resistors. 45 | 2. Upload the `.ino` code to your Arduino board. 46 | 3. Open the Serial Monitor (optional) to confirm the board is working. 47 | 4. Watch the display count from 0 to 9 repeatedly. 48 | 49 | ## 📚 Learning Outcome 50 | 51 | * Understand how a 7-segment display works. 52 | * Learn pin control using `digitalWrite()`. 53 | * Practice basic timing with `delay()`. 54 | * Understand how to break code into functions for readability. 55 | 56 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify, render_template 2 | import random 3 | import nltk 4 | from sklearn.feature_extraction.text import TfidfVectorizer 5 | from sklearn.metrics.pairwise import cosine_similarity 6 | import string 7 | 8 | # Initialize the app 9 | app = Flask(__name__) 10 | 11 | # Initialize NLTK 12 | nltk.data.path.append('/home/nithin/nltk_data') # Update this path as needed 13 | nltk.download('punkt') 14 | nltk.download('wordnet') 15 | nltk.download('punkt_tab') 16 | 17 | # Read and preprocess your data 18 | with open('Machine learning.txt', 'r', errors='ignore') as f: 19 | raw = f.read().lower() 20 | 21 | sentence_tokens = nltk.sent_tokenize(raw) 22 | word_tokens = nltk.word_tokenize(raw) 23 | 24 | # Lemmatization 25 | lemmer = nltk.stem.WordNetLemmatizer() 26 | remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation) 27 | 28 | def lem_tokens(tokens): 29 | return [lemmer.lemmatize(token) for token in tokens] 30 | 31 | def lem_normalize(text): 32 | return lem_tokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict))) 33 | 34 | # Greeting responses 35 | GREETING_INPUTS = ('hello', 'hi', 'greetings', 'sup', "what's up", 'hey',) 36 | GREETING_RESPONSES = ['hi', 'hey', '*nods*', 'hi there', 'hello', 'I am glad! You are talking to me'] 37 | 38 | def greeting(sentence): 39 | for word in sentence.split(): 40 | if word.lower() in GREETING_INPUTS: 41 | return random.choice(GREETING_RESPONSES) 42 | 43 | # Generate chatbot responses 44 | def response(user_response): 45 | robo_response = '' 46 | temp_tokens = sentence_tokens + [user_response] 47 | 48 | vectorizer = TfidfVectorizer(tokenizer=lem_normalize, stop_words='english') 49 | tfidf = vectorizer.fit_transform(temp_tokens) 50 | 51 | values = cosine_similarity(tfidf[-1], tfidf[:-1]) 52 | idx = values.argsort()[0][-1] 53 | flat = values.flatten() 54 | flat.sort() 55 | req_tfidf = flat[-1] 56 | 57 | if req_tfidf == 0: 58 | robo_response = '{} Sorry, I don\'t understand you'.format(robo_response) 59 | else: 60 | robo_response = robo_response + sentence_tokens[idx] 61 | return robo_response 62 | 63 | @app.route('/') 64 | def index(): 65 | return render_template('index.html') # Render the chat interface 66 | 67 | @app.route('/chat', methods=['POST']) 68 | def chat(): 69 | user_response = request.json.get('message', '').lower() 70 | if user_response == 'bye': 71 | return jsonify(response='BOT: Bye!') 72 | elif greeting(user_response): 73 | return jsonify(response=greeting(user_response)) 74 | else: 75 | return jsonify(response=response(user_response)) 76 | 77 | if __name__ == "__main__": 78 | # app.run(debug=True) 79 | app.run(debug=True, host='0.0.0.0', port=5000) 80 | -------------------------------------------------------------------------------- /ai_lab/local_llm/Readme.md: -------------------------------------------------------------------------------- 1 | # 🧠 Running Local LLMs with Ollama 2 | This folder contains demos and notes on how to run **Large Language Models (LLMs)** locally using [Ollama](https://ollama.com). 3 | Participants explored various open-source models and compared their performance directly on their own systems. 4 | 5 | --- 6 | 7 | ## 🛠️ What is Ollama? 8 | 9 | **Ollama** is a powerful tool for running LLMs locally on CPU/GPU. 10 | It supports models like: 11 | 12 | * LLaMA 2 13 | * Mistral 14 | * Gemma 15 | * Phi 16 | * Code LLMs (like `code-llama`) 17 | 18 | --- 19 | 20 | ## 🔧 Installing Ollama (Linux) 21 | 22 | 1. Open your terminal and run: 23 | 24 | ```bash 25 | curl -fsSL https://ollama.com/install.sh | sh 26 | ``` 27 | 28 | 2. Then start Ollama service: 29 | 30 | ```bash 31 | ollama serve 32 | ``` 33 | 34 | > If the service does not start automatically, you can manually start it using: 35 | 36 | ```bash 37 | sudo systemctl start ollama 38 | ``` 39 | 40 | --- 41 | 42 | ## 🚀 Running a Model 43 | 44 | To run your first LLM (e.g., LLaMA 2): 45 | 46 | ```bash 47 | ollama run llama2 48 | ``` 49 | 50 | This will download the model and start a chat session. 51 | 52 | --- 53 | 54 | ## 📦 Example Models Tested 55 | 56 | We tested and compared these models in the workshop: 57 | 58 | * `llama2` 59 | * `mistral` 60 | * `gemma` 61 | * `deepseek` 62 | * `phi` 63 | * `codellama` (for code generation) ... 64 | 65 | You can run any of them by: 66 | 67 | ```bash 68 | ollama run mistral 69 | ollama run deepseek-rf 70 | ollama run gemma 71 | ollama run phi 72 | ``` 73 | 74 | --- 75 | 76 | ## 🔍 Comparing LLMs 77 | 78 | We compared the models based on: 79 | 80 | * Response speed 81 | * Language understanding 82 | * Code generation ability 83 | * Accuracy on follow-up questions 84 | * Resource usage (RAM/CPU) 85 | 86 | --- 87 | 88 | ## 🛠️ Useful Ollama Commands 89 | 90 | ### 🔍 List all available local models 91 | 92 | ```bash 93 | ollama list 94 | ``` 95 | 96 | ### ⬇️ Pull a new model from Ollama hub 97 | 98 | ```bash 99 | ollama pull 100 | # Example: 101 | ollama pull mistral 102 | ``` 103 | 104 | ### ❌ Remove a model 105 | 106 | ```bash 107 | ollama rm 108 | ``` 109 | 110 | ### 🧠 Show model info 111 | 112 | ```bash 113 | ollama show 114 | ``` 115 | 116 | ### 📝 Run in one-shot mode (single message) 117 | 118 | ```bash 119 | ollama run mistral -p "Explain what is cosine similarity in ML" 120 | ``` 121 | 122 | --- 123 | 124 | ## 🤖 Advanced: Run Ollama via API 125 | 126 | You can also access models using Python with the Ollama REST API or tools like `llama-cpp-python`. 127 | 128 | --- 129 | 130 | ## ✅ Learning Outcomes 131 | 132 | * Understand how LLMs work offline 133 | * Run and test open-source models without cloud dependency 134 | * Compare performance across different architectures 135 | * Use command-line and API-based interaction with LLMs 136 | 137 | --- 138 | 139 | Ready to explore the world of open models on your own hardware! 💻🔥 140 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/Readme.md: -------------------------------------------------------------------------------- 1 | # 🧠 Chatbot with NLP 2 | This module introduces how to build a basic chatbot using **AI, Machine Learning**, and **Natural Language Processing (NLP)** techniques. 3 | 4 | --- 5 | 6 | ## 🤖 What is AI and ML? 7 | 8 | - **Artificial Intelligence (AI)** is the simulation of human intelligence by machines. 9 | - **Machine Learning (ML)** is a subset of AI that allows systems to **learn from data** without being explicitly programmed. 10 | 11 | --- 12 | 13 | ## 🧩 Types of Machine Learning 14 | 15 | 1. **Supervised Learning** – Model is trained on labeled data. 16 | _Example: Sentiment classification, spam detection_ 17 | 18 | 2. **Unsupervised Learning** – Model finds patterns in data without labels. 19 | _Example: Clustering, topic modeling_ 20 | 21 | 3. **Reinforcement Learning** – Agent learns to make decisions through rewards and penalties. 22 | _Example: Game AI, robotics movement control_ 23 | 24 | --- 25 | 26 | ## 🗣️ What is NLP? 27 | 28 | **Natural Language Processing (NLP)** is a field of AI that focuses on the interaction between computers and human languages. 29 | 30 | Used for: 31 | - Chatbots 32 | - Language translation 33 | - Sentiment analysis 34 | - Voice assistants 35 | 36 | --- 37 | 38 | ## 🧹 NLP Preprocessing Steps 39 | 40 | Text preprocessing is important before feeding text into an ML model. 41 | 42 | ### Basic Steps: 43 | 1. **Lowercasing** – Converts all characters to lowercase. 44 | 2. **Remove Punctuation** – Strips symbols like `!`, `?`, `.` etc. 45 | 3. **Tokenization** – Splits text into individual words or tokens. 46 | 4. **Stopword Removal** – Removes common words like "is", "the", "a", etc. 47 | 5. **Stemming** – Cuts words to their root form. 48 | _Example: “running” → “run” (can be crude)_ 49 | 6. **Lemmatization** – Converts word to dictionary form using context. 50 | _Example: “better” → “good”_ 51 | 7. **Named Entity Recognition (NER)** – Identifies names, dates, locations in text. 52 | _Example: “Elon Musk founded Tesla in 2003.”_ 53 | 54 | --- 55 | 56 | ## 📚 Intent Classification (for Chatbots) 57 | 58 | - Every user message (input) is matched to an **intent** (like greeting, asking help, etc.) 59 | - Intents are defined in a structured format (like txt) 60 | - Machine Learning model is trained to classify messages into intents 61 | 62 | --- 63 | 64 | ## 🔍 Text Vectorization 65 | 66 | Text needs to be converted into numerical format for training. 67 | 68 | ### Common Methods: 69 | 70 | - **Bag of Words (BoW)** – Simple word count 71 | - **TF-IDF (Term Frequency – Inverse Document Frequency)** 72 | - Scores words based on their importance in a sentence vs entire dataset 73 | 74 | --- 75 | 76 | ## 📏 Matching Input & Response 77 | 78 | Once text is vectorized, we can: 79 | - Train a classifier (e.g., SVM, Logistic Regression) 80 | - Or use **cosine similarity** to measure similarity between user input and stored examples 81 | 82 | --- 83 | 84 | ## 🛠️ This Project Includes: 85 | 86 | - A chatbot using: 87 | - Rule-based + ML-based logic 88 | - NLP preprocessing (with `nltk`) 89 | - TF-IDF + cosine similarity for response selection 90 | 91 | - Intent data in `ML.txt` 92 | - Simple interface via command line 93 | 94 | --- 95 | 96 | ## ✅ Learning Outcomes 97 | 98 | - Understand how chatbots use NLP 99 | - Learn the core steps in processing human language 100 | - Build your own intent-based assistant 101 | 102 | --- 103 | 104 | ## 📦 Requirements 105 | 106 | Install with: 107 | 108 | ```bash 109 | pip install nltk scikit-learn 110 | -------------------------------------------------------------------------------- /embedded_lab/7segment-Display.ino: -------------------------------------------------------------------------------- 1 | unsigned const int A = 13; 2 | unsigned const int B = 12; 3 | unsigned const int C = 11; 4 | unsigned const int D = 10; 5 | unsigned const int E = 9; 6 | unsigned const int F = 8; 7 | unsigned const int G = 7; 8 | unsigned const int H = 6; 9 | 10 | 11 | void setup(void) 12 | { 13 | pinMode(A, OUTPUT); 14 | pinMode(B, OUTPUT); 15 | pinMode(C, OUTPUT); 16 | pinMode(D, OUTPUT); 17 | pinMode(E, OUTPUT); 18 | pinMode(F, OUTPUT); 19 | pinMode(G, OUTPUT); 20 | pinMode(H, OUTPUT); 21 | } 22 | 23 | //My Functions 24 | 25 | void zero(void) { 26 | digitalWrite(A, HIGH); 27 | digitalWrite(B, HIGH); 28 | digitalWrite(C, HIGH); 29 | digitalWrite(D, HIGH); 30 | digitalWrite(E, HIGH); 31 | digitalWrite(F, HIGH); 32 | digitalWrite(G, LOW); 33 | digitalWrite(H, LOW); 34 | } 35 | 36 | void one(void) { 37 | digitalWrite(A, LOW); 38 | digitalWrite(B, HIGH); 39 | digitalWrite(C, HIGH); 40 | digitalWrite(D, LOW); 41 | digitalWrite(E, LOW); 42 | digitalWrite(F, LOW); 43 | digitalWrite(G, LOW); 44 | digitalWrite(H, LOW); 45 | } 46 | 47 | void two(void) { 48 | digitalWrite(A, HIGH); 49 | digitalWrite(B, HIGH); 50 | digitalWrite(C, LOW); 51 | digitalWrite(D, HIGH); 52 | digitalWrite(E, HIGH); 53 | digitalWrite(F, LOW); 54 | digitalWrite(G, HIGH); 55 | digitalWrite(H, LOW); 56 | } 57 | 58 | void three(void) { 59 | digitalWrite(A, HIGH); 60 | digitalWrite(B, HIGH); 61 | digitalWrite(C, HIGH); 62 | digitalWrite(D, HIGH); 63 | digitalWrite(E, LOW); 64 | digitalWrite(F, LOW); 65 | digitalWrite(G, HIGH); 66 | digitalWrite(H, LOW); 67 | } 68 | 69 | void four(void) { 70 | digitalWrite(A, LOW); 71 | digitalWrite(B, HIGH); 72 | digitalWrite(C, HIGH); 73 | digitalWrite(D, LOW); 74 | digitalWrite(E, LOW); 75 | digitalWrite(F, HIGH); 76 | digitalWrite(G, HIGH); 77 | digitalWrite(H, LOW); 78 | } 79 | 80 | void five(void) { 81 | digitalWrite(A, HIGH); 82 | digitalWrite(B, LOW); 83 | digitalWrite(C, HIGH); 84 | digitalWrite(D, HIGH); 85 | digitalWrite(E, LOW); 86 | digitalWrite(F, HIGH); 87 | digitalWrite(G, HIGH); 88 | digitalWrite(H, LOW); 89 | } 90 | 91 | void six(void) { 92 | digitalWrite(A, HIGH); 93 | digitalWrite(B, LOW); 94 | digitalWrite(C, HIGH); 95 | digitalWrite(D, HIGH); 96 | digitalWrite(E, HIGH); 97 | digitalWrite(F, HIGH); 98 | digitalWrite(G, HIGH); 99 | digitalWrite(H, LOW); 100 | } 101 | 102 | void seven(void) { 103 | digitalWrite(A, HIGH); 104 | digitalWrite(B, HIGH); 105 | digitalWrite(C, HIGH); 106 | digitalWrite(D, LOW); 107 | digitalWrite(E, LOW); 108 | digitalWrite(F, LOW); 109 | digitalWrite(G, LOW); 110 | digitalWrite(H, LOW); 111 | } 112 | 113 | void eight(void) { 114 | digitalWrite(A, HIGH); 115 | digitalWrite(B, HIGH); 116 | digitalWrite(C, HIGH); 117 | digitalWrite(D, HIGH); 118 | digitalWrite(E, HIGH); 119 | digitalWrite(F, HIGH); 120 | digitalWrite(G, HIGH); 121 | digitalWrite(H, LOW); 122 | } 123 | 124 | void nine(void) { 125 | digitalWrite(A, HIGH); 126 | digitalWrite(B, HIGH); 127 | digitalWrite(C, HIGH); 128 | digitalWrite(D, HIGH); 129 | digitalWrite(E, LOW); 130 | digitalWrite(F, HIGH); 131 | digitalWrite(G, HIGH); 132 | digitalWrite(H, LOW); 133 | } 134 | 135 | // Start 136 | void loop(void) 137 | { 138 | zero(); 139 | delay(1000); 140 | 141 | one(); 142 | delay(1000); 143 | 144 | two(); 145 | delay(1000); 146 | 147 | three(); 148 | delay(1000); 149 | 150 | four(); 151 | delay(1000); 152 | 153 | five(); 154 | delay(1000); 155 | 156 | six(); 157 | delay(1000); 158 | 159 | seven(); 160 | delay(1000); 161 | 162 | eight(); 163 | delay(1000); 164 | 165 | nine(); 166 | delay(1000); 167 | } 168 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Chatbot 7 | 70 | 71 | 72 |
73 |
74 |
75 | 76 | 77 |
78 |
79 | 80 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/ML.txt: -------------------------------------------------------------------------------- 1 | Machine learning is a subset of artificial intelligence that focuses on creating systems that can learn from data and improve their performance without being explicitly programmed. 2 | 3 | Traditional programming involves writing explicit rules for every task, while machine learning lets the system discover rules and patterns from the data itself. 4 | 5 | The main idea behind machine learning is that systems can automatically improve over time as they are exposed to more data, reducing the need for manual updates. 6 | 7 | There are three main categories of machine learning: supervised learning, unsupervised learning, and reinforcement learning, each suited for different types of tasks and data. 8 | 9 | Supervised learning involves training models on labeled data, where each input is associated with a known output, to predict outcomes on new, unseen data. 10 | 11 | Classification and regression are the two main types of supervised learning tasks. Classification predicts discrete labels, while regression predicts continuous values. 12 | 13 | Logistic Regression is used for binary classification problems and models the probability of an input belonging to a particular class. 14 | 15 | Decision Trees split the data based on feature values, creating a tree structure that leads to predictions based on decision rules. 16 | 17 | Random Forest is an ensemble learning method that builds multiple decision trees and averages their results to improve accuracy and reduce overfitting. 18 | 19 | Support Vector Machines (SVM) find the optimal hyperplane that separates different classes in a high-dimensional space for effective classification. 20 | 21 | Linear Regression models the relationship between features and a continuous output variable using a linear equation. 22 | 23 | Polynomial Regression extends linear regression by including polynomial terms to capture non-linear relationships in the data. 24 | 25 | Ridge Regression adds L2 regularization to linear regression to penalize large coefficients and prevent overfitting. 26 | 27 | Lasso Regression uses L1 regularization, which can shrink some coefficients to zero, effectively performing feature selection. 28 | 29 | Unsupervised learning deals with data that does not have labeled outputs and is used to find patterns or groupings within the data. 30 | 31 | Clustering is a common unsupervised learning task where data points are grouped based on their similarities. 32 | 33 | K-Means Clustering partitions data into a fixed number of clusters by minimizing variance within each cluster. 34 | 35 | Hierarchical Clustering builds a tree of nested clusters by either merging or splitting groups based on distance metrics. 36 | 37 | Dimensionality reduction reduces the number of features in a dataset while preserving important information, often for visualization or efficiency. 38 | 39 | Principal Component Analysis (PCA) transforms features into a new set of orthogonal components that capture the most variance in the data. 40 | 41 | t-SNE is a dimensionality reduction technique particularly good for visualizing high-dimensional data in two or three dimensions. 42 | 43 | Association rule learning identifies interesting relationships or co-occurrences between items in large datasets, such as products in a shopping cart. 44 | 45 | The Apriori algorithm finds frequent itemsets and uses them to generate association rules based on metrics like support and confidence. 46 | 47 | Reinforcement learning is a learning paradigm where an agent learns to make decisions by interacting with an environment and receiving feedback as rewards or penalties. 48 | 49 | In reinforcement learning, the agent learns a policy that maximizes the cumulative reward over time based on its experiences. 50 | 51 | Q-Learning is a value-based reinforcement learning algorithm that estimates the value of actions in each state using the Bellman equation. 52 | 53 | Deep Q-Networks (DQN) extend Q-Learning by using neural networks to approximate Q-values, allowing learning in complex environments with large state spaces. 54 | 55 | Policy Gradient methods directly optimize the agent’s policy by adjusting parameters to increase the expected reward. 56 | 57 | The REINFORCE algorithm is a basic policy gradient method that uses sampled episodes to update the policy in the direction of higher rewards. 58 | 59 | Proximal Policy Optimization (PPO) is a more stable and efficient policy optimization algorithm that maintains a balance between exploration and exploitation. 60 | 61 | Supervised learning is widely used in applications like spam detection, image recognition, medical diagnosis, and stock price prediction. 62 | 63 | Unsupervised learning is useful in tasks like customer segmentation, anomaly detection, and data compression. 64 | 65 | Reinforcement learning is commonly used in game playing, robotic control, autonomous vehicles, and resource management. 66 | 67 | Machine learning models are evaluated using metrics appropriate to their task, such as accuracy for classification or mean squared error for regression. 68 | 69 | Overfitting occurs when a model performs well on training data but poorly on new data due to capturing noise rather than patterns. 70 | 71 | Underfitting happens when a model is too simple to capture the underlying trend in the data, leading to poor performance on both training and test sets. 72 | 73 | The bias-variance trade-off is a key concept in machine learning that refers to the balance between a model's simplicity and its ability to generalize. 74 | 75 | Cross-validation is a method used to assess the performance of a model by training and testing it on different subsets of the data. 76 | 77 | Hyperparameter tuning involves selecting the best values for parameters that control the learning process, such as learning rate or tree depth. 78 | 79 | Grid search and random search are common techniques used to systematically explore combinations of hyperparameters. 80 | 81 | Feature engineering is the process of selecting, modifying, or creating features to improve model performance. 82 | 83 | Good quality data is crucial for machine learning, as models rely heavily on the quantity, variety, and accuracy of training data. 84 | 85 | Ethical considerations in machine learning include fairness, transparency, data privacy, and avoiding bias in algorithmic decisions. 86 | 87 | Explainable AI focuses on making machine learning models and their decisions more transparent and interpretable by humans. 88 | 89 | Federated learning is a privacy-preserving technique that trains machine learning models across multiple decentralized devices without sharing raw data. 90 | 91 | The field of machine learning is evolving rapidly, with ongoing research pushing boundaries in areas like self-supervised learning, large language models, and continual learning. 92 | 93 | Understanding the core concepts of machine learning provides the foundation needed to apply these techniques effectively to real-world problems. 94 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ACE College Drone & Robotics Workshop 🚁🤖 2 | 3 | Welcome to the official repository for the **Drone and Robotics Workshop** conducted at **ACE College**. This workshop is designed to give students hands-on experience with modern technologies used in robotics, automation, and drone development. 4 | 5 | --- 6 | 7 | ## 📅 Workshop Overview 8 | 9 | - **Event**: Drone & Robotics Hands-on Workshop 10 | - **Hosted at**: ACE College 11 | - **Trainers**: Allwin, Sahil, Nithin, Dani 12 | 13 | --- 14 | 15 | ## 🚀 Topics Covered 16 | 17 | ### 🤖 Robotics Workshop 18 | 19 | - 🛠️ Arduino & Microcontroller Basics 20 | - Introduction to Embedded Systems 21 | - Hands-on Mini Projects with Sensors & Actuators 22 | - 💻 Python Programming for Robotics 23 | - Serial Communication Between Python & Arduino 24 | - 👁️ Computer Vision with OpenCV 25 | - Basic Image Processing 26 | - Real-time Object Detection Demos 27 | - 🖥️ CAD with Fusion 360 28 | - Basic Mechanical Design for Prototypes 29 | - 🐧 Linux Essentials 30 | - Terminal Commands, File System, and Usage in Robotics 31 | - 🧠 AI, ML & NLP Basics 32 | - Supervised Learning, NLP Concepts 33 | - Building a Simple Chatbot 34 | - 🤖 Generative AI & LLMs 35 | - Introduction to LLMs (Local & Cloud) 36 | - Running Models Locally on CPU/GPU 37 | - Experimenting with Different LLMs 38 | - 🔌 API Integration 39 | - Using OpenAI & Google GenAI APIs 40 | - Customizing Your Own AI Workflows 41 | 42 | --- 43 | 44 | ### 🚁 Drone Workshop 45 | 46 | - 🔋 Drone Hardware Selection 47 | - Choosing the Right Battery (Type, Voltage, Capacity) 48 | - Understanding KV Ratings of Motors & BLDC Types 49 | - Flight Controller Types & ESCs 50 | - 🧱 Drone Building Workshop 51 | - Assembling Frame, Mounting Components 52 | - Wiring, Propeller Selection, Soldering Basics 53 | - ✈️ First Flight & Calibration 54 | - Safety Measures 55 | - Manual and Stabilized Flight Modes 56 | - 👁️ Python + OpenCV for Drones 57 | - Object Detection Fundamentals 58 | - Frame Capture, Color Detection, Contours 59 | - 🧠 Drone Applications Overview 60 | - Autonomous Drones 61 | - Real-world Use Cases (Surveillance, Mapping, Delivery) 62 | 63 | --- 64 | 65 | ## 🔩 Hardware Requirements 66 | 67 | ### 🤖 Robotics Components 68 | - Arduino Board (Uno/Nano) 69 | - Raspberry Pi (3/4) – for AI, OpenCV, and advanced tasks 70 | - Sensors: IR, Ultrasonic, LDR, Temperature, etc. 71 | - Actuators: Servo Motor, DC Motor with Motor Driver (e.g., L298N) 72 | - Display Modules: OLED / LCD Display (I2C or SPI) 73 | - Communication: USB Cable (for Arduino), Jumper Wires, Breadboard, Resistors 74 | - Audio I/O: Speaker & Microphone (USB or AUX-based) 75 | - Camera: USB Webcam for Vision Tasks 76 | 77 | ### 🚁 Drone Components 78 | - APM Flight Controller (APM 2.8 or similar) 79 | - ESCs (Electronic Speed Controllers) 80 | - BLDC Motors (Brushless DC) 81 | - Propellers (matched to motor specs) 82 | - GPS Module (e.g., Ublox Neo-6M) 83 | - Telemetry Module (e.g., 433MHz or 915MHz) 84 | - LiPo Battery (3S or 4S – depending on power requirement) 85 | - Servo Motors (for payload release, gimbal, etc.) 86 | - Raspberry Pi – for onboard AI (object detection, automation) 87 | - Pi Camera – for drone vision and object detection 88 | 89 | --- 90 | 91 | ### 💻 Software Tools 92 | 93 | - [Arduino IDE](https://www.arduino.cc/en/software) 94 | - [Python 3.8+](https://www.python.org/downloads/) 95 | - [OpenCV](https://pypi.org/project/opencv-python/) 96 | - [PySerial](https://pypi.org/project/pyserial/) 97 | - [Fusion 360 (Student/Educator license)](https://www.autodesk.com/products/fusion-360/personal) 98 | - [SolidWorks (Student/Educator license)](http://solidworks.com/product/students) 99 | - [Linux OS (Ubuntu)](https://ubuntu.com/download/desktop) 100 | - [Mission Planner](https://ardupilot.org/planner/) 101 | - OpenAI Python SDK: `openai` 102 | - Google Generative AI SDK: `google-generativeai` 103 | 104 | --- 105 | 106 | ## 🧠 Learning Outcomes 107 | 108 | By the end of this workshop, participants will be able to: 109 | 110 | ### 🤖 Robotics Track 111 | - Understand the basics of microcontrollers (Arduino) and embedded systems 112 | - Build and program circuits using sensors, actuators, and motor drivers 113 | - Use Python and OpenCV for real-time robotics applications 114 | - Design mechanical components in Fusion 360 115 | - Work with Linux systems and terminal tools 116 | - Understand the fundamentals of AI, Machine Learning, and NLP 117 | - Build and deploy chatbots using Python 118 | - Run large language models (LLMs) locally and through APIs 119 | - Integrate OpenAI and Google GenAI for custom AI applications 120 | 121 | ### 🚁 Drone Track 122 | - Choose the right drone components (battery, motors, ESC, FC) based on use-case 123 | - Understand BLDC motors and KV ratings 124 | - Assemble and wire a complete drone from scratch 125 | - Configure flight controllers (e.g., using Mission Planner or Betaflight) 126 | - Perform calibration and safe test flights 127 | - Apply Python + OpenCV for drone-based object detection and tracking 128 | 129 | --- 130 | 131 | ## 🧪 Final Projects 132 | 133 | ### ✅ Humanoid Robot 134 | Participants will build a **functioning humanoid robot** capable of: 135 | - Voice/text communication (chatbot integration) 136 | - Basic movements (e.g., arm/head gestures) 137 | - Running AI/ML models for interactive responses 138 | 139 | ### ✅ Custom Drone Projects 140 | Participants will build **special-purpose drones**, including: 141 | - 🚚 Delivery Drone – for transporting small packages 142 | - 🙌 Welcoming Drone – to greet or engage people at events 143 | - 🔥 Fire Extinguisher Drone – demo concept for fire response 144 | - 🤖 Autonomous Drone – follows pre-set paths or commands 145 | - 👁️ Surveillance Drone – with real-time camera feed 146 | - 🚨 Disaster Response Drone – for rescue, signaling, or supply drops 147 | 148 | These projects bring together electronics, mechanical design, software integration, and AI to create practical systems. 149 | 150 | --- 151 | 152 | ## 📸 Highlights 153 | 154 | 📷 *Photos and videos from sessions and final projects will be uploaded soon.* 155 | 156 | --- 157 | 158 | ## 👨‍🏫 Contributors 159 | - [Sahil Pillai](https://github.com/Sahilpillai006) – Robotics & Drone 160 | - [Nithin Ganesh](https://github.com/nithinganesh1) – Robotics, AI, Vision & LLMs 161 | - [Dani Johnson](https://github.com/danixj) – Embedded Systems & Robotics 162 | - [Allwin Jacob](https://github.com/allwinjacob) – Embedded system & Coordinatior 163 | 164 | --- 165 | 166 | ## 📬 Contact 167 | 168 | For queries: 169 | 170 | - 📧 sahilpillai117@gmail.com 171 | - 📧 nithingganesh1@gmail.com 172 | - 📧 allwinjacob007@gmail.com 173 | - 📧 danijohnson74074@gmail.com 174 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/chatbot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "c31b2f98-1400-40ca-a2e2-58be555fc90c", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import nltk #to process natural language\n", 11 | "import numpy as np\n", 12 | "import random # to generte random responses to feel less repetitive\n", 13 | "import string # to do string manipulations, because sometimes we need to remove punctuations,need to convert it in lowercase etc." 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "id": "d70b03cb-c590-456a-a147-80d39d9770ff", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 2, 27 | "id": "d1791962-f099-415f-a95c-2a8771a998ab", 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "f = open('Machine learning.txt', 'r', errors='ignore')\n", 32 | "raw = f.read()" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "id": "f1914670-7a5c-40f3-a5c4-2fce1605e8e6", 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "['machine learning is a rapidly evolving field within artificial intelligence (ai) that focuses on the development of algorithms and statistical models that enable computers to learn from and make predictions or decisions based on data.', 'unlike traditional programming where explicit instructions are given for each task, machine learning allows systems to learn patterns and relationships within data, and to improve their performance over time as they are exposed to more data.', 'this capability is grounded in the idea that systems can automatically improve their performance without human intervention through experience.', 'at its core, machine learning is divided into several categories, with the primary ones being supervised learning, unsupervised learning, and reinforcement learning.', 'each of these categories approaches the task of learning from data in a unique way, depending on the nature of the data and the desired outcome.']\n", 46 | "['machine', 'learning', 'is', 'a', 'rapidly']\n" 47 | ] 48 | }, 49 | { 50 | "name": "stderr", 51 | "output_type": "stream", 52 | "text": [ 53 | "[nltk_data] Error loading punkt_tab: \n", 55 | "[nltk_data] Error loading punkt: \n", 57 | "[nltk_data] Error loading wordnet: \n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "nltk.data.path.append('/home/nithin/nltk_data') # Add your nltk_data path\n", 64 | "nltk.download('punkt_tab')\n", 65 | "raw=raw.lower()# convert all strings to lowercase\n", 66 | "nltk.download('punkt')# Punkt is a pre-trained model that helps in sentence tokenization, i.e., splitting a text into sentences\n", 67 | "nltk.download('wordnet')#WordNet is a large database of English words that groups words into sets of synonyms \n", 68 | "sentence_tokens = nltk.sent_tokenize(raw)\n", 69 | "word_tokens = nltk.word_tokenize(raw)\n", 70 | "print(sentence_tokens[:5])\n", 71 | "print(word_tokens[:5])" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 4, 77 | "id": "5b7105e7-4e58-4a7f-aca6-92d074ce8ba9", 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "#normalize the text by removing punctuation and reducing words to their base or root form (lemmatization)\n", 82 | "lemmer = nltk.stem.WordNetLemmatizer()\n", 83 | "\n", 84 | "remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation) ##This dictionary will be used to remove punctuation from the text.\n", 85 | "\n", 86 | "def lem_tokens(tokens): #takes a list of tokens (words) as input and returns a list of lemmatized tokens.\n", 87 | " return [lemmer.lemmatize(token) for token in tokens]\n", 88 | "\n", 89 | "def lem_normalize(text):#This function, lem_normalize, normalizes the input text by performing translate(),lower(), tokenize()\n", 90 | " return lem_tokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))\n", 91 | "\n", 92 | "# translate() used to modify a string by replacing characters based on a specified translation table\n", 93 | "#text.lower() converts all characters in the text to lowercase, ensuring uniformity.\n", 94 | "#translate(remove_punct_dict) removes any punctuation from the text using the remove_punct_dict created earlier.\n", 95 | "#nltk.word_tokenize() splits the cleaned text into individual words (tokens).\n", 96 | "#lem_tokens() is then called to lemmatize each token in the list." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 5, 102 | "id": "c603ec47-5fb1-442b-9a2e-c84c75e26453", 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "GREETING_INPUTS = ('hello', 'hi', 'greetings', 'sup', 'what\\'s up', 'hey',)\n", 107 | "GREETING_RESPONSES = ['hi', 'hey', '*nods*', 'hi there', 'hello', 'I am glad! You are talking to me']\n", 108 | "\n", 109 | "def greeting(sentence):\n", 110 | " for word in sentence.split():\n", 111 | " if word.lower() in GREETING_INPUTS:\n", 112 | " return random.choice(GREETING_RESPONSES)" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 6, 118 | "id": "51665a04-da97-46d0-a42d-45d6f9100c50", 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "#generates a response to a user's input based on the similarity between the user's query and the chatbot's available data.\n", 123 | "\n", 124 | "GREETING_INPUTS = ('hello', 'hi', 'greetings', 'sup', 'what\\'s up', 'hey',)\n", 125 | "GREETING_RESPONSES = ['hi', 'hey', '*nods*', 'hi there', 'hello', 'I am glad! You are talking to me']\n", 126 | "\n", 127 | "def greeting(sentence):\n", 128 | " for word in sentence.split():\n", 129 | " if word.lower() in GREETING_INPUTS:\n", 130 | " return random.choice(GREETING_RESPONSES)\n", 131 | "\n", 132 | "\n", 133 | "from sklearn.feature_extraction.text import TfidfVectorizer #TF-IDF is a statistical measure used to evaluate the importance of a \n", 134 | "#word in a document relative to a collection of documents (corpus). TF-IDF allows the model to focus on the most important \n", 135 | "#words when comparing the user input to the available data.\n", 136 | "from sklearn.metrics.pairwise import cosine_similarity #Cosine similarity is widely used in text processing to measure\n", 137 | "# the similarity between two documents (or sentences) represented as vectors\n", 138 | "\n", 139 | "\n", 140 | "def response(user_response):\n", 141 | " robo_response = ''\n", 142 | " \n", 143 | " # Ensure sentence_tokens doesn't contain duplicates\n", 144 | " if user_response not in sentence_tokens:\n", 145 | " sentence_tokens.append(user_response)\n", 146 | "\n", 147 | " # Check if we have more than one sentence for comparison\n", 148 | " if len(sentence_tokens) > 1:\n", 149 | " # Vectorizing and calculating similarities\n", 150 | " vectorizer = TfidfVectorizer(tokenizer=lem_normalize, stop_words='english')\n", 151 | " tfidf = vectorizer.fit_transform(sentence_tokens) # TF-IDF matrix for all sentence tokens\n", 152 | "\n", 153 | " values = cosine_similarity(tfidf[-1], tfidf[:-1]) # Compare the new input against all previous sentences\n", 154 | " idx = values.argsort()[0][-2] # Get the index of the second most similar sentence\n", 155 | " flat = values.flatten()\n", 156 | " flat.sort()\n", 157 | " req_tfidf = flat[-2] # The second highest similarity score\n", 158 | " \n", 159 | " if req_tfidf == 0:\n", 160 | " # If similarity is too low, respond with a default message\n", 161 | " robo_response = \"Sorry, I don't understand you.\"\n", 162 | " else:\n", 163 | " # Return the most similar sentence\n", 164 | " robo_response = sentence_tokens[idx]\n", 165 | " else:\n", 166 | " # If only one sentence, return a default response\n", 167 | " robo_response = \"Sorry, I don't understand you.\"\n", 168 | "\n", 169 | " return robo_response\n", 170 | "\n" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": 23, 176 | "id": "f9665841-6bf6-44ad-b455-25afecd70bc2", 177 | "metadata": {}, 178 | "outputs": [ 179 | { 180 | "name": "stdout", 181 | "output_type": "stream", 182 | "text": [ 183 | "Requirement already satisfied: pyttsx3 in /home/nithin/anaconda3/lib/python3.12/site-packages (2.98)\n", 184 | "Note: you may need to restart the kernel to use updated packages.\n" 185 | ] 186 | } 187 | ], 188 | "source": [ 189 | "pip install pyttsx3" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 7, 195 | "id": "ecccf2b4-4eef-49d7-ab8c-97d272b0d4d3", 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [ 199 | "import pyttsx3\n", 200 | "engine = pyttsx3.init()\n", 201 | "# Set the rate (speed) of speech\n", 202 | "engine.setProperty('rate', 150) # 150 words per minute\n", 203 | "\n", 204 | "# Set the volume (0.0 to 1.0)\n", 205 | "engine.setProperty('volume', 0.9) # 90% volume\n", 206 | "engine.say(\"Hello, how can I assist you today?\")\n", 207 | "engine.runAndWait()" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": null, 213 | "id": "6cd7f762-8d18-4d90-ad1a-1511a22db8ac", 214 | "metadata": {}, 215 | "outputs": [], 216 | "source": [ 217 | "flag = True\n", 218 | "print('BOT: My name is Robo, I will answer your questions about Machine Learning. If you want to exit, type Bye')\n", 219 | "\n", 220 | "interactions = [\n", 221 | " 'hi',\n", 222 | " 'what is Machine Learning?',\n", 223 | " 'What are the different types of Machine Learning algorithms?',\n", 224 | " 'What is the difference between supervised and unsupervised learning',\n", 225 | " 'What is the difference between classification and regression?',\n", 226 | " 'machine learning algorithms?',\n", 227 | " 'sounds awesome',\n", 228 | " 'bye',\n", 229 | "]\n", 230 | "\n", 231 | "sentence_tokens = []\n", 232 | "\n", 233 | "while flag:\n", 234 | " user_response = input(\"User: \")\n", 235 | " user_response = user_response.lower()\n", 236 | "\n", 237 | " # Prevent adding duplicate questions to sentence_tokens\n", 238 | " if user_response not in sentence_tokens:\n", 239 | " sentence_tokens.append(user_response)\n", 240 | "\n", 241 | " if user_response != 'bye':\n", 242 | " if user_response == 'thanks' or user_response == 'thank you':\n", 243 | " flag = False\n", 244 | " print('BOT: You are welcome...')\n", 245 | " elif greeting(user_response) != None:\n", 246 | " print('ROBO: {}'.format(greeting(user_response)))\n", 247 | " #engine.say(format(greeting(user_response)))\n", 248 | " #engine.runAndWait()\n", 249 | " else:\n", 250 | " print('ROBO: ', end='')\n", 251 | " print(response(user_response))\n", 252 | " #engine.say(format(response(user_response)))\n", 253 | " #engine.runAndWait()\n", 254 | " else:\n", 255 | " flag = False\n", 256 | " print('BOT: bye!')\n" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": null, 262 | "id": "5fb8b46b-54f0-4dd8-b4dd-1f596b445d79", 263 | "metadata": {}, 264 | "outputs": [], 265 | "source": [] 266 | } 267 | ], 268 | "metadata": { 269 | "kernelspec": { 270 | "display_name": "Python 3 (ipykernel)", 271 | "language": "python", 272 | "name": "python3" 273 | }, 274 | "language_info": { 275 | "codemirror_mode": { 276 | "name": "ipython", 277 | "version": 3 278 | }, 279 | "file_extension": ".py", 280 | "mimetype": "text/x-python", 281 | "name": "python", 282 | "nbconvert_exporter": "python", 283 | "pygments_lexer": "ipython3", 284 | "version": "3.12.7" 285 | } 286 | }, 287 | "nbformat": 4, 288 | "nbformat_minor": 5 289 | } 290 | -------------------------------------------------------------------------------- /ai_lab/chatbot_nlp/chatbot1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "c31b2f98-1400-40ca-a2e2-58be555fc90c", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import nltk #to process natural language\n", 11 | "import numpy as np\n", 12 | "import random # to generte random responses to feel less repetitive\n", 13 | "import string # to do string manipulations, because sometimes we need to remove punctuations ,need to convert it in lowercase etc." 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "id": "d1791962-f099-415f-a95c-2a8771a998ab", 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "f = open('Machine learning.txt', 'r', errors='ignore')\n", 24 | "raw = f.read()" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 3, 30 | "id": "f1914670-7a5c-40f3-a5c4-2fce1605e8e6", 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "['machine learning is a rapidly evolving field within artificial intelligence (ai) that focuses on the development of algorithms and statistical models that enable computers to learn from and make predictions or decisions based on data.', 'unlike traditional programming where explicit instructions are given for each task, machine learning allows systems to learn patterns and relationships within data, and to improve their performance over time as they are exposed to more data.', 'this capability is grounded in the idea that systems can automatically improve their performance without human intervention through experience.', 'at its core, machine learning is divided into several categories, with the primary ones being supervised learning, unsupervised learning, and reinforcement learning.', 'each of these categories approaches the task of learning from data in a unique way, depending on the nature of the data and the desired outcome.']\n", 38 | "['machine', 'learning', 'is', 'a', 'rapidly']\n" 39 | ] 40 | }, 41 | { 42 | "name": "stderr", 43 | "output_type": "stream", 44 | "text": [ 45 | "[nltk_data] Downloading package punkt_tab to /home/nithin/nltk_data...\n", 46 | "[nltk_data] Package punkt_tab is already up-to-date!\n", 47 | "[nltk_data] Downloading package punkt to /home/nithin/nltk_data...\n", 48 | "[nltk_data] Package punkt is already up-to-date!\n", 49 | "[nltk_data] Downloading package wordnet to /home/nithin/nltk_data...\n", 50 | "[nltk_data] Package wordnet is already up-to-date!\n" 51 | ] 52 | } 53 | ], 54 | "source": [ 55 | "nltk.data.path.append('/home/nithin/nltk_data') # Add your nltk_data path\n", 56 | "nltk.download('punkt_tab')\n", 57 | "raw=raw.lower()# convert all strings to lowercase\n", 58 | "nltk.download('punkt')# Punkt is a pre-trained model that helps in sentence tokenization, i.e., splitting a text into sentences\n", 59 | "nltk.download('wordnet')#WordNet is a large database of English words that groups words into sets of synonyms \n", 60 | "sentence_tokens = nltk.sent_tokenize(raw)\n", 61 | "word_tokens = nltk.word_tokenize(raw)\n", 62 | "print(sentence_tokens[:5])\n", 63 | "print(word_tokens[:5])" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "id": "5b7105e7-4e58-4a7f-aca6-92d074ce8ba9", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "#normalize the text by removing punctuation and reducing words to their base or root form (lemmatization)\n", 74 | "lemmer = nltk.stem.WordNetLemmatizer()\n", 75 | "\n", 76 | "remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation) ##This dictionary will be used to remove punctuation from the text.\n", 77 | "\n", 78 | "def lem_tokens(tokens): #takes a list of tokens (words) as input and returns a list of lemmatized tokens.\n", 79 | " return [lemmer.lemmatize(token) for token in tokens]\n", 80 | "\n", 81 | "def lem_normalize(text):#This function, lem_normalize, normalizes the input text by performing translate(),lower(), tokenize()\n", 82 | " return lem_tokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))\n", 83 | "\n", 84 | "# translate() used to modify a string by replacing characters based on a specified translation table\n", 85 | "#text.lower() converts all characters in the text to lowercase, ensuring uniformity.\n", 86 | "#translate(remove_punct_dict) removes any punctuation from the text using the remove_punct_dict created earlier.\n", 87 | "#nltk.word_tokenize() splits the cleaned text into individual words (tokens).\n", 88 | "#lem_tokens() is then called to lemmatize each token in the list." 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 5, 94 | "id": "c603ec47-5fb1-442b-9a2e-c84c75e26453", 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "GREETING_INPUTS = ('hello', 'hi', 'greetings', 'sup', 'what\\'s up', 'hey',)\n", 99 | "GREETING_RESPONSES = ['hi', 'hey', '*nods*', 'hi there', 'hello', 'I am glad! You are talking to me']\n", 100 | "\n", 101 | "def greeting(sentence):\n", 102 | " for word in sentence.split():\n", 103 | " if word.lower() in GREETING_INPUTS:\n", 104 | " return random.choice(GREETING_RESPONSES)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 6, 110 | "id": "51665a04-da97-46d0-a42d-45d6f9100c50", 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "#generates a response to a user's input based on the similarity between the user's query and the chatbot's available data.\n", 115 | "\n", 116 | "\n", 117 | "from sklearn.feature_extraction.text import TfidfVectorizer #TF-IDF is a statistical measure used to evaluate the importance of a \n", 118 | "#word in a document relative to a collection of documents (corpus). TF-IDF allows the model to focus on the most important \n", 119 | "#words when comparing the user input to the available data.\n", 120 | "from sklearn.metrics.pairwise import cosine_similarity #Cosine similarity is widely used in text processing to measure\n", 121 | "# the similarity between two documents (or sentences) represented as vectors\n", 122 | "\n", 123 | "\n", 124 | "def response(user_response):\n", 125 | " robo_response = ''\n", 126 | " # Temporarily add user_response for similarity calculation\n", 127 | " temp_tokens = sentence_tokens + [user_response]\n", 128 | "\n", 129 | " vectorizer = TfidfVectorizer(tokenizer=lem_normalize, stop_words='english')\n", 130 | " tfidf = vectorizer.fit_transform(temp_tokens) # Use the temporary token list\n", 131 | "\n", 132 | " values = cosine_similarity(tfidf[-1], tfidf[:-1]) # Compare with all except the last one (user response)\n", 133 | " idx = values.argsort()[0][-1] # Find the most similar sentence\n", 134 | " flat = values.flatten()\n", 135 | " flat.sort()\n", 136 | " req_tfidf = flat[-1] # Get the highest similarity score\n", 137 | "\n", 138 | " if req_tfidf == 0:\n", 139 | " robo_response = '{} Sorry, I don\\'t understand you'.format(robo_response)\n", 140 | " else:\n", 141 | " robo_response = robo_response + sentence_tokens[idx]\n", 142 | " return robo_response\n" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 7, 148 | "id": "f9665841-6bf6-44ad-b455-25afecd70bc2", 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "Requirement already satisfied: pyttsx3 in c:\\users\\hp\\anaconda3\\lib\\site-packages (2.91)\n", 156 | "Requirement already satisfied: comtypes in c:\\users\\hp\\anaconda3\\lib\\site-packages (from pyttsx3) (1.4.6)\n", 157 | "Requirement already satisfied: pypiwin32 in c:\\users\\hp\\anaconda3\\lib\\site-packages (from pyttsx3) (223)\n", 158 | "Requirement already satisfied: pywin32 in c:\\users\\hp\\anaconda3\\lib\\site-packages (from pyttsx3) (305.1)\n", 159 | "Note: you may need to restart the kernel to use updated packages.\n" 160 | ] 161 | } 162 | ], 163 | "source": [ 164 | "pip install pyttsx3" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 7, 170 | "id": "ecccf2b4-4eef-49d7-ab8c-97d272b0d4d3", 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [ 174 | "import pyttsx3\n", 175 | "engine = pyttsx3.init()\n", 176 | "# Set the rate (speed) of speech\n", 177 | "engine.setProperty('rate', 150) # 150 words per minute\n", 178 | "\n", 179 | "# Set the volume (0.0 to 1.0)\n", 180 | "engine.setProperty('volume', 0.9) # 90% volume\n", 181 | "engine.say(\"Hello, how can I assist you today?\")\n", 182 | "engine.runAndWait()#generates a response to a user's input based on the similarity between the user's query and the chatbot's available data.\n", 183 | "\n", 184 | "\n", 185 | "from sklearn.feature_extraction.text import TfidfVectorizer #TF-IDF is a statistical measure used to evaluate the importance of a \n", 186 | "#word in a document relative to a collection of documents (corpus). TF-IDF allows the model to focus on the most important \n", 187 | "#words when comparing the user input to the available data.\n", 188 | "from sklearn.metrics.pairwise import cosine_similarity #Cosine similarity is widely used in text processing to measure\n", 189 | "# the similarity between two documents (or sentences) represented as vectors\n", 190 | "\n", 191 | "\n", 192 | "def response(user_response):\n", 193 | " robo_response = ''\n", 194 | " # Temporarily add user_response for similarity calculation\n", 195 | " temp_tokens = sentence_tokens + [user_response]\n", 196 | "\n", 197 | " vectorizer = TfidfVectorizer(tokenizer=lem_normalize, stop_words='english')\n", 198 | " tfidf = vectorizer.fit_transform(temp_tokens) # Use the temporary token list\n", 199 | "\n", 200 | " values = cosine_similarity(tfidf[-1], tfidf[:-1]) # Compare with all except the last one (user response)\n", 201 | " idx = values.argsort()[0][-1] # Find the most similar sentence\n", 202 | " flat = values.flatten()\n", 203 | " flat.sort()\n", 204 | " req_tfidf = flat[-1] # Get the highest similarity score\n", 205 | "\n", 206 | " if req_tfidf == 0:\n", 207 | " robo_response = '{} Sorry, I don\\'t understand you'.format(robo_response)\n", 208 | " else:\n", 209 | " robo_response = robo_response + sentence_tokens[idx]\n", 210 | " return robo_response\n" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 9, 216 | "id": "6cd7f762-8d18-4d90-ad1a-1511a22db8ac", 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "BOT: My name is Robo, I will answer your questions about Machine Learning. If you want to exit, type Bye\n" 224 | ] 225 | }, 226 | { 227 | "name": "stdin", 228 | "output_type": "stream", 229 | "text": [ 230 | "User: do you know about ml\n" 231 | ] 232 | }, 233 | { 234 | "name": "stdout", 235 | "output_type": "stream", 236 | "text": [ 237 | "ROBO: Sorry, I don't understand you\n" 238 | ] 239 | }, 240 | { 241 | "name": "stdin", 242 | "output_type": "stream", 243 | "text": [ 244 | "User: do you know about machine learing\n" 245 | ] 246 | }, 247 | { 248 | "name": "stdout", 249 | "output_type": "stream", 250 | "text": [ 251 | "ROBO: supervised learning is perhaps the most common type of machine learning.\n" 252 | ] 253 | }, 254 | { 255 | "name": "stdin", 256 | "output_type": "stream", 257 | "text": [ 258 | "User: do you know about ai\n" 259 | ] 260 | }, 261 | { 262 | "name": "stdout", 263 | "output_type": "stream", 264 | "text": [ 265 | "ROBO: machine learning is a rapidly evolving field within artificial intelligence (ai) that focuses on the development of algorithms and statistical models that enable computers to learn from and make predictions or decisions based on data.\n" 266 | ] 267 | }, 268 | { 269 | "name": "stdin", 270 | "output_type": "stream", 271 | "text": [ 272 | "User: hii, can you tell me about q learing\n" 273 | ] 274 | }, 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "ROBO: Sorry, I don't understand you\n" 280 | ] 281 | }, 282 | { 283 | "name": "stdin", 284 | "output_type": "stream", 285 | "text": [ 286 | "User: hii, do you know about dql\n" 287 | ] 288 | }, 289 | { 290 | "name": "stdout", 291 | "output_type": "stream", 292 | "text": [ 293 | "ROBO: Sorry, I don't understand you\n" 294 | ] 295 | }, 296 | { 297 | "name": "stdin", 298 | "output_type": "stream", 299 | "text": [ 300 | "User: hii, do you know about reenforcement learing\n" 301 | ] 302 | }, 303 | { 304 | "name": "stdout", 305 | "output_type": "stream", 306 | "text": [ 307 | "ROBO: Sorry, I don't understand you\n" 308 | ] 309 | }, 310 | { 311 | "name": "stdin", 312 | "output_type": "stream", 313 | "text": [ 314 | "User: hii, do you know about reinforcement learning\n" 315 | ] 316 | }, 317 | { 318 | "name": "stdout", 319 | "output_type": "stream", 320 | "text": [ 321 | "ROBO: at its core, machine learning is divided into several categories, with the primary ones being supervised learning, unsupervised learning, and reinforcement learning.\n" 322 | ] 323 | }, 324 | { 325 | "name": "stdin", 326 | "output_type": "stream", 327 | "text": [ 328 | "User: bye\n" 329 | ] 330 | }, 331 | { 332 | "name": "stdout", 333 | "output_type": "stream", 334 | "text": [ 335 | "BOT: bye!\n" 336 | ] 337 | } 338 | ], 339 | "source": [ 340 | "flag = True\n", 341 | "print('BOT: My name is Robo, I will answer your questions about Machine Learning. If you want to exit, type Bye')\n", 342 | "\n", 343 | "interactions = [\n", 344 | " 'hi',\n", 345 | " 'what is Machine Learning?',\n", 346 | " 'What are the different types of Machine Learning algorithms?',\n", 347 | " 'What is the difference between supervised and unsupervised learning',\n", 348 | " 'What is the difference between classification and regression?',\n", 349 | " 'machine learning algorithms?'\n", 350 | " 'sounds awesome',\n", 351 | " 'bye',\n", 352 | "]\n", 353 | "while flag:\n", 354 | " user_response = input(\"User: \")\n", 355 | " user_response = user_response.lower()\n", 356 | " if user_response != 'bye':\n", 357 | " if user_response == 'thanks' or user_response == 'thank you':\n", 358 | " flag = False\n", 359 | " print('BOT: You are welcome...')\n", 360 | " elif greeting(user_response) is not None:\n", 361 | " print('ROBO: {}'.format(greeting(user_response)))\n", 362 | " engine.say(format(greeting(user_response)))\n", 363 | " engine.runAndWait()\n", 364 | " else:\n", 365 | " print('ROBO: ', end='')\n", 366 | " print(response(user_response))\n", 367 | " engine.say(format(response(user_response)))\n", 368 | " engine.runAndWait()\n", 369 | "\n", 370 | " else:\n", 371 | " flag = False\n", 372 | " print('BOT: bye!')" 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": null, 378 | "id": "5fb8b46b-54f0-4dd8-b4dd-1f596b445d79", 379 | "metadata": {}, 380 | "outputs": [], 381 | "source": [] 382 | } 383 | ], 384 | "metadata": { 385 | "kernelspec": { 386 | "display_name": "Python 3 (ipykernel)", 387 | "language": "python", 388 | "name": "python3" 389 | }, 390 | "language_info": { 391 | "codemirror_mode": { 392 | "name": "ipython", 393 | "version": 3 394 | }, 395 | "file_extension": ".py", 396 | "mimetype": "text/x-python", 397 | "name": "python", 398 | "nbconvert_exporter": "python", 399 | "pygments_lexer": "ipython3", 400 | "version": "3.12.7" 401 | } 402 | }, 403 | "nbformat": 4, 404 | "nbformat_minor": 5 405 | } 406 | --------------------------------------------------------------------------------