Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FoodInformatics
msx-tool
Commits
531b5907
Commit
531b5907
authored
Apr 16, 2021
by
Jim Hoekstra
👋🏻
Browse files
merge
parent
82674525
Changes
3
Hide whitespace changes
Inline
Side-by-side
dash_app/callbacks.py
View file @
531b5907
...
...
@@ -41,6 +41,7 @@ def update_base_word(submit_word_button, base_word_input):
State
(
component_id
=
'graph-elements-div'
,
component_property
=
'children'
),
State
(
component_id
=
'msx-graph'
,
component_property
=
'tapNodeData'
),
State
(
component_id
=
'base-word-div'
,
component_property
=
'children'
),
# State(component_id='msx-graph', component_property='zoom'),
prevent_initial_call
=
True
)
def
update_graph_elements
(
submit_word_button
,
add_word_button
,
extend_graph_button
,
remove_word_button
,
base_word_input
,
...
...
@@ -50,6 +51,7 @@ def update_graph_elements(submit_word_button, add_word_button, extend_graph_butt
button_id
=
callback_context
.
triggered
[
0
][
'prop_id'
].
split
(
'.'
)[
0
]
graph
=
Graph
()
# print('graph zoom level: ', graph_zoom_level)
if
button_id
==
'submit-word-button'
:
graph
.
fill_with_associations
(
word2vec_model
,
base_word_input
)
...
...
dash_app/index.py
View file @
531b5907
import
os
from
dash_app.app
import
app
from
dash_app.layout
import
layout
import
dash_app.callbacks
app
.
layout
=
layout
...
...
dash_app/words.py
View file @
531b5907
...
...
@@ -5,13 +5,13 @@ import stringdist as sdi
class
AssociatedWords
:
def
__init__
(
self
):
print
(
"
\n
Word2Vec model is loading.This can take a couple of minutes."
)
self
.
model
=
api
.
load
(
'glove-twitter-200'
)
print
(
" Word2Vec model is ready. Enjoy!!!
\n
"
)
print
(
"
\n
Word2Vec model is loading.
This can take a couple of minutes."
)
#
self.model = api.load('glove-twitter-200')
#
print(" Word2Vec model is ready. Enjoy!!!\n")
def
get_associated_words
(
self
,
word
,
top_n
=
10
):
gensim_result
=
self
.
model
.
most_similar
(
word
,
topn
=
top_n
)
#
gensim_result = [('apple', 1.0), ('banana', 1.0), ('strawberry', 1.0)]
#
gensim_result = self.model.most_similar(word, topn=top_n)
gensim_result
=
[(
'apple'
,
1.0
),
(
'banana'
,
1.0
),
(
'strawberry'
,
1.0
)]
words
=
self
.
filter_results
(
gensim_result
,
word
)
return
words
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment