This file contains 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 json | |
from typing import NamedTuple, get_origin, get_args | |
def dict_to_namedtuple(d, namedtuple_type): | |
if isinstance(d, dict): | |
# ネストされた辞書を再帰的にnamedtupleに変換 | |
return namedtuple_type(**{k: dict_to_namedtuple(v, namedtuple_type.__annotations__[k]) | |
for k, v in d.items()}) | |
elif isinstance(d, list): |
This file contains 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 python:3.9-buster | |
ENV PYTHONUNBUFFERED=1 | |
RUN mkdir app | |
WORKDIR /app | |
RUN pip install --upgrade diffusers transformers scipy jupyter matplotlib |
This file contains 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
const express = require('express'); | |
const app = express(); | |
const PORT = 8080; | |
app.use(express.static('public', { | |
setHeaders: function (res, path) { | |
// no allow cache | |
res.set("Cache-Control", "no-cache"); | |
// CORS |
This file contains 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
#include <stdio.h> | |
#include <stdint.h> | |
#include <assert.h> | |
#define DATA_SIZE 2052 | |
float decode(uint16_t float16_value) | |
{ | |
// MSB -> LSB | |
// float16=1bit: sign, 5bit: exponent, 10bit: fraction |
This file contains 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
# runs model trained by imdb_lstm.py and gets input-output pair | |
import numpy as np | |
import keras | |
from keras.preprocessing import sequence | |
from keras.datasets import imdb | |
max_features = 20000 | |
maxlen = 80 # cut texts after this number of words (among top max_features most common words) |
This file contains 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
# reproduce lstm prediction by basic numpy operations | |
# model trained on imdb_lstm.py | |
# based on https://github.com/fchollet/keras/blob/master/keras/layers/recurrent.py#L1130 | |
import numpy as np | |
from scipy.special import expit # logistic function | |
import h5py | |
""" | |
{'class_name': 'Sequential', | |
'config': [{'class_name': 'Embedding', |
This file contains 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
'''Trains a LSTM on the IMDB sentiment classification task. | |
The dataset is actually too small for LSTM to be of any advantage | |
compared to simpler, much faster methods such as TF-IDF + LogReg. | |
Notes: | |
- RNNs are tricky. Choice of batch size is important, | |
choice of loss and optimizer is critical, etc. | |
Some configurations won't converge. | |
- LSTM loss decrease patterns during training can be quite different |
This file contains 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
#include <iostream> | |
#include <Eigen/Dense> | |
using namespace std; | |
using namespace Eigen; | |
// matrix multiplication using provided memory area | |
// compile with -std=c++11 | |
int main() | |
{ | |
const int size = 2; |