Skip to content

Instantly share code, notes, and snippets.

@databyjp
Last active March 17, 2020 04:21
Show Gist options
  • Save databyjp/b8c9dd67cd0830deaa236a8cf56b9f00 to your computer and use it in GitHub Desktop.
Save databyjp/b8c9dd67cd0830deaa236a8cf56b9f00 to your computer and use it in GitHub Desktop.
dbc.Row([
dbc.Col(['Choose a t-SNE perplexity value:'], md=6),
dbc.Col([
dcc.Dropdown(
id='bigrams-perplex-dropdown',
options=[{'label': str(i), 'value': i} for i in range(3, 7)],
value=3
)], md=3)
]),
dcc.Graph(id="bigrams-scatter"),
...
@app.callback(
Output("bigrams-scatter", "figure"),
[Input("bigrams-perplex-dropdown", "value")],
)
def populate_bigram_scatter(perplexity):
X_embedded = TSNE(n_components=2, perplexity=perplexity).fit_transform(vects_df)
embed_df['tsne_1'] = X_embedded[:, 0]
embed_df['tsne_2'] = X_embedded[:, 1]
fig = px.scatter(embed_df, x='tsne_1', y='tsne_2', hover_name='bigram', text='bigram', size='count', color='words', size_max=45
, template='plotly_white', title='Bigram similarity and frequency', labels={'words': 'Avg. Length<BR>(words)'}
, color_continuous_scale=px.colors.sequential.Sunsetdark)
fig.update_traces(marker=dict(line=dict(width=1, color='Gray')))
fig.update_xaxes(visible=False)
fig.update_yaxes(visible=False)
return fig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment