Skip to content

Instantly share code, notes, and snippets.

nihemak

Block or report user

Report or block nihemak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View en2ja_test.py
from Translator import Translator
# 英日翻訳のテスト
en_lines = open('en-test.txt').read().split('\n')
epoch_num = 100
for epoch in range(epoch_num):
model = Translator()
modelfile = "en2ja-" + str(epoch) + ".model"
View en2ja_learn.py
from Translator import Translator
import time
# 英日翻訳の学習
start_time = time.time()
print("model new start.")
model = Translator(True)
View Translator.py
import numpy as np
import chainer
from chainer import Variable, optimizers, serializers, Chain
import chainer.functions as F
import chainer.links as L
# 翻訳クラス(Encoder-Decoder翻訳モデルにAttentionを導入したモデルを使う)
class Translator(chainer.Chain):
def __init__(self, debug = False, source = 'en.txt', target = 'ja.txt', embed_size = 100):
self.embed_size = embed_size
View en2ja_setup.py
# en2ja_data_download.shで落としてきたデータから英日翻訳の訓練データを作成するスクリプト
import random
# 和文と英文を取り出す
en_sentences, ja_sentences = {}, {}
lines = open('sentences.csv').read().split('\n')
for i in range(len(lines)):
if lines[i] == '':
continue
View en2ja_data_download.sh
# 英日翻訳の訓練データの元となるファイルをダウンロードするシェル
# 例文
wget http://downloads.tatoeba.org/exports/sentences.tar.bz2
tar xf sentences.tar.bz2
# -> sentences.csv
# 日本語索引
wget http://downloads.tatoeba.org/exports/jpn_indices.tar.bz2
tar xf jpn_indices.tar.bz2
@nihemak
nihemak / mathpro7_2.hs
Last active Dec 27, 2015
http://nineties.github.io/math-seminar/7.html 練習問題(ガウス消去法/ピボット選択)をHaskellでmutableなarrayを使用して書いてみた
View mathpro7_2.hs
{-
- http://nineties.github.io/math-seminar/7.html
- 練習問題(ガウス消去法/ピボット選択)をHaskellで書いてみた
- (mutableなarrayを使用)
-}
import Data.Array
import Data.Array.ST
import Data.Array.MArray
import Control.Monad
import Control.Monad.State
@nihemak
nihemak / mathpro7.hs
Created Nov 2, 2013
http://nineties.github.io/math-seminar/7.html 練習問題(行列計算/ピボット選択まで)をHaskellで書いてみた
View mathpro7.hs
{-
- http://nineties.github.io/math-seminar/7.html
- 練習問題(行列計算/ピボット選択まで)をHaskellで書いてみた
-}
import Data.Array
{- 目的:行列aとbの和を求める -}
mat_add :: Num a => Array (Int, Int) a -> Array (Int, Int) a
-> Array (Int, Int) a
mat_add a b = array bs [((i,j),a!(i,j)+b!(i,j))|i<-range(l1,l2),j<-range(m1,m2)]
View tco.php
<?php
# 継続渡しスタイルの末尾再帰関数をwhile形式に変換して実行する関数
function tco(array $xs, $f) {
list($ys, $in, $run) = [[], false, false];
return call_user_func_array($g = function() use($f, &$ys, &$in, &$run) {
$zs = func_get_args();
if ($in) {
$ys = $zs;
$run = true;
You can’t perform that action at this time.