-
Notifications
You must be signed in to change notification settings - Fork 814
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
Add new datasets for text classification. #557
Add new datasets for text classification. #557
Conversation
def preprocess(raw_folder, processed_folder, dataset_name): | ||
"""Preprocess the csv files.""" | ||
|
||
def text_normalize(src_filepath, tgt_filepath): |
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.
I think you can split this out as well. It seems useful in its own right. But instead of taking a filepath, it can take a string and return a string (or a list of strings).
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.
Sure thing. Will do it.
return line | ||
|
||
|
||
def preprocess(raw_folder, processed_folder, dataset_name): |
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.
for filename in os.listdir('dirname):
with open(filename, 'r') as a, open(filename + '.processed', 'w') as b:
b.write(text_normalize(a.readline())
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.
I'd delete this and expect the user to know how to do this
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.
Maybe make it an example / add it to the tutorial
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.
I think we could keep it as internal function.
I would like to support the one-line data loading for the supervised learning dataset so we have to minimize the work on user side.
print('Dataset %s downloaded.' % dataset_name) | ||
|
||
|
||
def text_normalize(line): |
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.
Maybe "basic_normalization_english" or such? Is there a reference here (maybe within a paper)? Can be immediately moved into c++. It's very useful in general and we can indicate that.
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.
the supervised learning paper didn't mention how they did pre-processing. fastText just did this pre-processing in the bash script.
I think we could talk with some NLP guys and implement a basic pre-processor in C++.
from torchtext.data.iterator import generate_iterators | ||
|
||
|
||
def download(url, raw_folder, dataset_name): |
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.
extract_archive(
download_from_url(
torchtext.datasets.supervised.urls['AG_NEWS']) #returns a path in cache,
"path/to/AG_NEWS/folder"
)
)
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.
I don't this necessary needs to be its own function
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.
minor change. Put download and extract_archive together.
return examples | ||
|
||
|
||
def iters(train_examples, test_examples, fields, sort_key, |
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.
Let's add batching separately if we see that we need it.
c8f1e9d
to
8fa87d8
Compare
Add a few supervised learning datasets, including
- AG_NEWS
- SogouNews
- DBpedia
- YelpReviewPolarity
- YelpReviewFull
- YahooAnswers
- AmazonReviewPolarity
- AmazonReviewFull