aMLP Transformer Model for Japanese

Overview

aMLP-japanese

Japanese aMLP Pretrained Model

aMLPとは、Liu, Daiらが提案する、Transformerモデルです。

ざっくりというと、BERTの代わりに使えて、より性能の良いモデルです。

詳しい解説は、こちらの記事などを参考にしてください。

このプロジェクトは、スポンサーを募集しています

aMLP 日本語モデル

New

  • 2021/11/13 - 事前学習済みbaseモデルおよびSQuADモデルを公開しました

aMLP (Pay Attention to MLPs) とは

gMLPは、Liu, Daiらが、論文「Pay Attention to MLPs」で提案した、Self-Attention機構を排除したTransformerモデルです

BERTのTransformerモデルよりも、1層あたりのパラメーター数が少なく、その代わりに多数の層を重ねることで、同じパラメーター数あたりの性能で見て、BERTを超える性能を発揮します

ざっくりと「BERTと同じように使えてBERTより性能の良いモデル」と捉えて良いでしょう

aMLPは、gMLPにさらにSoft-Attention機構を追加することで、SQuAD等質疑応答タスクにおいてもBERTを超える性能を発揮すると報告されているモデルです

aMLP-japaneseとは、Tensorflow2で実装したaMLPモデルに、40GB超の日本語コーパスを事前学習させた、学習済みモデルです

日本語のエンコードにはJapanese-BPEEncoder_V2を使用し、トークン数は24Kです

TODO

✓baseモデルの公開(2021/11/13)
✓SQuADモデルの公開(2021/11/13)

公開モデル

  • 事前学習モデル
モデル名 ダウンロードURL パラメーター数 学習データサイズ
aMLP-base-ja https://nama.ne.jp/models/aMLP-base-ja.tar.bz2予備URL 67,923,648 40GB~
  • 質疑応答モデル
モデル名 ダウンロードURL パラメーター数 学習データサイズ
aMLP-SQuAD-base-ja https://nama.ne.jp/models/aMLP-SQuAD-base-ja.bz2予備URL 67,924,674 200K文章

質疑応答モデル

使い方

GitHubからコードをクローンします

$ git https://github.com/tanreinama/aMLP-japanese
$ cd aMLP-japanese

学習済みモデルファイルをダウンロードして展開します

$ wget https://www.nama.ne.jp/models/aMLP-SQuAD-base-ja.tar.bz2
$ tar xvfj aMLP-SQuAD-base-ja.tar.bz2

以下のように「run-squad.py」を実行します

学習済みモデルを「--restore_from」に、SQuAD形式のJSONファイルを「--pred_dataset」で指定すると、質問文に対する回答が表示されます

全ての解答の候補は、「squad-predicted.json」という名前で保存されます

$ python run-squad.py --restore_from aMLP-SQuAD-base-ja --pred_dataset squad-testdata.json
Question        Answer
ロッキード・マーティン社とボーイング社が共同開発したステルス戦闘機は?  F-22戦闘機
F-22戦闘機の愛称は?    猛禽類の意味のラプター
F-22戦闘機一機あたりの価格は?  1億5千万ドル
F-22戦闘機の航続距離は?        3200km
F-22戦闘機の巡航速度は?        マッハ1.82
F-22の生産数が削減された理由は?        調達コスト

SQuAD型の質疑応答モデルなので、JSONファイルにコンテキストが含まれている必要があります

ファインチューニング

ファインチューニング用の質疑応答データセットを用意して、SQuAD形式のJSONファイルで保存しておきます

そして、以下のように「run-squad.py」を実行します

学習済みモデルを「--restore_from」に、SQuAD形式のJSONファイルを「--dataset」で指定します

評価用のデータセットがあるときは、「--val_dataset」で指定すると、学習の途中で評価スコアが表示されます

$ python run-squad.py --restore_from aMLP-SQuAD-base-ja --dataset squad-testdata.json

一から学習させる場合は、事前学習済みモデルを「--base_model」に指定します

学習済みモデルは、「checkpoint」以下の、「--run_name」で指定したディレクトリ内に保存されます

なお、公開モデルの学習に使用した質疑応答データセットについては、著作権の関係から公開出来ません

クラス分類モデル

準備

GitHubからコードをクローンします

$ git https://github.com/tanreinama/aMLP-japanese
$ cd aMLP-japanese

事前学習済みモデルファイルをダウンロードして展開します

$ wget https://www.nama.ne.jp/models/aMLP-base-ja.tar.bz2
$ tar xvfj aMLP-base-ja.tar.bz2

学習

クラス分類タスクでは、

dir/<classA>/textA.txt
dir/<classA>/textB.txt
dir/<classB>/textC.txt
・・・

のように、「クラス名/ファイル」という形でテキストファイルが保存されている前提で、テキストファイルをクラス毎に分類するモデルを学習します

ここでは、livedoor ニュースコーパスを使用する例をサンプルとして提示します

まず、コーパスをダウンロードして展開すると、「text」以下に記事の入っているディレクトリが作成されます

$ wget https://www.rondhuit.com/download/ldcc-20140209.tar.gz
$ tar xvfz ldcc-20140209.tar.gz
$ ls text/

学習には、以下のように「run-classifier.py」を実行します

事前学習済みモデルを「--base_model」に、データセットのディレクトリを「--dataset」で指定します

評価用のデータセットがあるときは、「--val_dataset」で指定すると、学習の途中で評価スコアが表示されます

$ python run-classifier.py --dataset text --model aMLP-base-ja --clean_text

以下のようにサブディレクトリ名とクラスIDとの対応が表示された後、学習が進みます

Loading dataset...
livedoor-homme mapped index#0
kaden-channel mapped index#1
movie-enter mapped index#2
it-life-hack mapped index#3
topic-news mapped index#4
sports-watch mapped index#5
dokujo-tsushin mapped index#6
peachy mapped index#7
smax mapped index#8

学習済みモデルは、「checkpoint」以下の、「--run_name」で指定したディレクトリ内に保存されます

推論

推論には、以下のように「run-classifier.py」を実行します

学習済みモデルを「--restore_from」に、データセットのディレクトリを「--pred_dataset」、出力ファイルを「--output」で指定します

$ python run-classifier.py --pred_dataset text --output classifier-pred.csv --restore_from checkpoint/aMLP-classifier-ja/checkpoint-XXXX
$ head -n5 classifier-pred.csv
filename,pred,true
text/livedoor-homme/livedoor-homme-4956491.txt,livedoor-homme,livedoor-homme
text/livedoor-homme/livedoor-homme-5492081.txt,livedoor-homme,livedoor-homme
text/livedoor-homme/livedoor-homme-5818455.txt,livedoor-homme,livedoor-homme
text/livedoor-homme/livedoor-homme-6052744.txt,livedoor-homme,livedoor-homme

実行結果はCSVファイルで保存されます

テキストの穴埋め

Masked Language Modelとして実行します。aMLPのモデルは入力されたテキスト内の「[MASK]」部分を予測します

「run-mlm.py」で、直接穴埋め問題を解かせることが出来ます

「[MASK]」一つでエンコード後のBPE一つなので、「[MASK]」が日本語1文字から3文字になります

$ python run-mlm.py --context "俺の名前は坂本[MASK]。何処にでもいるサラリー[MASK]だ。" --model aMLP-base-ja
俺の名前は坂本だ。何処にでもいるサラリーマンだ。

文章のベクトル化

[CLS]トークンに対応するベクトル表現を得ます。「--output」を指定するとファイルにカンマ区切りのテキストでファイルに保存します

$ python run-vectrize.py --context "こんにちは、世界。" --model aMLP-base-ja
[1.777146577835083, 0.5332596898078918, 0.07858406007289886, 0.5532811880111694, 0.8075544238090515, 1.3260560035705566, 0.6111544370651245, 2.338435173034668, 1.0313552618026733, ・・・

REFERENCE

Hanxiao Liu, Zihang Dai, David R. So, Quoc V. Le "Pay Attention to MLPs" arXiv:2105.08050, 17 May 2021

Owner
tanreinama
日本語を扱うAIプロダクトを開発したいという企業様へ、お手伝いできるのでご連絡お待ちします。プロダクト企画を作成して開発チームを立ち上げるところから①からコミット出来ます。
tanreinama
Korean Sentence Embedding Repository

Korean-Sentence-Embedding 🍭 Korean sentence embedding repository. You can download the pre-trained models and inference right away, also it provides

80 Jan 02, 2023
Contains descriptions and code of the mini-projects developed in various programming languages

TexttoSpeechAndLanguageTranslator-project introduction A pleasant application where the client will be given buttons like play,reset and exit. The cli

Adarsh Reddy 1 Dec 22, 2021
Beyond Accuracy: Behavioral Testing of NLP models with CheckList

CheckList This repository contains code for testing NLP Models as described in the following paper: Beyond Accuracy: Behavioral Testing of NLP models

Marco Tulio Correia Ribeiro 1.8k Dec 28, 2022
A toolkit for document-level event extraction, containing some SOTA model implementations

Document-level Event Extraction via Heterogeneous Graph-based Interaction Model with a Tracker Source code for ACL-IJCNLP 2021 Long paper: Document-le

84 Dec 15, 2022
RoNER is a Named Entity Recognition model based on a pre-trained BERT transformer model trained on RONECv2

RoNER RoNER is a Named Entity Recognition model based on a pre-trained BERT transformer model trained on RONECv2. It is meant to be an easy to use, hi

Stefan Dumitrescu 9 Nov 07, 2022
Just a Basic like Language for Zeno INC

zeno-basic-language Just a Basic like Language for Zeno INC This is written in 100% python. this is basic language like language. so its not for big p

Voidy Devleoper 1 Dec 18, 2021
Ecco is a python library for exploring and explaining Natural Language Processing models using interactive visualizations.

Visualize, analyze, and explore NLP language models. Ecco creates interactive visualizations directly in Jupyter notebooks explaining the behavior of Transformer-based language models (like GPT2, BER

Jay Alammar 1.6k Dec 25, 2022
Extract Keywords from sentence or Replace keywords in sentences.

FlashText This module can be used to replace keywords in sentences or extract keywords from sentences. It is based on the FlashText algorithm. Install

Vikash Singh 5.3k Jan 01, 2023
AudioCLIP Extending CLIP to Image, Text and Audio

AudioCLIP Extending CLIP to Image, Text and Audio This repository contains implementation of the models described in the paper arXiv:2106.13043. This

458 Jan 02, 2023
The proliferation of disinformation across social media has led the application of deep learning techniques to detect fake news.

Fake News Detection Overview The proliferation of disinformation across social media has led the application of deep learning techniques to detect fak

Kushal Shingote 1 Feb 08, 2022
InferSent sentence embeddings

InferSent InferSent is a sentence embeddings method that provides semantic representations for English sentences. It is trained on natural language in

Facebook Research 2.2k Dec 27, 2022
💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants

Rasa Open Source Rasa is an open source machine learning framework to automate text-and voice-based conversations. With Rasa, you can build contextual

Rasa 15.3k Dec 30, 2022
Live Speech Portraits: Real-Time Photorealistic Talking-Head Animation (SIGGRAPH Asia 2021)

Live Speech Portraits: Real-Time Photorealistic Talking-Head Animation This repository contains the implementation of the following paper: Live Speech

OldSix 575 Dec 31, 2022
Code to reprudece NeurIPS paper: Accelerated Sparse Neural Training: A Provable and Efficient Method to Find N:M Transposable Masks

Accelerated Sparse Neural Training: A Provable and Efficient Method to FindN:M Transposable Masks Recently, researchers proposed pruning deep neural n

itay hubara 4 Feb 23, 2022
Unsupervised text tokenizer focused on computational efficiency

YouTokenToMe YouTokenToMe is an unsupervised text tokenizer focused on computational efficiency. It currently implements fast Byte Pair Encoding (BPE)

VK.com 847 Dec 19, 2022
A minimal code for fairseq vq-wav2vec model inference.

vq-wav2vec inference A minimal code for fairseq vq-wav2vec model inference. Runs without installing the fairseq toolkit and its dependencies. Usage ex

Vladimir Larin 7 Nov 15, 2022
Text classification is one of the popular tasks in NLP that allows a program to classify free-text documents based on pre-defined classes.

Deep-Learning-for-Text-Document-Classification Text classification is one of the popular tasks in NLP that allows a program to classify free-text docu

Happy N. Monday 2 Mar 17, 2022
T‘rex Park is a Youzan sponsored project. Offering Chinese NLP and image models pretrained from E-commerce datasets

T‘rex Park is a Youzan sponsored project. Offering Chinese NLP and image models pretrained from E-commerce datasets (product titles, images, comments, etc.).

55 Nov 22, 2022
This is an incredibly powerful calculator that is capable of many useful day-to-day functions.

Description 💻 This is an incredibly powerful calculator that is capable of many useful day-to-day functions. Such functions include solving basic ari

Jordan Leich 37 Nov 19, 2022
This is a GUI program that will generate a word search puzzle image

Word Search Puzzle Generator Table of Contents About The Project Built With Getting Started Prerequisites Installation Usage Roadmap Contributing Cont

11 Feb 22, 2022