MRPCDownloader.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (c) 2019 NVIDIA CORPORATION. All rights reserved.
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. import bz2
  14. import os
  15. import urllib.request
  16. import sys
  17. class MRPCDownloader:
  18. def __init__(self, save_path):
  19. self.save_path = save_path + '/mrpc'
  20. if not os.path.exists(self.save_path):
  21. os.makedirs(self.save_path)
  22. # Documentation - Download link obtained from here: https://github.com/nyu-mll/GLUE-baselines/blob/master/download_glue_data.py
  23. self.download_urls = {
  24. 'https://firebasestorage.googleapis.com/v0/b/mtl-sentence-representations.appspot.com/o/data%2Fmrpc_dev_ids.tsv?alt=media&token=ec5c0836-31d5-48f4-b431-7480817f1adc' : 'mrpc_dev_ids.tsv'
  25. }
  26. def download(self):
  27. for item in self.download_urls:
  28. url = item
  29. file = self.download_urls[item]
  30. print('Downloading:', url)
  31. if os.path.isfile(self.save_path + '/' + file):
  32. print('** Download file already exists, skipping download')
  33. else:
  34. response = urllib.request.urlopen(url)
  35. with open(self.save_path + '/' + file, "wb") as handle:
  36. handle.write(response.read())