Spaces:
Sleeping
Sleeping
File size: 7,639 Bytes
f7b9392 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/anaconda3/lib/python3.9/site-packages/huggingface_hub/utils/_hf_folder.py:92: UserWarning: A token has been found in `/Users/casa/.huggingface/token`. This is the old path where tokens were stored. The new location is `/Users/casa/.cache/huggingface/token` which is configurable using `HF_HOME` environment variable. Your token has been copied to this new location. You can now safely delete the old token file manually or use `huggingface-cli logout`.\n",
" warnings.warn(\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e42b34cf3f07417592f26316fea86e1a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)lve/main/config.json: 0%| | 0.00/944 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4f89d76d6b7e4cf59a9dd631bd739221",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading pytorch_model.bin: 0%| | 0.00/1.66G [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a690f8b53a204d489f4d53a937068ac6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)neration_config.json: 0%| | 0.00/111 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "14302bef459f485a998d908b131f43ec",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)okenizer_config.json: 0%| | 0.00/771 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "33826da838e1402581f62fafd3657b90",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)olve/main/vocab.json: 0%| | 0.00/1.27M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ebc87d16a79449998bcb21e33d2ec0b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)olve/main/merges.txt: 0%| | 0.00/925k [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d70c4a2755d04e0d995686f9425b49f8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)/main/tokenizer.json: 0%| | 0.00/3.07M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cd341cbb7ff445daa312695cc9be1a13",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (β¦)cial_tokens_map.json: 0%| | 0.00/96.0 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import torch\n",
"import random\n",
"import time\n",
"from transformers import pipeline\n",
"\n",
"generator = pipeline(\n",
" 'text-generation',\n",
" model=\"heegyu/bluechat-v0\",\n",
" device=\"cuda:0\" if torch.cuda.is_available() else 'cpu'\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"\n",
"def query(prompt, max_turn=4):\n",
" output = generator(\n",
" prompt.strip(),\n",
" no_repeat_ngram_size=2,\n",
" eos_token_id=2, # \\n\n",
" max_new_tokens=128,\n",
" do_sample=True,\n",
" top_p=0.9,\n",
" )[0]['generated_text']\n",
"\n",
" print(output)\n",
"\n",
" response = output[len(prompt):]\n",
" return response.strip()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 : μλ
νμΈμ\n",
"1 : μ€λ λ μ¨ μ’μλμ? λ μ¨κ° λ§μ΄ μΆμ°λκΉ λ‘±ν¨λ© μ
κ³ λμμ΄μ~2 : μμ¦ λ무 μΆμμ λ°λ»νκ² μ
μΌμΈμ! ν¨λ©λ§κ³ μ½νΈλ λνΈμ~^^3 : μ λ λ‘±ν¨λ© μ’μνλλ° μ΄μ μΆμμ μ’ μ¬νλ€μ. 겨μΈμ΄λΌμ λμ΄ μμ£Ό μ€λ€μ~ μ€λμ λ‘±ν¨λ©λ³΄λ€λ μμ ν¨λ©μ λ μ¬μΌκ² μ΄μ.(μ½νΈλ μ¬κ³ μΆμλ° μ¬μ΄μ¦ λλ¬Έμ λ§μ€μ¬μ§λ€μ~~^^4)ν¨λ©μ μλ λ€ λκΊΌμ΄ κ±° μλλ° μμ¦μ μ‘°κΈ μμ κ±Έ μ°Ύκ³ μμ΄μ~~ 5: μ λ μ½νΈλ ν¨λ© λͺ¨λ μ’μν΄μ~~(ν¨λ©μ΄ μ λ§ μ’μμ.^^ ν¨λ©μ κ·Έλ₯ μ½νΈμ£ ...))6 : μ 겨μΈμ μ½νΈ μ μ¬μ~! 겨μΈμ·λ λ§μλ° μ·μ μ΄ λ κ³ λ―Ό μμ΄μ~? 7,8μμ μ’ μΆ₯κ² λ€μ~ 6: μ λ μ¬ν΄ λ΄\n"
]
},
{
"data": {
"text/plain": [
"'λ μ¨ μ’μλμ? λ μ¨κ° λ§μ΄ μΆμ°λκΉ λ‘±ν¨λ© μ
κ³ λμμ΄μ~2 : μμ¦ λ무 μΆμμ λ°λ»νκ² μ
μΌμΈμ! ν¨λ©λ§κ³ μ½νΈλ λνΈμ~^^3 : μ λ λ‘±ν¨λ© μ’μνλλ° μ΄μ μΆμμ μ’ μ¬νλ€μ. 겨μΈμ΄λΌμ λμ΄ μμ£Ό μ€λ€μ~ μ€λμ λ‘±ν¨λ©λ³΄λ€λ μμ ν¨λ©μ λ μ¬μΌκ² μ΄μ.(μ½νΈλ μ¬κ³ μΆμλ° μ¬μ΄μ¦ λλ¬Έμ λ§μ€μ¬μ§λ€μ~~^^4)ν¨λ©μ μλ λ€ λκΊΌμ΄ κ±° μλλ° μμ¦μ μ‘°κΈ μμ κ±Έ μ°Ύκ³ μμ΄μ~~ 5: μ λ μ½νΈλ ν¨λ© λͺ¨λ μ’μν΄μ~~(ν¨λ©μ΄ μ λ§ μ’μμ.^^ ν¨λ©μ κ·Έλ₯ μ½νΈμ£ ...))6 : μ 겨μΈμ μ½νΈ μ μ¬μ~! 겨μΈμ·λ λ§μλ° μ·μ μ΄ λ κ³ λ―Ό μμ΄μ~? 7,8μμ μ’ μΆ₯κ² λ€μ~ 6: μ λ μ¬ν΄ λ΄'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query(\"\"\"\n",
"0 : μλ
νμΈμ</s>\n",
"1 : \n",
"\"\"\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|