Lora
commited on
Commit
·
87fccdc
1
Parent(s):
5bd9754
add safeguard for looking up empty string
Browse files
app.py
CHANGED
|
@@ -76,6 +76,9 @@ Returns:
|
|
| 76 |
- contextualization_weights: gr.State variable, stores the contextualization weights for the input sentence
|
| 77 |
"""
|
| 78 |
def predict_next_word (sentence, top_k = 5, contextualization_weights = None):
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
# For better tokenization, by default, adds a space at the beginning of the sentence if it doesn't already have one
|
| 81 |
# and remove trailing space
|
|
@@ -282,10 +285,9 @@ with gr.Blocks( theme = gr.themes.Base(),
|
|
| 282 |
selected_token = gr.Textbox(label="Current Selected Token", interactive=False)
|
| 283 |
with gr.Column(scale=8):
|
| 284 |
gr.Markdown("""####
|
| 285 |
-
Once a token is chosen, you can **use the sliders below to change the
|
| 286 |
and then click "Predict next word" to see updated next-word predictions. \
|
| 287 |
-
You can change the weights of *multiple senses of multiple tokens
|
| 288 |
-
changes will be preserved until you click "Reset weights".
|
| 289 |
""")
|
| 290 |
# sense sliders and top sense words dataframes
|
| 291 |
with gr.Row():
|
|
|
|
| 76 |
- contextualization_weights: gr.State variable, stores the contextualization weights for the input sentence
|
| 77 |
"""
|
| 78 |
def predict_next_word (sentence, top_k = 5, contextualization_weights = None):
|
| 79 |
+
|
| 80 |
+
if sentence == "":
|
| 81 |
+
return None, None, None, None
|
| 82 |
|
| 83 |
# For better tokenization, by default, adds a space at the beginning of the sentence if it doesn't already have one
|
| 84 |
# and remove trailing space
|
|
|
|
| 285 |
selected_token = gr.Textbox(label="Current Selected Token", interactive=False)
|
| 286 |
with gr.Column(scale=8):
|
| 287 |
gr.Markdown("""####
|
| 288 |
+
Once a token is chosen, you can **use the sliders below to change the weight of any sense** for that token, \
|
| 289 |
and then click "Predict next word" to see updated next-word predictions. \
|
| 290 |
+
You can change the weights of *multiple senses of multiple tokens*. Erase all changes with "Reset weights".
|
|
|
|
| 291 |
""")
|
| 292 |
# sense sliders and top sense words dataframes
|
| 293 |
with gr.Row():
|