asahi417 commited on
Commit
ca8db30
1 Parent(s): 1cd2c60

Update tweet_sentiment_multilingual.py

Browse files
Files changed (1) hide show
  1. tweet_sentiment_multilingual.py +13 -11
tweet_sentiment_multilingual.py CHANGED
@@ -26,8 +26,9 @@ _HOMEPAGE = "https://github.com/cardiffnlp/xlm-t"
26
  _BASE_URL = "https://huggingface.co/datasets/cardiffnlp/tweet_sentiment_multilingual/resolve/main/data"
27
  _LANGUAGE = ["arabic", "english", "french", "german", "hindi", "italian", "portuguese", "spanish"]
28
  _URLS = {l: {
29
- k: f'{_BASE_URL}/{l}/{k}.jsonl' for k in [str(datasets.Split.TEST), str(datasets.Split.TRAIN), str(datasets.Split.VALIDATION)]
30
  } for l in _LANGUAGE}
 
31
 
32
 
33
  class TweetSentimentMultilingualConfig(datasets.BuilderConfig):
@@ -65,15 +66,16 @@ class TweetSentimentMultilingual(datasets.GeneratorBasedBuilder):
65
  return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_file[str(i)]})
66
  for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]
67
 
68
- def _generate_examples(self, filepath):
69
  """This function returns the examples in the raw (text) form."""
70
  _key = 0
71
- logger.info("generating examples from = %s", filepath)
72
- with open(filepath, encoding="utf-8") as f:
73
- _list = f.read().split('\n')
74
- if _list[-1] == '':
75
- _list = _list[:-1]
76
- for i in _list:
77
- data = json.loads(i)
78
- yield _key, data
79
- _key += 1
 
 
26
  _BASE_URL = "https://huggingface.co/datasets/cardiffnlp/tweet_sentiment_multilingual/resolve/main/data"
27
  _LANGUAGE = ["arabic", "english", "french", "german", "hindi", "italian", "portuguese", "spanish"]
28
  _URLS = {l: {
29
+ k: [f'{_BASE_URL}/{l}/{k}.jsonl'] for k in [str(datasets.Split.TEST), str(datasets.Split.TRAIN), str(datasets.Split.VALIDATION)]
30
  } for l in _LANGUAGE}
31
+ _URLS['all'] = {k: [f'{_BASE_URL}/{l}/{k}.jsonl' for l in _LANGUAGE] for k in [str(datasets.Split.TEST), str(datasets.Split.TRAIN), str(datasets.Split.VALIDATION)]}
32
 
33
 
34
  class TweetSentimentMultilingualConfig(datasets.BuilderConfig):
 
66
  return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_file[str(i)]})
67
  for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]
68
 
69
+ def _generate_examples(self, filepaths):
70
  """This function returns the examples in the raw (text) form."""
71
  _key = 0
72
+ for filepath in filepaths:
73
+ logger.info("generating examples from = %s", filepath)
74
+ with open(filepath, encoding="utf-8") as f:
75
+ _list = f.read().split('\n')
76
+ if _list[-1] == '':
77
+ _list = _list[:-1]
78
+ for i in _list:
79
+ data = json.loads(i)
80
+ yield _key, data
81
+ _key += 1