Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Api runs with adhoc mentor (#91)
Browse files Browse the repository at this point in the history
* make rule configure mentor-api to run with host/adhoc checkpoint
* fix: prevent classifier from failing if only one answer is available
* feat: update api make with checkpoint with wildcard
* feat: make mentor api trainable and runnable from mentor dir
  • Loading branch information
mechristenson authored Aug 13, 2019
1 parent ec00cf1 commit a1c6343
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
7 changes: 5 additions & 2 deletions checkpoint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ checkpoint-vector-models:
-o ${CHECKPOINT_ROOT}/vector_models \
-h ${VECTOR_MODEL_BASE_URL} \
${CHECKPOINT_PATH}


.PHONY: checkpoint-clean/mentor/%
checkpoint-clean/mentor/%:
rm -rf classifiers/$(ARCH)/*$**

# CHECKPOINT={CHECKPOINT} MENTOR={MENTOR} make test-checkpoint
.PHONY: checkpoint-test
Expand All @@ -39,7 +42,7 @@ checkpoint-train: checkpoint-vector-models

.PHONY: checkpoint-train/mentor/%
checkpoint-train/mentor/%: checkpoint-vector-models
./bin/checkpoint_train.sh $(ARCH) ${CHECKPOINT}-$* $*
./bin/checkpoint_train.sh $(ARCH) ${CHECKPOINT} $*

.PHONY: docker-run-dev
docker-run-dev:
Expand Down
16 changes: 10 additions & 6 deletions classifier/src/mentorpal/classifiers/arch/lstm_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ def __get_prediction(self, w2v_vector, topic_vector):
test_vector = np.concatenate((w2v_vector, topic_vector))
test_vector = test_vector.reshape(1, -1)
prediction = self.logistic_model.predict(test_vector)
highestConfidence = sorted(
self.logistic_model.decision_function(test_vector)[0]
)[self.logistic_model.decision_function(test_vector).size - 1]
if highestConfidence < -0.88:
return "_OFF_TOPIC_", "_OFF_TOPIC_", highestConfidence
return self.mentor.answer_ids[prediction[0]], prediction[0], highestConfidence

decision = self.logistic_model.decision_function(test_vector)
confidence_scorces = (
sorted(decision[0]) if decision.ndim >= 2 else sorted(decision)
)
highest_confidence = confidence_scorces[-1]
if highest_confidence < -0.88:
return "_OFF_TOPIC_", "_OFF_TOPIC_", highest_confidence

return self.mentor.answer_ids[prediction[0]], prediction[0], highest_confidence
2 changes: 2 additions & 0 deletions mentors/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Makefile
README.md
19 changes: 15 additions & 4 deletions mentors/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
DOCKER_IMAGE?=mentor-processing-pipeline
DOCKER_IMAGE_ID=$(shell docker images -q $(DOCKER_IMAGE))
DOCKER_CONTAINER=mentor-processing-pipeline
MENTOR?=julianne
SESSION?=1
MENTOR_SOURCE_VIDEOS?=http://mentorpal-source-videos.s3-website-us-east-1.amazonaws.com
PROJECT_ROOT?=$(shell git rev-parse --show-toplevel 2> /dev/null)
WATSON_CREDENTIALS=secrets/watson_credentials.txt
WATSON_USERNAME?=$(shell if [ -f $(WATSON_CREDENTIALS) ]; then head -n 1 $(WATSON_CREDENTIALS); else echo ""; fi)
WATSON_PASSWORD?=$(shell if [ -f $(WATSON_CREDENTIALS) ]; then tail -n 1 $(WATSON_CREDENTIALS); else echo ""; fi)
Expand Down Expand Up @@ -56,9 +56,7 @@ shell: docker-image-exists $(WATSON_CREDENTIALS)
-e WATSON_USERNAME=$(WATSON_USERNAME) \
-e WATSON_PASSWORD=$(WATSON_PASSWORD) \
--entrypoint /bin/bash \
-v $(shell pwd)/$(MENTOR):/app/mounts/$(MENTOR) \
-v $(shell pwd)/data:/app/mounts/data \
-v $(shell pwd)/videos:/app/mounts/videos \
-v $(shell pwd):/app/mounts \
-v $(shell pwd)/src:/app/src \
$(DOCKER_IMAGE)

Expand Down Expand Up @@ -127,3 +125,16 @@ shell: docker-image-exists $(WATSON_CREDENTIALS)
-v $(shell pwd)/data:/app/mounts/data \
-v $(shell pwd)/videos:/app/mounts/videos \
$(DOCKER_IMAGE) --mentor $* --qpa_pu_data --classification_data --videos

# Build checkpoint from mentor data
.PHONY: %/checkpoint
%/checkpoint: %/data
cd $(PROJECT_ROOT)/checkpoint && \
CHECKPOINT=$*-latest $(MAKE) checkpoint-clean/mentor/$* checkpoint-train/mentor/$*

# Run latest checkpoint for mentor
# To run custom checkpoint, use rules inside /mentor-api
.PHONY: %/checkpoint-run
%/checkpoint-run:
cd $(PROJECT_ROOT)/services/mentor-api && \
$(MAKE) docker-run-checkpoint/$*-latest
16 changes: 15 additions & 1 deletion services/mentor-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,21 @@ docker-run:
--name $(DOCKER_CONTAINER) \
--shm-size 8G \
-p 5000:5000 \
$(DOCKER_IMAGE)
$(DOCKER_IMAGE)


.PHONY: docker-run-checkpoint/%
docker-run-checkpoint/%:
docker run \
-it \
--rm \
--name $(DOCKER_CONTAINER) \
-v $(PROJECT_ROOT)/checkpoint:/app/checkpoint \
-v $(PROJECT_ROOT)/mentors:/app/mentors \
-e CLASSIFIER_CHECKPOINT=$* \
--shm-size 8G \
-p 5000:5000 \
$(DOCKER_IMAGE)


.PHONY: docker-run-dev
Expand Down

0 comments on commit a1c6343

Please sign in to comment.