Skip to content

Instantly share code, notes, and snippets.

View BankNatchapol's full-sized avatar
🏠
Working from home

Bank Natchapol BankNatchapol

🏠
Working from home
View GitHub Profile
import re
import unicodedata
from transformers import AutoTokenizer
from . import punctuation, symbols, pu_symbols
from num2words import num2words
from pythainlp.tokenize import word_tokenize
from pythainlp.transliterate import romanize
from pythainlp.util import normalize as thai_normalize
from pythainlp.util import thai_to_eng, eng_to_thai
from melo.text.thai_dictionary import english_dictionary, etc_dictionary
datagen = ImageDataGenerator(
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2
)
@BankNatchapol
BankNatchapol / TTF2Image.py
Created October 26, 2021 14:35
Code for converting ttf to image
from PIL import Image, ImageDraw, ImageFont
# Settings
W, H = (224, 224)
# Font
for font_name in font_names:
font = ImageFont.truetype("fonts/"+font_name, 224, encoding='utf-8')
for i in range(ord('ก'), ord('ฮ')+1):
import classical
import quantum
import pandas as pd
from IPython.core import display as ICD
sbits = [0, 1]
tbits = [(0, 0), (0, 1), (1, 0), (1, 1)]
tables = []
classicalTable = pd.DataFrame(columns=['bit', 'not'])
@BankNatchapol
BankNatchapol / quantum_xor.py
Created January 5, 2021 08:59
Quantum XOR Gate
def xor_gate(bit1, bit2, backend='sim', token=None):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
quantumBits = 2
classicalBits = 1
XOR = QuantumCircuit(quantumBits, classicalBits)
if bit1 == 1:
XOR.x(0)
if bit2 == 1:
XOR.x(1)
@BankNatchapol
BankNatchapol / classical_xor.py
Created January 5, 2021 08:56
Classical XOR Gate
def xor_gate(bit1, bit2):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
if bit1 != bit2:
return 1
return 0
def or_gate(bit1, bit2, backend='sim', token=None):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
quantumBits = 3
classicalBits = 1
OR = QuantumCircuit(quantumBits, classicalBits)
if bit1 == 1:
OR.x(0)
if bit2 == 1:
OR.x(1)
@BankNatchapol
BankNatchapol / classical_or.py
Last active January 5, 2021 07:24
Classical OR Gate
def or_gate(bit1, bit2):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
if 1 in (bit1, bit2):
return 1
return 0
@BankNatchapol
BankNatchapol / quantum_and.py
Created January 5, 2021 04:56
Quantum AND Gate
def and_gate(bit1, bit2, backend='sim', token=None):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
quantumBits = 3
classicalBits = 1
AND = QuantumCircuit(quantumBits, classicalBits)
if bit1 == 1:
AND.x(0)
if bit2 == 1:
AND.x(1)
@BankNatchapol
BankNatchapol / classical_and.py
Created January 5, 2021 04:53
Classical AND Gate
def and_gate(bit1, bit2):
assert bit1 in (0, 1) and bit2 in (0, 1), "Only 0 or 1"
return bit1 * bit2