Instructions to use eunyounglee/mBART_translator_json_all_2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eunyounglee/mBART_translator_json_all_2 with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("eunyounglee/mBART_translator_json_all_2") model = AutoModelForSeq2SeqLM.from_pretrained("eunyounglee/mBART_translator_json_all_2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
b02b709
1
Parent(s): a7fd7c4
update model card README.md
Browse files- .ipynb_checkpoints/Untitled-checkpoint.ipynb +0 -6
- README.md +62 -0
- Untitled.ipynb +0 -558
.ipynb_checkpoints/Untitled-checkpoint.ipynb
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [],
|
| 3 |
-
"metadata": {},
|
| 4 |
-
"nbformat": 4,
|
| 5 |
-
"nbformat_minor": 5
|
| 6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- generated_from_trainer
|
| 4 |
+
metrics:
|
| 5 |
+
- bleu
|
| 6 |
+
model-index:
|
| 7 |
+
- name: mBART_translator_json_all_2
|
| 8 |
+
results: []
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 12 |
+
should probably proofread and complete it, then remove this comment. -->
|
| 13 |
+
|
| 14 |
+
# mBART_translator_json_all_2
|
| 15 |
+
|
| 16 |
+
This model is a fine-tuned version of [facebook/mbart-large-cc25](https://huggingface.co/facebook/mbart-large-cc25) on the None dataset.
|
| 17 |
+
It achieves the following results on the evaluation set:
|
| 18 |
+
- Loss: 0.1595
|
| 19 |
+
- Bleu: 76.137
|
| 20 |
+
- Gen Len: 11.966
|
| 21 |
+
|
| 22 |
+
## Model description
|
| 23 |
+
|
| 24 |
+
More information needed
|
| 25 |
+
|
| 26 |
+
## Intended uses & limitations
|
| 27 |
+
|
| 28 |
+
More information needed
|
| 29 |
+
|
| 30 |
+
## Training and evaluation data
|
| 31 |
+
|
| 32 |
+
More information needed
|
| 33 |
+
|
| 34 |
+
## Training procedure
|
| 35 |
+
|
| 36 |
+
### Training hyperparameters
|
| 37 |
+
|
| 38 |
+
The following hyperparameters were used during training:
|
| 39 |
+
- learning_rate: 5e-05
|
| 40 |
+
- train_batch_size: 4
|
| 41 |
+
- eval_batch_size: 4
|
| 42 |
+
- seed: 42
|
| 43 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
| 44 |
+
- lr_scheduler_type: linear
|
| 45 |
+
- num_epochs: 3
|
| 46 |
+
- mixed_precision_training: Native AMP
|
| 47 |
+
|
| 48 |
+
### Training results
|
| 49 |
+
|
| 50 |
+
| Training Loss | Epoch | Step | Validation Loss | Bleu | Gen Len |
|
| 51 |
+
|:-------------:|:-----:|:----:|:---------------:|:-------:|:-------:|
|
| 52 |
+
| 1.914 | 1.0 | 2908 | 0.7158 | 26.1202 | 44.2761 |
|
| 53 |
+
| 0.948 | 2.0 | 5816 | 0.3113 | 74.3952 | 12.4625 |
|
| 54 |
+
| 0.5552 | 3.0 | 8724 | 0.1595 | 76.137 | 11.966 |
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
### Framework versions
|
| 58 |
+
|
| 59 |
+
- Transformers 4.17.0
|
| 60 |
+
- Pytorch 1.12.0
|
| 61 |
+
- Datasets 1.18.3
|
| 62 |
+
- Tokenizers 0.11.0
|
Untitled.ipynb
DELETED
|
@@ -1,558 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": null,
|
| 6 |
-
"id": "8f8a2b2c-8606-4217-85bf-b5e7b737acbd",
|
| 7 |
-
"metadata": {},
|
| 8 |
-
"outputs": [],
|
| 9 |
-
"source": []
|
| 10 |
-
},
|
| 11 |
-
{
|
| 12 |
-
"cell_type": "code",
|
| 13 |
-
"execution_count": 9,
|
| 14 |
-
"id": "3c797ac5-85bc-483e-82b1-331d8a10581c",
|
| 15 |
-
"metadata": {
|
| 16 |
-
"id": "X78SICZhiOU5"
|
| 17 |
-
},
|
| 18 |
-
"outputs": [
|
| 19 |
-
{
|
| 20 |
-
"ename": "AttributeError",
|
| 21 |
-
"evalue": "'collections.OrderedDict' object has no attribute 'to'",
|
| 22 |
-
"output_type": "error",
|
| 23 |
-
"traceback": [
|
| 24 |
-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 25 |
-
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
| 26 |
-
"Input \u001b[1;32mIn [9]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m model \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mload(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpytorch_model.bin\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 2\u001b[0m device \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mdevice(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcuda\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m----> 3\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto\u001b[49m(device)\n\u001b[0;32m 4\u001b[0m model\u001b[38;5;241m.\u001b[39meval()\n",
|
| 27 |
-
"\u001b[1;31mAttributeError\u001b[0m: 'collections.OrderedDict' object has no attribute 'to'"
|
| 28 |
-
]
|
| 29 |
-
}
|
| 30 |
-
],
|
| 31 |
-
"source": [
|
| 32 |
-
"model = torch.load('pytorch_model.bin')\n",
|
| 33 |
-
"device = torch.device(\"cuda\")\n",
|
| 34 |
-
"model.to(device)\n",
|
| 35 |
-
"model.eval()"
|
| 36 |
-
]
|
| 37 |
-
},
|
| 38 |
-
{
|
| 39 |
-
"cell_type": "markdown",
|
| 40 |
-
"id": "d738795b-24af-4194-ae57-d757fc2dbfb8",
|
| 41 |
-
"metadata": {
|
| 42 |
-
"id": "ZOitQbWQBUF0"
|
| 43 |
-
},
|
| 44 |
-
"source": [
|
| 45 |
-
"# Get the Score"
|
| 46 |
-
]
|
| 47 |
-
},
|
| 48 |
-
{
|
| 49 |
-
"cell_type": "code",
|
| 50 |
-
"execution_count": 1,
|
| 51 |
-
"id": "b3613c9c-a5d3-44b3-947f-21ffad526c7d",
|
| 52 |
-
"metadata": {
|
| 53 |
-
"id": "Xm580mBbBhpe"
|
| 54 |
-
},
|
| 55 |
-
"outputs": [],
|
| 56 |
-
"source": [
|
| 57 |
-
"import torch"
|
| 58 |
-
]
|
| 59 |
-
},
|
| 60 |
-
{
|
| 61 |
-
"cell_type": "code",
|
| 62 |
-
"execution_count": 2,
|
| 63 |
-
"id": "8b63ea65-0ce7-43f8-8799-9e73d776898e",
|
| 64 |
-
"metadata": {
|
| 65 |
-
"id": "IsCCLx1uBjcZ"
|
| 66 |
-
},
|
| 67 |
-
"outputs": [],
|
| 68 |
-
"source": [
|
| 69 |
-
"device = torch.device(\"cuda\") # if torch.cuda.is_available() else \"cpu\")"
|
| 70 |
-
]
|
| 71 |
-
},
|
| 72 |
-
{
|
| 73 |
-
"cell_type": "code",
|
| 74 |
-
"execution_count": 3,
|
| 75 |
-
"id": "6ffcb2f2-fb2e-42f9-a16c-1b9b1cfdc32a",
|
| 76 |
-
"metadata": {
|
| 77 |
-
"colab": {
|
| 78 |
-
"base_uri": "https://localhost:8080/"
|
| 79 |
-
},
|
| 80 |
-
"id": "qBRxA4mTBke8",
|
| 81 |
-
"outputId": "75886e1c-cefd-432e-f681-dcc2ae268369"
|
| 82 |
-
},
|
| 83 |
-
"outputs": [
|
| 84 |
-
{
|
| 85 |
-
"ename": "NameError",
|
| 86 |
-
"evalue": "name 'model' is not defined",
|
| 87 |
-
"output_type": "error",
|
| 88 |
-
"traceback": [
|
| 89 |
-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 90 |
-
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
| 91 |
-
"Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[0;32m 2\u001b[0m model\u001b[38;5;241m.\u001b[39meval()\n",
|
| 92 |
-
"\u001b[1;31mNameError\u001b[0m: name 'model' is not defined"
|
| 93 |
-
]
|
| 94 |
-
}
|
| 95 |
-
],
|
| 96 |
-
"source": [
|
| 97 |
-
"model.to(device)\n",
|
| 98 |
-
"model.eval()"
|
| 99 |
-
]
|
| 100 |
-
},
|
| 101 |
-
{
|
| 102 |
-
"cell_type": "code",
|
| 103 |
-
"execution_count": 12,
|
| 104 |
-
"id": "c956811c-b2e6-4601-b737-1fd09d49cc3c",
|
| 105 |
-
"metadata": {
|
| 106 |
-
"id": "y7eiuqiJB8mW",
|
| 107 |
-
"tags": []
|
| 108 |
-
},
|
| 109 |
-
"outputs": [],
|
| 110 |
-
"source": [
|
| 111 |
-
"from torch.utils.data import Dataset, DataLoader\n",
|
| 112 |
-
"\n",
|
| 113 |
-
"class DatasetRetriever(Dataset):\n",
|
| 114 |
-
" def __init__(self, features):\n",
|
| 115 |
-
" super(DatasetRetriever, self).__init__()\n",
|
| 116 |
-
" self.features = features\n",
|
| 117 |
-
"\n",
|
| 118 |
-
" def __len__(self):\n",
|
| 119 |
-
" return len(self.features)\n",
|
| 120 |
-
" \n",
|
| 121 |
-
" def __getitem__(self, index): \n",
|
| 122 |
-
" feature = self.features[index]\n",
|
| 123 |
-
" max_target_length = 50\n",
|
| 124 |
-
" embedding = tokenizer(feature, max_length=max_target_length, truncation=True)\n",
|
| 125 |
-
" # embedding = tokenizer(feature, truncation=True, max_length=512, return_attention_mask=False, return_token_type_ids=False)\n",
|
| 126 |
-
" return {'input_ids' : embedding['input_ids']}"
|
| 127 |
-
]
|
| 128 |
-
},
|
| 129 |
-
{
|
| 130 |
-
"cell_type": "code",
|
| 131 |
-
"execution_count": 13,
|
| 132 |
-
"id": "e01fe9fe-4b44-4730-aa13-6b59f6811c4d",
|
| 133 |
-
"metadata": {},
|
| 134 |
-
"outputs": [
|
| 135 |
-
{
|
| 136 |
-
"name": "stdout",
|
| 137 |
-
"output_type": "stream",
|
| 138 |
-
"text": [
|
| 139 |
-
"903\n"
|
| 140 |
-
]
|
| 141 |
-
}
|
| 142 |
-
],
|
| 143 |
-
"source": [
|
| 144 |
-
"import pandas as pd\n",
|
| 145 |
-
"original = pd.read_csv(\"./DeepLoading/Slang/slang_dataframe.csv\")\n",
|
| 146 |
-
"print(len(original)) "
|
| 147 |
-
]
|
| 148 |
-
},
|
| 149 |
-
{
|
| 150 |
-
"cell_type": "code",
|
| 151 |
-
"execution_count": 14,
|
| 152 |
-
"id": "3b36ede5-546e-4b89-9b0f-c942224fb6b2",
|
| 153 |
-
"metadata": {
|
| 154 |
-
"id": "0YJZuvMCYYUg"
|
| 155 |
-
},
|
| 156 |
-
"outputs": [],
|
| 157 |
-
"source": [
|
| 158 |
-
"test_slang, test_answer = [], []\n",
|
| 159 |
-
"for i in range(100):\n",
|
| 160 |
-
" test_slang.append(original['slang'][i])\n",
|
| 161 |
-
" test_answer.append(original['standard'][i])"
|
| 162 |
-
]
|
| 163 |
-
},
|
| 164 |
-
{
|
| 165 |
-
"cell_type": "code",
|
| 166 |
-
"execution_count": 15,
|
| 167 |
-
"id": "a5e50a50-ce56-41f2-918e-9516e3162f73",
|
| 168 |
-
"metadata": {
|
| 169 |
-
"id": "Ffd1xDXsCBMU"
|
| 170 |
-
},
|
| 171 |
-
"outputs": [],
|
| 172 |
-
"source": [
|
| 173 |
-
"test_dataset = DatasetRetriever(test_slang)"
|
| 174 |
-
]
|
| 175 |
-
},
|
| 176 |
-
{
|
| 177 |
-
"cell_type": "code",
|
| 178 |
-
"execution_count": 16,
|
| 179 |
-
"id": "67a2e271-4d04-42c9-8c8b-0fd554aa0ea0",
|
| 180 |
-
"metadata": {
|
| 181 |
-
"colab": {
|
| 182 |
-
"base_uri": "https://localhost:8080/"
|
| 183 |
-
},
|
| 184 |
-
"id": "xQDf51qIYkeu",
|
| 185 |
-
"outputId": "547c9f14-b31d-4e0e-f68c-ae03dceeeedd"
|
| 186 |
-
},
|
| 187 |
-
"outputs": [
|
| 188 |
-
{
|
| 189 |
-
"data": {
|
| 190 |
-
"text/plain": [
|
| 191 |
-
"<__main__.DatasetRetriever at 0x1e9dd5ceee0>"
|
| 192 |
-
]
|
| 193 |
-
},
|
| 194 |
-
"execution_count": 16,
|
| 195 |
-
"metadata": {},
|
| 196 |
-
"output_type": "execute_result"
|
| 197 |
-
}
|
| 198 |
-
],
|
| 199 |
-
"source": [
|
| 200 |
-
"test_dataset"
|
| 201 |
-
]
|
| 202 |
-
},
|
| 203 |
-
{
|
| 204 |
-
"cell_type": "code",
|
| 205 |
-
"execution_count": 17,
|
| 206 |
-
"id": "949de28e-8f30-4494-8eb8-b406eb7acec7",
|
| 207 |
-
"metadata": {
|
| 208 |
-
"id": "Fs5W7QapCC5y"
|
| 209 |
-
},
|
| 210 |
-
"outputs": [],
|
| 211 |
-
"source": [
|
| 212 |
-
"from transformers import DataCollatorForSeq2Seq\n",
|
| 213 |
-
"data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)"
|
| 214 |
-
]
|
| 215 |
-
},
|
| 216 |
-
{
|
| 217 |
-
"cell_type": "code",
|
| 218 |
-
"execution_count": 18,
|
| 219 |
-
"id": "258a1ba2-08c3-43b3-8016-ea5adce470de",
|
| 220 |
-
"metadata": {
|
| 221 |
-
"id": "j7J8i2k9CI0o"
|
| 222 |
-
},
|
| 223 |
-
"outputs": [],
|
| 224 |
-
"source": [
|
| 225 |
-
"collator = DataCollatorForSeq2Seq(tokenizer, model)\n",
|
| 226 |
-
"\n",
|
| 227 |
-
"test_loader = DataLoader(\n",
|
| 228 |
-
" test_dataset,\n",
|
| 229 |
-
" batch_size=4, \n",
|
| 230 |
-
" shuffle=False,\n",
|
| 231 |
-
" collate_fn=collator,\n",
|
| 232 |
-
" num_workers=1)"
|
| 233 |
-
]
|
| 234 |
-
},
|
| 235 |
-
{
|
| 236 |
-
"cell_type": "code",
|
| 237 |
-
"execution_count": 19,
|
| 238 |
-
"id": "02ffd5ae-bc39-4f6c-ab71-c3b346cdf51a",
|
| 239 |
-
"metadata": {
|
| 240 |
-
"colab": {
|
| 241 |
-
"base_uri": "https://localhost:8080/"
|
| 242 |
-
},
|
| 243 |
-
"id": "1YEoF7QUnsab",
|
| 244 |
-
"outputId": "d4417fc2-4827-4a9e-b196-82fb99f68006"
|
| 245 |
-
},
|
| 246 |
-
"outputs": [
|
| 247 |
-
{
|
| 248 |
-
"data": {
|
| 249 |
-
"text/plain": [
|
| 250 |
-
"<torch.utils.data.dataloader.DataLoader at 0x1e9de53adc0>"
|
| 251 |
-
]
|
| 252 |
-
},
|
| 253 |
-
"execution_count": 19,
|
| 254 |
-
"metadata": {},
|
| 255 |
-
"output_type": "execute_result"
|
| 256 |
-
}
|
| 257 |
-
],
|
| 258 |
-
"source": [
|
| 259 |
-
"test_loader"
|
| 260 |
-
]
|
| 261 |
-
},
|
| 262 |
-
{
|
| 263 |
-
"cell_type": "code",
|
| 264 |
-
"execution_count": 20,
|
| 265 |
-
"id": "0354a617-a667-49b5-a9cd-cad56c9e7f38",
|
| 266 |
-
"metadata": {
|
| 267 |
-
"id": "o4k2lYoOCOX8"
|
| 268 |
-
},
|
| 269 |
-
"outputs": [],
|
| 270 |
-
"source": [
|
| 271 |
-
"from tqdm import tqdm\n",
|
| 272 |
-
"\n",
|
| 273 |
-
"def get_prediction(text):\n",
|
| 274 |
-
" embeddings = tokenizer(text, max_length=256, return_attention_mask=False, return_token_type_ids=False, return_tensors='pt')\n",
|
| 275 |
-
" embeddings.to(device)\n",
|
| 276 |
-
" output = model.generate(**embeddings, max_length=256, bos_token_id=tokenizer.cls_token_id, eos_token_id=tokenizer.sep_token_id)[0, 0:-1].cpu()\n",
|
| 277 |
-
" return tokenizer.decode(output[1:])\n",
|
| 278 |
-
"\n",
|
| 279 |
-
"def get_predictions(data):\n",
|
| 280 |
-
" # inputs = processor(batch[\"speech\"], sampling_rate=16000, return_tensors=\"pt\", padding=\"longest\")\n",
|
| 281 |
-
" result = []\n",
|
| 282 |
-
" for batch in tqdm(data):\n",
|
| 283 |
-
" batch = {key: value.to(device) for key, value in batch.items()}\n",
|
| 284 |
-
" print(batch)\n",
|
| 285 |
-
" output = model.generate(batch['input_ids'], max_length=256).cpu()\n",
|
| 286 |
-
" try:\n",
|
| 287 |
-
" outputs = [tokenizer.decode(item[2:item.tolist().index(tokenizer.sep_token_id)]) for item in output]\n",
|
| 288 |
-
" except ValueError:\n",
|
| 289 |
-
" outputs = [tokenizer.decode(item[2:]) for item in output]\n",
|
| 290 |
-
" result.extend(outputs)\n",
|
| 291 |
-
" return result"
|
| 292 |
-
]
|
| 293 |
-
},
|
| 294 |
-
{
|
| 295 |
-
"cell_type": "code",
|
| 296 |
-
"execution_count": 21,
|
| 297 |
-
"id": "338b3ed5-0f39-4a4d-896e-1ffb258c6223",
|
| 298 |
-
"metadata": {
|
| 299 |
-
"colab": {
|
| 300 |
-
"base_uri": "https://localhost:8080/"
|
| 301 |
-
},
|
| 302 |
-
"id": "zSRHHADHCRC0",
|
| 303 |
-
"outputId": "bb0f0d98-260f-4d1b-d81b-6e3c5902bcc6"
|
| 304 |
-
},
|
| 305 |
-
"outputs": [],
|
| 306 |
-
"source": [
|
| 307 |
-
"# embeddings = tokenizer(\"5층에서 3개월째 구조대 기다리고 있는데 탈출할 기미가 안보여. 언제까지 존버해야 될지 모르겠지만 익절을 해 독기로 버틴다. 그래도 점점 오르고 있는 추세니까 해볼만 해.\", return_attention_mask=False, return_token_type_ids=False, return_tensors='pt')\n",
|
| 308 |
-
"# print(embeddings)\n",
|
| 309 |
-
"# embeddings.to(device)\n",
|
| 310 |
-
"# output = model.generate(**embeddings, max_length=256, bos_token_id=tokenizer.cls_token_id, eos_token_id=tokenizer.sep_token_id)[0, 0:-1].cpu()\n",
|
| 311 |
-
"# print(output)\n",
|
| 312 |
-
"# print(tokenizer.decode(output[1:]))"
|
| 313 |
-
]
|
| 314 |
-
},
|
| 315 |
-
{
|
| 316 |
-
"cell_type": "code",
|
| 317 |
-
"execution_count": 22,
|
| 318 |
-
"id": "e065f9b3-5f8b-4ce1-bf94-9a7de422658c",
|
| 319 |
-
"metadata": {},
|
| 320 |
-
"outputs": [
|
| 321 |
-
{
|
| 322 |
-
"name": "stdout",
|
| 323 |
-
"output_type": "stream",
|
| 324 |
-
"text": [
|
| 325 |
-
"print\n"
|
| 326 |
-
]
|
| 327 |
-
}
|
| 328 |
-
],
|
| 329 |
-
"source": [
|
| 330 |
-
"print(\"print\")"
|
| 331 |
-
]
|
| 332 |
-
},
|
| 333 |
-
{
|
| 334 |
-
"cell_type": "code",
|
| 335 |
-
"execution_count": 23,
|
| 336 |
-
"id": "0882dd65-260a-4728-9ce3-9138f70e6b15",
|
| 337 |
-
"metadata": {
|
| 338 |
-
"id": "iUfIalpvgMAw"
|
| 339 |
-
},
|
| 340 |
-
"outputs": [
|
| 341 |
-
{
|
| 342 |
-
"ename": "NameError",
|
| 343 |
-
"evalue": "name 'train' is not defined",
|
| 344 |
-
"output_type": "error",
|
| 345 |
-
"traceback": [
|
| 346 |
-
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 347 |
-
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
| 348 |
-
"Input \u001b[1;32mIn [23]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m train \u001b[38;5;241m=\u001b[39m \u001b[43mtrain\u001b[49m\u001b[38;5;241m.\u001b[39mdrop([\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUnnamed: 0\u001b[39m\u001b[38;5;124m'\u001b[39m], axis \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m)\n",
|
| 349 |
-
"\u001b[1;31mNameError\u001b[0m: name 'train' is not defined"
|
| 350 |
-
]
|
| 351 |
-
}
|
| 352 |
-
],
|
| 353 |
-
"source": [
|
| 354 |
-
"train = train.drop(['Unnamed: 0'], axis = 1)"
|
| 355 |
-
]
|
| 356 |
-
},
|
| 357 |
-
{
|
| 358 |
-
"cell_type": "code",
|
| 359 |
-
"execution_count": null,
|
| 360 |
-
"id": "b5794321-bec2-41da-bfac-6d656cfc2db9",
|
| 361 |
-
"metadata": {
|
| 362 |
-
"colab": {
|
| 363 |
-
"base_uri": "https://localhost:8080/"
|
| 364 |
-
},
|
| 365 |
-
"id": "Enk7jC6AC1BM",
|
| 366 |
-
"outputId": "ccc150d4-907f-4833-a3fa-b4c795fd4a26"
|
| 367 |
-
},
|
| 368 |
-
"outputs": [],
|
| 369 |
-
"source": [
|
| 370 |
-
"rnd_num = []\n",
|
| 371 |
-
"for i in range(30):\n",
|
| 372 |
-
" rnd_num.append(random.randint(0, len(train)))\n",
|
| 373 |
-
"print(rnd_num)"
|
| 374 |
-
]
|
| 375 |
-
},
|
| 376 |
-
{
|
| 377 |
-
"cell_type": "code",
|
| 378 |
-
"execution_count": null,
|
| 379 |
-
"id": "fca0a6ae-1d1e-4949-93e1-70c47c7fd1e8",
|
| 380 |
-
"metadata": {
|
| 381 |
-
"colab": {
|
| 382 |
-
"base_uri": "https://localhost:8080/"
|
| 383 |
-
},
|
| 384 |
-
"id": "Lm1dGSuXCU8I",
|
| 385 |
-
"outputId": "21f3feaa-90e8-47d4-b2b7-2f581d9e4d7f"
|
| 386 |
-
},
|
| 387 |
-
"outputs": [],
|
| 388 |
-
"source": [
|
| 389 |
-
"for i in range(5):\n",
|
| 390 |
-
" print(\"original: \", slang[i])\n",
|
| 391 |
-
" print(\"answer: \", standard[i])\n",
|
| 392 |
-
" print(\"prediction: \", get_prediction(slang[i]) , \"\\n\")"
|
| 393 |
-
]
|
| 394 |
-
},
|
| 395 |
-
{
|
| 396 |
-
"cell_type": "code",
|
| 397 |
-
"execution_count": 24,
|
| 398 |
-
"id": "0455c8b4-3606-4d25-89e4-27d290f47930",
|
| 399 |
-
"metadata": {},
|
| 400 |
-
"outputs": [],
|
| 401 |
-
"source": [
|
| 402 |
-
"import random as rand \n",
|
| 403 |
-
"random_num = []\n",
|
| 404 |
-
"for i in range(100):\n",
|
| 405 |
-
" num = rand.randint(0, len(original))\n",
|
| 406 |
-
" random_num.append(num)"
|
| 407 |
-
]
|
| 408 |
-
},
|
| 409 |
-
{
|
| 410 |
-
"cell_type": "code",
|
| 411 |
-
"execution_count": 26,
|
| 412 |
-
"id": "ec73f1f9-dd5f-4f21-a118-b4fd50428e48",
|
| 413 |
-
"metadata": {
|
| 414 |
-
"colab": {
|
| 415 |
-
"base_uri": "https://localhost:8080/"
|
| 416 |
-
},
|
| 417 |
-
"id": "lfjfmq5JZ6X_",
|
| 418 |
-
"outputId": "a6cf8c09-4eba-49f9-9fe5-ba25dcf7c65d"
|
| 419 |
-
},
|
| 420 |
-
"outputs": [],
|
| 421 |
-
"source": [
|
| 422 |
-
"prediction = []\n",
|
| 423 |
-
"for i in range(10):\n",
|
| 424 |
-
" prediction.append(get_prediction(original['slang'][i]))"
|
| 425 |
-
]
|
| 426 |
-
},
|
| 427 |
-
{
|
| 428 |
-
"cell_type": "code",
|
| 429 |
-
"execution_count": 28,
|
| 430 |
-
"id": "3386b8ae-71ea-4e9c-8a92-4ce2ef6a0bcb",
|
| 431 |
-
"metadata": {},
|
| 432 |
-
"outputs": [
|
| 433 |
-
{
|
| 434 |
-
"name": "stdout",
|
| 435 |
-
"output_type": "stream",
|
| 436 |
-
"text": [
|
| 437 |
-
"시험기간에 스카가서 나는 폰으로 유튜브 봤는데 주위에서 다들 열공하는 모습에 현타옴 앞으로 나도 열심히 해야겠어.\n",
|
| 438 |
-
"하교 시간에 초등학교 앞을 지나가니까 그 잠깐 사이에 급식체를 원없이 들을 수 있었어.\n",
|
| 439 |
-
"버스에서 급식충들이 자기들끼리 시끄럽게 떠드는 소리에 머리가 지끈거렸어.\n",
|
| 440 |
-
"일주일 내내 약속이 있다니. 너 정말 인싸구나.\n",
|
| 441 |
-
"같이 놀 친구가 없어서 이번 수학여행을 갈지 말지 고민이야, 나는 아무래도 아싸인가봐.\n",
|
| 442 |
-
"이번에 쟤가 전교 1등이라고 했지? 공부도 잘하는데 인기도 많고 진짜 엄친아인 것 같아.\n",
|
| 443 |
-
"어쩔 수 없다. 이렇게 된 이상 이번 시험은 조삼모사 전략으로 갈게, 우리 평균만 넘자.\n",
|
| 444 |
-
"올해 사망년이라 진로 걱정도 많고 취업 걱정도 많아서 힘들어. 아무 걱정 없던 새내기 때로 돌아가고 싶다.\n",
|
| 445 |
-
"생명과학 교양 첫 수업이었는데 국어국문학과인 나는 도저히 무슨 소리인지 하나도 모르겠어서 정말 문송했어.\n",
|
| 446 |
-
"이번 중간고사에서 역대급으로 어려웠는데 올백이 나왔다고? 믿기지가 않아.\n"
|
| 447 |
-
]
|
| 448 |
-
}
|
| 449 |
-
],
|
| 450 |
-
"source": [
|
| 451 |
-
"for i in range(10):\n",
|
| 452 |
-
" print(original['slang'][i])"
|
| 453 |
-
]
|
| 454 |
-
},
|
| 455 |
-
{
|
| 456 |
-
"cell_type": "code",
|
| 457 |
-
"execution_count": null,
|
| 458 |
-
"id": "2c59bf28-dba7-4d09-a7a4-de31b0cc8d03",
|
| 459 |
-
"metadata": {
|
| 460 |
-
"colab": {
|
| 461 |
-
"base_uri": "https://localhost:8080/"
|
| 462 |
-
},
|
| 463 |
-
"id": "4316coIrCt8U",
|
| 464 |
-
"outputId": "f5fdaccf-6c88-49f2-de2b-f738d557371f"
|
| 465 |
-
},
|
| 466 |
-
"outputs": [],
|
| 467 |
-
"source": [
|
| 468 |
-
"import nltk\n",
|
| 469 |
-
"\n",
|
| 470 |
-
"BLEUscore_sum = []\n",
|
| 471 |
-
"order = 0 \n",
|
| 472 |
-
"for i in random_num:\n",
|
| 473 |
-
" hypothesis = prediction[order]\n",
|
| 474 |
-
" reference = original['standard'][i]\n",
|
| 475 |
-
" BLEU = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis)\n",
|
| 476 |
-
" BLEUscore_sum.append(BLEU)\n",
|
| 477 |
-
" order += 1 "
|
| 478 |
-
]
|
| 479 |
-
},
|
| 480 |
-
{
|
| 481 |
-
"cell_type": "code",
|
| 482 |
-
"execution_count": null,
|
| 483 |
-
"id": "a7c2760a-e3b2-4f58-b304-b169875b675e",
|
| 484 |
-
"metadata": {
|
| 485 |
-
"colab": {
|
| 486 |
-
"base_uri": "https://localhost:8080/"
|
| 487 |
-
},
|
| 488 |
-
"id": "go5ElXjlCvtm",
|
| 489 |
-
"outputId": "4aff6690-f5e5-41e2-98e8-73d25f2bd0d9",
|
| 490 |
-
"scrolled": true
|
| 491 |
-
},
|
| 492 |
-
"outputs": [],
|
| 493 |
-
"source": [
|
| 494 |
-
"avg = sum(BLEUscore_sum, 0.0) / len(BLEUscore_sum)\n",
|
| 495 |
-
"print(\"테스트 데이터셋 BLEU 스코어: \", avg)"
|
| 496 |
-
]
|
| 497 |
-
},
|
| 498 |
-
{
|
| 499 |
-
"cell_type": "code",
|
| 500 |
-
"execution_count": null,
|
| 501 |
-
"id": "d1cd78f9-fe66-47d1-9168-874888d72786",
|
| 502 |
-
"metadata": {
|
| 503 |
-
"colab": {
|
| 504 |
-
"base_uri": "https://localhost:8080/"
|
| 505 |
-
},
|
| 506 |
-
"id": "m9BtsCieiciv",
|
| 507 |
-
"outputId": "6fd739a6-e012-47d7-f425-a5ac0139ab61",
|
| 508 |
-
"scrolled": true
|
| 509 |
-
},
|
| 510 |
-
"outputs": [],
|
| 511 |
-
"source": [
|
| 512 |
-
"order = 0\n",
|
| 513 |
-
"for i in random_num:\n",
|
| 514 |
-
" print(\"original: \", original['slang'][i])\n",
|
| 515 |
-
" print(\"answer: \", original['standard'][i])\n",
|
| 516 |
-
" print(\"prediction: \", prediction[order] , \"\\n\")\n",
|
| 517 |
-
" order += 1"
|
| 518 |
-
]
|
| 519 |
-
},
|
| 520 |
-
{
|
| 521 |
-
"cell_type": "code",
|
| 522 |
-
"execution_count": null,
|
| 523 |
-
"id": "4e4f1064-a7b5-43ef-adb0-ec2821d0b22c",
|
| 524 |
-
"metadata": {},
|
| 525 |
-
"outputs": [],
|
| 526 |
-
"source": []
|
| 527 |
-
},
|
| 528 |
-
{
|
| 529 |
-
"cell_type": "code",
|
| 530 |
-
"execution_count": null,
|
| 531 |
-
"id": "fb06b3d8-3046-44c5-b0af-bdcfd7a70b23",
|
| 532 |
-
"metadata": {},
|
| 533 |
-
"outputs": [],
|
| 534 |
-
"source": []
|
| 535 |
-
}
|
| 536 |
-
],
|
| 537 |
-
"metadata": {
|
| 538 |
-
"kernelspec": {
|
| 539 |
-
"display_name": "Python 3 (ipykernel)",
|
| 540 |
-
"language": "python",
|
| 541 |
-
"name": "python3"
|
| 542 |
-
},
|
| 543 |
-
"language_info": {
|
| 544 |
-
"codemirror_mode": {
|
| 545 |
-
"name": "ipython",
|
| 546 |
-
"version": 3
|
| 547 |
-
},
|
| 548 |
-
"file_extension": ".py",
|
| 549 |
-
"mimetype": "text/x-python",
|
| 550 |
-
"name": "python",
|
| 551 |
-
"nbconvert_exporter": "python",
|
| 552 |
-
"pygments_lexer": "ipython3",
|
| 553 |
-
"version": "3.9.13"
|
| 554 |
-
}
|
| 555 |
-
},
|
| 556 |
-
"nbformat": 4,
|
| 557 |
-
"nbformat_minor": 5
|
| 558 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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