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
Hierarchical unsupervised and semi-supervised topic models for sparse count data with CorEx

Anchored CorEx: Hierarchical Topic Modeling with Minimal Domain Knowledge Correlation Explanation (CorEx) is a topic model that yields rich topics tha

Greg Ver Steeg 592 Dec 18, 2022
[NeurIPS 2021] Code for Learning Signal-Agnostic Manifolds of Neural Fields

Learning Signal-Agnostic Manifolds of Neural Fields This is the uncleaned code for the paper Learning Signal-Agnostic Manifolds of Neural Fields. The

60 Dec 12, 2022
a CTF web challenge about making screenshots

screenshotter (web) A CTF web challenge about making screenshots. It is inspired by a bug found in real life. The challenge was created by @LiveOverfl

219 Jan 02, 2023
justCTF [*] 2020 challenges sources

justCTF [*] 2020 This repo contains sources for justCTF [*] 2020 challenges hosted by justCatTheFish. TLDR: Run a challenge with ./run.sh (requires Do

justCatTheFish 25 Dec 27, 2022
Concept Modeling: Topic Modeling on Images and Text

Concept is a technique that leverages CLIP and BERTopic-based techniques to perform Concept Modeling on images.

Maarten Grootendorst 120 Dec 27, 2022
The implementation of Parameter Differentiation based Multilingual Neural Machine Translation

The implementation of Parameter Differentiation based Multilingual Neural Machine Translation .

Qian Wang 21 Dec 17, 2022
2021海华AI挑战赛·中文阅读理解·技术组·第三名

文字是人类用以记录和表达的最基本工具,也是信息传播的重要媒介。透过文字与符号,我们可以追寻人类文明的起源,可以传播知识与经验,读懂文字是认识与了解的第一步。对于人工智能而言,它的核心问题之一就是认知,而认知的核心则是语义理解。

21 Dec 26, 2022
Türkçe küfürlü içerikleri bulan bir yapay zeka kütüphanesi / An ML library for profanity detection in Turkish sentences

"Kötü söz sahibine aittir." -Anonim Nedir? sinkaf uygunsuz yorumların bulunmasını sağlayan bir python kütüphanesidir. Farkı nedir? Diğer algoritmalard

KaraGoz 4 Feb 18, 2022
Blender addon - Scrub timeline from viewport with a shortcut

Viewport scrub timeline Move in the timeline directly in viewport and snap to nearest keyframe Note : This standalone feature will be added in the nat

Samuel Bernou 40 Nov 07, 2022
Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS)

TOPSIS implementation in Python Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) CHING-LAI Hwang and Yoon introduced TOPSIS

Hamed Baziyad 8 Dec 10, 2022
☀️ Measuring the accuracy of BBC weather forecasts in Honolulu, USA

Accuracy of BBC Weather forecasts for Honolulu This repository records the forecasts made by BBC Weather for the city of Honolulu, USA. Essentially, t

Max Halford 12 Oct 15, 2022
This is a really simple text-to-speech app made with python and tkinter.

Tkinter Text-to-Speech App by Souvik Roy This is a really simple tkinter app which converts the text you have entered into a speech. It is created wit

Souvik Roy 1 Dec 21, 2021
CrossNER: Evaluating Cross-Domain Named Entity Recognition (AAAI-2021)

CrossNER is a fully-labeled collected of named entity recognition (NER) data spanning over five diverse domains (Politics, Natural Science, Music, Literature, and Artificial Intelligence) with specia

Zihan Liu 89 Nov 10, 2022
BiNE: Bipartite Network Embedding

BiNE: Bipartite Network Embedding This repository contains the demo code of the paper: BiNE: Bipartite Network Embedding. Ming Gao, Leihui Chen, Xiang

leihuichen 214 Nov 24, 2022
Python library for processing Chinese text

SnowNLP: Simplified Chinese Text Processing SnowNLP是一个python写的类库,可以方便的处理中文文本内容,是受到了TextBlob的启发而写的,由于现在大部分的自然语言处理库基本都是针对英文的,于是写了一个方便处理中文的类库,并且和TextBlob

Rui Wang 6k Jan 02, 2023
Weaviate demo with the text2vec-openai module

Weaviate demo with the text2vec-openai module This repository contains an example of how to use the Weaviate text2vec-openai module. When using this d

SeMI Technologies 11 Nov 11, 2022
Connectionist Temporal Classification (CTC) decoding algorithms: best path, beam search, lexicon search, prefix search, and token passing. Implemented in Python.

CTC Decoding Algorithms Update 2021: installable Python package Python implementation of some common Connectionist Temporal Classification (CTC) decod

Harald Scheidl 736 Jan 03, 2023
Generate text line images for training deep learning OCR model (e.g. CRNN)

Generate text line images for training deep learning OCR model (e.g. CRNN)

532 Jan 06, 2023
Full Spectrum Bioinformatics - a free online text designed to introduce key topics in Bioinformatics using the Python

Full Spectrum Bioinformatics is a free online text designed to introduce key topics in Bioinformatics using the Python programming language. The text is written in interactive Jupyter Notebooks, whic

Jesse Zaneveld 33 Dec 28, 2022
Grover is a model for Neural Fake News -- both generation and detectio

Grover is a model for Neural Fake News -- both generation and detection. However, it probably can also be used for other generation tasks.

Rowan Zellers 856 Dec 24, 2022