Artificial Intelligence project 02
AI Intent Classification Project
Build a complete intent classification assistant workflow with reproducible Python code, transparent inputs, reviewable output, and responsible-use limits.
Explore AI training in VizagView all project ideas
AI objective
Classify a short request into one of four supported intents and expose the predicted probability.
Data or knowledge source
Twenty-four labelled synthetic requests across greeting, course information, fees, and schedule intents.
Requirements
- Python 3.10 or later
- A terminal or command prompt
python -m pip install scikit-learn- About 45-60 minutes to build and review
How the system works
Train a TF-IDF and logistic-regression pipeline so text preprocessing and classification are applied consistently.
Validation checklist
- Every intent has the same example count
- A fixed model configuration makes fitting repeatable
- Probabilities remain available for thresholding
- Unsupported requests are identified as a production gap
Complete Python code
Save the program as ai_intent_classifier.py. The code runs locally and requires no paid API key or model download.
"""Classify short assistant requests into supported intents."""
from __future__ import annotations
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
TRAINING_DATA = {
"greeting": ["hello", "hi there", "good morning", "hey assistant", "good evening", "nice to meet you"],
"course_info": ["tell me about the course", "what topics are covered", "show the syllabus", "course duration please", "what will I learn", "share course details"],
"fees": ["what is the fee", "how much does training cost", "course price", "payment details", "tell me the tuition", "is there an installment option"],
"schedule": ["when is the next batch", "class timings", "weekend schedule", "what time are classes", "batch start date", "weekday training time"],
}
def train_classifier() -> Pipeline:
texts, labels = [], []
for label, examples in TRAINING_DATA.items():
texts.extend(examples)
labels.extend([label] * len(examples))
model = Pipeline([
("tfidf", TfidfVectorizer(ngram_range=(1, 2), lowercase=True)),
("classifier", LogisticRegression(max_iter=1000, random_state=42)),
])
return model.fit(texts, labels)
def classify(model: Pipeline, text: str) -> tuple[str, float]:
probabilities = model.predict_proba([text])[0]
index = int(probabilities.argmax())
return str(model.classes_[index]), float(probabilities[index])
def main() -> None:
model = train_classifier()
for message in ("Hello assistant", "How much is the course?", "When does the weekend batch start?"):
label, confidence = classify(model, message)
print(f"{message!r}: {label} ({confidence:.3f})")
if __name__ == "__main__":
main()
Run the project
- Create and activate a virtual environment.
- Install dependencies with
python -m pip install scikit-learnwhen packages are required. - Run
python ai_intent_classifier.py. - Review confidence, fallbacks, sources, or error metrics rather than accepting output automatically.
- Test additional normal, edge, unsupported, and adversarial inputs.
Expected output
An intent label and confidence for each input message.
Accuracy, privacy, and responsible-use limits
A tiny closed-set dataset forces every input into a known class. Production systems need an unknown intent, representative language, monitoring, and human correction.
Ways to extend the project
Add an unknown class, stratified validation, confusion matrix, multilingual examples, calibrated thresholds, and drift monitoring.
Continue learning Artificial Intelligence
Try the next project, return to the Softenant project library, or explore the AI training in Vizag for guided NLP, retrieval, evaluation, automation, and responsible AI practice.