@@ -25,15 +25,20 @@ public class TextClassificationTrain : IExample
2525 public string Name => "Text Classification" ;
2626 public int ? DataLimit = null ;
2727 public bool ImportGraph { get ; set ; } = true ;
28+ public bool UseSubset = true ; // <----- set this true to use a limited subset of dbpedia
2829
2930 private string dataDir = "text_classification" ;
3031 private string dataFileName = "dbpedia_csv.tar.gz" ;
3132
3233 public string model_name = "vd_cnn" ; // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn
3334
35+ private const string TRAIN_PATH = "text_classification/dbpedia_csv/train.csv" ;
36+ private const string SUBSET_PATH = "text_classification/dbpedia_csv/dbpedia_6400.csv" ;
37+ private const string TEST_PATH = "text_classification/dbpedia_csv/test.csv" ;
38+
3439 private const int CHAR_MAX_LEN = 1014 ;
3540 private const int WORD_MAX_LEN = 1014 ;
36- private const int NUM_CLASS = 2 ;
41+ private const int NUM_CLASS = 14 ;
3742 private const int BATCH_SIZE = 64 ;
3843 private const int NUM_EPOCHS = 10 ;
3944 protected float loss_value = 0 ;
@@ -55,7 +60,8 @@ protected virtual bool RunWithImportedGraph(Session sess, Graph graph)
5560 {
5661 var stopwatch = Stopwatch . StartNew ( ) ;
5762 Console . WriteLine ( "Building dataset..." ) ;
58- var ( x , y , alphabet_size ) = DataHelpers . build_char_dataset ( "train" , model_name , CHAR_MAX_LEN , DataLimit = null ) ;
63+ var path = UseSubset ? SUBSET_PATH : TRAIN_PATH ;
64+ var ( x , y , alphabet_size ) = DataHelpers . build_char_dataset ( path , model_name , CHAR_MAX_LEN , DataLimit = null , shuffle : ! UseSubset ) ;
5965 Console . WriteLine ( "\t DONE " ) ;
6066
6167 var ( train_x , valid_x , train_y , valid_y ) = train_test_split ( x , y , test_size : 0.15f ) ;
@@ -249,9 +255,18 @@ private static void FillWithShuffledLabels(int[][] x, int[] y, int[][] shuffled_
249255
250256 public void PrepareData ( )
251257 {
252- string url = "https://github.com/le-scientifique/torchDatasets/raw/master/dbpedia_csv.tar.gz" ;
253- Web . Download ( url , dataDir , dataFileName ) ;
254- Compress . ExtractTGZ ( Path . Join ( dataDir , dataFileName ) , dataDir ) ;
258+ if ( UseSubset )
259+ {
260+ var url = "https://raw.githubusercontent.com/SciSharp/TensorFlow.NET/master/data/dbpedia_subset.zip" ;
261+ Web . Download ( url , dataDir , "dbpedia_subset.zip" ) ;
262+ Compress . UnZip ( Path . Combine ( dataDir , "dbpedia_subset.zip" ) , Path . Combine ( dataDir , "dbpedia_csv" ) ) ;
263+ }
264+ else
265+ {
266+ string url = "https://github.com/le-scientifique/torchDatasets/raw/master/dbpedia_csv.tar.gz" ;
267+ Web . Download ( url , dataDir , dataFileName ) ;
268+ Compress . ExtractTGZ ( Path . Join ( dataDir , dataFileName ) , dataDir ) ;
269+ }
255270
256271 if ( ImportGraph )
257272 {
@@ -264,7 +279,7 @@ public void PrepareData()
264279 Console . WriteLine ( "Discarding cached file: " + meta_path ) ;
265280 File . Delete ( meta_path ) ;
266281 }
267- url = "https://raw.githubusercontent.com/SciSharp/TensorFlow.NET/master/graph/" + meta_file ;
282+ var url = "https://raw.githubusercontent.com/SciSharp/TensorFlow.NET/master/graph/" + meta_file ;
268283 Web . Download ( url , "graph" , meta_file ) ;
269284 }
270285 }
0 commit comments