sonic314 commited on
Commit
266c9c5
1 Parent(s): b892ab1

Create streamlit example

Browse files
Files changed (2) hide show
  1. app.py +50 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datasets import load_dataset
3
+ from transformer_ranker import TransformerRanker, prepare_popular_models
4
+
5
+ st.title("Choose Your Transformer")
6
+
7
+ # 1) Select multiple models from HuggingFace model hub
8
+ model_options = ['prajjwal1/bert-tiny', 'google/electra-small-discriminator', 'microsoft/deberta-v3-small',
9
+ 'bert-base-uncased', 'bert-base-cased', 'distilbert-base-uncased', 'roberta-base'] # List of models
10
+ selected_models = st.multiselect("Select Models", model_options, default=model_options[:1])
11
+
12
+ # 2) Select dataset names (from text classification or token classification subcategory)
13
+ dataset_options = ['trec', 'conll2003'] # Example datasets; you can expand this list
14
+ selected_dataset = st.selectbox("Select Dataset", dataset_options)
15
+
16
+ # 3) Select the parameter for dataset downsampling
17
+ downsample_values = [0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
18
+ downsample_ratio = st.select_slider("Dataset Downsample Ratio", options=downsample_values, value=0.2)
19
+
20
+ # 4) Select the parameter for "layer selection" with layermean as the default
21
+ layer_options = ['lastlayer', 'layermean', 'bestlayer']
22
+ selected_layer = st.selectbox("Layer Selection", layer_options, index=1)
23
+
24
+ # Add real-time logging in the future
25
+ log_expander = st.expander("Expand to view log")
26
+ log_placeholder = log_expander.empty() # Placeholder for log updates
27
+
28
+ # Button to run the ranking process
29
+ if st.button("Run Model Ranking"):
30
+ with st.spinner("Running the transformer-ranker..."):
31
+
32
+ # Step 1: Load the selected dataset
33
+ dataset = load_dataset(selected_dataset)
34
+
35
+ # Step 2: Prepare the selected models
36
+ language_models = prepare_popular_models('base') if selected_models == [] else selected_models
37
+
38
+ # Step 3: Initialize the ranker
39
+ ranker = TransformerRanker(dataset, dataset_downsample=downsample_ratio)
40
+
41
+ # Placeholder for log updates
42
+ log_placeholder.text("Real-time logging will be added here...")
43
+
44
+ # Run the ranker
45
+ results = ranker.run(language_models, batch_size=64)
46
+
47
+ # Display the final results
48
+ st.write(results)
49
+
50
+ st.success("Ranking is Done!")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformer-ranker
2
+ streamlit