Skip to content

Instantly share code, notes, and snippets.

View Elfsong's full-sized avatar
😃
Excelsior

游刃 Elfsong

😃
Excelsior
View GitHub Profile
@Elfsong
Elfsong / open_fd.py
Last active January 3, 2019 10:00
Open a file #File #Open
with open("FILE_NAME", MODE, encoding="utf-8") as file_fd:
for item in file_fd.readlines():
print(item)
@Elfsong
Elfsong / douban_pip.bash
Last active January 6, 2019 10:45
Pip downloading by douban source #pip #douban
sudo -H pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ipython
pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com ipython
@Elfsong
Elfsong / sc.py
Last active January 3, 2019 10:01
Scenario classifier #Keras #word2vec
import json
import os
import gensim
import numpy as np
from keras.layers import Dense, Activation, Dropout
from keras.models import Sequential
from keras.optimizers import RMSprop
from keras.utils import np_utils
@Elfsong
Elfsong / seperate_sentence.py
Last active January 7, 2019 16:32
seperate_sentence #python #NLP
def cut_sent(para):
para = para.replace(u'\u3000', '')
para = re.sub('([。!?\?])([^”’])', r"\1\n\2", para) # 单字符断句符
para = re.sub('(\.{6})([^”’])', r"\1\n\2", para) # 英文省略号
para = re.sub('(\…{2})([^”’])', r"\1\n\2", para) # 中文省略号
para = re.sub('([。!?\?][”’])([^,。!?\?])', r'\1\n\2', para)
para = para.rstrip()
return [sentence for sentence in para.split("\n") if sentence]
@Elfsong
Elfsong / sentence_level_detector_CNN.py
Created January 7, 2019 16:34
Sentence Level scenario detector_CNN #CNN #NLP
import os
import numpy as np
import pandas as pd
from bert_serving.client import BertClient
from keras.layers import Conv1D
from keras.layers import Dense, Activation, Dropout, Flatten, AveragePooling1D
from keras.models import Sequential
from keras.optimizers import RMSprop
from keras.utils import np_utils
@Elfsong
Elfsong / fetch_ltp.py
Created January 9, 2019 08:15
LTP online demo fetch
#############################
Wanxiang Che, Zhenghua Li, Ting Liu.
LTP: A Chinese Language Technology Platform.
In Proceedings of the Coling 2010:Demonstrations. 2010.08, pp13-16, Beijing, China.
#############################
import requests
def fetch(sentence):
@Elfsong
Elfsong / TFB.plaintext
Created January 18, 2019 02:51
Temporary File Bridge
“不许动,在动我们就开枪了!”一名尉官模样持枪大喝道。
“刷刷刷”周围的几十名士兵此刻也是拉动的手中的枪栓,打开了保险,枪头此刻也是瞄准着唐铭。
唐铭闯入了军区之中,军区中的警报四响,无数的士兵更是纷纷拿起的枪支准备迎敌。唐铭一路快速的轻功赶路正好在此处遇见了收到了警报的士兵。
“指挥部,我三连四排在***地点发现可疑人员,请求指示。。。。”尉官也是急忙的对着胸口前的对讲上报情况。
唐铭没有理会士兵的警告,更是不急不缓的继续的向前走去。
“啪”枪响了,一发子弹从枪**击而出,打在了唐铭脚前的地面上,露出了一个冒着白烟的深洞。
“不许动,再敢动一步,信不信我一枪杀了你。”尉官手中的枪口更是向上抬了一台,警告道。
唐铭停了一步,随即又仿佛没看到一般,再次的向前走去。
“啪”又是一枪响起,这一枪直奔唐铭的膝盖而去,军队的规矩是第一次鸣枪警告,警告无效第二次便是直接开枪击毙,但这尉官见唐铭手中并无武器和其他威胁,便是心软了一下,想要打中他的腿,制止他的行动。
“啪”的一声,子弹打空的,打在的地面之上,而唐铭此时却消失在了原地。
@Elfsong
Elfsong / mnist_gan.py
Last active January 25, 2019 09:37
MNIST_GAN #GAN #python
import os # Get system method
import shutil # Recursive traversing file path
import tensorflow as tf # Neural Network2
import numpy as np # Matrix Computing
from skimage.io import imsave # Image operation
from tensorflow.examples.tutorials.mnist import input_data
data = input_data.read_data_sets('MNIST_data/')
@Elfsong
Elfsong / excel_writer.py
Last active January 26, 2019 04:56
Excel writer #spreadsheet #python
import xlwt
import random
import demo_night
ROOT_PATH = r"C:\Users\t-midu\PycharmProjects\Scenario_detecter"
RESOURCE_PATH = os.path.join(ROOT_PATH, "resource")
file_path = os.path.join(RESOURCE_PATH, "stories.json.txt")
# Crating a new sheet
@Elfsong
Elfsong / excel_reader
Created January 26, 2019 06:11
Excel Reader #spreadsheet #python
import os
import xlrd
ROOT_PATH = r"C:\Users\t-midu\PycharmProjects\Scenario"
RESOURCE_PATH = os.path.join(ROOT_PATH, "resource")
file_path = os.path.join(RESOURCE_PATH, "sentence_class.xls")
data = xlrd.open_workbook(file_path)