指数関数eを用いた数値表記 [Python]

F1 scoreを計算する際など,分母にゼロが代入される可能性がある数式を記述する際は,数値リテラルを用いて微小な値を記述するのが便利.
例えば以下のように
def calc_f1(d): d = d/(d + d ...RuntimeError: The size of tensor a (1104) must match the size of tensor b (512) at non-singleton dimension 1

Hugging FaceのTransformersを使って,事前学習済モデルを読み込んで推定させるとタイトルのようなエラーがでることがある.
このエラーはBERTにおけるトークン(サブワード)の最大長512を超えた文が入力 ...
Tensorflowをpipでインストールするときのエラー

pip install tensorflow
を実行した際,
ERROR: Could not find a version that satisfies the requirement tensorflow
OptunaでFlair NERのパラメーターチューニング

とある仕事で,固有表現抽出器の性能をぎりぎりまで向上させる必要があったため,自作のコーパスに対してFlairでNERを学習し,Optunaでハイパーパラメータチューニングを行なった.本記事ではそのときのコードを示す.
Em ...
torch.saveとstate_dictの違い

Pytorchで学習したモデルを保存する時は
torch.save(model.state_dict(), model_path)でモデルを保存することが推奨される.
state_dictがsaveで直接保存す ...
AttributeError: ‘_IncompatibleKeys’ object has no attribute ‘to’

Pytorchを使っている時に出たエラー.これがでたときには,モデルの読み込みの順番でエラーが発生していることが多い.少し順番を変えてあげればケロっとエラーが解消されることが多い.
よくあるエラーが,.load_state ...
Flairでエラーがでたらバージョンを上げる

エラー
ModuleNotFoundError: No module named ‘flair.embeddings.token’; ‘flair.embeddings’ i ...
サポート外の引数が入ってきたときの例外処理 [Python]

スクリプトに一行挿入する.この場合,変数hogeに括弧内以外の文字列が入っているときにエラーをだす.
assert hoge in ("hogeA", "hogeB", "hogeC")yamlとdocoptを利用した引数指定 [Python]

個人的に,入出力をdocoptを記述し,コンフィグ情報はyamlを使って引数として取り込むのが好きなので,そのスクリプトについてメモしておく.decoptの記述では,空行を設けることが重要なので,必要以上に詰めて書かないこと. ...
ELECTRAをTPUで事前学習 [GCP]

GCP経由でTPUを利用することによって,ELECTRAの事前学習を実行する方法を紹介.
必要なサービスCompute EngineCloud TPU
Cloud Storage
手順Cloud Shell ...