Skip to content

Instantly share code, notes, and snippets.

View wannaphong's full-sized avatar
🧭
out-of-time

Wannaphong Phatthiyaphaibun wannaphong

🧭
out-of-time
View GitHub Profile
@lewtun
lewtun / sft_trainer.py
Last active April 12, 2024 14:51
Fine-tuning Mistral 7B with TRL & DeepSpeed ZeRO-3
# This is a modified version of TRL's `SFTTrainer` example (https://github.com/huggingface/trl/blob/main/examples/scripts/sft_trainer.py),
# adapted to run with DeepSpeed ZeRO-3 and Mistral-7B-V1.0. The settings below were run on 1 node of 8 x A100 (80GB) GPUs.
#
# Usage:
# - Install the latest transformers & accelerate versions: `pip install -U transformers accelerate`
# - Install deepspeed: `pip install deepspeed==0.9.5`
# - Install TRL from main: pip install git+https://github.com/huggingface/trl.git
# - Clone the repo: git clone github.com/huggingface/trl.git
# - Copy this Gist into trl/examples/scripts
# - Run from root of trl repo with: accelerate launch --config_file=examples/accelerate_configs/deepspeed_zero3.yaml --gradient_accumulation_steps 8 examples/scripts/sft_trainer.py
@alexanderbazo
alexanderbazo / build.yml
Created December 6, 2019 16:07
Github Actions: Build and Release Android-APK
name: Minimal Android CI Workflow
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
@korakot
korakot / colab_download.py
Created November 15, 2017 08:40
Google colab file upload/download
files.download('example.txt') # from colab to browser download
@korakot
korakot / thai_datetime.py
Created October 30, 2017 13:45
Thai datetime in python
import datetime, pytz
tz = pytz.timezone('Asia/Bangkok')
def now():
now1 = datetime.datetime.now(tz)
month_name = 'x มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤศจิกายน ธันวาคม'.split()[now1.month]
thai_year = now1.year + 543
time_str = now1.strftime('%H:%M:%S')
return "%d %s %d %s"%(now1.day, month_name, thai_year, time_str) # 30 ตุลาคม 2560 20:45:30
@korakot
korakot / collation.py
Last active October 26, 2017 13:04
A simplified pure-python thaisort
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, print_function
import re
try:
import icu
thkey = icu.Collator.createInstance(icu.Locale('th_TH')).getSortKey
except ImportError:
def thkey(word):
cv = re.sub('[็-์]', '', word) # remove tone
@korakot
korakot / lmcut.py
Last active January 18, 2020 06:43
Longest matching Thai word tokenization
from marisa_trie import Trie
# wordlist = ...
trie = Trie(wordlist)
def lmcut(text):
for w in reversed(trie.prefixes(text)):
if w==text:
yield [w]
else:
@korakot
korakot / multicut.py
Last active February 1, 2018 09:39
Return all possible ways to cut(tokenize) Thai text.
import re
from collections import defaultdict
from marisa_trie import Trie
wordlist = [li.strip() for li in open('wordlist.txt')]
trie = Trie(wordlist) # สร้างครั้งเดียว ข้างนอก function
class LatticeString(str):
''' String subclass เพื่อเก็บวิธีตัดหลายๆ วิธี
'''
@korakot
korakot / LK82.py
Last active April 13, 2020 04:16
Thai Soundex LK82, Udom83
# ตาม guru.sanook.com/1520
import re
t1 = str.maketrans("กขฃคฅฆงจฉชฌซศษสญยฎดฏตณนฐฑฒถทธบปผพภฝฟมรลฬฤฦวหฮอ",
"กกกกกกงจชชชซซซซยยดดตตนนททททททบปพพพฟฟมรรรรรวหหอ")
t2 = str.maketrans(
"กขฃคฅฆงจฉชซฌฎฏฐฑฒดตถทธศษสญณนรลฬฤฦบปพฟภผฝมำยวไใหฮาๅึืเแโุูอ",
"1111112333333333333333333444444445555555667777889AAABCDEEF")
def LK82(s):
res = []
@avinassh
avinassh / container.xml
Created October 27, 2015 05:38 — forked from anqxyr/archived
Create EPUB files with Python
<?xml version='1.0' encoding='UTF-8'?>
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<rootfiles>
<rootfile media-type="application/oebps-package+xml" full-path="content.opf"/>
</rootfiles>
</container>
@stewartpark
stewartpark / xor.py
Created October 12, 2015 08:17
Simple XOR learning with keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD
import numpy as np
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[1],[1],[0]])
model = Sequential()
model.add(Dense(8, input_dim=2))