Skip to content

Instantly share code, notes, and snippets.

View ratsgo's full-sized avatar
💭
I may be slow to respond.

gichang.lee ratsgo

💭
I may be slow to respond.
View GitHub Profile
@ratsgo
ratsgo / test.py
Created March 8, 2017 08:44
test
def helloworld:
print('hello world')
return tmp
@ratsgo
ratsgo / LSTM_loss.py
Last active June 9, 2020 06:53
lstm loss 함수
def lossFun(inputs, targets, hprev, cprev):
xs, hs, cs, is_, fs, os, gs, ys, ps= {}, {}, {}, {}, {}, {}, {}, {}, {}
hs[-1] = np.copy(hprev) # t=0일때 t-1 시점의 hidden state가 필요하므로
cs[-1] = np.copy(cprev)
loss = 0
H = hidden_size
# forward pass
for t in range(len(inputs)):
xs[t] = np.zeros((vocab_size, 1))
xs[t][inputs[t]] = 1
@ratsgo
ratsgo / news_seq2seq.py
Created March 12, 2017 10:58
news seq2seq model
import tensorflow as tf
import numpy as np
import tool as tool
import time
# data loading
data_path = 'C:/newscorpus.csv'
title, contents = tool.loading_data(data_path, eng=False, num=False, punc=False)
word_to_ix, ix_to_word = tool.make_dict_all_cut(title+contents, minlength=0, maxlength=3, jamo_delete=True)
@ratsgo
ratsgo / tool.py
Created March 12, 2017 11:05
news preprocessing
import numpy as np
import pandas as pd
from collections import defaultdict
####################################################
# loading function #
####################################################
def loading_data(data_path, eng=True, num=True, punc=False):
# data example : "title","content"
@ratsgo
ratsgo / RotationForest.R
Created March 16, 2017 13:32
Rotation Forest
library(rpart)
library(Matrix)
library(stringr)
####################################
# function #
####################################
regression.perf_eval <- function(real,hat) {
MSE <- mean((real - hat)^2)
RMSE <- sqrt(MSE)
@ratsgo
ratsgo / cnn_sentence_classification.py
Last active December 12, 2018 08:29
cnn sentence classification
import os
import time
import datetime
from tensorflow import flags
import tensorflow as tf
import numpy as np
import cnn_tool as tool
class TextCNN(object):
"""
@ratsgo
ratsgo / cnn_tool.py
Created March 19, 2017 05:42
cnn tool
import numpy as np
import pandas as pd
import re
import tensorflow as tf
import random
####################################################
# cut words function #
####################################################
class BranchingEntropy:
def __init__(self, min_length=2, max_length=7):
self.min_length = min_length
self.max_length = max_length
self.encoder = IntegerEncoder()
self.L = defaultdict(lambda: defaultdict(int))
self.R = defaultdict(lambda: defaultdict(int))
class CohesionProbability:
def __init__(self, left_min_length=1, left_max_length=10, right_min_length=1, right_max_length=6):
self.left_min_length = left_min_length
self.left_max_length = left_max_length
self.right_min_length = right_min_length
self.right_max_length = right_max_length
self.L = defaultdict(int)
self.R = defaultdict(int)
@ratsgo
ratsgo / pLSA.R
Last active April 4, 2021 11:17
pLSA
library(stringr)
# prepare corpus
corpus <- matrix(c(1,2,0,0,0,0,
3,1,0,0,0,0,
2,0,0,0,0,0,
3,3,2,3,2,4,
0,0,3,2,0,0,
0,0,4,1,0,0,
0,0,0,0,4,3,