73% of tech job listings require AI skills now: How to show off yours
Back to Tutorials
aiTutorialbeginner

73% of tech job listings require AI skills now: How to show off yours

July 15, 20261 views4 min read

Learn to build a simple AI chatbot that demonstrates practical AI skills using Python and machine learning libraries. Perfect for showcasing AI competencies in job applications.

Introduction

In today's rapidly evolving job market, AI skills are becoming essential for tech professionals. According to recent reports, 73% of tech job listings now require AI skills. This tutorial will teach you how to build a simple AI-powered chatbot that you can showcase in your portfolio or job applications. This project demonstrates practical AI skills using Python and a popular machine learning library.

Prerequisites

To follow this tutorial, you'll need:

  • A computer with Python 3.6 or higher installed
  • Basic understanding of Python programming concepts
  • Internet connection for downloading packages
  • Text editor or IDE (like VS Code or PyCharm)

Step-by-Step Instructions

Step 1: Set Up Your Python Environment

Install Required Packages

First, you'll need to install the necessary Python packages. Open your terminal or command prompt and run:

pip install nltk scikit-learn numpy

This command installs the Natural Language Toolkit (nltk), scikit-learn for machine learning algorithms, and numpy for numerical operations. These tools form the foundation of our AI chatbot.

Step 2: Create Your Project Structure

Set Up Your Project Folder

Create a new folder called ai_chatbot on your computer. Inside this folder, create a file named chatbot.py. This will be our main program file.

Step 3: Import Required Libraries

Write the Initial Code

Open your chatbot.py file and add the following code:

import nltk
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import warnings
warnings.filterwarnings('ignore')

# Download required NLTK data
nltk.download('punkt')

We import the necessary libraries and download the punkt tokenizer from NLTK, which helps us break text into sentences and words. The warnings filter suppresses unnecessary messages during execution.

Step 4: Prepare Sample Training Data

Create Conversation Examples

Add this code to your chatbot.py file:

# Sample training data
training_data = [
    "Hello",
    "Hi there!",
    "How are you?",
    "I'm doing well, thanks!",
    "What can you do?",
    "I can chat with you and answer basic questions!",
    "Tell me a joke",
    "Why don't scientists trust atoms? Because they make up everything!",
    "Goodbye",
    "See you later!"
]

# Create responses for each question
responses = [
    "Hello there!",
    "Hi! How can I help you today?",
    "I'm doing great! How about you?",
    "That's wonderful to hear!",
    "I can chat with you, answer simple questions, and tell jokes!",
    "I'm here to assist you with basic queries.",
    "Why don't scientists trust atoms? Because they make up everything!",
    "Here's a joke: Why don't scientists trust atoms? Because they make up everything!",
    "Goodbye! Have a great day!",
    "Take care!"
]

This creates a simple dataset of questions and answers that our chatbot will learn from. Each question has a corresponding response that our AI will use to generate replies.

Step 5: Create the Chatbot Class

Build the Core Functionality

Add this class definition to your code:

class SimpleChatbot:
    def __init__(self):
        self.training_data = training_data
        self.responses = responses
        self.vectorizer = TfidfVectorizer()
        self.vectors = self.vectorizer.fit_transform(training_data)
        
    def get_response(self, user_input):
        # Transform user input into vector
        user_vector = self.vectorizer.transform([user_input])
        
        # Calculate similarity with all training data
        similarities = cosine_similarity(user_vector, self.vectors)
        
        # Get the index of the most similar response
        best_match_index = similarities.argmax()
        
        return self.responses[best_match_index]

This class creates our AI chatbot. The __init__ method prepares our training data by converting it into numerical vectors that the computer can understand. The get_response method compares user input with our training data to find the most similar question and returns its corresponding answer.

Step 6: Add the Main Chat Loop

Implement Interactive Chat

Add this final code to complete your chatbot:

# Create chatbot instance
chatbot = SimpleChatbot()

# Main chat loop
print("Chatbot: Hello! I'm your AI assistant. Type 'quit' to exit.")

while True:
    user_input = input("You: ")
    
    if user_input.lower() in ['quit', 'exit', 'bye']:
        print("Chatbot: Goodbye! Have a great day!")
        break
    
    response = chatbot.get_response(user_input)
    print(f"Chatbot: {response}")

This creates an interactive chat loop where users can type messages and receive responses. The loop continues until the user types 'quit', 'exit', or 'bye'.

Step 7: Test Your Chatbot

Run and Experiment

Save your file and run it using:

python chatbot.py

Try different inputs like 'Hello', 'How are you?', 'Tell me a joke', and 'Goodbye'. You should see responses that match your training data.

Summary

In this tutorial, you've built a simple AI chatbot that demonstrates practical AI skills using natural language processing and machine learning concepts. This project showcases your ability to work with:

  • Machine learning algorithms (cosine similarity)
  • Natural language processing (tokenization)
  • Text vectorization techniques
  • Python programming for AI applications

This chatbot represents real-world AI skills that employers value. You can extend this project by adding more training data, implementing more complex algorithms, or integrating it into web applications. Having projects like this in your portfolio demonstrates your practical AI knowledge to potential employers.

Source: ZDNet AI

Related Articles