hacpdsae2023 commited on
Commit
376e087
·
1 Parent(s): 094d202

Changing the app: removing the slider and adding a section to find most likely topic of example

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -5,10 +5,16 @@ st.markdown('# Semantic search and topic classification (v1)')
5
  st.markdown(' - Author: hcontreras')
6
  st.markdown(' - Description: We want to classify sentences into a predefined set of topics. We use semantic search with a pre-trained transformer and we embed the input sentences and find the score relative to each topic')
7
 
 
 
 
8
  from sentence_transformers import SentenceTransformer
9
  model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
10
 
11
- input_sentence = st.text_input('Movie title', 'Life of Brian')
 
 
 
12
  #st.write('The current movie title is', title)
13
 
14
  #Sentences we want to encode. Example:
@@ -16,14 +22,17 @@ sentence = ['This framework generates embeddings for each input sentence']
16
 
17
 
18
  #Sentences are encoded by calling model.encode()
19
- embedding = model.encode([input_sentence])
 
20
 
21
- x = st.slider('Select a value')
22
  #embedding = model.encode(input_sentence)
23
  #st.write(x, 'squared is', x * x, 'embedding', embedding[0][0])
24
- st.write('The embedding of', '"' + input_sentence + '"', 'at position',x,'is',embedding[0][int(x)])
25
 
 
26
 
 
27
  uploaded_file1 = st.file_uploader("Choose a file: sentence list")
28
  if uploaded_file1 is not None:
29
  #read csv
 
5
  st.markdown(' - Author: hcontreras')
6
  st.markdown(' - Description: We want to classify sentences into a predefined set of topics. We use semantic search with a pre-trained transformer and we embed the input sentences and find the score relative to each topic')
7
 
8
+ st.markdown('## A quick test')
9
+ st.markdown('As a test we can create an embedding for a movie title and explore each component with the slider. Have fun!')
10
+
11
  from sentence_transformers import SentenceTransformer
12
  model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
13
 
14
+ input_sentence = st.text_input('Sentence', 'This is a test for a news article')
15
+ input_topic = st.selectbox(
16
+ 'Topic',
17
+ ('Space', 'Transportation', 'Health'))
18
  #st.write('The current movie title is', title)
19
 
20
  #Sentences we want to encode. Example:
 
22
 
23
 
24
  #Sentences are encoded by calling model.encode()
25
+ embedding_sentence = model.encode([input_sentence])
26
+ embedding_topics = model.encode(['Space','Transportation','Health'])
27
 
28
+ #x = st.slider('Select a value')
29
  #embedding = model.encode(input_sentence)
30
  #st.write(x, 'squared is', x * x, 'embedding', embedding[0][0])
31
+ #st.write('The embedding of', '"' + input_sentence + '"', 'at position',x,'is',embedding[0][int(x)])
32
 
33
+ st.write('Score for topic', input_topic, ':')
34
 
35
+ st.markdown('## ')
36
  uploaded_file1 = st.file_uploader("Choose a file: sentence list")
37
  if uploaded_file1 is not None:
38
  #read csv