diff --git a/checkpoint/Makefile b/checkpoint/Makefile index d52797db..e8c3a430 100644 --- a/checkpoint/Makefile +++ b/checkpoint/Makefile @@ -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 @@ -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: diff --git a/classifier/src/mentorpal/classifiers/arch/lstm_v1/__init__.py b/classifier/src/mentorpal/classifiers/arch/lstm_v1/__init__.py index 474e0ccc..44c9f981 100644 --- a/classifier/src/mentorpal/classifiers/arch/lstm_v1/__init__.py +++ b/classifier/src/mentorpal/classifiers/arch/lstm_v1/__init__.py @@ -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 diff --git a/mentors/.dockerignore b/mentors/.dockerignore new file mode 100644 index 00000000..10769ebe --- /dev/null +++ b/mentors/.dockerignore @@ -0,0 +1,2 @@ +Makefile +README.md diff --git a/mentors/Makefile b/mentors/Makefile index 086ab4be..745ce172 100644 --- a/mentors/Makefile +++ b/mentors/Makefile @@ -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) @@ -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) @@ -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 diff --git a/services/mentor-api/Makefile b/services/mentor-api/Makefile index 1cc849f4..eb4e9a0e 100644 --- a/services/mentor-api/Makefile +++ b/services/mentor-api/Makefile @@ -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