vinod-verso commited on
Commit
1aaac35
·
0 Parent(s):

First commit

Browse files
Files changed (4) hide show
  1. data/test.csv +3 -0
  2. data/train.csv +4 -0
  3. preprocess.py +20 -0
  4. tiny_text_dataset.py +34 -0
data/test.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ text,label
2
+ This is great!,1
3
+ Not good at all.,0
data/train.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ text,label
2
+ Hello World!,1
3
+ I love Hugging Face!,1
4
+ Bad weather today.,0
preprocess.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # preprocess.py
2
+
3
+ def preprocess_text(text: str) -> str:
4
+ """
5
+ Example preprocessing function:
6
+ - Lowercases
7
+ - Strips whitespace
8
+ - Removes punctuation (optional)
9
+ """
10
+ import string
11
+ text = text.lower().strip()
12
+ text = text.translate(str.maketrans("", "", string.punctuation))
13
+ return text
14
+
15
+
16
+ if __name__ == "__main__":
17
+ # Quick manual test
18
+ sample = "Hello, Hugging Face!"
19
+ print("Before:", sample)
20
+ print("After:", preprocess_text(sample))
tiny_text_dataset.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import datasets
3
+
4
+ _DESCRIPTION = "A tiny text dataset example with built-in preprocessing."
5
+
6
+ class TinyTextDataset(datasets.GeneratorBasedBuilder):
7
+ def _info(self):
8
+ return datasets.DatasetInfo(
9
+ description=_DESCRIPTION,
10
+ features=datasets.Features({
11
+ "text": datasets.Value("string"),
12
+ "label": datasets.Value("int32"),
13
+ }),
14
+ )
15
+
16
+ def _split_generators(self, dl_manager):
17
+ urls = {
18
+ "train": dl_manager.download("https://huggingface.co/datasets/YOUR_USERNAME/tiny_text_dataset/resolve/main/data/train.csv"),
19
+ "test": dl_manager.download("https://huggingface.co/datasets/YOUR_USERNAME/tiny_text_dataset/resolve/main/data/test.csv"),
20
+ }
21
+ return [
22
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": urls["train"]}),
23
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": urls["test"]}),
24
+ ]
25
+
26
+ def _generate_examples(self, filepath):
27
+ """Yields examples."""
28
+ with open(filepath, encoding="utf-8") as f:
29
+ reader = csv.DictReader(f)
30
+ for i, row in enumerate(reader):
31
+ # Basic preprocessing example
32
+ text = row["text"].lower().strip()
33
+ label = int(row["label"])
34
+ yield i, {"text": text, "label": label}