0% found this document useful (0 votes)
25 views1 page

Ai Code

This document outlines the process of building a basic AI assistant using Python and the NLTK library. It includes a sample code for a chatbot that can respond to user queries and specifies the requirements for setting up the environment. The assistant is designed to recognize specific phrases and provide appropriate responses.

Uploaded by

SaHa OnTu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Ai Code

This document outlines the process of building a basic AI assistant using Python and the NLTK library. It includes a sample code for a chatbot that can respond to user queries and specifies the requirements for setting up the environment. The assistant is designed to recognize specific phrases and provide appropriate responses.

Uploaded by

SaHa OnTu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import nltk

from nltk.tokenize import word_tokenize


from nltk.corpus import wordnet

# Initialize the NLTK data


nltk.download('punkt')
nltk.download('wordnet')

# Define a dictionary to store the AI assistant's knowledge


knowledge = {
'hello': 'Hello! How can I assist you today?',
'how are you': 'I\'m doing great, thanks for asking!',
'what is your name': 'My name is Friday',
'default': 'I didn\'t understand that. Can you please rephrase?'
}

# Define a function to process user input


def process_input(input_text):
# Tokenize the input text
tokens = word_tokenize(input_text)

# Check if the input text matches any of the known phrases


for phrase, response in knowledge.items():
if phrase in input_text.lower():
return response

# If no match is found, return the default response


return knowledge['default']

# Define a function to interact with the AI assistant


def interact():
print('Welcome to the AI Assistant!')
while True:
user_input = input('You: ')
response = process_input(user_input)
print('AI Assistant:', response)

# Start the interaction


interact()

I'll guide you through the process of building a basic AI assistant using Python
and the Natural Language Processing (NLP) library, NLTK. We'll create a simple
chatbot that can understand and respond to basic user queries.

AI Assistant Requirements:

1.Python 3.8 or later


2.NLTK library (install using pip install nltk)
3.nltk.download('punkt') for tokenization
4.nltk.download('wordnet') for wordnet

You might also like