python导入文件为字典_在python中将数据从文件导入字典

我想把文件导入字典以便进一步处理。该文件包含NLP的嵌入向量。它看起来像:the 0.011384 0.010512 -0.008450 -0.007628 0.000360 -0.010121 0.004674 -0.000076

of 0.002954 0.004546 0.005513 -0.004026 0.002296 -0.016979 -0.011469 -0.009159

and 0.004691 -0.012989 -0.003122 0.004786 -0.002907 0.000526 -0.006146 -0.003058

one 0.014722 -0.000810 0.003737 -0.001110 -0.011229 0.001577 -0.007403 -0.005355

我使用的代码是:

^{pr2}$

错误:---------------------------------------------------------------------------

ValueError Traceback (most recent call last)

in ()

24 with open("D:\\Embedding\\test.txt") as f:

25 for line in f:

---> 26 (key, val) = line.split()

27 d[key] = val

28 print(embeddingTable)

ValueError: too many values to unpack (expected 2)

我知道它需要2个值而不是9,但是有没有可能将单词作为键插入,将向量作为值插入?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值