dynamic-learning-model 4.0.4__tar.gz → 4.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/PKG-INFO +1 -1
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dlm/DLM.py +20 -7
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dlm/DLM_Compute_Model.py +9 -1
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dlm/DLM_Memory_Model.py +8 -3
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dynamic_learning_model.egg-info/PKG-INFO +1 -1
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/pyproject.toml +1 -1
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/LICENSE +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/README.md +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dlm/__init__.py +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dynamic_learning_model.egg-info/SOURCES.txt +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dynamic_learning_model.egg-info/dependency_links.txt +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dynamic_learning_model.egg-info/requires.txt +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/dynamic_learning_model.egg-info/top_level.txt +0 -0
- {dynamic_learning_model-4.0.4 → dynamic_learning_model-4.0.6}/setup.cfg +0 -0
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import warnings
|
|
3
2
|
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
|
4
3
|
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
4
|
+
os.environ["HF_HUB_VERBOSITY"] = "error"
|
|
5
|
+
import warnings
|
|
5
6
|
warnings.filterwarnings("ignore")
|
|
7
|
+
import logging
|
|
8
|
+
logging.getLogger("huggingface_hub").setLevel(logging.ERROR)
|
|
9
|
+
from transformers.utils import logging as hf_logging
|
|
10
|
+
hf_logging.disable_progress_bar()
|
|
11
|
+
hf_logging.set_verbosity_error()
|
|
6
12
|
import difflib
|
|
7
13
|
import string
|
|
8
14
|
import random
|
|
9
15
|
import spacy
|
|
10
16
|
import time
|
|
11
17
|
import sqlite3
|
|
12
|
-
from transformers.utils import logging as hf_logging
|
|
13
|
-
hf_logging.disable_progress_bar()
|
|
14
|
-
hf_logging.set_verbosity_error()
|
|
15
18
|
from .DLM_Compute_Model import perform_advanced_CoT
|
|
16
19
|
from .DLM_Memory_Model import get_category
|
|
17
20
|
from .DLM_Memory_Model import get_specific_question
|
|
@@ -21,6 +24,7 @@ from transformers import pipeline
|
|
|
21
24
|
from better_profanity import profanity
|
|
22
25
|
from nltk.corpus import names
|
|
23
26
|
|
|
27
|
+
|
|
24
28
|
class DLM:
|
|
25
29
|
# for one-time, shared model loaders so that each object won't load a new model (> 2GB)
|
|
26
30
|
_shared_nlp = None
|
|
@@ -369,7 +373,7 @@ class DLM:
|
|
|
369
373
|
"Let’s reset. Rephrase your question without the frustration, and I’ll be able to help you effectively."
|
|
370
374
|
]
|
|
371
375
|
|
|
372
|
-
def __init__(self, mode, db_filename=
|
|
376
|
+
def __init__(self, mode, db_filename=None): # initializes SQL database & SpaCy NLP
|
|
373
377
|
"""
|
|
374
378
|
Initialize the Dynamic-Learning Model (DLM) chatbot.
|
|
375
379
|
|
|
@@ -377,7 +381,7 @@ class DLM:
|
|
|
377
381
|
mode (str): The access mode. Options:
|
|
378
382
|
'learn' for training mode (to train the bot with queries).
|
|
379
383
|
'apply' for a trained model to choose between compute and memory mode.
|
|
380
|
-
db_filename (str): The SQLite database file used to train and retrieve
|
|
384
|
+
db_filename (str, optional): The SQLite database file used to train and retrieve
|
|
381
385
|
question-answer-category triples.
|
|
382
386
|
|
|
383
387
|
Behavior:
|
|
@@ -407,7 +411,16 @@ class DLM:
|
|
|
407
411
|
self.__nlp = DLM._shared_nlp
|
|
408
412
|
self.__hf_classifier = DLM._shared_hf
|
|
409
413
|
|
|
410
|
-
|
|
414
|
+
if db_filename is None:
|
|
415
|
+
# Create an absolute path to a hidden folder in the user's home directory
|
|
416
|
+
home_dir = os.path.expanduser("~")
|
|
417
|
+
dlm_dir = os.path.join(home_dir, ".dlm")
|
|
418
|
+
|
|
419
|
+
# Ensure the directory exists before SQLite tries to connect
|
|
420
|
+
os.makedirs(dlm_dir, exist_ok=True)
|
|
421
|
+
self.__filename = os.path.join(dlm_dir, "dlm_database.db")
|
|
422
|
+
else:
|
|
423
|
+
self.__filename = db_filename
|
|
411
424
|
self.__mode = mode
|
|
412
425
|
|
|
413
426
|
try:
|
|
@@ -292,11 +292,19 @@ def pick_out_names(self, doc, persons_mentioned, filtered_query):
|
|
|
292
292
|
if cleaned:
|
|
293
293
|
persons_mentioned.append(cleaned)
|
|
294
294
|
|
|
295
|
-
|
|
295
|
+
# this is to solve a problematic issue with nltk if a certain package is not already downloaded
|
|
296
|
+
try:
|
|
297
|
+
tokens = nltk.word_tokenize(filtered_query)
|
|
298
|
+
except LookupError:
|
|
299
|
+
# silently download the tokenizer if it is missing
|
|
300
|
+
nltk.download('punkt_tab', quiet=True)
|
|
301
|
+
tokens = nltk.word_tokenize(filtered_query)
|
|
302
|
+
|
|
296
303
|
for tok in tokens:
|
|
297
304
|
cleaned = re.sub(r"[^a-zA-Z]", "", tok).lower()
|
|
298
305
|
if cleaned in self._DLM__nltk_names:
|
|
299
306
|
persons_mentioned.append(cleaned.capitalize())
|
|
307
|
+
|
|
300
308
|
persons_mentioned = {name for name in set(persons_mentioned) if len(name.split()) == 1}
|
|
301
309
|
persons_mentioned = set(persons_mentioned)
|
|
302
310
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import sqlite3
|
|
2
|
-
|
|
3
1
|
def get_category(self, exact_question): # returns category as a string or None
|
|
4
2
|
"""
|
|
5
3
|
Retrieve the category (question type) associated with a specific question from the SQLite knowledge base.
|
|
@@ -71,6 +69,7 @@ def get_specific_question(self, exact_answer): # returns question as a string o
|
|
|
71
69
|
def learn(self, expectation, category): # no return, void
|
|
72
70
|
"""
|
|
73
71
|
Store a new question-answer-category entry in the SQLite knowledge base.
|
|
72
|
+
If the question already exists and the trainer gives a new response, it updates the answer and category of that existing question
|
|
74
73
|
|
|
75
74
|
Parameters:
|
|
76
75
|
expectation (str): The expected answer or response to the current user query.
|
|
@@ -88,7 +87,13 @@ def learn(self, expectation, category): # no return, void
|
|
|
88
87
|
|
|
89
88
|
try:
|
|
90
89
|
self._DLM__cursor.execute(
|
|
91
|
-
"
|
|
90
|
+
"""
|
|
91
|
+
INSERT INTO knowledge_base (question, answer, category)
|
|
92
|
+
VALUES (?, ?, ?)
|
|
93
|
+
ON CONFLICT(question) DO UPDATE SET
|
|
94
|
+
answer = excluded.answer,
|
|
95
|
+
category = excluded.category
|
|
96
|
+
""",
|
|
92
97
|
(self._DLM__special_stripped_query, expectation, category)
|
|
93
98
|
)
|
|
94
99
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dynamic-learning-model"
|
|
7
|
-
version = "4.0.
|
|
7
|
+
version = "4.0.6"
|
|
8
8
|
description = "A Dynamic-Learning Model (DLM) chatbot with memory and compute reasoning modes."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|