2018년에 하나도 글을 쓰지 않았다는 점이 새삼 놀랍다.
뭔가 끄적거리려다가도 Blogger 플랫폼자체가 맘에 안드는 것도 있었고, (분류, 에디터, 포맷, ...) 안쓰다 쓰려면 시간 아까운 느낌도 있고, 아주 약간 부담도 되고.
올해는 그래도 몇자 적어보려 한다.
특히 스마트폰 덕에 독서량이 대폭 줄었기에 올해 계획 중 일부인 독서와 관련한 기록은 아주 약간이라도 트래킹할겸 남길 예정.
def computeLongestPalindrome_recur(text): input_len = len(text) if input_len == 0: return 0 elif input_len == 1: return 1 elif (input_len > 1) and (text[0] == text[-1]): return 2 + computeLongestPalindrome_recur(text[1:input_len-1]) elif (input_len > 1) and (text[0] != text[-1]): return max(computeLongestPalindrome_recur(text[:input_len-1]), computeLongestPalindrome_recur(text[1:input_len])) return 0
from collections import defaultdict
memory = defaultdict(int)
def computeLongestPalindrome(text): if text in memory: return memory[text] else: text_length = len(text) if text_length == 0: return 0 elif text_length == 1: return 1 else: if text[0] == text[-1]: memory[text] = 2 + computeLongestPalindrome(text[1:-1]) else: memory[text] = max([ computeLongestPalindrome(text[:-1]), computeLongestPalindrome(text[1:]) ]) return memory[text]
지역 | 업종 |
경기도 | 요식업 |
경기도 | 헬스 |
서울 | 한식 |
서울 | 학원 |
강원도 | 초등학교 |
강원도 | 커피 |
… |
...
|
제주도 | 제과점 |
지역 | 업종 |
경기도 | 요식업, 헬스, … |
서울 | 한식, 학원, … |
강원도 | 초등학교, 커피, … |
제주도 | 제과점, … |
# coding: utf-8 # # #### Gensim model building # In[98]: # Import required modules import gensim, codecs import re # In[99]: sentences_vocab = [] for line in codecs.open('impeachment_sentence.txt', encoding='utf-8'): sentences = [word+'다.' for word in line.split('다. ') if word!='\n'] for sentence in sentences: sentence = re.sub('\\n다.' , '' ,sentence) sentence = re.sub('\\u3000.' , '' ,sentence) sentences_vocab.append(sentence) # In[101]: from konlpy.tag import Twitter pos_tagger = Twitter() def tokenize(doc): return ['/'.join(t) for t in pos_tagger.pos(doc, norm=True, stem=True) ] # In[102]: tokenize('전국경제인연합회(다음부터 \'전경련\'이라 한다)가 주도하여 만든 것으로 알려져있던') # In[103]: # Preprocessing sentences_vocab = [] for line in codecs.open('impeachment_sentence.txt', encoding='utf-8'): sentences = [word+'다.' for word in line.split('다. ') if word!='\n'] for sentence in sentences: sentences_vocab.append(tokenize(sentence)) # In[104]: sentences_vocab[41] # In[105]: import multiprocessing config = { 'min_count': 1, 'size': 300, 'sg': 1, 'batch_words': 10, 'iter': 100, 'workers': multiprocessing.cpu_count(), } model = gensim.models.Word2Vec(**config) # In[106]: model.build_vocab(sentences_vocab) # In[140]: num_w2v = len(model.wv.index2word) print (num_w2v) # In[141]: import numpy as np w2v = np.zeros((num_w2v,300)) with open("./projector/metadata.tsv", 'w+') as file_metadata: for i,word in enumerate(model.wv.index2word): w2v[i] = model[word] file_metadata.write(word + '\n') # #### Tensorflow Visualization # In[134]: import tensorflow as tf from tensorflow.contrib.tensorboard.plugins import projector import numpy as np # setup a TensorFlow session tf.reset_default_graph() sess = tf.InteractiveSession() X = tf.Variable([0.0], name='embedding') place = tf.placeholder(tf.float32, shape=[None, 300]) set_x = tf.assign(X, place, validate_shape=False) sess.run(tf.global_variables_initializer()) sess.run(set_x, feed_dict={place: w2v}) # create a TensorFlow summary writer summary_writer = tf.summary.FileWriter('projector', sess.graph) config = projector.ProjectorConfig() embedding_conf = config.embeddings.add() embedding_conf.tensor_name = 'embedding:0' embedding_conf.metadata_path = './projector/metadata.tsv' projector.visualize_embeddings(summary_writer, config) # save the model saver = tf.train.Saver() saver.save(sess, './projector/model.ckpt') sess.close()
![]() |
Docker image Pull & Run |
![]() |
localhost 접속 결과. 안된다. |
![]() |
virtual ip를 확인하자! |
![]() |
노트북 리스트가 떴다! |