loubnabnl HF staff commited on
Commit
c4cced7
1 Parent(s): 4948a7d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from datasets import load_dataset
3
+ import os
4
+
5
+ HF_TOKEN = os.environ.get("HF_TOKEN", None)
6
+
7
+ st.set_page_config(
8
+ page_title="Logprobs inspection", layout="wide"
9
+ )
10
+
11
+ st.markdown("# Logprobs inspection")
12
+
13
+ @st.cache_data
14
+ def load_data():
15
+ ds = load_dataset(
16
+ "HuggingFaceTB/sample_log_probs",
17
+ split="train",
18
+ token=HF_TOKEN,
19
+ )
20
+ return ds
21
+
22
+ ds = load_data()
23
+
24
+ min_log = min(ds["logprobs"])
25
+ max_log = max(ds["logprobs"])
26
+ col_1, col_2 = st.columns(2)
27
+ with col_1:
28
+ min_score = st.slider("Select minimum logprob", min_value=min_log, max_value=max_log, value=min_log, step=0.2, key="min_score")
29
+ with col_2:
30
+ max_score = st.slider("Select maximum logprob", min_value=min_log, max_value=max_log, value=max_log, step=0.2, key="max_score")
31
+
32
+ filtered_ds = ds.filter(lambda x: min_score <= x["logprobs"] <= max_score)
33
+ index = st.slider("Select a sample", 0, len(filtered_ds), 0)
34
+
35
+ with st.expander("The prompt"):
36
+ st.markdown(filtered_ds[index]['prompt'])
37
+
38
+ st.markdown(f"**Metadata:** log_prob is {filtered_ds[index]['logprobs']:.2f}, seed: {filtered_ds[index]['seed_data']}, {filtered_ds[index]['format']} for {filtered_ds[index]['audience']}.")
39
+ st.markdown(filtered_ds[index]["text"])