Skip to content

Commit

Permalink
adding topics version to training
Browse files Browse the repository at this point in the history
  • Loading branch information
rha930 committed Feb 15, 2022
1 parent a70d704 commit a310817
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
16 changes: 9 additions & 7 deletions gamechangerml/api/fastapi/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def getTopicModel(self):
)
ModelLoader.initTopics()
return ModelLoader.__topic_model

def getRecommender(self):
if ModelLoader.__recommender is None:
logger.warning(
Expand Down Expand Up @@ -211,7 +211,8 @@ def initSentenceSearcher(
Args:
Returns:
"""
logger.info(f"Loading Sentence Searcher with sent index path: {index_path}")
logger.info(
f"Loading Sentence Searcher with sent index path: {index_path}")
try:
if MODEL_LOAD_FLAG:
ModelLoader.__sentence_searcher = SentenceSearcher(
Expand Down Expand Up @@ -259,23 +260,24 @@ def initSentenceEncoder(transformer_path=LOCAL_TRANSFORMERS_DIR.value):
def initSparse(model_name=latest_intel_model_trans.value):
try:
if MODEL_LOAD_FLAG:
ModelLoader.__sparse_reader = sparse.SparseReader(model_name=model_name)
ModelLoader.__sparse_reader = sparse.SparseReader(
model_name=model_name)
logger.info(f"Sparse Reader: {model_name} loaded")
except Exception as e:
logger.warning("** Could not load Sparse Reader")
logger.warning(e)

@staticmethod
def initTopics() -> None:
def initTopics(model_path=TOPICS_MODEL.value) -> None:
"""initTopics - load topics model on start
Args:
Returns:
"""
try:
if MODEL_LOAD_FLAG:
logger.info("Starting Topic pipeline")
logger.info(f"Loading topic model {model_path}")
logger.info(TopicsConfig.DATA_ARGS)
ModelLoader.__topic_model = Topics(directory=TOPICS_MODEL.value)
ModelLoader.__topic_model = Topics(directory=model_path)
logger.info("Finished loading Topic Model")
except Exception as e:
logger.warning("** Could not load Topic model")
Expand All @@ -293,4 +295,4 @@ def initRecommender():
ModelLoader.__recommender = Recommender()
logger.info("Finished loading Recommender")
except OSError:
logger.error(f"** Could not load Recommender")
logger.error(f"** Could not load Recommender")
13 changes: 7 additions & 6 deletions gamechangerml/api/fastapi/routers/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,21 +518,21 @@ def reload_thread(model_dict):
processmanager.reloading, progress, total
)
if "jbook_qexp" in model_dict:
qexp_name = os.path.join(
jbook_qexp_name = os.path.join(
Config.LOCAL_PACKAGED_MODELS_DIR, model_dict["jbook_qexp"]
)
# uses QEXP_MODEL_NAME by default
logger.info("Attempting to load Jbook QE")
MODELS.initQE(qexp_name)
QEXP_MODEL_NAME.value = qexp_name
MODELS.initQEJBook(jbook_qexp_name)
QEXP_JBOOK_MODEL.value = jbook_qexp_name
progress += 1
processmanager.update_status(
processmanager.reloading, progress, total
)

if "topics" in model_dict:
if "topic_models" in model_dict:
topics_name = os.path.join(
Config.LOCAL_PACKAGED_MODELS_DIR, model_dict["topics"]
Config.LOCAL_PACKAGED_MODELS_DIR, model_dict["topic_models"]
)

logger.info("Attempting to load Topics")
Expand Down Expand Up @@ -708,7 +708,8 @@ def train_topics(model_dict):
logger.info("Attempting to train topic model")
logger.info(model_dict)
args = {"sample_rate": model_dict["sample_rate"],
"upload": model_dict["upload"]}
"upload": model_dict["upload"],
"version": model_dict["version"]}
pipeline.run(
build_type=model_dict["build_type"],
run_name=datetime.now().strftime("%Y%m%d"),
Expand Down
Empty file.
15 changes: 0 additions & 15 deletions gamechangerml/models/topic_models/tfidf.py

This file was deleted.

3 changes: 1 addition & 2 deletions gamechangerml/train/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,8 @@ def create_ltr(self, daysBack: int = 180):
except Exception as e:
logger.error("Could not create LTR")

def create_topics(self, sample_rate=None, upload=False, corpus_dir=CORPUS_DIR):
def create_topics(self, sample_rate=None, upload=False, corpus_dir=CORPUS_DIR, version="v2"):
try:
version = "v2"
model_id = datetime.now().strftime("%Y%m%d%H%M%S")
model_dir = DefaultConfig.LOCAL_MODEL_DIR

Expand Down

0 comments on commit a310817

Please sign in to comment.