Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

data.py 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  1. # -*- coding: utf-8 -*-
  2. """Data Loader"""
  3. import pandas as pd
  4. import tensorflow as tf
  5. class DataLoader():
  6. """Data Loader class"""
  7. def __init__(self):
  8. super().__init__()
  9. def load_train_data(self,path):
  10. """Loads dataset from path"""
  11. return self.preprocess_data(pd.read_csv(path))
  12. def load_val_data(self,path):
  13. """Loads dataset from path"""
  14. return self.preprocess_data(pd.read_csv(path))
  15. def load_test_data(self,path):
  16. """Loads dataset from path"""
  17. return self.preprocess_data(pd.read_csv(path))
  18. def preprocess_data(self,dataframe, shuffle=True, batch_size=256):
  19. """Preprocesses data"""
  20. df = dataframe.copy()
  21. labels = df.pop('target')
  22. features = df.pop('tweet')
  23. ds = tf.data.Dataset.from_tensor_slices((features.values, labels.values))
  24. if shuffle:
  25. ds = ds.shuffle(buffer_size=len(dataframe))
  26. ds = ds.batch(batch_size)
  27. ds = ds.prefetch(batch_size)
  28. return ds
  29. if __name__ == "__main__":
  30. data_model = DataLoader()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...