Am splitting a text into tokens and for each toke, creating a select box. How would I be able to save the token and the corresponding selected value? Here is my noob attempt.
checkpoint = “bert-base-uncased”
tokenizer = BertTokenizer.from_pretrained(checkpoint)
if “load_state” not in st.session_state:
st.session_state.load_state = False
#txt = “There is a leak on the third floor with the HVAC”
saved = False
txt = st.text_area(“”)
tokenize = st.button(“Tokenize”)
input_cols = st.container()
if tokenize or st.session_state.load_state:
st.session_state.load_state = True
tokens = tokenizer.tokenize(txt)
token_length = len(tokens)
print(token_length)
options = [“L”, “E”]
with input_cols:
cols = st.columns(token_length)
for ix, col in enumerate(cols):
tokenboxes = col.selectbox(tokens[ix], key=ix, options=options)
save = st.button(“Save”)
if save:
st.write(tokenboxes[1]) # the key should exist from above but this index doesnt exist