ELMoEmbeddingsのときはallennlp==0.9.0
![Thumbnail of post image 197](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/bram-van-oost-6WvZo5FOxww-unsplash.jpg?resize=150%2C150&ssl=1)
NLPフレームワークのFlairでELMoの言語モデルを使おうとすると、from flair.embeddings import ELMoEmbeddingsをして関数を呼び出す必要があるのだが、allennlpがインストールされてい ...
RuntimeError: The size of tensor a (1104) must match the size of tensor b (512) at non-singleton dimension 1
![Thumbnail of post image 168](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sambazon-qfIVXu7nxGU-unsplash.jpg?resize=150%2C150&ssl=1)
Hugging FaceのTransformersを使って,事前学習済モデルを読み込んで推定させるとタイトルのようなエラーがでることがある.
このエラーはBERTにおけるトークン(サブワード)の最大長512を超えた文が入力 ...
OptunaでFlair NERのパラメーターチューニング
![Thumbnail of post image 174](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/mockaroon-bzLhhI3MpYY-unsplash.jpg?resize=150%2C150&ssl=1)
とある仕事で,固有表現抽出器の性能をぎりぎりまで向上させる必要があったため,自作のコーパスに対してFlairでNERを学習し,Optunaでハイパーパラメータチューニングを行なった.本記事ではそのときのコードを示す.
Em ...
Flairのtraining.logからmicro recallとprecisionを算出するコード
![Thumbnail of post image 042](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/georgia-de-lotz-muN_TndU9A0-unsplash.jpg?resize=150%2C150&ssl=1)
FlairでNERを実施した際,training.logというのが出力されるのだが,これにはmicro F1は載っているが,micro recallとprecisionは載っていない.このため,ログファイルからTP, FP, FNを読 ...
FlairでサクッとNERを実行するコード [Python]
![Thumbnail of post image 076](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/piotr-wilk-Kc-OBw1fMJg-unsplash.jpg?resize=150%2C150&ssl=1)
from flair.data import Corpusfrom flair.datasets import ColumnCorpusfrom flair.models import SequenceTaggerfrom flair.tr ...
Flair trainer.trainのパラメータ一覧 [Python]
![Thumbnail of post image 166](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/brooke-lark-HlNcigvUi4Q-unsplash.jpg?resize=150%2C150&ssl=1)
“””
Trains any class that implements the flair.nn.Model interface.
:param base_path: Main p ...
Flairで文をembedding
![Thumbnail of post image 146](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/erik-dungan-MQyCrJVFG8U-unsplash.jpg?resize=150%2C150&ssl=1)
from flair.data import Sentencefrom flair.embeddings import CharacterEmbeddings# init embeddingembedding = CharacterEmbe ...
FlairでELMoをEmbeddingとして使う
![Thumbnail of post image 014](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/xps-DYAf-8UTFN8-unsplash.jpg?resize=150%2C150&ssl=1)
from flair.data import Corpusfrom flair.embeddings import TokenEmbeddings, WordEmbeddings, StackedEmbeddingsfrom flair.d ...
Flairのtag_dictionaryをハードコーディングで入力
![Thumbnail of post image 074](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/brooke-lark-HlNcigvUi4Q-unsplash.jpg?resize=150%2C150&ssl=1)
datapath = "/path/to/BIO" # train.tsv, test.tsv, devel.tsvが入っているフォルダcorpus: Corpus = loadCorpus(datapath)tag_type = "ner ...
自作ELMoで単語をEmbeddingした後,Numpyに戻す[Flair][NLP]
![Thumbnail of post image 197](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/debby-hudson-hWVVtG0d8jM-unsplash.jpg?resize=150%2C150&ssl=1)
from flair.embeddings import ELMoEmbeddingsfrom flair.data import Sentence# ELMoのモデルは各自で用意options = '/home/ubuntu/elmo-e ...