Kriyans commited on
Commit
28552e1
1 Parent(s): 519724f

Update indian_names.py

Browse files
Files changed (1) hide show
  1. indian_names.py +7 -3
indian_names.py CHANGED
@@ -56,7 +56,8 @@ class indina_names(datasets.GeneratorBasedBuilder):
56
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
57
  ]
58
 
59
- def _generate_examples(self, filepath):
 
60
  with open(filepath, encoding="utf-8") as f:
61
  current_tokens = []
62
  current_labels = []
@@ -64,13 +65,15 @@ class indina_names(datasets.GeneratorBasedBuilder):
64
  for row in f:
65
  row = row.rstrip()
66
  if row:
67
- token, label = row.split(",")
68
  current_tokens.append(token)
69
  current_labels.append(label)
70
  else:
 
71
  if not current_tokens:
 
72
  continue
73
- assert len(current_tokens) == len(current_labels), "Mismatch between tokens and labels"
74
  sentence = (
75
  sentence_counter,
76
  {
@@ -83,6 +86,7 @@ class indina_names(datasets.GeneratorBasedBuilder):
83
  current_tokens = []
84
  current_labels = []
85
  yield sentence
 
86
  if current_tokens:
87
  yield sentence_counter, {
88
  "id": str(sentence_counter),
 
56
  datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
57
  ]
58
 
59
+ def _generate_examples(self, filepath):
60
+ logger.info("⏳ Generating examples from = %s", filepath)
61
  with open(filepath, encoding="utf-8") as f:
62
  current_tokens = []
63
  current_labels = []
 
65
  for row in f:
66
  row = row.rstrip()
67
  if row:
68
+ token, label = row.split("\t")
69
  current_tokens.append(token)
70
  current_labels.append(label)
71
  else:
72
+ # New sentence
73
  if not current_tokens:
74
+ # Consecutive empty lines will cause empty sentences
75
  continue
76
+ assert len(current_tokens) == len(current_labels), "💔 between len of tokens & labels"
77
  sentence = (
78
  sentence_counter,
79
  {
 
86
  current_tokens = []
87
  current_labels = []
88
  yield sentence
89
+ # Don't forget last sentence in dataset 🧐
90
  if current_tokens:
91
  yield sentence_counter, {
92
  "id": str(sentence_counter),