Spaces:
Runtime error
Runtime error
[update]edit main
Browse files
main.py
CHANGED
@@ -34,114 +34,19 @@ def get_args():
|
|
34 |
|
35 |
|
36 |
description = """
|
37 |
-
##
|
38 |
|
39 |
-
基于 [
|
40 |
-
|
41 |
-
该分类任务有一百多个类别, 但标注数据总是只有 3 万, 并且有一半是 "无关领域", 实现思路是:
|
42 |
-
1. 首先采用传统算法做硬分类, 然后提取概率 top 10 的标签.
|
43 |
-
2. 将 top 10 的标签作为候选标签, 并为每个标签提供一个句子示例.
|
44 |
-
3. 要求 LLM 输出目标句子的类别.
|
45 |
-
|
46 |
-
Gradio 布署代码参考了: https://huggingface.co/spaces/aodianyun/ChatGLM-6B
|
47 |
|
|
|
|
|
48 |
"""
|
49 |
|
50 |
|
51 |
examples = [
|
52 |
-
""
|
53 |
-
|
54 |
-
|
55 |
-
如果你认为给定的句子不属于这些意图中的任务一个, 你可以回答: 不知道.
|
56 |
-
|
57 |
-
Tips:
|
58 |
-
1. 如果候选意图中有 "无关领域", 当你不知道时, 则它有可能属于无关领域.
|
59 |
-
|
60 |
-
|
61 |
-
Examples:
|
62 |
-
|
63 |
-
---------
|
64 |
-
|
65 |
-
ExampleSentence: 其实不是
|
66 |
-
ExampleIntent: 否定(不是)
|
67 |
-
|
68 |
-
ExampleSentence: 嗯!嘿嘿!早点休息,晚安咯
|
69 |
-
ExampleIntent: 礼貌用语
|
70 |
-
|
71 |
-
ExampleSentence: 没问诶
|
72 |
-
ExampleIntent: 否定答复
|
73 |
-
|
74 |
-
ExampleSentence: 不好意思都需要谢谢
|
75 |
-
ExampleIntent: 肯定(需要)
|
76 |
-
|
77 |
-
ExampleSentence: 对呀我在忙
|
78 |
-
ExampleIntent: 用户正忙
|
79 |
-
|
80 |
-
ExampleSentence: 。嗯也也不需要吧唉呀现在不需要那个啊嗯
|
81 |
-
ExampleIntent: 否定(不需要)
|
82 |
-
|
83 |
-
ExampleSentence: 我的处理器需要很少的电源。
|
84 |
-
ExampleIntent: 无关领域
|
85 |
-
|
86 |
-
ExampleSentence: 。呃我好像没有在太平洋买过保险,吧拜拜
|
87 |
-
ExampleIntent: 否定(没有)
|
88 |
-
|
89 |
-
ExampleSentence: 嗯不用谢谢
|
90 |
-
ExampleIntent: 否定(不用了)
|
91 |
-
|
92 |
-
ExampleSentence: 费用贵。
|
93 |
-
ExampleIntent: 价格太高
|
94 |
-
|
95 |
-
---------
|
96 |
-
|
97 |
-
Sentence: 。嗯各位不需要,啊谢谢
|
98 |
-
Intent:""",
|
99 |
-
"""我们在做电话营销场景的意图识别任务, 可选的意图如下:
|
100 |
-
语音信箱; 无关领域; 查物品信息; 污言秽语; 疑问(时间); 疑问(数值); 答时间; 查收费方式; 价格太高; 答数值
|
101 |
|
102 |
-
如果你认为给定的句子不属于这些意图中的任务一个, 你可以回答: 不知道.
|
103 |
-
|
104 |
-
Tips:
|
105 |
-
1. 如果候选意图中有 "无关领域", 当你不知道时, 则它有可能属于无关领域.
|
106 |
-
|
107 |
-
|
108 |
-
Examples:
|
109 |
-
---------
|
110 |
-
|
111 |
-
ExampleSentence: 我们留言。
|
112 |
-
ExampleIntent: 语音信箱
|
113 |
-
|
114 |
-
ExampleSentence: 很刚刚打
|
115 |
-
ExampleIntent: 无关领域
|
116 |
-
|
117 |
-
ExampleSentence: 什么东西我听
|
118 |
-
ExampleIntent: 查物品信息
|
119 |
-
|
120 |
-
ExampleSentence: 知道!AV女优!日本人的骄傲!
|
121 |
-
ExampleIntent: 污言秽语
|
122 |
-
|
123 |
-
ExampleSentence: 最后期限
|
124 |
-
ExampleIntent: 疑问(时间)
|
125 |
-
|
126 |
-
ExampleSentence: 一共借了多少钱
|
127 |
-
ExampleIntent: 疑问(数值)
|
128 |
-
|
129 |
-
ExampleSentence: 22号
|
130 |
-
ExampleIntent: 答时间
|
131 |
-
|
132 |
-
ExampleSentence: 运费
|
133 |
-
ExampleIntent: 查收费方式
|
134 |
-
|
135 |
-
ExampleSentence: 利息高
|
136 |
-
ExampleIntent: 价格太高
|
137 |
-
|
138 |
-
ExampleSentence: 20。
|
139 |
-
ExampleIntent: 答数值
|
140 |
-
|
141 |
-
---------
|
142 |
-
|
143 |
-
Sentence: 。对啊什么东西啊我6月份出来的
|
144 |
-
Intent:"""
|
145 |
]
|
146 |
|
147 |
|
@@ -175,20 +80,26 @@ def main():
|
|
175 |
)
|
176 |
model = model.eval()
|
177 |
|
178 |
-
def fn(inputs
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
182 |
with torch.no_grad():
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
with gr.Blocks() as blocks:
|
188 |
gr.Markdown(value=description)
|
189 |
|
190 |
-
state = gr.State([])
|
191 |
-
|
192 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
|
193 |
with gr.Row():
|
194 |
with gr.Column(scale=4):
|
@@ -198,8 +109,8 @@ def main():
|
|
198 |
|
199 |
gr.Examples(examples, text)
|
200 |
|
201 |
-
text.submit(fn, [text
|
202 |
-
button.click(fn, [text
|
203 |
|
204 |
blocks.queue().launch()
|
205 |
|
|
|
34 |
|
35 |
|
36 |
description = """
|
37 |
+
## Qwen-7B
|
38 |
|
39 |
+
基于 [Qwen-7B](https://huggingface.co/qgyd2021/Qwen-7B) 模型, 在 [chinese_modern_poetry](https://huggingface.co/datasets/Iess/chinese_modern_poetry) 的 prompt 数据集上训练.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
可用于生成现代诗. 如下:
|
42 |
+
使用下列意象写一首现代诗:智慧,刀刃
|
43 |
"""
|
44 |
|
45 |
|
46 |
examples = [
|
47 |
+
"使用下列意象写一首现代诗:石头,森林",
|
48 |
+
"使用下列意象写一首现代诗:花,纱布"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
]
|
51 |
|
52 |
|
|
|
80 |
)
|
81 |
model = model.eval()
|
82 |
|
83 |
+
def fn(inputs: str):
|
84 |
+
input_ids = tokenizer(
|
85 |
+
inputs,
|
86 |
+
return_tensors="pt",
|
87 |
+
add_special_tokens=False,
|
88 |
+
).input_ids.to(args.device)
|
89 |
with torch.no_grad():
|
90 |
+
outputs = model.generate(
|
91 |
+
input_ids=input_ids, max_new_tokens=args.max_new_tokens, do_sample=True,
|
92 |
+
top_p=args.top_p, temperature=args.temperature, repetition_penalty=args.repetition_penalty,
|
93 |
+
eos_token_id=tokenizer.eos_token_id
|
94 |
+
)
|
95 |
+
outputs = outputs.tolist()[0][len(input_ids[0]):]
|
96 |
+
response = tokenizer.decode(outputs)
|
97 |
+
response = response.strip().replace(tokenizer.eos_token, "").strip()
|
98 |
+
return response
|
99 |
|
100 |
with gr.Blocks() as blocks:
|
101 |
gr.Markdown(value=description)
|
102 |
|
|
|
|
|
103 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
|
104 |
with gr.Row():
|
105 |
with gr.Column(scale=4):
|
|
|
109 |
|
110 |
gr.Examples(examples, text)
|
111 |
|
112 |
+
text.submit(fn, [text], [chatbot])
|
113 |
+
button.click(fn, [text], [chatbot])
|
114 |
|
115 |
blocks.queue().launch()
|
116 |
|