Skip to content

Instantly share code, notes, and snippets.

View butsugiri's full-sized avatar
💦

Shun Kiyono butsugiri

💦
View GitHub Profile
# -*- coding: utf-8 -*-
"""
Parse iTunes Library and Generate Word Cloud
"""
"""
Copy "iTunes Music Library.xml" to the same directory as Python script
"""
import matplotlib.pyplot as plt
from lxml import etree
from collections import defaultdict
@butsugiri
butsugiri / my_mlp.py
Last active May 17, 2016 00:18
多層パーセプトロンの実装例
# -*- coding: utf-8 -*-
"""
"""
import numpy as np
def sigmoid(x):
return 1./(1.+np.exp(-x))
def sigmoid_deriv(x):
return x * (1.0 - x)
@butsugiri
butsugiri / my_mlp_tutorial.py
Created May 17, 2016 00:18
チュートリアルから作った多層パーセプトロン
# -*- coding: utf-8 -*-
"""
お手製のニューラルネットワーク
トレーニング編
"""
import sys
import numpy as np
from collections import defaultdict
def create_features(line, ids):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# -*- coding: utf-8 -*-
"""
Chainerを用いた多層パーセプトロンの実装
多分に参考にしました: https://github.com/ichiroex/xor-mlp-chainer
"""
import sys
import numpy as np
import chainer
from chainer import cuda, Function, gradient_check, Variable, optimizers, serializers, utils
from chainer import Link, Chain, ChainList
# -*- coding: utf-8 -*-
"""
docomoの言語解析API(固有表現抽出)を叩くサンプルコード
"""
import requests
import json
BASEURL = "https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/entity?APIKEY="
APIKEY = "YOUR APIKEY" #ここにAPIKEYを入力
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@butsugiri
butsugiri / parse_shift_jis_xml.py
Created November 11, 2016 12:52
shift_jisとヘッダーのエンコーディングに記述されたshift_jisなxmlファイルとうまくやる方法
text = open("00001.dict", encoding="shift-jis").read()
tree = etree.fromstring(text.encode("shift-jis"))
print(etree.tostring(tree, encoding="utf-8", xml_declaration=True, doctype="<!DOCTYPE gda>").decode("utf8"))
# -*- coding: utf-8 -*-
from nltk.tree import Tree
from nltk.tree import ParentedTree
from nltk.tree import ImmutableParentedTree
def main():
tree = ImmutableParentedTree.fromstring("(ROOT (S (NP (NNP Dog)) (VP (VBZ likes) (NP (NN cat))) (. .)))")
t = tree.leaf_treeposition(1)
x = tree.leaf_treeposition(2)
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import pandas as pd\n",