espejelomar commited on
Commit
d25a081
1 Parent(s): 5df619b

Second version

Browse files
Files changed (2) hide show
  1. .app.py.swp +0 -0
  2. app.py +2 -112
.app.py.swp ADDED
Binary file (20.5 kB). View file
app.py CHANGED
@@ -7,7 +7,7 @@ from backend.config import MODELS_ID, QA_MODELS_ID, SEARCH_MODELS_ID
7
  st.title('Demo using Flax-Sentence-Tranformers')
8
 
9
  st.sidebar.title('Tasks')
10
- menu = st.sidebar.radio("", options=["Sentence Similarity", "Asymmetric QA", "Search / Cluster", 'Identifying misleading vaccine texts'], index=0)
11
 
12
  st.markdown('''
13
 
@@ -20,117 +20,7 @@ View our models here : https://huggingface.co/flax-sentence-embeddings
20
 
21
  ''')
22
 
23
- if menu == "Sentence Similarity":
24
- st.header('Sentence Similarity')
25
- st.markdown('''
26
- **Instructions**: You can compare the similarity of a main text with other texts of your choice. In the background, we'll create an embedding for each text, and then we'll use the cosine similarity function to calculate a similarity metric between our main sentence and the others.
27
-
28
- For more cool information on sentence embeddings, see the [sBert project](https://www.sbert.net/examples/applications/computing-embeddings/README.html).
29
- ''')
30
- select_models = st.multiselect("Choose models", options=list(MODELS_ID), default=list(MODELS_ID)[0])
31
-
32
- anchor = st.text_input(
33
- 'Please enter here the main text you want to compare:'
34
- )
35
-
36
- n_texts = st.number_input(
37
- f'''How many texts you want to compare with: '{anchor}'?''',
38
- value=2,
39
- min_value=2)
40
-
41
- inputs = []
42
-
43
- for i in range(int(n_texts)):
44
- input = st.text_input(f'Text {i + 1}:')
45
-
46
- inputs.append(input)
47
-
48
- if st.button('Tell me the similarity.'):
49
- results = {model: inference.text_similarity(anchor, inputs, model, MODELS_ID) for model in select_models}
50
- df_results = {model: results[model] for model in results}
51
-
52
- index = [f"{idx + 1}:{input[:min(15, len(input))]}..." for idx, input in enumerate(inputs)]
53
- df_total = pd.DataFrame(index=index)
54
- for key, value in df_results.items():
55
- df_total[key] = list(value['score'].values)
56
-
57
- st.write('Here are the results for selected models:')
58
- st.write(df_total)
59
- st.write('Visualize the results of each model:')
60
- st.line_chart(df_total)
61
- elif menu == "Asymmetric QA":
62
- st.header('Asymmetric QA')
63
- st.markdown('''
64
- **Instructions**: You can compare the Answer likeliness of a given Query with answer candidates of your choice. In the background, we'll create an embedding for each answers, and then we'll use the cosine similarity function to calculate a similarity metric between our query sentence and the others.
65
- `mpnet_asymmetric_qa` model works best for hard negative answers or distinguishing similar queries due to separate models applied for encoding questions and answers.
66
-
67
- For more cool information on sentence embeddings, see the [sBert project](https://www.sbert.net/examples/applications/computing-embeddings/README.html).
68
- ''')
69
-
70
- select_models = st.multiselect("Choose models", options=list(QA_MODELS_ID), default=list(QA_MODELS_ID)[0])
71
-
72
- anchor = st.text_input(
73
- 'Please enter here the query you want to compare with given answers:',
74
- value="What is the weather in Paris?"
75
- )
76
-
77
- n_texts = st.number_input(
78
- f'''How many answers you want to compare with: '{anchor}'?''',
79
- value=10,
80
- min_value=2)
81
-
82
- inputs = []
83
-
84
- defaults = ["It is raining in Paris right now with 70 F temperature.", "What is the weather in Berlin?", "I have 3 brothers."]
85
- for i in range(int(n_texts)):
86
- input = st.text_input(f'Answer {i + 1}:', value=defaults[i] if i < len(defaults) else "")
87
-
88
- inputs.append(input)
89
-
90
- if st.button('Tell me Answer likeliness.'):
91
- results = {model: inference.text_similarity(anchor, inputs, model, QA_MODELS_ID) for model in select_models}
92
- df_results = {model: results[model] for model in results}
93
-
94
- index = [f"{idx + 1}:{input[:min(15, len(input))]}..." for idx, input in enumerate(inputs)]
95
- df_total = pd.DataFrame(index=index)
96
- for key, value in df_results.items():
97
- df_total[key] = list(value['score'].values)
98
-
99
- st.write('Here are the results for selected models:')
100
- st.write(df_total)
101
- st.write('Visualize the results of each model:')
102
- st.line_chart(df_total)
103
-
104
- elif menu == "Search / Cluster":
105
- st.header('Search / Cluster')
106
- st.markdown('''
107
- **Instructions**: Make a query for anything related to "Python" and the model you choose will return you similar queries.
108
-
109
- For more cool information on sentence embeddings, see the [sBert project](https://www.sbert.net/examples/applications/computing-embeddings/README.html).
110
- ''')
111
-
112
- select_models = st.multiselect("Choose models", options=list(SEARCH_MODELS_ID), default=list(SEARCH_MODELS_ID)[0])
113
-
114
- anchor = st.text_input(
115
- 'Please enter here your query about "Python", we will look for similar ones:',
116
- value="How do I sort a dataframe by column"
117
- )
118
-
119
- n_texts = st.number_input(
120
- f'''How many similar queries you want?''',
121
- value=3,
122
- min_value=2)
123
-
124
- if st.button('Give me my search.'):
125
- results = {model: inference.text_search(anchor, n_texts, model, QA_MODELS_ID) for model in select_models}
126
- st.table(pd.DataFrame(results[select_models[0]]).T)
127
-
128
- if st.button('3D Clustering of search result using T-SNE on generated embeddings'):
129
- st.write("Currently only works at local due to Spaces / plotly integration.")
130
- st.write("Demonstration : https://gyazo.com/1ff0aa438ae533de3b3c63382af7fe80")
131
- # fig = inference.text_cluster(anchor, 1000, select_models[0], QA_MODELS_ID)
132
- # fig.show()
133
- elif menu == "Identifying misleading vaccine texts":
134
  st.header('Identifying misleading vaccine texts')
135
  st.markdown('''
136
  **Instructions**: You can compare the similarity of a given text and key words that identify 'misleading' texts regarding vaccination. In the background, we'll create an embedding for each text, and then we'll use the cosine similarity function to calculate a similarity metric between our main sentence and the keywords.
7
  st.title('Demo using Flax-Sentence-Tranformers')
8
 
9
  st.sidebar.title('Tasks')
10
+ menu = st.sidebar.radio("", options=['Identifying misleading vaccine texts'], index=0)
11
 
12
  st.markdown('''
13
 
20
 
21
  ''')
22
 
23
+ if menu == "Identifying misleading vaccine texts":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  st.header('Identifying misleading vaccine texts')
25
  st.markdown('''
26
  **Instructions**: You can compare the similarity of a given text and key words that identify 'misleading' texts regarding vaccination. In the background, we'll create an embedding for each text, and then we'll use the cosine similarity function to calculate a similarity metric between our main sentence and the keywords.