python程序运行中改变环境变量:

Trying to change the way the loader works for a running Python is very tricky; probably OS/version dependent; may not work. One work-around that might help in some circumstances is to launch a sub-process that changes the environment parameter using a shell script and then launch a new Python using the shell.

So, before the python code is executed, the env var is loaded.

Ref: https://stackoverflow.com/questions/1178094/change-current-process-environments-ld-library-path

But how to launch a sub-process that changes the environment parameter:

You can ref: https://stackoverflow.com/questions/8365394/set-environment-variable-in-python-script?rq=1

All these env var changing tricks is for frozen the embd gened by Word2Vec each launch:

'''
one corpus, gen the embd without variance in multiple time.
run this code by command:
$ PYTHONHASHSEED=123 python c1_frozEmbd.py
or by c2_run_c1.py via a subprocess mechanism
Note:
Word2Vec(walks, size=16, window=5, min_count=1, workers=1) # workers = 1 for frozen random seed.
''' from gensim.models import Word2Vec corpus_path = 'corpus/my_walks_2.txt'
walks = [] with open(corpus_path, 'r') as cpsReader:
for line in cpsReader.readlines():
walks.append(line.strip().split(' '))
cpsReader.close() # for i in range(20):
for i in range(3):
w2v_model = Word2Vec(walks, size=16, window=5, min_count=1, workers=1) # fit the model
print(w2v_model['17'])
print(w2v_model.wv.most_similar('17'), '\n')

最新文章

  1. java中对final关键字的理解以及使用场景
  2. php实现网页trace方法
  3. Maven的简单使用,HelloWorld
  4. Unity正式发布首个“实验性”VR编辑器,支持HTC Vive和Oculus Rift
  5. [ACM_图论] Fire Net (ZOJ 1002 带障碍棋盘布炮,互不攻击最大数量)
  6. FAQ: Machine Learning: What and How
  7. LINQ找出重复和不重复的元素及linq OrderBy 方法 两个字段同时排序有关问题
  8. Remove Duplicates from Sorted List II leetcode java
  9. jquery之css()改变字体大小,颜色,背景色
  10. 后台构建 html 字符串传到前台字符串转码(html)处理
  11. <meta http-equiv="refresh" content="0; url=">
  12. Git 远程分支的pull与push
  13. Codeforces 812E Sagheer and Apple Tree
  14. Lucene 学习资料
  15. 数据库设计,表与表的关系,一对一。One-To-One(1)
  16. ajax实现图片上传
  17. Log4j 日志记录
  18. file类和io流
  19. Android 真机投影到PC端,真机投影工具;Vysor
  20. Ubuntu安装mysql及设置远程访问方法

热门文章

  1. p4841 城市规划
  2. 2009年4月,Twitter宣布他们已经把大部分后端程序从Ruby迁移到Scala
  3. 【C++】fill函数,fill与memset函数的区别
  4. requests模块(请求接口)
  5. 正则表达式——POSIX字符组
  6. C++实现,拓展中国剩余定理——解同余方程组(理论证明和代码实现)
  7. Java核心技术
  8. Spring MVC-学习笔记(3)参数绑定注解、HttpMessageConverter<T>信息转换、jackson、fastjson、XML
  9. Java 13 发布了!
  10. java_第一年_JDBC(7)