Skip to content
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

Merged

Conversation

zhangguanheng66
Copy link
Contributor

Add a few supervised learning datasets, including
- AG_NEWS
- SogouNews
- DBpedia
- YelpReviewPolarity
- YelpReviewFull
- YahooAnswers
- AmazonReviewPolarity
- AmazonReviewFull

def preprocess(raw_folder, processed_folder, dataset_name):
"""Preprocess the csv files."""

def text_normalize(src_filepath, tgt_filepath):
Copy link
Contributor

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).

Copy link
Contributor Author

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.

@zhangguanheng66 zhangguanheng66 changed the title Add new datasets for text classification. [WIP] Add new datasets for text classification. Jul 14, 2019
return line


def preprocess(raw_folder, processed_folder, dataset_name):
Copy link
Contributor

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())

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

@zhangguanheng66 zhangguanheng66 Jul 22, 2019

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):
Copy link
Contributor

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.

Copy link
Contributor Author

@zhangguanheng66 zhangguanheng66 Jul 22, 2019

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):
Copy link
Contributor

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"
    )
)

Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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.

@zhangguanheng66 zhangguanheng66 force-pushed the new_supervised_learning_dataset branch from c8f1e9d to 8fa87d8 Compare July 24, 2019 14:25
@cpuhrsch cpuhrsch merged commit 844f403 into pytorch:master Jul 24, 2019
@zhangguanheng66 zhangguanheng66 changed the title [WIP] Add new datasets for text classification. Add new datasets for text classification. Jul 24, 2019
@zhangguanheng66 zhangguanheng66 deleted the new_supervised_learning_dataset branch November 25, 2019 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants