Spaces:
Sleeping
Sleeping
Add preamble
Browse files
app.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -631,25 +631,46 @@
|
|
631 |
},
|
632 |
{
|
633 |
"cell_type": "code",
|
634 |
-
"execution_count":
|
635 |
"metadata": {},
|
636 |
"outputs": [],
|
637 |
"source": [
|
638 |
"# |export\n",
|
639 |
"title = \"\"\"<h1 align=\"center\">Chatty Language Models</h1>\"\"\"\n",
|
640 |
-
"description = \"\"\"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
641 |
]
|
642 |
},
|
643 |
{
|
644 |
"cell_type": "code",
|
645 |
-
"execution_count":
|
646 |
"metadata": {},
|
647 |
"outputs": [
|
648 |
{
|
649 |
"name": "stdout",
|
650 |
"output_type": "stream",
|
651 |
"text": [
|
652 |
-
"Running on local URL: http://127.0.0.1:
|
653 |
"\n",
|
654 |
"To create a public link, set `share=True` in `launch()`.\n"
|
655 |
]
|
@@ -657,7 +678,7 @@
|
|
657 |
{
|
658 |
"data": {
|
659 |
"text/html": [
|
660 |
-
"<div><iframe src=\"http://127.0.0.1:
|
661 |
],
|
662 |
"text/plain": [
|
663 |
"<IPython.core.display.HTML object>"
|
@@ -670,20 +691,9 @@
|
|
670 |
"data": {
|
671 |
"text/plain": []
|
672 |
},
|
673 |
-
"execution_count":
|
674 |
"metadata": {},
|
675 |
"output_type": "execute_result"
|
676 |
-
},
|
677 |
-
{
|
678 |
-
"name": "stdout",
|
679 |
-
"output_type": "stream",
|
680 |
-
"text": [
|
681 |
-
"The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n",
|
682 |
-
"\n",
|
683 |
-
"Current conversation:\n",
|
684 |
-
"Human: hi\n",
|
685 |
-
"AI:\n"
|
686 |
-
]
|
687 |
}
|
688 |
],
|
689 |
"source": [
|
@@ -746,34 +756,9 @@
|
|
746 |
" label=\"Chat Output\",\n",
|
747 |
" )\n",
|
748 |
"\n",
|
749 |
-
" with gr.Column(scale=1):\n",
|
750 |
-
" chat_input = gr.Textbox(lines=1, label=\"Chat Input\")\n",
|
751 |
-
" chat_input.submit(\n",
|
752 |
-
" inference_chat,\n",
|
753 |
-
" [\n",
|
754 |
-
" model_id,\n",
|
755 |
-
" prompt_template,\n",
|
756 |
-
" chat_input,\n",
|
757 |
-
" temperature,\n",
|
758 |
-
" top_p,\n",
|
759 |
-
" state,\n",
|
760 |
-
" ],\n",
|
761 |
-
" [chatbot, state],\n",
|
762 |
-
" )\n",
|
763 |
-
"\n",
|
764 |
" with gr.Row():\n",
|
765 |
-
"
|
766 |
-
"
|
767 |
-
" lambda: (\"\", [], []),\n",
|
768 |
-
" [],\n",
|
769 |
-
" [chat_input, chatbot, state],\n",
|
770 |
-
" queue=False,\n",
|
771 |
-
" )\n",
|
772 |
-
"\n",
|
773 |
-
" submit_button = gr.Button(\n",
|
774 |
-
" value=\"Submit\", interactive=True, variant=\"primary\"\n",
|
775 |
-
" )\n",
|
776 |
-
" submit_button.click(\n",
|
777 |
" inference_chat,\n",
|
778 |
" [\n",
|
779 |
" model_id,\n",
|
@@ -785,6 +770,31 @@
|
|
785 |
" ],\n",
|
786 |
" [chatbot, state],\n",
|
787 |
" )\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
788 |
"iface.launch()\n"
|
789 |
]
|
790 |
},
|
@@ -807,20 +817,9 @@
|
|
807 |
},
|
808 |
{
|
809 |
"cell_type": "code",
|
810 |
-
"execution_count":
|
811 |
"metadata": {},
|
812 |
-
"outputs": [
|
813 |
-
{
|
814 |
-
"name": "stdout",
|
815 |
-
"output_type": "stream",
|
816 |
-
"text": [
|
817 |
-
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
|
818 |
-
"To disable this warning, you can either:\n",
|
819 |
-
"\t- Avoid using `tokenizers` before the fork if possible\n",
|
820 |
-
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
|
821 |
-
]
|
822 |
-
}
|
823 |
-
],
|
824 |
"source": [
|
825 |
"from nbdev.export import nb_export\n",
|
826 |
"nb_export('app.ipynb', lib_path='.', name='app')"
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 14,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
631 |
},
|
632 |
{
|
633 |
"cell_type": "code",
|
634 |
+
"execution_count": 28,
|
635 |
"metadata": {},
|
636 |
"outputs": [],
|
637 |
"source": [
|
638 |
"# |export\n",
|
639 |
"title = \"\"\"<h1 align=\"center\">Chatty Language Models</h1>\"\"\"\n",
|
640 |
+
"description = \"\"\"Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:\n",
|
641 |
+
"\n",
|
642 |
+
"```\n",
|
643 |
+
"User: <utterance>\n",
|
644 |
+
"Assistant: <utterance>\n",
|
645 |
+
"User: <utterance>\n",
|
646 |
+
"Assistant: <utterance>\n",
|
647 |
+
"...\n",
|
648 |
+
"```\n",
|
649 |
+
"\n",
|
650 |
+
"In this app, you can explore the outputs of several language models conditioned on different conversational prompts. The models are trained on different datasets and have different objectives, so they will have different personalities and strengths.\n",
|
651 |
+
"\n",
|
652 |
+
"So far, the following prompts are available:\n",
|
653 |
+
"\n",
|
654 |
+
"* `langchain_default`: The default prompt used in the [LangChain library](https://github.com/hwchase17/langchain/blob/bc53c928fc1b221d0038b839d111039d31729def/langchain/chains/conversation/prompt.py#L4). Around 67 tokens long.\n",
|
655 |
+
"* `openai_chatgpt`: The prompt used in the OpenAI ChatGPT model. Around 261 tokens long.\n",
|
656 |
+
"* `deepmind_sparrow`: The prompt used in the DeepMind Sparrow model (Table 7 of [their paper](https://arxiv.org/abs/2209.14375)). Around 880 tokens long.\n",
|
657 |
+
"* `deepmind_gopher`: The prompt used in the DeepMind Gopher model (Table A30 of [their paper](https://arxiv.org/abs/2112.11446)). Around 791 tokens long.\n",
|
658 |
+
"* `anthropic_hhh`: The prompt used in the [Anthropic HHH models](https://gist.github.com/jareddk/2509330f8ef3d787fc5aaac67aab5f11#file-hhh_prompt-txt). A whopping 6,341 tokens long!\n",
|
659 |
+
"\n",
|
660 |
+
"As you can see, most of these prompts exceed the maximum context size of models like Flan-T5, so an error usually means the Inference API has timed out.\n",
|
661 |
+
"\"\"\""
|
662 |
]
|
663 |
},
|
664 |
{
|
665 |
"cell_type": "code",
|
666 |
+
"execution_count": 29,
|
667 |
"metadata": {},
|
668 |
"outputs": [
|
669 |
{
|
670 |
"name": "stdout",
|
671 |
"output_type": "stream",
|
672 |
"text": [
|
673 |
+
"Running on local URL: http://127.0.0.1:7867\n",
|
674 |
"\n",
|
675 |
"To create a public link, set `share=True` in `launch()`.\n"
|
676 |
]
|
|
|
678 |
{
|
679 |
"data": {
|
680 |
"text/html": [
|
681 |
+
"<div><iframe src=\"http://127.0.0.1:7867/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
682 |
],
|
683 |
"text/plain": [
|
684 |
"<IPython.core.display.HTML object>"
|
|
|
691 |
"data": {
|
692 |
"text/plain": []
|
693 |
},
|
694 |
+
"execution_count": 29,
|
695 |
"metadata": {},
|
696 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
697 |
}
|
698 |
],
|
699 |
"source": [
|
|
|
756 |
" label=\"Chat Output\",\n",
|
757 |
" )\n",
|
758 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
" with gr.Row():\n",
|
760 |
+
" chat_input = gr.Textbox(lines=1, label=\"Chat Input\")\n",
|
761 |
+
" chat_input.submit(\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
762 |
" inference_chat,\n",
|
763 |
" [\n",
|
764 |
" model_id,\n",
|
|
|
770 |
" ],\n",
|
771 |
" [chatbot, state],\n",
|
772 |
" )\n",
|
773 |
+
"\n",
|
774 |
+
" with gr.Row():\n",
|
775 |
+
" clear_button = gr.Button(value=\"Clear\", interactive=True)\n",
|
776 |
+
" clear_button.click(\n",
|
777 |
+
" lambda: (\"\", [], []),\n",
|
778 |
+
" [],\n",
|
779 |
+
" [chat_input, chatbot, state],\n",
|
780 |
+
" queue=False,\n",
|
781 |
+
" )\n",
|
782 |
+
"\n",
|
783 |
+
" submit_button = gr.Button(\n",
|
784 |
+
" value=\"Submit\", interactive=True, variant=\"primary\"\n",
|
785 |
+
" )\n",
|
786 |
+
" submit_button.click(\n",
|
787 |
+
" inference_chat,\n",
|
788 |
+
" [\n",
|
789 |
+
" model_id,\n",
|
790 |
+
" prompt_template,\n",
|
791 |
+
" chat_input,\n",
|
792 |
+
" temperature,\n",
|
793 |
+
" top_p,\n",
|
794 |
+
" state,\n",
|
795 |
+
" ],\n",
|
796 |
+
" [chatbot, state],\n",
|
797 |
+
" )\n",
|
798 |
"iface.launch()\n"
|
799 |
]
|
800 |
},
|
|
|
817 |
},
|
818 |
{
|
819 |
"cell_type": "code",
|
820 |
+
"execution_count": 15,
|
821 |
"metadata": {},
|
822 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
823 |
"source": [
|
824 |
"from nbdev.export import nb_export\n",
|
825 |
"nb_export('app.ipynb', lib_path='.', name='app')"
|
app.py
CHANGED
@@ -64,7 +64,28 @@ def inference_chat(
|
|
64 |
|
65 |
# %% app.ipynb 12
|
66 |
title = """<h1 align="center">Chatty Language Models</h1>"""
|
67 |
-
description = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
# %% app.ipynb 13
|
70 |
with gr.Blocks(
|
@@ -125,34 +146,9 @@ with gr.Blocks(
|
|
125 |
label="Chat Output",
|
126 |
)
|
127 |
|
128 |
-
with gr.Column(scale=1):
|
129 |
-
chat_input = gr.Textbox(lines=1, label="Chat Input")
|
130 |
-
chat_input.submit(
|
131 |
-
inference_chat,
|
132 |
-
[
|
133 |
-
model_id,
|
134 |
-
prompt_template,
|
135 |
-
chat_input,
|
136 |
-
temperature,
|
137 |
-
top_p,
|
138 |
-
state,
|
139 |
-
],
|
140 |
-
[chatbot, state],
|
141 |
-
)
|
142 |
-
|
143 |
with gr.Row():
|
144 |
-
|
145 |
-
|
146 |
-
lambda: ("", [], []),
|
147 |
-
[],
|
148 |
-
[chat_input, chatbot, state],
|
149 |
-
queue=False,
|
150 |
-
)
|
151 |
-
|
152 |
-
submit_button = gr.Button(
|
153 |
-
value="Submit", interactive=True, variant="primary"
|
154 |
-
)
|
155 |
-
submit_button.click(
|
156 |
inference_chat,
|
157 |
[
|
158 |
model_id,
|
@@ -164,5 +160,30 @@ with gr.Blocks(
|
|
164 |
],
|
165 |
[chatbot, state],
|
166 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
iface.launch()
|
168 |
|
|
|
64 |
|
65 |
# %% app.ipynb 12
|
66 |
title = """<h1 align="center">Chatty Language Models</h1>"""
|
67 |
+
description = """Language models can be conditioned to act like dialogue agents through a conversational prompt that typically takes the form:
|
68 |
+
|
69 |
+
```
|
70 |
+
User: <utterance>
|
71 |
+
Assistant: <utterance>
|
72 |
+
User: <utterance>
|
73 |
+
Assistant: <utterance>
|
74 |
+
...
|
75 |
+
```
|
76 |
+
|
77 |
+
In this app, you can explore the outputs of several language models conditioned on different conversational prompts. The models are trained on different datasets and have different objectives, so they will have different personalities and strengths.
|
78 |
+
|
79 |
+
So far, the following prompts are available:
|
80 |
+
|
81 |
+
* `langchain_default`: The default prompt used in the [LangChain library](https://github.com/hwchase17/langchain/blob/bc53c928fc1b221d0038b839d111039d31729def/langchain/chains/conversation/prompt.py#L4). Around 67 tokens long.
|
82 |
+
* `openai_chatgpt`: The prompt used in the OpenAI ChatGPT model. Around 261 tokens long.
|
83 |
+
* `deepmind_sparrow`: The prompt used in the DeepMind Sparrow model (Table 7 of [their paper](https://arxiv.org/abs/2209.14375)). Around 880 tokens long.
|
84 |
+
* `deepmind_gopher`: The prompt used in the DeepMind Gopher model (Table A30 of [their paper](https://arxiv.org/abs/2112.11446)). Around 791 tokens long.
|
85 |
+
* `anthropic_hhh`: The prompt used in the [Anthropic HHH models](https://gist.github.com/jareddk/2509330f8ef3d787fc5aaac67aab5f11#file-hhh_prompt-txt). A whopping 6,341 tokens long!
|
86 |
+
|
87 |
+
As you can see, most of these prompts exceed the maximum context size of models like Flan-T5, so an error usually means the Inference API has timed out.
|
88 |
+
"""
|
89 |
|
90 |
# %% app.ipynb 13
|
91 |
with gr.Blocks(
|
|
|
146 |
label="Chat Output",
|
147 |
)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
with gr.Row():
|
150 |
+
chat_input = gr.Textbox(lines=1, label="Chat Input")
|
151 |
+
chat_input.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
inference_chat,
|
153 |
[
|
154 |
model_id,
|
|
|
160 |
],
|
161 |
[chatbot, state],
|
162 |
)
|
163 |
+
|
164 |
+
with gr.Row():
|
165 |
+
clear_button = gr.Button(value="Clear", interactive=True)
|
166 |
+
clear_button.click(
|
167 |
+
lambda: ("", [], []),
|
168 |
+
[],
|
169 |
+
[chat_input, chatbot, state],
|
170 |
+
queue=False,
|
171 |
+
)
|
172 |
+
|
173 |
+
submit_button = gr.Button(
|
174 |
+
value="Submit", interactive=True, variant="primary"
|
175 |
+
)
|
176 |
+
submit_button.click(
|
177 |
+
inference_chat,
|
178 |
+
[
|
179 |
+
model_id,
|
180 |
+
prompt_template,
|
181 |
+
chat_input,
|
182 |
+
temperature,
|
183 |
+
top_p,
|
184 |
+
state,
|
185 |
+
],
|
186 |
+
[chatbot, state],
|
187 |
+
)
|
188 |
iface.launch()
|
189 |
|