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

code2vec.py 1.5 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
  1. from vocabularies import VocabType
  2. from config import Config
  3. from interactive_predict import InteractivePredictor
  4. from model_base import Code2VecModelBase
  5. def load_model_dynamically(config: Config) -> Code2VecModelBase:
  6. assert config.DL_FRAMEWORK in {'tensorflow', 'keras'}
  7. if config.DL_FRAMEWORK == 'tensorflow':
  8. from tensorflow_model import Code2VecModel
  9. elif config.DL_FRAMEWORK == 'keras':
  10. from keras_model import Code2VecModel
  11. return Code2VecModel(config)
  12. if __name__ == '__main__':
  13. config = Config(set_defaults=True, load_from_args=True, verify=True)
  14. model = load_model_dynamically(config)
  15. config.log('Done creating code2vec model')
  16. if config.is_training:
  17. model.train()
  18. if config.SAVE_W2V is not None:
  19. model.save_word2vec_format(config.SAVE_W2V, VocabType.Token)
  20. config.log('Origin word vectors saved in word2vec text format in: %s' % config.SAVE_W2V)
  21. if config.SAVE_T2V is not None:
  22. model.save_word2vec_format(config.SAVE_T2V, VocabType.Target)
  23. config.log('Target word vectors saved in word2vec text format in: %s' % config.SAVE_T2V)
  24. if (config.is_testing and not config.is_training) or config.RELEASE:
  25. eval_results = model.evaluate()
  26. if eval_results is not None:
  27. config.log(
  28. str(eval_results).replace('topk', 'top{}'.format(config.TOP_K_WORDS_CONSIDERED_DURING_PREDICTION)))
  29. if config.PREDICT:
  30. predictor = InteractivePredictor(config, model)
  31. predictor.predict()
  32. model.close_session()
Tip!

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

Comments

Loading...