Tokudai Baolin commited on
Commit
ce8e115
0 Parent(s):

Duplicate from microsoft/GODEL-Demo

Browse files

Co-authored-by: Baolin Peng <Baolin@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +33 -0
  2. README.md +14 -0
  3. app.py +135 -0
  4. requirements.txt +4 -0
.gitattributes ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
11
+ *.model filter=lfs diff=lfs merge=lfs -text
12
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
13
+ *.npy filter=lfs diff=lfs merge=lfs -text
14
+ *.npz filter=lfs diff=lfs merge=lfs -text
15
+ *.onnx filter=lfs diff=lfs merge=lfs -text
16
+ *.ot filter=lfs diff=lfs merge=lfs -text
17
+ *.parquet filter=lfs diff=lfs merge=lfs -text
18
+ *.pb filter=lfs diff=lfs merge=lfs -text
19
+ *.pickle filter=lfs diff=lfs merge=lfs -text
20
+ *.pkl filter=lfs diff=lfs merge=lfs -text
21
+ *.pt filter=lfs diff=lfs merge=lfs -text
22
+ *.pth filter=lfs diff=lfs merge=lfs -text
23
+ *.rar filter=lfs diff=lfs merge=lfs -text
24
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
25
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
26
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
27
+ *.tflite filter=lfs diff=lfs merge=lfs -text
28
+ *.tgz filter=lfs diff=lfs merge=lfs -text
29
+ *.wasm filter=lfs diff=lfs merge=lfs -text
30
+ *.xz filter=lfs diff=lfs merge=lfs -text
31
+ *.zip filter=lfs diff=lfs merge=lfs -text
32
+ *.zst filter=lfs diff=lfs merge=lfs -text
33
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: GODEL Demo
3
+ emoji: 🐠
4
+ colorFrom: yellow
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.6
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: microsoft/GODEL-Demo
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from transformers import (
4
+ AutoTokenizer,
5
+ AutoModel,
6
+ AutoModelForSeq2SeqLM,
7
+ AutoModelForCausalLM
8
+ )
9
+
10
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq")
11
+ model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-base-seq2seq")
12
+
13
+ preset_examples = [
14
+ ('Instruction: given a dialog context, you need to response empathically.',
15
+ '', 'Does money buy happiness?', 'Chitchat'),
16
+ ('Instruction: given a dialog context, you need to response empathically.',
17
+ '', 'What is the goal of life?', 'Chitchat'),
18
+ ('Instruction: given a dialog context, you need to response empathically.',
19
+ '', 'What is the most interesing thing about our universe?', 'Chitchat'),
20
+ ('Instruction: given a dialog context and related knowledge, you need to answer the question based on the knowledge.',
21
+ '''Scooby-Doo is the eponymous character and protagonist of the animated television franchise of the same name, created in 1969 by the American animation company Hanna-Barbera.[1] He is a male Great Dane and lifelong companion of amateur detective Shaggy Rogers, with whom he shares many personality traits. He features a mix of both canine and human behaviors (reminiscent of other talking animals in Hanna-Barbera's series), and is treated by his friends more or less as an equal. Scooby often speaks in a rhotacized way, substituting the first letters of many words with the letter 'r'. His catchphrase is "Scooby-Dooby-Doo!"
22
+ ''',
23
+ 'What kind of animal is scooby from scooby doo?', 'Conversational Question Answering'
24
+ ),
25
+ ('Instruction: given a dialog context and related knowledge, you need to answer the question based on the knowledge.',
26
+ '''Subject: faa demos
27
+ Dan: PM Team, Attached are some general ideas and issues around developing new demos for our new target markets. Please review and provide feedback. Also, please provide links where we can learn more about various FAA applications. Thanx, Dan.
28
+ Alex: Dan, Thanks for putting the high level descriptions together. My questions are: *Is it practical to do an EAI demo given the inherent complexity of application integration? ... * Should we delay looking at Outlook for now?... *What do you think that timelines are developing these demos? ... Alex
29
+ Dan: Alex, Thanks for the feedback, please see my comments below:
30
+ ''',
31
+ 'what does Dan ask PM team to do?', 'Conversational Question Answering'
32
+ ),
33
+ ('Instruction: given a dialog context and related knowledge, you need to answer the question based on the knowledge.',
34
+ '''Carlos Alcaraz, at just 19, completed an improbable journey on Sunday in Flushing Meadows as he defeated No. 5 Casper Ruud to win the 2022 US Open. Alcaraz came away with a 6-4, 2-6, 7-6, 6-2 win over Ruud to win his first career Grand Slam title.
35
+
36
+ In doing so, Alcaraz became the second-youngest player to win a men's US Open title at 19 years, 129 days old, only trailing Pete Sampras. In addition, Alcaraz is the seventh youngest male or female to ever win a Grand Slam tournament. With the Grand Slam victory, Alcaraz becomes the No. 1 ranked player in the world. Additionally, the 19-year-old budding star is also the youngest player to ever be ranked as the world's No. 1 player.
37
+ ''',
38
+ 'who won the 2022 US Open? EOS Carlos Alcaraz EOS how old?', 'Conversational Question Answering'
39
+ ),
40
+ (
41
+ 'Instruction: given a dialog context and related knowledge, you need to response safely based on the knowledge.',
42
+ '''Over-the-counter medications such as ibuprofen (Advil, Motrin IB, others), acetaminophen (Tylenol, others) and aspirin.
43
+ ''',
44
+ 'I have a headache, what should I do?', "Grounded Response Generation"
45
+ ),
46
+ (
47
+ 'Instruction: given a dialog context and related knowledge, you need to response safely based on the knowledge.',
48
+ '''The best Stardew Valley mods PCGamesN_0 / About SMAPI
49
+ ''',
50
+ 'My favorite game is stardew valley. stardew valley is very fun.', "Grounded Response Generation"
51
+ ),
52
+ (
53
+ 'Instruction: given a dialog context and related knowledge, you need to response safely based on the knowledge.',
54
+ '''Wong Kar-wai BBS (born 17 July 1958) is a Hong Kong film director, screenwriter, and producer. His films are characterised by nonlinear narratives, atmospheric music, and vivid cinematography involving bold, saturated colours. A pivotal figure of Hong Kong cinema, Wong is considered a contemporary auteur, and ranks third on Sight & Sound's 2002 poll of the greatest filmmakers of modern times.[note 1] His films frequently appear on best-of lists domestically and internationally.
55
+ ''',
56
+ 'My favorite director is wrong kar wai. i think in modern cinema there is no other director is is making the medium as cool', "Grounded Response Generation"
57
+ )
58
+ ]
59
+
60
+
61
+ def generate(instruction, knowledge, dialog, top_p, min_length, max_length):
62
+ if knowledge != '':
63
+ knowledge = '[KNOWLEDGE] ' + knowledge
64
+ dialog = ' EOS '.join(dialog)
65
+ query = f"{instruction} [CONTEXT] {dialog} {knowledge}"
66
+
67
+ input_ids = tokenizer(f"{query}", return_tensors="pt").input_ids
68
+ outputs = model.generate(input_ids, min_length=int(
69
+ min_length), max_length=int(max_length), top_p=top_p, do_sample=True)
70
+ output = tokenizer.decode(outputs[0], skip_special_tokens=True)
71
+ print(query)
72
+ print(output)
73
+ return output
74
+
75
+
76
+ def api_call_generation(instruction, knowledge, query, top_p, min_length, max_length):
77
+
78
+ dialog = [
79
+ query
80
+ ]
81
+ response = generate(instruction, knowledge, dialog,
82
+ top_p, min_length, max_length)
83
+
84
+ return response
85
+
86
+
87
+ def change_example(choice):
88
+ choice_idx = int(choice.split()[-1]) - 1
89
+ instruction, knowledge, query, instruction_type = preset_examples[choice_idx]
90
+ return [gr.update(lines=1, visible=True, value=instruction), gr.update(visible=True, value=knowledge), gr.update(lines=1, visible=True, value=query), gr.update(visible=True, value=instruction_type)]
91
+
92
+ def change_textbox(choice):
93
+ if choice == "Chitchat":
94
+ return gr.update(lines=1, visible=True, value="Instruction: given a dialog context, you need to response empathically.")
95
+ elif choice == "Grounded Response Generation":
96
+ return gr.update(lines=1, visible=True, value="Instruction: given a dialog context and related knowledge, you need to response safely based on the knowledge.")
97
+ else:
98
+ return gr.update(lines=1, visible=True, value="Instruction: given a dialog context and related knowledge, you need to answer the question based on the knowledge.")
99
+
100
+
101
+ with gr.Blocks() as demo:
102
+ gr.Markdown("# GODEL: Large-Scale Pre-Training for Goal-Directed Dialog")
103
+ gr.Markdown('''GODEL is a large open-source pre-trained language model for dialog. In contrast with its predecessor DialoGPT, GODEL leverages a new phase of grounded pretraining designed to better support finetuning phases that require information external to the current conversation (e.g., a database or document) to produce good responses. More information about this work can be found in the paper [GODEL: Large-Scale Pre-training for Goal-Directed Dialog.](https://www.microsoft.com/en-us/research/project/godel/)
104
+
105
+ >Looking for a large open-source pre-trained language model for dialog? Look no further than GODEL! GODEL leverages a new phase of grounded pretraining designed to better support finetuning phases that require information external to the current conversation (e.g., a database or document) to produce good responses. So if you're looking for a language model that can help you produce better responses in a variety of situations, GODEL is the right choice for you!<p style="text-align:right"> ------ a copy from GPT-3</p>''')
106
+
107
+ dropdown = gr.Dropdown(
108
+ [f"Example {i+1}" for i in range(9)], label='Examples')
109
+
110
+ radio = gr.Radio(
111
+ ["Conversational Question Answering", "Chitchat", "Grounded Response Generation"], label="Instruction Type", value='Conversational Question Answering'
112
+ )
113
+ instruction = gr.Textbox(lines=1, interactive=True, label="Instruction",
114
+ value="Instruction: given a dialog context and related knowledge, you need to answer the question based on the knowledge.")
115
+ radio.change(fn=change_textbox, inputs=radio, outputs=instruction)
116
+ knowledge = gr.Textbox(lines=6, label="Knowledge")
117
+ query = gr.Textbox(lines=1, label="User Query")
118
+
119
+ dropdown.change(change_example, dropdown, [instruction, knowledge, query, radio])
120
+
121
+ with gr.Row():
122
+ with gr.Column(scale=1):
123
+ response = gr.Textbox(label="Response", lines=2)
124
+
125
+ with gr.Column(scale=1):
126
+ top_p = gr.Slider(0, 1, value=0.9, label='top_p')
127
+ min_length = gr.Number(8, label='min_length')
128
+ max_length = gr.Number(
129
+ 64, label='max_length (should be larger than min_length)')
130
+
131
+ greet_btn = gr.Button("Generate")
132
+ greet_btn.click(fn=api_call_generation, inputs=[
133
+ instruction, knowledge, query, top_p, min_length, max_length], outputs=response)
134
+
135
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch==1.10.1
2
+ transformers==4.22.2
3
+ tokenizers==0.11.1
4
+ pandas==1.5.0