-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
37 lines (33 loc) · 974 Bytes
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import plotly.graph_objects as go
import textwrap
import numpy as np
def plot_text_sim(similarities: list, texts: list, title=''):
plt_texts = []
shorten_width = 1000 # characters
line_width = 60
for text in texts:
# first add "[...]" for very long texts
text = textwrap.shorten(text, width=shorten_width)
# wrap
lines = textwrap.wrap(text, width=line_width)
plt_texts.append('<br>'.join(lines))
fig = go.Figure(
data = [
go.Bar(
x=np.arange(0, len(similarities)),
y=similarities,
hovertext=plt_texts,
)
]
)
fig.update_layout(
title=title,
xaxis_title="text chunk number",
yaxis_title="similarity to context",
hoverlabel=dict(
bgcolor="white",
font_size=13,
font_family="Rockwell"
),)
_ = fig.show()
return fig