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 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" |
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 Translator import Translator | |
import time | |
# 英日翻訳の学習 | |
start_time = time.time() | |
print("model new start.") | |
model = Translator(True) |
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 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 |
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
# 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 |
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
# 英日翻訳の訓練データの元となるファイルをダウンロードするシェル | |
# 例文 | |
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 |
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
{- | |
- 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 |
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
{- | |
- 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)] |
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
<?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; |