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.

Word2Vec.cs 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Tensorflow;
  5. namespace TensorFlowNET.Examples
  6. {
  7. /// <summary>
  8. /// Implement Word2Vec algorithm to compute vector representations of words.
  9. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/word2vec.py
  10. /// </summary>
  11. public class Word2Vec : Python, IExample
  12. {
  13. public int Priority => 12;
  14. public bool Enabled { get; set; } = true;
  15. public string Name => "Word2Vec";
  16. // Training Parameters
  17. float learning_rate = 0.1f;
  18. int batch_size = 128;
  19. int num_steps = 3000000;
  20. int display_step = 10000;
  21. int eval_step = 200000;
  22. // Evaluation Parameters
  23. string[] eval_words = new string[] { "five", "of", "going", "hardware", "american", "britain" };
  24. public bool Run()
  25. {
  26. PrepareData();
  27. var graph = tf.Graph().as_default();
  28. tf.train.import_meta_graph("graph/word2vec.meta");
  29. return false;
  30. }
  31. public void PrepareData()
  32. {
  33. var url = "";
  34. }
  35. }
  36. }

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