This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
from typing import NamedTuple | |
from dataclasses import dataclass, asdict | |
# Python 3.7.3 で検証 | |
D = namedtuple('D', ('a', 'b', 'c')) | |
# 一部のメンバだけデフォルト値指定、というのができない? また、mypyに怒られる(正式な書き方じゃない?)。 | |
D.__new__.__defaults__ = (1, None, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas import json_normalize | |
import json | |
def read_json__normalize(json_file, add_key_category: bool = True): | |
""" | |
jsonファイルを読みこんでpandasのテーブル形式で返す | |
出力されるテーブルの各列の意味は以下の通り | |
* key_category : キーが階層的になっている場合、その一番上の階層での文字列 | |
* key : キー |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Dict, Any | |
import yaml | |
def read_setting_file(setting_file_path: str) -> Dict[str, Any]: | |
""" | |
設定ファイルの読み込みを行う関数 | |
""" | |
with open(setting_file_path, mode='r', encoding='utf-8') as f: | |
settings = yaml.safe_load(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from typing import Dict, List, Tuple, Any, Callable, Optional, Union, TypeVar | |
from pandas.core.frame import DataFrame as DF | |
from pandas.core.series import Series as S | |
from numpy import ndarray as ARR | |
from pathlib import Path | |
import pickle | |
import json | |
import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import hashlib | |
import dill | |
from pystan import StanModel | |
def textfile2hash(filename): | |
""" | |
テキストファイルの内容からハッシュ値を計算する | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
import argparse | |
# https://github.com/nn116003/self-attention-classification/blob/master/imdb_attn.pyより | |
parser = argparse.ArgumentParser(description='PyTorch IMDB Example') | |
parser.add_argument('--h-dim', type=int, default=32, metavar='N', | |
help='hidden state dim (default: 32)') | |
parser.add_argument('--emb_dim', type=int, default=100, metavar='N', | |
help='word embedding dim (default: 100)') | |
parser.add_argument('--batch-size', type=int, default=32, metavar='N', | |
help='input batch size for training (default: 32)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.metrics import accuracy_score | |
from sklearn.externals import joblib | |
import torch | |
from torch import nn | |
import torch.nn.functional as F | |
from tensorflow.keras.datasets import mnist | |
from skorch import NeuralNet |