Skip to content

Instantly share code, notes, and snippets.

@RainJayTsai
RainJayTsai / minimize_docker_python_application
Last active May 26, 2022 06:25
using docker BUILDKIT example, cache pip and mount temp whl to install. tensorflow python3.6
# syntax = docker/dockerfile:experimental
FROM python:3.6 as base
######################################
FROM base as builder
ENV PYTHONPATH=$PYTHONPATH:/install/lib/python3.6/site-packages/
# bind a wheel and install it
@RainJayTsai
RainJayTsai / build_tensorflow_in_docker
Created April 15, 2019 01:56
build tensorflow in docker the image is python:3.6 ( debian )
FROM python:3.6
# install bazel
# check the bazel version what you want to build tensroflw and change the VERSION
# https://www.tensorflow.org/install/source#linux
ARG BAZEL_VERSION 0.15.0
ARG TENSORFLOW_VERSION 1.12.0
RUN apt-get update; apt-get install openjdk-8-jdk
RUN set -ex && wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
&& chmod +x bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh ./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
@RainJayTsai
RainJayTsai / Makefile
Created January 13, 2020 03:25 — forked from doubleyou/Makefile
grpc-gateway python example
GATEWAY_FLAGS := -I. -I/usr/local/include -I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include
GRPC_FLAGS := --python_out=. --grpc_python_out=.
code:
python -m grpc_tools.protoc $(GRPC_FLAGS) $(GATEWAY_FLAGS) *.proto
gw:
protoc $(GATEWAY_FLAGS) \
--go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
@RainJayTsai
RainJayTsai / server.conf
Created June 7, 2021 03:04 — forked from laurenorsini/server.conf
OpenVPN configuration for /etc/openvpn/server.conf
local 192.168.2.0 # SWAP THIS NUMBER WITH YOUR RASPBERRY PI IP ADDRESS
dev tun
proto udp #Some people prefer to use tcp. Don't change it if you don't know.
port 1194
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME
key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME
dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!
server 10.8.0.0 255.255.255.0
# server and remote endpoints
@RainJayTsai
RainJayTsai / convert_voc2createml.py
Created September 9, 2021 14:13 — forked from bezineb5/convert_voc2createml.py
Pascal VOC annotation to Apple createML annotations conversion tool
import argparse
import json
import logging
import pathlib
from xml.etree import ElementTree
log = logging.getLogger(__name__)
def _parse_arguments() -> argparse.Namespace:
S3_ACCESS_KEY_ID_GITLAB_BACKUP=<ACCESS_KEY>
S3_SECRET_ACCESS_KEY_GITLAB_BACKUP=<SECRET_KEY>
@RainJayTsai
RainJayTsai / tw_address_analysis.py
Last active November 29, 2023 02:15
regex to analysis tw address
try:
import re2 as re
except:
import re
pattern = '(?P<code>\d{5}|\d{3})?\s*(?P<country>[台臺]灣)?(?P<city>\D+?[縣市])(?P<district>\D+?(市區|鎮區|鎮市|[鄉鎮市區]))?(?P<village>\D+?[村里](?!路))?(?P<neighbor>\d+[鄰])?(?P<road>\D+?(村路|[路街道段]))?(?P<section>(\d|\D)?段)?(?P<lane>\d+巷)?(?P<alley>\d+弄)?(?P<no>\d+號?)?(?P<seq>[-之]\d+?(號))?(?P<floor>(((\D|\d)+樓)|((B|地下室?)\d+)))?(?P<other>.+)?'
addr_regex = re.compile(pattern)
cn_num = '一二三四五六七八九十'
cn_mapping = {k: str(v) for k, v in zip(list(cn_num),

PyTorch實作NLP中的Self-Attention

輸入準備

我們準備了兩個句子來進行這次實驗

sentences = ['helo attention','have a nice day']

一開始先建立詞表與對應的單詞one-hot encoding

vocabs = ' '.join(sentences).split()
vocabs = list(set(vocabs))