# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="xaXRKmrNTDtj" executionInfo={"status": "ok", "timestamp": 1603611297371, "user_tz": -540, "elapsed": 1909, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="fd54e5e8-a3c9-4a58-90dc-78c6473e4489" colab={"base_uri": "https://localhost:8080/", "height": 377}
# !nvidia-smi

# + id="HdJ4Of9JTMRJ" executionInfo={"status": "ok", "timestamp": 1603611317894, "user_tz": -540, "elapsed": 22415, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="4b477603-017a-4c15-bc63-60c0102a9e8e" colab={"base_uri": "https://localhost:8080/", "height": 35}
from google.colab import drive
drive.mount('/content/drive')

# + id="OZCkG0XD5IYV" executionInfo={"status": "ok", "timestamp": 1603611318995, "user_tz": -540, "elapsed": 23506, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="98fa6675-6818-413c-e5fd-34520a8f028a" colab={"base_uri": "https://localhost:8080/", "height": 71}
# !ls drive/'My Drive'/'WEB_Ask_06devbros'/'ai'/'chatbot'

# + id="OcbVtTcs5TdU" executionInfo={"status": "ok", "timestamp": 1603611331902, "user_tz": -540, "elapsed": 36404, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="11c9fe89-bc0a-4307-eae9-11968d1641e0" colab={"base_uri": "https://localhost:8080/", "height": 1000}
# !pip install -r drive/'My Drive'/'WEB_Ask_06devbros'/'ai'/'chatbot'/requirements.txt

# + id="LywYq8D-5VwE" executionInfo={"status": "ok", "timestamp": 1603611334855, "user_tz": -540, "elapsed": 39348, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="f1f74fa0-dd58-4d10-a5d0-372aae2db1de" colab={"base_uri": "https://localhost:8080/", "height": 161}
# !pip install --upgrade tokenizers==0.8.1.rc1

# + id="BkWNHWvZ5m7q" executionInfo={"status": "ok", "timestamp": 1603611334859, "user_tz": -540, "elapsed": 39349, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}}
import sys
sys.path.append('/content/drive/My Drive/WEB_Ask_06devbros/ai/chatbot')

# + id="Th_ZZBGj5ZNS" executionInfo={"status": "ok", "timestamp": 1603611342330, "user_tz": -540, "elapsed": 46817, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}}
import os
import numpy as np
import torch
from model.kogpt2 import DialogKoGPT2
from kogpt2_transformers import get_kogpt2_tokenizer

# + id="OW-ZHy_95hIq" executionInfo={"status": "ok", "timestamp": 1603611402269, "user_tz": -540, "elapsed": 106747, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="50cbad04-e25c-45b9-87fd-c22a6cda51e4" colab={"base_uri": "https://localhost:8080/", "height": 317, "referenced_widgets": ["6eb4c4ea7a814072b918e2517044fb64", "<KEY>", "7e27252a5f7a443abeae6e3c22caf95d", "88b2df8f98df42c89740a57d8d7ba995", "<KEY>", "<KEY>", "4a44acef6fcb4e26bd85b02370053adb", "ad7e008a4b1a4368b2da80d1c5df624b", "<KEY>", "b919300429434e52a08a7853a41e6e5a", "a2f8e115bad54ccda66ba4d9f51fa3af", "0ef14f998ae34562b63109201840d26e", "55f333781b0843abaf020b827aa68540", "8e9c6644584648469156a54fd82fe284", "<KEY>", "acefd0d0b96144d1adc387da04c2fa3c", "02c9c04531ed4c8da17ed66e71d101ac", "e36fa5b91ce8484d9c8b6ac7952bca60", "c1e841026c6a433db04a9f734859ac3a", "e6a7f47e603f4162ac8a61b0da9a87b4", "737cfeef992a451ba18d22b77ca25e55", "2217a8f04e754aa49a8d02dca03d9c64", "<KEY>", "e3e5dfec5c5e4dcebd2a29e59f13d03a", "83f1c23076434edcbd9e1883c41a800e", "<KEY>", "a69843e124d649bb9263ba49238f14e5", "6581ffeef1d74cd5a6d0c9c448e5a89a", "dff03380331a4751832c4518e38d44ea", "94272af87e6742fe8d189b2202981210", "4b8a5797897442238cde001c000aea3a", "<KEY>", "<KEY>", "<KEY>", "<KEY>", "<KEY>", "a028c538a62247909c443ecfc6e2ba05", "b3c8ef0098fe4562beb6e2a78801b628", "249e8017dccf49e79e6fa71dfac903b8", "<KEY>", "<KEY>", "<KEY>", "9816c6e78fd24e8398c99600988ea1d0", "<KEY>", "10280504cb89466792bad4e4e9e72757", "2c530abfd5d3479d8c23edfff230a158", "659e554813ba4c2c937dc7e3e46f19e2", "a8b06eb6286e450b803a8ef4e386a0f7"]}
root_path='/content/drive/My Drive/WEB_Ask_06devbros/ai/chatbot'
data_path = f"{root_path}/data/wellness_dialog_for_autoregressive.txt"
checkpoint_path =f"{root_path}/checkpoint"
save_ckpt_path = f"{checkpoint_path}/kogpt2-wellnesee-auto-regressive-20201022-add-chatbotdata.pth"

ctx = "cuda" if torch.cuda.is_available() else "cpu"
device = torch.device(ctx)

# 저장한 Checkpoint 불러오기
checkpoint = torch.load(save_ckpt_path, map_location=device)

model = DialogKoGPT2()
model.load_state_dict(checkpoint['model_state_dict'])

model.eval()

tokenizer = get_kogpt2_tokenizer()

count = 0
output_size = 200 # 출력하고자 하는 토큰 갯수



# + id="IB3xnLGjQFFo" executionInfo={"status": "ok", "timestamp": 1603611402570, "user_tz": -540, "elapsed": 107038, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="bfdf13fd-65f0-4180-af0e-686acb08b4cf" colab={"base_uri": "https://localhost:8080/", "height": 377}
# !nvidia-smi

# + id="vSFIAggML5z3" executionInfo={"status": "error", "timestamp": 1603611612335, "user_tz": -540, "elapsed": 316795, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}} outputId="ed26a65c-6c8f-4dd2-83b0-913a4f5b3e21" colab={"base_uri": "https://localhost:8080/", "height": 1000}
while 1:
#for i in range(5):
  sent = input('Question: ')  # '요즘 기분이 우울한 느낌이에요'
  tokenized_indexs = tokenizer.encode(sent)

  input_ids = torch.tensor([tokenizer.bos_token_id,]  + tokenized_indexs +[tokenizer.eos_token_id]).unsqueeze(0)
  # set top_k to 50
  sample_output = model.generate(
      input_ids=input_ids
      )


  print("Answer: " + tokenizer.decode(sample_output[0].tolist()[len(tokenized_indexs)+1:],skip_special_tokens=True))
  print(100 * '-')

# for s in kss.split_sentences(sent):
#     print(s)

# + id="EopdYg6ESrwO" executionInfo={"status": "aborted", "timestamp": 1603611612330, "user_tz": -540, "elapsed": 316787, "user": {"displayName": "\uc774\uc6a9\uc6b0", "photoUrl": "", "userId": "08200059377748879944"}}


StarcoderdataJupyterScriptsDedupFiltered