Spaces:
Sleeping
Sleeping
s-a-malik
commited on
Commit
·
f3099db
1
Parent(s):
3dc5f5e
add paper links
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 13 |
# TODO Sentence level highlighting instead (prediction after every word is not what it was trained on). Also solves token-level highlighting issues.
|
| 14 |
# TODO log prob output scaling highlighting instead?
|
| 15 |
# TODO make it look nicer
|
|
|
|
| 16 |
# TODO streaming output (need custom generation function because of probes)
|
| 17 |
# TODO add options to switch between models, SLT/TBG, layers?
|
| 18 |
# TODO full semantic entropy calculation
|
|
@@ -23,12 +24,18 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
| 23 |
|
| 24 |
DESCRIPTION = """
|
| 25 |
<h1>Llama-2 7B Chat with Uncertainty Probes</h1>
|
| 26 |
-
<p>This Space demonstrates the Llama-2-7b-chat model with a semantic uncertainty probe.</p>
|
| 27 |
<p>The highlighted text shows the model's uncertainty in real-time:</p>
|
| 28 |
<ul>
|
| 29 |
<li><span style="background-color: #00FF00; color: black">Green</span> indicates more certain generations</li>
|
| 30 |
<li><span style="background-color: #FF0000; color: black">Red</span> indicates more uncertain generations</li>
|
| 31 |
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
"""
|
| 33 |
|
| 34 |
EXAMPLES = [
|
|
@@ -101,6 +108,7 @@ def generate(
|
|
| 101 |
se_highlighted_text = ""
|
| 102 |
acc_highlighted_text = ""
|
| 103 |
|
|
|
|
| 104 |
for i in range(1, len(hidden)):
|
| 105 |
|
| 106 |
# Semantic Uncertainty Probe
|
|
|
|
| 13 |
# TODO Sentence level highlighting instead (prediction after every word is not what it was trained on). Also solves token-level highlighting issues.
|
| 14 |
# TODO log prob output scaling highlighting instead?
|
| 15 |
# TODO make it look nicer
|
| 16 |
+
# TODO better examples.
|
| 17 |
# TODO streaming output (need custom generation function because of probes)
|
| 18 |
# TODO add options to switch between models, SLT/TBG, layers?
|
| 19 |
# TODO full semantic entropy calculation
|
|
|
|
| 24 |
|
| 25 |
DESCRIPTION = """
|
| 26 |
<h1>Llama-2 7B Chat with Uncertainty Probes</h1>
|
| 27 |
+
<p>This Space demonstrates the Llama-2-7b-chat model with a semantic uncertainty probe. This demo is based on our paper: <a href="https://arxiv.org/abs/2406.15927" target="_blank">"Semantic Uncertainty and Accuracy Probes for Language Models"</a> by Jannik Kossen*, Jiatong Han*, Muhammed Razzak*, Lisa Schut, Shreshth Malik and Yarin Gal.</p>
|
| 28 |
<p>The highlighted text shows the model's uncertainty in real-time:</p>
|
| 29 |
<ul>
|
| 30 |
<li><span style="background-color: #00FF00; color: black">Green</span> indicates more certain generations</li>
|
| 31 |
<li><span style="background-color: #FF0000; color: black">Red</span> indicates more uncertain generations</li>
|
| 32 |
</ul>
|
| 33 |
+
<p>The demo compares the model's uncertainty with two different probes:</p>
|
| 34 |
+
<ul>
|
| 35 |
+
<li><b>Semantic Uncertainty Probe:</b> Predicts the semantic uncertainty of the model's generations.</li>
|
| 36 |
+
<li><b>Accuracy Probe:</b> Predicts the accuracy of the model's generations.</li>
|
| 37 |
+
</ul>
|
| 38 |
+
<p>Please see our paper for more details.</p>
|
| 39 |
"""
|
| 40 |
|
| 41 |
EXAMPLES = [
|
|
|
|
| 108 |
se_highlighted_text = ""
|
| 109 |
acc_highlighted_text = ""
|
| 110 |
|
| 111 |
+
# skip the first hidden state as it is the prompt
|
| 112 |
for i in range(1, len(hidden)):
|
| 113 |
|
| 114 |
# Semantic Uncertainty Probe
|