Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diazdavilajesus16-stack/IA-LUMINA/llms.txt
Use this file to discover all available pages before exploring further.
chatbot.py is the ML inference engine for Lumina AI. It loads the trained model (chatbot_model.h5), vocabulary (words.pkl), and intent list (classes.pkl) at import time, then exposes functions for classifying user input and retrieving responses. You can import it directly to use Lumina’s intent classification in your own scripts, outside of the Streamlit interface.
predict_class
Classifies a sentence and returns the matched intents ranked by confidence.Raw student input text. The function normalizes, tokenizes, and lemmatizes this string internally before classification.
"intent"— the matched intent tag string (e.g.,"algebra","saludo")"probability"— string representation of the raw softmax probability (e.g.,"0.8731452")
predict_class uses a three-stage cascade:
- Neural network with high threshold (
0.60) — if any class exceeds this confidence, results are returned immediately. - Keyword fallback — if no class exceeds the high threshold, the normalized sentence is scanned against
_KEYWORD_MAP. A match returns a single-item list with probability"0.50". - Neural network with low threshold (
0.35) — if keywords also fail, any class exceeding the low threshold is returned as a best-effort result.
_context deque (max length 3), which get_response uses to generate contextual fallback messages.
get_response
Retrieves a response string for the top-ranked intent frompredict_class.
The output from
predict_class(). The function reads only the first element (highest-confidence intent). Pass an empty list to trigger a contextual fallback response.The parsed contents of
respuestas.json. Must contain an "intents" key whose value is a list of intent objects, each with "tag" and "responses" fields.responses list. If intents_list is empty, or if no intent in intents_json matches the tag, returns a contextual fallback string generated from the recent conversation history in _context.
bag_of_words
Converts a sentence to a binary vector over the full vocabulary.Text to vectorize. Internally calls
clean_up_sentence to tokenize and lemmatize before comparison.numpy array of length len(words), where index i is 1 if the corresponding vocabulary token appears in the sentence and 0 otherwise.
clean_up_sentence
Tokenizes and lemmatizes a sentence for vocabulary lookup.Raw text to process. Normalization (accent removal, punctuation stripping, lowercasing) is applied before tokenization.
"ecuaciones de primer grado" becomes ["ecuacion", "de", "primer", "grado"].
Usage example
The typical call pattern is to runpredict_class on the user input, then pass the result to get_response along with the loaded intents data:
chatbot.py loads chatbot_model.h5, words.pkl, and classes.pkl at module import time. All three files must be present in the working directory before importing, or the module will raise a FileNotFoundError. Run training_chatbot.py first if these files do not exist.