CoolFace
Apppublic

shouryasiso/question-difficulty-analysis

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
App README

๐ŸŽ“ Question Bloom Level & Difficulty Prediction

A machine learning project that classifies educational questions into Bloom's Taxonomy levels and Difficulty categories using Logistic Regression. The project implements a custom NLP pipeline with Sentence Transformers and provides a beautified Streamlit interface for real-time predictions.


๐Ÿ“‹ Table of Contents


๐Ÿ” Overview

This project performs an end-to-end machine learning pipeline for analyzing the cognitive complexity and difficulty of educational questions. It covers:

  1. 1.Data Exploration โ€” Analyzing question text distributions and student performance metadata
  2. 2.Feature Engineering โ€” Generating semantic embeddings and normalizing student success metrics
  3. 3.Model Training & Evaluation โ€” Developing calibrated Logistic Regression models for multi-class classification
  4. 4.Deployment โ€” Creating a modern, interactive dashboard for production-ready inference

๐Ÿ“Š Dataset

[!NOTE] This dataset was synthesized using a Large Language Model (LLM) due to the scarcity of publicly available datasets for multi-class Bloom's Taxonomy classification on specific educational content.
PropertyDetails
Filefinal.csv
Rows5,500
Columns~11 predictive columns
Target Variablesbloom_level, difficulty

Features

The model uses a total of 12 features (9 base features from the dataset + 3 engineered features):

FeatureTypeSourceDescription
Question TextstringBaseThe raw text of the question (Vectorized via NLP)
SubjectobjectBaseBroad subject category (e.g., Science, Maths)
TopicobjectBaseSpecific topic within the subject
Avg Scorefloat64BaseAverage score achieved by students (0.0 - 1.0)
Correct %float64BasePercentage of students who got the question right
Students Attemptedint64BaseTotal count of students who answered the question
Students Correctint64BaseTotal count of students who answered correctly
Time Takenfloat64BaseAverage time spent on the question (minutes)
Success Ratefloat64EngineeredCalculated as (Correct / Attempted)
Log Attemptsfloat64EngineeredLog-transformed attempt count for better scaling
Question Lengthint64EngineeredTotal word count of the question text

โš™๏ธ Milestone 1: ML Predictive Modeling

1. Data Cleaning & Engineering

  • โ€”NLP Processing: Text is vectorized using SentenceTransformer ('all-MiniLM-L6-v2') to capture semantic intent.
  • โ€”Categorical Encoding: One-Hot Encoding applied to Subject and Topic features.
  • โ€”Scaling: Standardized numerical metrics using StandardScaler for model stability.

2. Implementation Approach

  • โ€”Standalone Module: All logic encapsulated in BloomModelDeployer class for modular usage.
  • โ€”Balanced Weights: Implemented class_weight='balanced' to handle imbalanced levels in Bloom's Taxonomy.

3. Training & Evaluation

  • โ€”Splitting data into 80% training and 20% testing sets.
  • โ€”Model Selection: During experimentation, XGBoost and Random Forest were tested. However, they did not provide a significant improvement in accuracy for this specific categorical text task, leading to the selection of Logistic Regression for its better generalization and interpretability.
  • โ€”Persistence of all artifacts (models, encoders, scalers) into the models/ directory.

๐Ÿ“ˆ Milestone 1: Results

Metric (Accuracy)Bloom LevelDifficulty
Accuracy Score0.330.40
F1 Score (Macro)0.330.39
[!IMPORTANT] The current accuracy levels are primarily limited by the synthesized nature of the dataset. LLM-generated data, while useful for bootstrapping, often lacks the subtle nuances of real-world educational assessments, which affects the model's ability to reach higher precision.

LibraryPurpose
Python 3.9Programming language
StreamlitUI Framework & Dashboard
Sentence-TransformersNLP & Semantic Embeddings for ML/RAG
scikit-learnML Models, Preprocessing, and Metrics
LangGraph / LangChainMulti-Agent Orchestration & Core AI logic
FAISSIn-Memory Vector Database
Groq (Llama 3.1)Free-tier, ultra-fast LLM API
Pandas / NumPyData manipulation and Numerical logic
DockerContainerization

๐Ÿ“ Project Structure

capstone_genai/
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ final.csv                  # Main dataset
โ”‚   โ””โ”€โ”€ pedagogy_guidelines.md     # RAG document source
โ”œโ”€โ”€ agent/                         # Multi-Agent LangGraph Logic
โ”‚   โ”œโ”€โ”€ graph.py                   # Agent workflow compilation
โ”‚   โ”œโ”€โ”€ nodes.py                   # Sub-agent logical nodes
โ”‚   โ”œโ”€โ”€ rag.py                     # FAISS Vector Store logic
โ”‚   โ””โ”€โ”€ state.py                   # Shared typed dictionary 
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ milestone1.ipynb           # Model Research and Training
โ”‚   โ”œโ”€โ”€ milestone2.ipynb           # Agentic Assistant Execution
โ”‚   โ””โ”€โ”€ rag.ipynb                  # Vector Search Isolation Testing
โ”œโ”€โ”€ models/                        # Saved Joblib Pickles
โ”œโ”€โ”€ app.py                         # Beautiful Streamlit Dashboard
โ”œโ”€โ”€ logistic_regression_deployment.py # ML Deployment Module
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿค– Milestone 2: Agentic AI Assistant

The second milestone extends the ML foundational model by introducing a multi-agent orchestrated workflow using LangGraph paired with Retrieval-Augmented Generation (RAG) to provide highly specific instructional recommendations.

1. Knowledge Base & Vector Store (RAG)

  • โ€”Pedagogical Corpus: We constructed pedagogy_guidelines.md consisting of structured Bloom's Taxonomy definitions, learning gap heuristics, and actionable question-refinement strategies.
  • โ€”Embedding & Storage: The corpus is split into chunks and embedded locally using the identical sentence-transformers/all-MiniLM-L6-v2 model from Milestone 1 for maximum efficiency. It is stored in memory using a FAISS vector database for split-second contextual retrieval.

2. Multi-Agent Workflow (LangGraph)

The LLM inference is rigorously structured via an explicit StateGraph architecture:

  • โ€”QuestionAnalyzer Node: Evaluates the initial question's properties and imports the Logistic Regression model predictions.
  • โ€”GapDetector Node: Calculates learning gaps algorithmically based on success rates and completion time.
  • โ€”RAGRetriever Node: Executes a semantic similarity search against the FAISS vector store to retrieve appropriate pedagogical guidelines mapped to the detected gaps.
  • โ€”RecommendationGenerator Node: Constructs a structured prompt encompassing the stats, gaps, and RAG context, sending it to the Groq LLM (Llama 3.1) API to generate natural, actionable redesign efforts.
  • โ€”ReportBuilder Node: Formats all state artifacts into a unified dictionary for frictionless dashboard rendering.

3. Integrated UI Dashboard

  • โ€”Transformed the legacy form into a unified, seamless interface leveraging native container components (st.container, st.metric).
  • โ€”ML classifications and Agentic Recommendations run chronologically on a single button press.
  • โ€”LLM feedback is formatted inside st.chat_message components for an intuitive "AI Co-pilot" collaborative experience.

๐Ÿš€ Getting Started

Prerequisites

  • โ€”Python 3.9+
  • โ€”Groq API Key

Installation

bash
# Create an environments file and add your Groq API key
echo "GROQ_API_KEY=your_key_here" > .env

# Install dependencies
python3 -m pip install -r requirements.txt

# Train the models (if pkl files are missing)
python3 logistic_regression_deployment.py --train

# Launch the dashboard
streamlit run app.py

Running with Docker

bash
# Build the Docker image
docker build -t question-classifier .

# Run the container (Make sure .env contains API keys)
docker run -p 7860:7860 --env-file .env question-classifier

๐Ÿ“ License

This project is part of the GenAI Capstone project.