/
ตัวอย่าง Colab to TARA HPC

ตัวอย่าง Colab to TARA HPC

my.ipynb บน Colab

  1. ติดตั้ง package ที่ต้องการใช้งานให้กับ session

!pip install pythainlp

2. จัดการกับแหล่งข้อมูลโดยเชื่อมต่อกับ google drive หรือโอนถ่ายข้อมูลขึ้น Colab session

from google.colab import drive drive.mount('/content/drive')

3. โปรแกรมที่กำลังพัฒนาเพื่อสร้างโมเดล (… โดยย่อ)

import pandas as pd from pythainlp import word_tokenize ... listtext = [] with open('/content/drive/MyDrive/news.txt', 'r', encoding = 'utf8') as f: for line in f.readlines(): listtext.append(line.strip()) df = pd.DataFrame(listtext, columns=['text']) ... df['tokenized'] = df.text.apply(tokenize) embedding_model = word2vec.Word2Vec(...) embedding_model.build_vocab(df.tokenized) %time embedding_model.train(df.tokenized, total_examples = embedding_model.corpus_count, epochs = 15)

8. การทดสอบโมเดล

Colab-to-TARA

Common Steps

Colab

TARA

Common Steps

Colab

TARA

ติดตั้ง package ที่ต้องการใช้งานให้กับ session environment

!pip install pythainlp

การจัดการกับ environment บน HPC สามารถทำได้หลายรูปแบบ เช่น virtualenv / conda / Singularity container (อ่านเพิ่มเติมได้ที่นี่)

ในตัวอย่างนี้ใช้ virtualenv

$ module avail python
$ module load Python/3.7...
$ virtualenv venv
$ source venv/bin/activate

(venv) $ pip install pythainlp

จัดการกับแหล่งข้อมูลโดยเชื่อมต่อกับ google drive หรือโอนถ่ายข้อมูลขึ้น Colab session

scp data from your local machine to your Project Home (proj{xxxx}) in HPC

$ scp news.txt username@tara.nstda.or.th:/{your-project-home-path}/

โปรแกรมที่กำลังพัฒนาเพื่อสร้างโมเดล

เป็น interactive session ผ่าน Jupyter notebook style บน Colab

เตรียม my.py โดยหากพัฒนาโปรแกรมเสร็จแล้วจาก Colab ก็สามารถ nbconvert file จาก Colab มาเป็น python file ได้เลย
$ jupyter my.ipynb nbconvert --to python

สั่งรันโปรแกรม

เป็น interactive session ผ่าน Jupyter notebook style บน Colab

เตรียม sbatch submission script (submit.sh)

$ sbatch submit.sh

การทดสอบโมเดล

เป็น interactive session ผ่าน Jupyter notebook style บน Colab

สามารถเรียกใช้งาน interactive mode เพื่อการทดสอบโมเดลได้ด้วยคำสั่ง

$ sinteract เพื่อเปิด interactive session และสามารถรัน python เพื่อทดสอบโมเดลได้บน compute node เช่น

(venv) [apiyatum@tara-c-057 w2v]$ python
Python 3.7.4 (default, Apr 30 2020, 13:19:10) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> testmodel = word2vec.Word2Vec.load("/tarafs/data/project/projxxxx/workingdir/xyz.model")
>>> testmodel.wv.most_similar('AI', topn=5)
[('Ai', 0.2572551369667053),
('เทคโนโลยี', 0.21931828558444977),
('หุ่นยนต์', 0.21708077192306519),
('Photoshop', 0.19669440388679504),
('ปัญญาประดิษฐ์', 0.19432862102985382)]

อ่านเพิ่มเติมเกี่ยวกับ sinteract ได้ที่นี่

 

Related content

PyThaiNLP
More like this
Multi-GPUs Training with PyTorch -- Distributed Data-Parallel
Multi-GPUs Training with PyTorch -- Distributed Data-Parallel
More like this
multi-GPUs Training with PyTorch -- DataParallel
multi-GPUs Training with PyTorch -- DataParallel
Read with this
การติดตั้งโปรแกรม NCL ผ่านทาง Conda
การติดตั้งโปรแกรม NCL ผ่านทาง Conda
More like this
การติดตั้งและการใช้งาน conda หรือ mamba
การติดตั้งและการใช้งาน conda หรือ mamba
Read with this
ThaiSC Pioneer Program
ThaiSC Pioneer Program
More like this