-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IMDB Classifier #319
IMDB Classifier #319
Changes from 2 commits
67308ae
0daf443
68044a0
2d29725
12342a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,11 @@ | |
|
||
import os | ||
|
||
from forte.models.imdb_text_classifier.model import IMDBClassifier | ||
import config_data | ||
import config_classifier | ||
|
||
from forte.models.imdb_text_classifier.model import IMDBClassifier | ||
|
||
|
||
def main(): | ||
model = IMDBClassifier(config_data, config_classifier) | ||
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. Why the model is responsible for 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. The model expects a pickle data format which is specific to the model. 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. It is not a good idea to put all these into the model. This fix the model so that it can only do one thing. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2020 The Forte Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Read all data in IMDB and merge them to a csv file.""" | ||
import os | ||
|
||
from forte.data.caster import MultiPackBoxer | ||
from forte.data.multi_pack import MultiPack | ||
from forte.data.readers import LargeMovieReader | ||
from forte.pipeline import Pipeline | ||
from forte.utils.utils_io import maybe_create_dir | ||
from ft.onto.base_ontology import Document | ||
|
||
|
||
def main(): | ||
pipeline = Pipeline[MultiPack]() | ||
reader = LargeMovieReader() | ||
pipeline.set_reader(reader) | ||
pipeline.add(MultiPackBoxer()) | ||
|
||
pipeline.initialize() | ||
|
||
dataset_path = "data/IMDB_raw/aclImdb/" | ||
input_file_path = { | ||
"train": os.path.join(dataset_path, "train"), | ||
"test": os.path.join(dataset_path, "test") | ||
} | ||
output_path = "data/IMDB/" | ||
maybe_create_dir(output_path) | ||
output_file_path = { | ||
"train": os.path.join(output_path, "train.csv"), | ||
"test": os.path.join(output_path, "test.csv") | ||
} | ||
set_labels = { | ||
"train": ["pos", "neg", "unsup"], | ||
"test": ["pos", "neg"], | ||
} | ||
|
||
for split in ["train", "test"]: | ||
with open(output_file_path[split], "w", encoding="utf-8")\ | ||
as output_file: | ||
output_file.write("\t".join(["content", "label", "id"]) + "\n") | ||
for label in set_labels[split]: | ||
data_packs = \ | ||
pipeline.process_dataset( | ||
os.path.join(input_file_path[split], label)) | ||
for pack in data_packs: | ||
example_id = pack.get_pack('default').pack_name | ||
for pack_name in pack.pack_names: | ||
p = pack.get_pack(pack_name) | ||
for doc in p.get(Document): | ||
output_file.write( | ||
"\t".join([doc.text, label, example_id]) + "\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
python download_imdb.py | ||
python utils/imdb_format.py --raw_data_dir=data/IMDB_raw/aclImdb --train_id_path=data/IMDB_raw/train_id_list.txt --output_dir=data/IMDB | ||
python preprocess_pipeline.py | ||
python main.py | ||
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. Add a new line at the end. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# used for bert executor example | ||
max_batch_tokens = 128 | ||
|
||
train_batch_size = 32 | ||
train_batch_size = 24 | ||
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. Why do we have two copies of config data? 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. I put it in the model directory as an example of the expected parameters in 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. We should probably only keep one to reduce maintenance effort. |
||
max_train_epoch = 5 | ||
display_steps = 50 # Print training loss every display_steps; -1 to disable | ||
|
||
|
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.
In which PR can I find this classifier?
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.
Is the classifier for
IMDB
only? if it is a general LSTM or CNN classifier we should consider renaming it.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.
It is in this PR
forte/models/imdb_text_classifier
. It is a BERT text classifier. The BERT model itself is not specific to IMDB but this PR contains preprocessing code specific to IMDB dataset to make it work.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.
Can you move the preprocessing out from the core model?