An intelligent FAQ-based chatbot built with SentenceTransformers. It combines semantic similarity and keyword matching to provide accurate answers to user queries. The chatbot supports API integration, fine-tuning, logging, and automatic FAQ updates.
- Hybrid Search: Combines semantic similarity (SentenceTransformers) with keyword matching.
- Fallback Mechanism: Returns a default response if similarity is too low.
- Embedding Storage: Saves embeddings with Pickle for faster startup.
- FastAPI Integration: Provides REST API endpoints for chatbot interaction.
- Automatic Logging: Stores all queries and responses in CSV logs.
- FAQ Correction: Dynamically update chatbot answers.
- Fine-tuning: Retrain the model on custom FAQ data.
- Evaluation with BERTScore: Measure model accuracy before and after fine-tuning.
- Dataset: Uses the Ecommerce FAQ Dataset.
Install dependencies:
pip install pandas sentence-transformers torch datasets scikit-learn fastapi uvicorn bert-score
uvicorn your_file_name:app --reload
The server will start at: http://127.0.0.1:8000
- Ask the chatbot:
POST /chat
{
"query": "What are your payment methods?"
}
- Correct chatbot response:
POST /correct
{
"question": "What are your payment methods?",
"correct_answer": "Payment is available only via credit card."
}
-
Evaluate baseline accuracy: Uses BERTScore to measure model performance on test data.
-
Fine-tuning the model:
fine_tune(df, epochs=2, batch_size=8)
- Re-evaluate after fine-tuning: BERTScore is run again to compare performance before/after training.
ecommerce_faq.csv
โ Main FAQ datasetfaq_embeddings.pkl
โ Pre-computed embeddingschat_logs.csv
โ Query/response logsfine_tuned_model/
โ Saved fine-tuned model
- Add a user-friendly interface (web/Telegram).
- Multilingual support (English + Persian).
- Database integration (SQLite, MongoDB).
- Speed optimization using FAISS or Milvus.