Created
January 5, 2018 14:44
-
-
Save dfalbel/98342b0d7207c2f34e81e70caec9bcb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Quora Question Pairs" | |
output: | |
flexdashboard::flex_dashboard: | |
orientation: columns | |
runtime: shiny | |
--- | |
```{r global, include=FALSE} | |
library(keras) | |
library(flexdashboard) | |
model <- load_model_hdf5("model-question-pairs.hdf5", compile = FALSE) | |
tokenizer <- load_text_tokenizer("tokenizer-question-pairs") | |
predict_question_pairs <- function(model, tokenizer, q1, q2) { | |
q1 <- texts_to_sequences(tokenizer, list(q1)) | |
q2 <- texts_to_sequences(tokenizer, list(q2)) | |
q1 <- pad_sequences(q1, 20) | |
q2 <- pad_sequences(q2, 20) | |
as.numeric(predict(model, list(q1, q2))) | |
} | |
``` | |
Column | |
----------------------------------------------------------------------- | |
### Questions | |
```{r} | |
textAreaInput( | |
"q1", | |
label = h3("Question 1"), | |
value = "What is the future of deep learning?" | |
) | |
textAreaInput( | |
"q2", | |
label = h3("Question 2"), | |
value = "What does the future of deep learning look like?" | |
) | |
actionButton(inputId = "calculate", "Calculate Duplication Probability") | |
``` | |
Column | |
----------------------------------------------------------------------- | |
### Results | |
```{r} | |
probability <- eventReactive( | |
input$calculate, | |
predict_question_pairs(model, tokenizer, input$q1, input$q2) | |
) | |
renderGauge({ | |
gauge( | |
round(probability()*100, 2), | |
min = 0, | |
max = 100, | |
symbol = "%" | |
) | |
}) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment