This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add doc of TextNAS #2260
Merged
Merged
Add doc of TextNAS #2260
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7afafdf
Add evalutaion scripts for TextNAS.
931ca92
Remove duplicated run_sst2.sh and run_sst5.sh.
5160ac0
Minor fixes.
5137dcd
Bug fix.
d02bc97
Adjust the running paramters.
eefe0e0
Adopted to nni interface.
0f9a7c6
Add doc of TextNAS.
f46e7ba
Merge branch 'master' of https://github.com/microsoft/nni into fix-2259
cc06ecd
Undo modification of the Chinese document.
4c1b0f2
Incorporate previous doc
ultmaster 7f8e747
Add direct link to dataset
ultmaster bf90867
Change to py3 and add doc to the index.
43d5502
Merge branch 'fix-2259' of https://github.com/pkuyym/nni into fix-2259
56b804c
Update TextNAS.md
QuanluZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# TextNAS | ||
|
||
## Introduction | ||
|
||
This is the implementation of the TextNAS algorithm proposed in the paper [TextNAS: A Neural Architecture Search Space tailored for Text Representation](https://arxiv.org/pdf/1912.10729.pdf). TextNAS is a neural architecture search algorithm tailored for text representation, more specifically, TextNAS is based on a novel search space consists of operators widely adopted to solve various NLP tasks, and TextNAS also supports multi-path ensemble within a single network to balance the width and depth of the architecture. | ||
|
||
The search space of TextNAS contains: | ||
|
||
* 1-D convolutional operator with filter size 1, 3, 5, 7 | ||
* recurrent operator (bi-directional GRU) | ||
* self-attention operator | ||
* pooling operator (max/average) | ||
|
||
Following the ENAS algorithm, TextNAS also utilizes parameter sharing to accelerate the search speed and adopts a reinforcement-learning controller for the architecture sampling and generation. Please refer to the paper for more details of TextNAS. | ||
|
||
## Preparation | ||
|
||
Prepare the word vectors and SST dataset, and organize them in data directory as shown below: | ||
|
||
``` | ||
textnas | ||
├── data | ||
│ ├── sst | ||
│ │ └── trees | ||
│ │ ├── dev.txt | ||
│ │ ├── test.txt | ||
│ │ └── train.txt | ||
│ └── glove.840B.300d.txt | ||
├── dataloader.py | ||
├── model.py | ||
├── ops.py | ||
├── README.md | ||
├── search.py | ||
└── utils.py | ||
``` | ||
|
||
The following link might be helpful for finding and downloading the corresponding dataset: | ||
|
||
* [GloVe: Global Vectors for Word Representation](https://nlp.stanford.edu/projects/glove/) | ||
* [glove.840B.300d.txt](http://nlp.stanford.edu/data/glove.840B.300d.zip) | ||
* [Recursive Deep Models for Semantic Compositionality Over a Sentiment Treebank](https://nlp.stanford.edu/sentiment/) | ||
* [trainDevTestTrees_PTB.zip](https://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip) | ||
|
||
## Examples | ||
|
||
### Search Space | ||
|
||
[Example code](https://github.com/microsoft/nni/tree/master/examples/nas/textnas) | ||
|
||
```bash | ||
# In case NNI code is not cloned. If the code is cloned already, ignore this line and enter code folder. | ||
git clone https://github.com/Microsoft/nni.git | ||
|
||
# search the best architecture | ||
cd examples/nas/textnas | ||
|
||
# view more options for search | ||
python3 search.py -h | ||
``` | ||
|
||
After each search epoch, 10 sampled architectures will be tested directly. Their performances are expected to be 40% - 42% after 10 epochs. | ||
|
||
By default, 20 sampled architectures will be exported into `checkpoints` directory for next step. | ||
|
||
### retrain | ||
|
||
```bash | ||
# In case NNI code is not cloned. If the code is cloned already, ignore this line and enter code folder. | ||
git clone https://github.com/Microsoft/nni.git | ||
|
||
# search the best architecture | ||
cd examples/nas/textnas | ||
|
||
# default to retrain on sst-2 | ||
sh run_retrain.sh | ||
``` | ||
|
||
## Reference | ||
|
||
TextNAS directly uses EnasTrainer, please refer to [ENAS](./ENAS.md) for the trainer APIs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
{ | ||
"LayerChoice1": [ | ||
false, false, false, false, false, true, false, false | ||
], | ||
"InputChoice2": [ | ||
true | ||
], | ||
"LayerChoice3": [ | ||
false, false, false, false, false, false, false, true | ||
], | ||
"InputChoice4": [ | ||
false | ||
], | ||
"InputChoice5": [ | ||
true, false | ||
], | ||
"LayerChoice6": [ | ||
false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice7": [ | ||
false, false | ||
], | ||
"InputChoice8": [ | ||
false, false, true | ||
], | ||
"LayerChoice9": [ | ||
false, false, false, false, false, false, true, false | ||
], | ||
"InputChoice10": [ | ||
false, true, true | ||
], | ||
"InputChoice11": [ | ||
false, false, true, false | ||
], | ||
"LayerChoice12": [ | ||
false, true, false, false, false, false, false, false | ||
], | ||
"InputChoice13": [ | ||
false, true, false, false | ||
], | ||
"InputChoice14": [ | ||
false, false, false, false, true | ||
], | ||
"LayerChoice15": [ | ||
false, true, false, false, false, false, false, false | ||
], | ||
"InputChoice16": [ | ||
false, false, true, false, true | ||
], | ||
"InputChoice17": [ | ||
false, false, false, false, true | ||
], | ||
"LayerChoice18": [ | ||
true, false, false, false, false, false, false, false | ||
], | ||
"InputChoice19": [ | ||
false, false, true, true, true, true | ||
], | ||
"InputChoice20": [ | ||
true, false, false, false, false | ||
], | ||
"LayerChoice21": [ | ||
false, false, false, false, false, false, true, false | ||
], | ||
"InputChoice22": [ | ||
false, true, true, false, false, false, false | ||
], | ||
"InputChoice23": [ | ||
false, true, false, false, false | ||
], | ||
"LayerChoice24": [ | ||
false, false, false, false, false, true, false, false | ||
], | ||
"InputChoice25": [ | ||
false, true, false, true, true, false, true, true | ||
], | ||
"InputChoice26": [ | ||
false, false, true, false, false | ||
], | ||
"LayerChoice27": [ | ||
false, false, false, false, false, true, false, false | ||
], | ||
"InputChoice28": [ | ||
false, false, false, false, false, true, false, true, true | ||
], | ||
"InputChoice29": [ | ||
true, false, false, false, false | ||
], | ||
"LayerChoice30": [ | ||
false, false, false, false, false, false, false, true | ||
], | ||
"InputChoice31": [ | ||
true, true, false, false, true, false, false, true, true, false | ||
], | ||
"InputChoice32": [ | ||
true, false, false, false, false | ||
], | ||
"LayerChoice33": [ | ||
false, false, false, false, true, false, false, false | ||
], | ||
"InputChoice34": [ | ||
true, false, false, true, true, true, true, false, false, false, false | ||
], | ||
"InputChoice35": [ | ||
false, false, false, true, false | ||
], | ||
"LayerChoice36": [ | ||
false, true, false, false, false, false, false, false | ||
], | ||
"InputChoice37": [ | ||
true, true, false, true, false, true, false, false, true, false, false, false | ||
], | ||
"InputChoice38": [ | ||
false, false, false, true, false | ||
], | ||
"LayerChoice39": [ | ||
false, false, true, false, false, false, false, false | ||
], | ||
"InputChoice40": [ | ||
true, true, false, false, false, false, true, false, false, true, true, false, true | ||
], | ||
"InputChoice41": [ | ||
false, false, false, true, false | ||
], | ||
"LayerChoice42": [ | ||
true, false, false, false, false, false, false, false | ||
], | ||
"InputChoice43": [ | ||
false, false, true, false, false, false, true, true, true, false, true, true, false, false | ||
], | ||
"InputChoice44": [ | ||
false, false, false, false, true | ||
], | ||
"LayerChoice45": [ | ||
false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice46": [ | ||
true, false, false, false, false, false, true, false, false, false, true, true, false, false, true | ||
], | ||
"InputChoice47": [ | ||
false, false, false, true, false | ||
], | ||
"LayerChoice48": [ | ||
false, false, true, false, false, false, false, false | ||
], | ||
"InputChoice49": [ | ||
false, false, false, false, false, false, false, false, false, true, true, false, true, false, true, false | ||
], | ||
"InputChoice50": [ | ||
false, false, false, false, true | ||
], | ||
"LayerChoice51": [ | ||
false, false, false, false, true, false, false, false | ||
], | ||
"InputChoice52": [ | ||
false, true, true, true, true, false, false, true, false, true, false, false, false, false, true, false, false | ||
], | ||
"InputChoice53": [ | ||
false, false, true, false, false | ||
], | ||
"LayerChoice54": [ | ||
false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice55": [ | ||
false, false, false, false, false, true, false, false, false, false, false, false, false, true, true, true, false, true | ||
], | ||
"InputChoice56": [ | ||
false, false, true, false, false | ||
], | ||
"LayerChoice57": [ | ||
false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice58": [ | ||
false, false, false, true, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice59": [ | ||
false, true, false, false, false | ||
], | ||
"LayerChoice60": [ | ||
false, false, false, false, false, true, false, false | ||
], | ||
"InputChoice61": [ | ||
true, true, false, false, false, false, false, false, false, false, true, true, false, false, true, true, true, true, false, false | ||
], | ||
"InputChoice62": [ | ||
true, false, false, false, false | ||
], | ||
"LayerChoice63": [ | ||
false, false, false, false, false, false, false, true | ||
], | ||
"InputChoice64": [ | ||
false, true, true, true, false, false, false, true, false, true, true, true, true, false, true, false, false, false, false, false, false | ||
], | ||
"InputChoice65": [ | ||
false, false, false, false, true | ||
], | ||
"LayerChoice66": [ | ||
false, false, false, false, false, false, false, true | ||
], | ||
"InputChoice67": [ | ||
false, false, true, true, true, true, false, true, false, true, true, false, false, false, false, true, false, false, false, false, false, true | ||
], | ||
"InputChoice68": [ | ||
false, false, false, true, false | ||
], | ||
"LayerChoice69": [ | ||
false, false, false, true, false, false, false, false | ||
], | ||
"InputChoice70": [ | ||
true, false, false, true, false, false, false, true, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
export PYTHONPATH="$(pwd)" | ||
export CUDA_VISIBLE_DEVICES=0 | ||
|
||
python -u retrain.py \ | ||
python3 -u retrain.py \ | ||
--train_ratio=1.0 \ | ||
--valid_ratio=1.0 \ | ||
--min_count=1 \ | ||
|
@@ -36,6 +36,6 @@ python -u retrain.py \ | |
--child_lr_T_0=10 \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
--child_lr_T_mul=2 \ | ||
--multi_path=True \ | ||
--child_fixed_arc="./checkpoints/architecture_00.json" \ | ||
--child_fixed_arc="./arc/final_arc.json" \ | ||
--fixed_seed=True \ | ||
"$@" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could @pkuyym or @ultmaster add the guideline for preparing data?