この記事は CAMPHOR- Advent Calendar 2014 5日目の記事です。 こんにちは @Shtr28です。自然言語処理の研究とかしてます。 今日は研究してる時に便利だった concurrent.futures モジュールを紹介します。 Future は並列計算のパターンのひとつです。 今回はテキストを使って機械学習するときによく使う ngram を Future で並列計算します! 日本語を形態素解析器 mecab で分かち書きして、一行ずつ ngram を計算します。 フルのコードはここ(gist)。 メインの並列化のコードはここ。 def multi_process(): # kgram に対して識別番号を順番にふるための dict kgram2id = defaultdict(lambda: len(kgram2id)) # 並列計算のプロセスプールを確保! wit