Spaces:
Sleeping
Sleeping
바뀐 bluechat-v0 에 맞춰 usr, bot 토큰 사용
Browse files- app.py +8 -8
- test.ipynb +18 -27
app.py
CHANGED
|
@@ -15,20 +15,20 @@ def query(message, chat_history, max_turn=4):
|
|
| 15 |
if len(chat_history) > max_turn:
|
| 16 |
chat_history = chat_history[-max_turn:]
|
| 17 |
for user, bot in chat_history:
|
| 18 |
-
prompt.append(f"
|
| 19 |
-
prompt.append(f"
|
| 20 |
|
| 21 |
-
prompt.append(f"
|
| 22 |
-
prompt = "\n".join(prompt) + "\
|
| 23 |
|
| 24 |
output = generator(
|
| 25 |
prompt,
|
| 26 |
-
repetition_penalty=1.3,
|
| 27 |
-
no_repeat_ngram_size=2,
|
| 28 |
eos_token_id=2, # \n
|
| 29 |
-
max_new_tokens=
|
| 30 |
do_sample=True,
|
| 31 |
-
top_p=0.
|
| 32 |
)[0]['generated_text']
|
| 33 |
|
| 34 |
print(output)
|
|
|
|
| 15 |
if len(chat_history) > max_turn:
|
| 16 |
chat_history = chat_history[-max_turn:]
|
| 17 |
for user, bot in chat_history:
|
| 18 |
+
prompt.append(f"<usr> {user}")
|
| 19 |
+
prompt.append(f"<bot> {bot}")
|
| 20 |
|
| 21 |
+
prompt.append(f"<usr> {message}")
|
| 22 |
+
prompt = "\n".join(prompt) + "\n<bot>"
|
| 23 |
|
| 24 |
output = generator(
|
| 25 |
prompt,
|
| 26 |
+
# repetition_penalty=1.3,
|
| 27 |
+
# no_repeat_ngram_size=2,
|
| 28 |
eos_token_id=2, # \n
|
| 29 |
+
max_new_tokens=128,
|
| 30 |
do_sample=True,
|
| 31 |
+
top_p=0.9,
|
| 32 |
)[0]['generated_text']
|
| 33 |
|
| 34 |
print(output)
|
test.ipynb
CHANGED
|
@@ -141,7 +141,7 @@
|
|
| 141 |
},
|
| 142 |
{
|
| 143 |
"cell_type": "code",
|
| 144 |
-
"execution_count":
|
| 145 |
"metadata": {},
|
| 146 |
"outputs": [],
|
| 147 |
"source": [
|
|
@@ -149,54 +149,45 @@
|
|
| 149 |
"def query(prompt, max_turn=4):\n",
|
| 150 |
" output = generator(\n",
|
| 151 |
" prompt.strip(),\n",
|
| 152 |
-
" no_repeat_ngram_size=2,\n",
|
| 153 |
-
" eos_token_id=
|
| 154 |
" max_new_tokens=128,\n",
|
| 155 |
" do_sample=True,\n",
|
| 156 |
-
" top_p=0.
|
|
|
|
| 157 |
" )[0]['generated_text']\n",
|
| 158 |
"\n",
|
| 159 |
" print(output)\n",
|
| 160 |
"\n",
|
| 161 |
-
" response = output[len(prompt):]\n",
|
| 162 |
-
" return response.strip()"
|
| 163 |
]
|
| 164 |
},
|
| 165 |
{
|
| 166 |
"cell_type": "code",
|
| 167 |
-
"execution_count":
|
| 168 |
"metadata": {},
|
| 169 |
"outputs": [
|
| 170 |
-
{
|
| 171 |
-
"name": "stderr",
|
| 172 |
-
"output_type": "stream",
|
| 173 |
-
"text": [
|
| 174 |
-
"/opt/anaconda3/lib/python3.9/site-packages/transformers/generation/utils.py:1186: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use a generation configuration file (see https://huggingface.co/docs/transformers/main_classes/text_generation)\n",
|
| 175 |
-
" warnings.warn(\n"
|
| 176 |
-
]
|
| 177 |
-
},
|
| 178 |
{
|
| 179 |
"name": "stdout",
|
| 180 |
"output_type": "stream",
|
| 181 |
"text": [
|
| 182 |
-
"0 :
|
| 183 |
-
"1 :
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
]
|
| 185 |
-
},
|
| 186 |
-
{
|
| 187 |
-
"data": {
|
| 188 |
-
"text/plain": [
|
| 189 |
-
"'날씨 좋았나요? 날씨가 많이 추우니까 롱패딩 입고 나왔어요~2 : 요즘 너무 추워요 따뜻하게 입으세요! 패딩말고 코트나 니트요~^^3 : 저도 롱패딩 좋아하는데 어제 추워서 좀 슬프네요. 겨울이라서 눈이 자주 오네요~ 오늘은 롱패딩보다는 얇은 패딩을 더 사야겠어요.(코트도 사고 싶은데 사이즈 때문에 망설여지네요~~^^4)패딩은 원래 다 두꺼운 거 샀는데 요즘은 조금 얇은 걸 찾고 있어요~~ 5: 저는 코트랑 패딩 모두 좋아해요~~(패딩이 정말 좋아요.^^ 패딩은 그냥 코트죠...))6 : 저 겨울에 코트 안 사요~! 겨울옷도 많은데 옷을 살 땐 고민 없어요~? 7,8월은 좀 춥겠네요~ 6: 저도 올해 봄'"
|
| 190 |
-
]
|
| 191 |
-
},
|
| 192 |
-
"execution_count": 4,
|
| 193 |
-
"metadata": {},
|
| 194 |
-
"output_type": "execute_result"
|
| 195 |
}
|
| 196 |
],
|
| 197 |
"source": [
|
| 198 |
"query(\"\"\"\n",
|
| 199 |
"0 : 안녕하세요</s>\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
"1 : \n",
|
| 201 |
"\"\"\")"
|
| 202 |
]
|
|
|
|
| 141 |
},
|
| 142 |
{
|
| 143 |
"cell_type": "code",
|
| 144 |
+
"execution_count": 32,
|
| 145 |
"metadata": {},
|
| 146 |
"outputs": [],
|
| 147 |
"source": [
|
|
|
|
| 149 |
"def query(prompt, max_turn=4):\n",
|
| 150 |
" output = generator(\n",
|
| 151 |
" prompt.strip(),\n",
|
| 152 |
+
" # no_repeat_ngram_size=2,\n",
|
| 153 |
+
" eos_token_id=0, # 375=\\n 2=</s>, 0:open-end\n",
|
| 154 |
" max_new_tokens=128,\n",
|
| 155 |
" do_sample=True,\n",
|
| 156 |
+
" top_p=0.7,\n",
|
| 157 |
+
" early_stopping=True\n",
|
| 158 |
" )[0]['generated_text']\n",
|
| 159 |
"\n",
|
| 160 |
" print(output)\n",
|
| 161 |
"\n",
|
| 162 |
+
" # response = output[len(prompt):]\n",
|
| 163 |
+
" # return response.strip()"
|
| 164 |
]
|
| 165 |
},
|
| 166 |
{
|
| 167 |
"cell_type": "code",
|
| 168 |
+
"execution_count": 33,
|
| 169 |
"metadata": {},
|
| 170 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
{
|
| 172 |
"name": "stdout",
|
| 173 |
"output_type": "stream",
|
| 174 |
"text": [
|
| 175 |
+
"0 : 안녕하세요</s>\n",
|
| 176 |
+
"1 : 반가워요</s>\n",
|
| 177 |
+
"0 : 요즘 좋아하는 음악 있으신가요?</s>\n",
|
| 178 |
+
"1 : 최근에 들어서인지 너무 많이 들어요</s>\n",
|
| 179 |
+
"0 : 음 주로 어떤거요?</s>\n",
|
| 180 |
+
"1 : 최근에 들어올린 음악은 무엇인가요?0 : 네 키키 제가 좋아하는 곡은 바로 아이유에요1 : 아 아이유 노래 정말 좋네요0 : 아이유 노래 참 좋아요1 : 아이유 노래 진짜 좋아요0 : 아 진짜 아이유 노래 잘부르세요1 : 네 아이유 노래 좋아요0 : 아이유 노래 진짜 좋죠1 : 아 진짜 좋네요0 : 아이유 노래는 참 좋아요1 : 아이유 노래 정말 좋아요0 : 아이유 노래 정말 좋아요1 : 아이유 노래 정말 좋아요0 : 아이유 노래 진짜 좋아요1 : 아이유 노래 정말 좋아요0 : 아 진짜 좋아요1 : 아 진짜 좋아요0 : 아이유 노래\n"
|
| 181 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
}
|
| 183 |
],
|
| 184 |
"source": [
|
| 185 |
"query(\"\"\"\n",
|
| 186 |
"0 : 안녕하세요</s>\n",
|
| 187 |
+
"1 : 반가워요</s>\n",
|
| 188 |
+
"0 : 요즘 좋아하는 음악 있으신가요?</s>\n",
|
| 189 |
+
"1 : 최근에 들어서인지 너무 많이 들어요</s>\n",
|
| 190 |
+
"0 : 음 주로 어떤거요?</s>\n",
|
| 191 |
"1 : \n",
|
| 192 |
"\"\"\")"
|
| 193 |
]
|