Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: Cannot modify header information - headers already sent by (output started at /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php:340) in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/all-in-one-seo-pack/app/Common/Meta/Robots.php on line 87

Warning: Cannot modify header information - headers already sent by (output started at /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php:340) in /home/procedure/knowledge-io.com/public_html/wp-includes/feed-rss2.php on line 8
Knowledge-IO https://knowledge-io.com IT系のネタや知識をアウトプットしたかった Sun, 07 Jun 2020 14:45:50 +0000 ja hourly 1 https://wordpress.org/?v=6.4.3 150232208 事前学習済みのBERTベクトルを取得する https://knowledge-io.com/archives/425 Sun, 07 Jun 2020 14:45:50 +0000 http://knowledge-io.com/?p=425   事前学習済みのBERTから、文のベクトルを抽出します。 今回は、Googleの多言語モデル(multilingual)を利用します。   まずはmultilingual mod ...

The post 事前学習済みのBERTベクトルを取得する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
 

事前学習済みのBERTから、文のベクトルを抽出します。

今回は、Googleの多言語モデル(multilingual)を利用します。

 

まずはmultilingual model(cased)をダウンロード。

wget "https://storage.googleapis.com/bert_models/2018_11_23/multi_cased_L-12_H-768_A-12.zip"

解凍

unzip multi_cased_L-12_H-768_A-12.zip

 

この後必要なbert_configや学習済みモデル、語彙ファイルなどが入っています。

ls -l multi_cased_L-12_H-768_A-12
# total 1410608
# -rw-r--r--  1 user  staff        521 11 24  2018 bert_config.json
# -rw-r--r--  1 user  staff  714266612 11 24  2018 bert_model.ckpt.data-00000-of-00001
# -rw-r--r--  1 user  staff       8631 11 24  2018 bert_model.ckpt.index
# -rw-r--r--  1 user  staff     908833 11 24  2018 bert_model.ckpt.meta
# -rw-r--r--  1 user  staff     995526 11 24  2018 vocab.txt

gitからプログラム類をダウンロード

git clone https://github.com/google-research/bert.git

 

ベクトルの取得には、extract_features.pyを利用します。
ベクトルを取得するテキストファイルを作成。複数文ある場合は|||で区切ります。

echo 'Who was Jim Henson ? ||| Jim Henson was a puppeteer' > /tmp/input.txt

BERTベクトルの取得。output_fileに指定したPATHにベクトルが出力されます。

cd ~/bert
BERT_BASE_DIR=~/multi_cased_L-12_H-768_A-12

python extract_features.py \
  --input_file=/tmp/input.txt \
  --output_file=/tmp/output.jsonl \
  --vocab_file=$BERT_BASE_DIR/vocab.txt \
  --bert_config_file=$BERT_BASE_DIR/bert_config.json \
  --init_checkpoint=$BERT_BASE_DIR/bert_model.ckpt \
  --layers=-1,-2,-3,-4 \
  --max_seq_length=128 \
  --batch_size=8

確認

less /tmp/output.jsonl

 

以上です。

 

 

The post 事前学習済みのBERTベクトルを取得する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
425
【Python】Pickleで巨大データの読み込みを高速化する https://knowledge-io.com/archives/404 Fri, 05 Jun 2020 18:15:46 +0000 http://knowledge-io.com/?p=404   はじめに CSVファイルなどの巨大データを読み込む際、読み込みだけでなくパース処理なども行われるので、非常に時間がかかります。 Pythonでは、DataFrameやその他オブジェクトを ...

The post 【Python】Pickleで巨大データの読み込みを高速化する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
 

はじめに

CSVファイルなどの巨大データを読み込む際、読み込みだけでなくパース処理なども行われるので、非常に時間がかかります。

Pythonでは、DataFrameやその他オブジェクトを、Pickle(漬物)としてファイルに出力することで、次回以降の読み込みを高速化することが可能です。

Pickleファイルを読み込むことで、オブジェクトを再利用できます。また、CSVなどのファイルから読み込むのに対して、非常に高速です。

Pickle化は、通常のファイル出力と同じように出力できます。

注意点としては、openのモードはwb(rb)、また、巨大データを出力する際はサイズ制限があるので、dump時にprotocol=4とするくらいです。

import pickle

# df・・・Pickleにしたいオブジェクト

# Pickleとして出力
with open('example.pickle', 'wb') as f:
    pickle.dump(df, f, protocol=4)

# Piclkleを読み込み
with open('example.pickle', 'rb') as f:
    df = pickle.load(f)

 

以下、速度比較

テスト用のCSV作成

巨大ファイルとは言い難いですが、今回は検証として約2GBのテーブルデータを作成。CSVとして出力しました。

# テストデータ作成
# 1000000×100 1.98GB
data = make_classification(n_samples=1000000, n_features=100, n_classes=2)
pd.DataFrame(data[0]).to_csv('~/example.csv')

pd.read_csv()でCSVファイル読み込み

pd.read_csv()で通常通り読み込み。43.4s

%%time
df = pd.read_csv('~/example.csv')

# CPU times: user 32.6 s, sys: 2.45 s, total: 35 s
# Wall time: 43.4 s

Pickleファイルとして書き出し

DataFrameを書き出し。2.4s

%%time
import pickle

with open('example.pickle', 'wb') as f:
    pickle.dump(df, f, protocol=4)

# CPU times: user 326 ms, sys: 848 ms, total: 1.17 s
# Wall time: 2.4 s

Pickleファイルは771MBになりました。容量も削減できますね。

Pickleファイルを読み込み

Pickleファイルを読み込み。1.8s

%%time
import pickle

with open('example.pickle', 'rb') as f:
    df = pickle.load(f)
    
# CPU times: user 262 ms, sys: 1.12 s, total: 1.38 s
# Wall time: 1.8 s

 

読み込みだけで比較すると、43.4sから1.8sになりました。

一度巨大データをDataFrameとして読み込んだなら、Pickle化しておくと捗りそうですね。




The post 【Python】Pickleで巨大データの読み込みを高速化する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
404
OptunaでLightGBMのパラメータを自動でチューニングする https://knowledge-io.com/archives/386 Fri, 05 Jun 2020 16:59:45 +0000 http://knowledge-io.com/?p=386 OptunaにLightGBMが組み込まれて、より簡単に利用できるようになったので試してみました。 (ちなみに、オプチューナーと読むのが正しいようです。) 基本的に、LightGBMのimport文を ...

The post OptunaでLightGBMのパラメータを自動でチューニングする first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
OptunaにLightGBMが組み込まれて、より簡単に利用できるようになったので試してみました。
(ちなみに、オプチューナーと読むのが正しいようです。)

基本的に、LightGBMのimport文をoptuna配下のLightGBMに書き換え、train部分に少しの手直しするだけで簡単に使うことができます。

自動でサーチされるパラメータは下記の7つ。

  • lambda_l1
  • lambda_l2
  • num_leaves
  • feature_fraction
  • bagging_fraction
  • bagging_freq
  • min_child_samples

(私の場合、別途num_boost_roundとearly_stopping_roundsを設定して、early_stopするようにします。)
まずOptunaをインストール。LightGBMもOptunaに入っています。

pip install optuna

 

コード

import numpy as np
import pandas as pd

from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification

# import lightgbm as lgb
import optuna.integration.lightgbm as lgb

# ダミーのデータセット作成  
data = make_classification(n_samples=10000, n_features=100, n_classes=2)
X = pd.DataFrame(data[0])
y = pd.DataFrame(data[1])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, shuffle=False)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.3, shuffle=False)


# train用・valid用のデータセットを生成する
lgb_train = lgb.Dataset(X_train, y_train)
lgb_val = lgb.Dataset(X_val, y_val, reference=lgb_train)

# ベストなパラメータ、途中経過を保存する
best_params, tuning_history = dict(), list() 

lgbm_params = {'objective': 'binary', 
               'learning_rate':0.01, 
               'num_boost_round':10000, 
               'early_stopping_rounds':10
              }

# 学習
model = lgb.train(lgbm_params, 
                    lgb_train, 
                    valid_sets=lgb_val, 
                    verbose_eval=0,
                    best_params=best_params,
                    tuning_history=tuning_history)

 

best_paramsを使って学習・予測

import lightgbm as lgb

# 最適なパラメーターで学習

# train用・valid用のデータセットを生成する
lgb_train = lgb.Dataset(X_train, y_train)
lgb_val = lgb.Dataset(X_val, y_val, reference=lgb_train)

# 学習
model = lgb.train(best_params, 
                  lgb_train, 
                  valid_sets=lgb_val)

# フォールドアウト検証
predict_proba = model.predict(X_test)

 

以上です。めっちゃ楽。

 

参考

PFNの公式ブログ
Optuna の拡張機能 LightGBM Tuner によるハイパーパラメータ自動最適化

 




The post OptunaでLightGBMのパラメータを自動でチューニングする first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
386
【導入】SEOに強くてお洒落なWordPressテーマを使う【STINGER PLUS2】 https://knowledge-io.com/archives/366 Thu, 09 Jan 2020 15:44:49 +0000 http://knowledge-io.com/?p=366   今回は、私もお世話になっているSTINGER PLUS2というWordPressテーマの導入手順を、自分用メモも兼ねて紹介します。 STINGER PLUS2は、SEOにも強く、デフォル ...

The post 【導入】SEOに強くてお洒落なWordPressテーマを使う【STINGER PLUS2】 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
 

今回は、私もお世話になっているSTINGER PLUS2というWordPressテーマの導入手順を、自分用メモも兼ねて紹介します。

STINGER PLUS2は、SEOにも強く、デフォルトでも超おしゃれなWordPressテーマです。

さらに機能を拡張した有料版もありますが、(というか無料版が機能制限されているだけなんですが)、今のところ無料版で困ってはいないです。

必要に応じて有料版に切り替えていく予定。


 

WordPressのダッシュボードから、新しいテーマをダウンロードして変更したことがある方もいるかと思います。

STINGER PLUS2は、公式ホームページからダウンロード、インストールしてから有効化する必要があるので、手順をまとめます。

ダウンロード

ダウンロード場所が正直わかりにくく、毎回探してしまうのですが、下記からダウンロードできます。

ダウンロード及び規約

ダウンロードボタンがどこだかわかりにくいのですが、この紺色の吹き出しを押すとダウンロードが開始されます。

スクショにある、下記2つともにダウンロードしてください。

zip形式ですが、解凍せずにzipのまま使用します。

  • STINGER_PLUS2ver20171207
  • STINGER_PLUS2用子テーマver20170621

アップロード

ダウンロードしたテーマファイルを、ご自身のWordPress上にインストールします。

WordPressダッシュボードから、下記のように辿っていきます。

  1. 外観
  2. テーマ
  3. 新規追加
  4. テーマのアップロード

先ほどダウンロードした、2つのzipファイルをアップロード、インストールします。

順番は親テーマを先にインストールしてから、子テーマをインストールしてください。

有効化

インストールが完了すると、他のテーマと同じように、テーマ一覧に表示されるようになります。

インストール後はトップページヘッダーに、デフォルトのヘッダーがセットされていたりするので、必要に応じて無効化したり、他の画像に変更してください。

また、固定ページも設定されているので、こちらも非表示にしておくと良いでしょう。

カスタマイズ

公式サイトなどにもカスタマイズについて詳しく紹介されていますので、

参考にカスタマイズしてみてください。

こちらについては、また別途記事にできればと思います。

 

以上です。




The post 【導入】SEOに強くてお洒落なWordPressテーマを使う【STINGER PLUS2】 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
366
dpkgで入れたパッケージを強制的に削除する https://knowledge-io.com/archives/204 Sun, 16 Sep 2018 14:53:44 +0000 https://knowledge-io.com/?p=204 Ubuntuにdpkgで入れたパッケージがなんか削除できないときに、強制的に削除するメモ。 まず、パッケージの削除は基本的に -P(–purge)オプションをつければOK [crayon- ...

The post dpkgで入れたパッケージを強制的に削除する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
Ubuntuにdpkgで入れたパッケージがなんか削除できないときに、強制的に削除するメモ。

まず、パッケージの削除は基本的に -P(–purge)オプションをつければOK

sudo dpkg -P 【package】

ただ、パッケージや依存関係が壊れてたりすると、消えてくれないことがあるっぽい。

–force-remove-reinstreq オプションもつけると消えてくれた。

sudo dpkg -P --force-remove-reinstreq 【package】

以上です。




The post dpkgで入れたパッケージを強制的に削除する first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
204
リモートマシンのJupyterNotebook環境を使う https://knowledge-io.com/archives/251 Sat, 08 Sep 2018 04:10:30 +0000 https://knowledge-io.com/?p=251   こんにちは。 最近は機械学習分野に関わることが多いのですが、この分野ではJupyter Notebookが大活躍です。   私のマシン環境はMacBookPro1台、GPU付き ...

The post リモートマシンのJupyterNotebook環境を使う first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
 


こんにちは。

最近は機械学習分野に関わることが多いのですが、この分野ではJupyter Notebookが大活躍です。

 

私のマシン環境はMacBookPro1台、GPU付きのデスクトップPC1台です。

MacBookPro上でJupyterを使っても勿論いいんですが、やはりGPUマシンで機械学習を実行したい。

でも普段はMacBookPro使いしたい・・・

ということで、サーバ(デスクトップマシン)上でJupyterを走らせて、

クライアント(MacBookPro)のブラウザから閲覧、実行できる環境を構築したのでメモ。

Jupyter Notebookとは・・・こんな感じです。

セルにPythonのコードや、Markdownの記述を行うことができます。

Jupytercap

 

Jupyter Notebookは便利なショートカットがたくさんあり、知っていると知らないとでは作業効率に雲泥の差が出ます。一度本なりネットなりで体系的に調べてみることをおすすめします。

 


インストール

サーバ側

インストールは・・・AnacondaでPython入れれば、もともと入っています。

そうでない人は、pipでインストール

pip install jupyter


設定

サーバ側

クライアントから利用できるようにするための設定です。

sha1の鍵を取得

python

>>> from notebook.auth import passwd

>>> passwd()

パスフレーズを2回入力。Jupyterにログインするときに必要になります。

’sha1:hogehoge’的な鍵が出力されます。

mkdir ~/.jupyter

vi ~/.jupyter/jupyter_notebook_config.py

c = get_config()

c.NotebookApp.ip = '*'
c.NotebookApp.password = u’sha1:hogehoge'

c.NotebookApp.open_browser = False

c.NotebookApp.port = 9999 #接続ポート指定

参考:Jupyter notebookをリモートサーバで実行する


起動

サーバ側

jupyter notebook &

マシン起動時に自動でデーモン実行させる設定

vi /etc/rc.local

nohup jupyter notebook &


接続

クライアント側

ブラウザから以下にアクセス

http://<サーバのIP>:9999

パスワードの入力を求められるので、SHA1の鍵を作ったときのパスを入れてログイン。

以上、お疲れ様です。




The post リモートマシンのJupyterNotebook環境を使う first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
251
【手順】Ubuntu18.04 + CUDA + CuDNN + Chainerの環境構築 https://knowledge-io.com/archives/205 Sun, 12 Aug 2018 08:53:44 +0000 http://knowledge-io.com/?p=205 こんにちは。 Ubuntu18.04LTSにGPU版のChainerをインストールしたので、手順を残しておきます。   Ubuntu18向けのCUDAが無かったり、悩む箇所が多かったです。 ...

The post 【手順】Ubuntu18.04 + CUDA + CuDNN + Chainerの環境構築 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
こんにちは。

Ubuntu18.04LTSにGPU版Chainerインストールしたので、手順を残しておきます。

 

Ubuntu18向けのCUDAが無かったり、悩む箇所が多かったです。

2020年1月現在、Ubuntu18.04向けのCUDA tool kitがリリースされています。

最新版は10.2です。

CUDA tool kit 10.2をダウンロード

環境

OS : Ubuntu18.04 LTS
GPU : Geforce GTX780
Anaconda3.7 (Python3.7)

 

補足

Anacondaのバージョンは最新の3.7です。

ChainerはPython3.7で問題なく動きますが、

TensorFlowはPython3.7に対応していないようです。

TensorFlowを入れる場合は、3.6の仮想環境を作るか、

古いAnaconda(Anaconda3-5.2より前?)を入れましょう。

今回導入するライブラリ

CUDA 9.0
CuDNN 7.2.1

Chainer
Cupy

手順

作業項目としては以下の通り。

  1. 標準ドライバを無効化する。
  2. Nvidia Driverをインストール
  3. Cuda 9.0のインストール
  4. CuDNNのインストール
  5. ChainerとCupyのインストール
  6. 動作確認

作業途中に何度かリブートしてますが、一応やったほうが良いです。

最後まで無事に入ったけど、リブートしたら画面真っ暗・・・ということもあったので。

どこで動かなくなったかの切り分けをする意味でも、慎重めにいきましょう。

 

標準ドライバを無効化する。

 

標準ドライバのモジュールを読み込まないように、Ubuntuの起動時に読み込むモジュールのブラックリストに追加します。

sudo vi /etc/modprobe.d/blacklist-nouveau.conf

以下を記述

blacklist nouveau
options nouveau modeset=0

再起動

reboot

 

Nvidia Driverをインストール

 

対応バージョンの確認は以下から。自分の環境を選択して確認する。
NVIDIAドライバの確認

GTX780のドライバはnvidia-390です。

レポジトリにnvidia-390がないため、先にレポジトリを追加してからインストール。

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt install nvidia-390

 

再起動。

reboot

 

GPUが認識されているか確認。

nvidia-smi

GPUが表示されていたら成功。

Cuda 9.0のインストール

 

CUDA9.0をNVIDIAからダウンロードします。
残念ながらUbuntu18.04用はありません。

仕方ないのでUbuntu17.04のもので代用・・・

CUDA9.0のダウンロード

 

インストール

sudo apt install ./Downloads/cuda-repo-ubuntu1704-9-0-local_9.0.176-1_amd64.deb 
sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub 
sudo apt update 
sudo apt install cuda

 

またまた、一応再起動。慎重にいきましょう・・・

reboot

 

CuDNNのインストール

 

次に、CuDNNをインストールします。

CuDNNのダウンロードには会員登録が必要です。
面倒ですが、ここは素直に登録しましょう。

登録とCuDNNのダウンロードは以下から。CuDNNのダウンロード

 

登録が完了したら、先ほどインストールしたCUDAのバージョン(9.0)に合わせたCuDNNをダウンロードします。

 

今回はCuda9.0を入れたので、
Download cuDNN v7.2.1 (August 7, 2018), for CUDA 9.0 から、

  • cuDNN v7.2.1 Runtime Library for Ubuntu16.04 (Deb)
  • cuDNN v7.2.1 Developer Library for Ubuntu16.04 (Deb)

の2つをダウンロード。

こちらも、Ubuntu18.04版はないので16.04版で代用

 

インストール

sudo dpkg -i./Downloads/libcudnn7_7.2.1.38-1+cuda9.0_amd64.deb
sudo dpkg -i./Downloads/libcudnn7-dev_7.2.1.38-1+cuda9.0_amd64.deb

 

ChainerとCupyのインストール

pip install msgpack # 依存ライブラリ?
pip install chainer
pip install cupy-cuda90

 

動作確認

ChainerでGPU確認

python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import chainer
/home/mamoru/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> chainer.cuda.cupy.cuda.device.get_device_id()
0

 

利用可能なGPUの番号(0)が表示されれば成功です。

GPU版のChainerが動けば、TensorFlow(GPU)なども問題なく入るでしょう。

 

以上、お疲れさまでした。




The post 【手順】Ubuntu18.04 + CUDA + CuDNN + Chainerの環境構築 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
205
Ubuntu18.04にVisual Studio Codeをインストールする。 https://knowledge-io.com/archives/210 Sun, 12 Aug 2018 07:53:14 +0000 http://knowledge-io.com/?p=210 こんにちは。 今回は、Ubuntu18.04にVisual Studio Code(以下VScode)をインストールします。 Anaconda3をインストールするときに、VScode入れとく?と聞かれ ...

The post Ubuntu18.04にVisual Studio Codeをインストールする。 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
こんにちは。

今回は、Ubuntu18.04にVisual Studio Code(以下VScode)をインストールします。

Anaconda3をインストールするときに、VScode入れとく?と聞かれますが、いろいろあって入れ損ねました。

あとから自分でdebを落としてインストールしようとしたら
地味にはハマったのでメモとして残しておきます。
(地味にハマってばかり)

参考
Visual Studio Code Installation Error on Ubuntu 18.04

 


まず必要なファイルをダウンロード

VScode本体だけでインストールしようとしても通りませんでした。

まず依存ライブラリをインストールしてからVS code本体をインストールしましょう。

 

以下ダウンロード先

依存ライブラリ2つ

gconf2-common_3.2.6-4ubuntu1_all.deb

libgconf-2-4_3.2.6-4ubuntu1_amd64.deb

 

VScode本体
code_1.25.1-1531323788_amd64.deb

 

インストール

cd ./Download
sudo dpkg -i gconf2-common_3.2.6-4ubuntu1_all.deb
sudo dpkg -i libgconf-2-4_3.2.6-4ubuntu1_amd64.deb
sudo dpkg -i code_1.24.1-1528912196_amd64.deb

 

起動

code
#または
code ファイル名

 


以上です。




The post Ubuntu18.04にVisual Studio Codeをインストールする。 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
210
Ubuntu16.04にChromeをインストールする【地味にハマる】 https://knowledge-io.com/archives/188 Sat, 11 Aug 2018 11:09:39 +0000 http://knowledge-io.com/?p=188 こんばんは。 Ubuntu16.04にChromeをインストールしようとしたら地味にハマったので備忘録として記事にしておきます。 参考 Ubuntu 16.04 にGoogle Chromeをインスト ...

The post Ubuntu16.04にChromeをインストールする【地味にハマる】 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>

Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 84

Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 84

Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 84

Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /home/procedure/knowledge-io.com/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 84

こんばんは。

Ubuntu16.04にChromeをインストールしようとしたら地味にハマったので備忘録として記事にしておきます。

参考
Ubuntu 16.04 にGoogle Chromeをインストール

 

同じくインストールでハマったという記事はいくつもありましたが、
そのままだと自分の環境ではうまくインストールできませんでした。


Chromeのダウンロードはこちらから。

Chromeをダウンロード

実行ではなく保存しておきましょう。

 

前準備

おそらくこの記事を見ている方は、インストールしようとしたらハマった方が多いのではないでしょうか。

中途半端にパッケージが入っていても厄介なので、一応remove

sudo apt remove google-chrome-stable

依存パッケージをインストール

Chrome本体の前に、依存パッケージをインストール

sudo apt install libappindicator1

 

Chromeをインストール

ダウンロードしたdebからChromeをインストール

# sudo apt install 【ダウンロードしたdebファイルのPATH】
sudo apt install ./Downloads/google-chrome-stable_current_amd64.deb

起動

google-chrome


以上です。

apt-getは通らないけどaptは通るみたいな微妙な違いですが、
私の環境ではこれでうまくいきました。




The post Ubuntu16.04にChromeをインストールする【地味にハマる】 first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
188
WordPressにソースコードを埋め込む https://knowledge-io.com/archives/159 Sun, 22 Jul 2018 05:52:46 +0000 http://procedure.xsrv.jp/metrics/?p=159 こんにちは。 前回の記事から約一年ぶりの投稿となってしまいました・・・ 技術系のブログやQiitaなど、ソースコードが埋め込まれたブログをよく目にします。 本ブログでも同じようなことをしたいため、方法 ...

The post WordPressにソースコードを埋め込む first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>




こんにちは。
前回の記事から約一年ぶりの投稿となってしまいました・・・

技術系のブログやQiitaなど、ソースコードが埋め込まれたブログをよく目にします。

本ブログでも同じようなことをしたいため、方法を調べてみました。

ソースコードを埋め込む方法は大きく分けて2つ

  • WordPressのプラグインを入れる
  • ソースコードからHTML+CSSを生成してくれるサービスを使う

 

せっかくなので、どちらも試してみましょう。


まずはプラグインでソースコードを埋め込む方法。

Crayon Syntax Highlighter」というプラグインを利用します。

 

プラグインを導入すると、記事の作成画面で新たなプラグインのボタンが表示されます。

 

ここからソースコードを作成。

 

変更をプレビュー・・・
あれ、背景は灰色に変わったけど、うまく反映されない・・・

WordPressの変更プレビューではうまく反映されませんでしたが、
公開するとうまく反映されていました。

以下、埋め込んだソースコード。
特に意味はありませんが、PythonでOSを判別するプログラムです。

# ライブラリのインポート
import os
 
# OS種別取得 mt / posix 
os_type = os.name
 
# OS名出力
if os_type == 'nt':
    print('Windows')
elif os_type == 'posix':
    print('Linux')

これこれ!
いい感じに埋め込みましたね!


 

次は2つ目の方法で、GitHubが提供しているGitHubGistというサービスを試してみたいと思います。

GitHubGist上でソースコードを公開、それを記事内のスクリプトで読み込むという流れです。

登録・ソースコードの公開は以下から。
GithubGist

GitHubのサービスなので、Gitとしての機能も使用できます。
(バージョン管理)

 

以下埋め込んでみた結果

どうですか?いい感じに埋め込めましたね。


今回は2パターン試してみましたが、一度プラグインを入れて使い方がわかってしまえば、プラグインのほうが手間が少なく簡単に感じました。

 

あえて使い分けるとすれば、

簡単に短いコードを埋め込みたいとき・・・プラグイン
長いコード、差分管理を行いたいコード・・・GitHubGist

という感じでしょうか。

これで技術系の記事が書きやすくなりました。

 

 

参考

WordPress 記事にソースコードを埋め込むテクニック&プラグイン紹介

記事内にソースコードをキレイに表示するWordPressプラグイン「Crayon Syntax Highlighter」




The post WordPressにソースコードを埋め込む first appeared on Knowledge-IO.

Copyright © 2024 Knowledge-IO All Rights Reserved.

]]>
159