我对NLP比较陌生,主要使用Jupyter,请让我知道我做错了什么:
我遵循了这里提供的所有说明:
https://github.com/explosion/sense2vec
但是当我尝试使用如下所述的reddit_vectors时:
s2v = Sense2VecComponent(nlp.vocab).from_disk("/path/to/s2v_reddit_2015_md")我得到一个ValueError,如下所示:
ValueError Traceback (most recent call last)
<ipython-input-36-0d396d0145de> in <module>
----> 1 s2v=Sense2Vec().from_disk('reddit_vectors-1.1.0/vectors.bin/')
~/.conda/envs/NewEnv6/lib/python3.7/site-packages/sense2vec/sense2vec.py in from_disk(self, path,
exclude)
343 cache_path = path / "cache"
344 self.vectors = Vectors().from_disk(path)
--> 345 self.cfg.update(srsly.read_json(path / "cfg"))
346 if freqs_path.exists():
347 self.freqs = dict(srsly.read_json(freqs_path))
~/.conda/envs/NewEnv6/lib/python3.7/site-packages/srsly/_json_api.py in read_json(location)
48 data = sys.stdin.read()
49 return ujson.loads(data)
---> 50 file_path = force_path(location)
51 with file_path.open("r", encoding="utf8") as f:
52 return ujson.load(f)
~/.conda/envs/NewEnv6/lib/python3.7/site-packages/srsly/util.py in force_path(location,
require_exists)
19 location = Path(location)
20 if require_exists and not location.exists():
---> 21 raise ValueError("Can't read file: {}".format(location))
22 return location
23 ValueError:无法读取文件:reddit_vectors 1.1.0/vectors.bin/cfg
*我安装了requirements.txt所需的所有适当版本的库/包
发布于 2020-10-08 22:18:41
这是对我有效的方法:
cfg
发布于 2021-04-04 15:37:35
将reddit_vectors x.x.x文件夹放在.py文件所在的文件夹中。
使用路径库确保您的路径是正确的。
from pathlib import Path
path = Path(__file__).parent.joinpath('reddit_vectors-1.1.0')
s2v.from_disk(path)矢量如果仍然出现错误,请删除reddit_
https://stackoverflow.com/questions/61149652
复制相似问题