You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextClassificationTrain.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using NumSharp.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using Tensorflow;
  8. using TensorFlowNET.Examples.Utility;
  9. namespace TensorFlowNET.Examples.CnnTextClassification
  10. {
  11. /// <summary>
  12. /// https://github.com/dongjun-Lee/text-classification-models-tf
  13. /// </summary>
  14. public class TextClassificationTrain : Python, IExample
  15. {
  16. private string dataDir = "text_classification";
  17. private string dataFileName = "dbpedia_csv.tar.gz";
  18. private const int CHAR_MAX_LEN = 1014;
  19. public void Run()
  20. {
  21. download_dbpedia();
  22. Console.WriteLine("Building dataset...");
  23. var (x, y, alphabet_size) = DataHelpers.build_char_dataset("train", "vdcnn", CHAR_MAX_LEN);
  24. //var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15);
  25. }
  26. public void download_dbpedia()
  27. {
  28. string url = "https://github.com/le-scientifique/torchDatasets/raw/master/dbpedia_csv.tar.gz";
  29. Web.Download(url, dataDir, dataFileName);
  30. Compress.ExtractTGZ(Path.Join(dataDir, dataFileName), dataDir);
  31. }
  32. }
  33. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。