jamescalam commited on
Commit
d583a77
1 Parent(s): d8a2039

Upload unsplash-25k-photos.py

Browse files
Files changed (1) hide show
  1. unsplash-25k-photos.py +62 -0
unsplash-25k-photos.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+ _CITATION = """\
4
+ @InProceedings{huggingface:dataset,
5
+ title = {Unsplash 25K Photos},
6
+ author={James Briggs},
7
+ year={2022}
8
+ }
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+ This is a dataset that streams photos data from the Unsplash 25K servers.
13
+ """
14
+ _HOMEPAGE = "https://grouplens.org/datasets/movielens/"
15
+
16
+ _LICENSE = ""
17
+
18
+ _URL = "https://files.grouplens.org/datasets/movielens/ml-25m.zip"
19
+
20
+ class MovieLens(datasets.GeneratorBasedBuilder):
21
+ """The MovieLens 25M dataset for ratings"""
22
+
23
+ def _info(self):
24
+ return datasets.DatasetInfo(
25
+ description=_DESCRIPTION,
26
+ features=datasets.Features(
27
+ {
28
+ "imdb_id": datasets.Value("string"),
29
+ "movie_id": datasets.Value("int32"),
30
+ "user_id": datasets.Value("int32"),
31
+ "rating": datasets.Value("float32"),
32
+ "title": datasets.Value("string"),
33
+ "year": datasets.Value("int32"),
34
+ }
35
+ ),
36
+ supervised_keys=None,
37
+ homepage="https://grouplens.org/datasets/movielens/",
38
+ citation=_CITATION,
39
+ )
40
+
41
+ def _split_generators(self, dl_manager):
42
+ new_url = dl_manager.download_and_extract(_URL)
43
+ return [
44
+ datasets.SplitGenerator(
45
+ name=datasets.Split.TRAIN,
46
+ gen_kwargs={"filepath": new_url+"/photos.tsv000"}
47
+ ),
48
+ ]
49
+
50
+ def _generate_examples(self, filepath):
51
+ """This function returns the examples in the raw (text) form."""
52
+ with open(filepath, "r") as f:
53
+ id_ = 0
54
+ for line in f:
55
+ if id_ == 0:
56
+ cols = line.split("\t")
57
+ id_ += 1
58
+ else:
59
+ values = line.split("\t")
60
+ print(id_, {cols[i]: values[i] for i in range(len(cols))})
61
+ id_ += 1
62
+ if id_ > 5: break