Skip to content

Instantly share code, notes, and snippets.

View MSWon's full-sized avatar

Minsub Won MSWon

View GitHub Profile
@MSWon
MSWon / tensorflow_text_classification.py
Created July 4, 2021 07:51
tensorflow_text_classification.py
import bentoml
import tensorflow as tf
from tensorflow import keras
from bentoml.artifact import TensorflowSavedModelArtifact
from bentoml.adapters import JsonInput
REVIEW_CLASSES = ['negative', 'positive']
@MSWon
MSWon / shuffle_two_corpus_linux
Created April 4, 2020 10:47
shuffling two parallel corpus using linux command
$ paste -d : file1 file2 | shuf
five:5
two:2
one:1
four:4
three:3
$ paste -d ':' file1 file2 | shuf | awk -v FS=":" '{ print $1 > "out1" ; print $2 > "out2" }'
@MSWon
MSWon / tf.py_func.py
Created March 22, 2020 03:59
using tf.py_func to implement in np op
import tensorflow as tf
import numpy as np
def my_func(input_x):
result = []
for idx in input_x:
if idx % 2 == 1:
result.append(3)
return np.array(result)
@MSWon
MSWon / tensorboard_example.py
Last active February 26, 2020 13:24
ex for using tensor board
import tensorflow as tf
X_1 = tf.placeholder(shape=None, dtype=tf.float32)
Y_1 = tf.placeholder(shape=None, dtype=tf.float32)
Y_2 = tf.placeholder(shape=None, dtype=tf.float32)
W1 = tf.get_variable("W1", [1,10])
W2 = tf.get_variable("W2", [1,10])
result = tf.multiply(X_1, W1)
@MSWon
MSWon / preprocess_bpe.py
Created December 6, 2019 11:09
preprocessing with bpe
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 6 18:13:34 2019
@author: jbk48
"""
import pandas as pd
import sentencepiece as spm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
def bar_plot(col, data, hue=None): ## 정수형을 위한
f, ax = plt.subplots(figsize=(10, 5))
sns.countplot(x=col, hue=hue, data=data, alpha=0.5)
plt.show()
@MSWon
MSWon / linear_regression.R
Created October 28, 2019 10:19
linear_regression
library(MASS)
library(car)
install.packages("cars")
a = read.csv("남한산성_train.csv", sep=",")
train_data = a[, -1]
linear_model <- lm(eightdays_aud ~. , data = train_data)
@MSWon
MSWon / shuffle_word.py
Created September 20, 2019 08:42
shuffling word's character order
import random
import numpy as np
class shuffle():
def __init__(self):
np.random.seed(1234)
def shuffle_string(self, string):
chars = list(string)
@MSWon
MSWon / tf_record.py
Last active April 29, 2021 15:50
tf record example
import tensorflow as tf
import numpy as np
import sys
def _bytes_feature(value):
"""Returns a bytes_list from a string / byte."""
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _float_feature(value):
"""Returns a float_list from a float / double."""
@MSWon
MSWon / tf_dataset_iter.py
Created June 26, 2019 06:33
tf_dataset_iter.py
import tensorflow as tf
import numpy as np
features, labels = (np.random.sample((100,2)), np.random.randint(low=0, high=10 , size=(100,1)))
dataset = tf.data.Dataset.from_tensor_slices((features,labels))
dataset = tf.data.Dataset.from_tensor_slices((features,labels))
dataset = dataset.shuffle(len(features))
dataset = dataset.batch(16)
dataset = dataset.repeat()