尝试在Python中运行truecase时收到“UnpicklingError:Invalid load key,'v.”

2024-04-26 01:21:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行一个使用truecase Python包(用于恢复文本中的大写)的代码片段,我收到了一个UnpicklingError,因为它从nltk加载了一个标记器。在

由于网络上的服务器限制,我无法使用nltk.download安装丢失的nltk文件,所以我直接将nltk_数据目录下载到我的计算机上。它看起来可以找到文件,但在打开语言pickle文件时遇到麻烦。在

import truecase
truecase.get_true_case('hey, what is the weather in new york?')

In [4]: runfile('/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py', wdir='/Users/{me}/Downloads/truecase-0.0.4')
Reloaded modules: truecase, truecase.TrueCaser
Traceback (most recent call last):

  File "<ipython-input-4-82ea1175dde8>", line 1, in <module>
    runfile('/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py', wdir='/Users/{me}/Downloads/truecase-0.0.4')

  File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py", line 10, in <module>
    truecase.get_true_case('hey, what is the weather in new york?')

  File "/Users/y99b/Downloads/truecase-0.0.4/truecase/__init__.py", line 7, in get_true_case
    return caser.get_true_case(sentence, out_of_vocabulary_token_option=out_of_vocabulary_token_option)

  File "/Users/{me}/Downloads/truecase-0.0.4/truecase/TrueCaser.py", line 80, in get_true_case
    tokens = nltk.word_tokenize(sentence)

  File "/anaconda3/lib/python3.7/site-packages/nltk/tokenize/__init__.py", line 143, in word_tokenize
    sentences = [text] if preserve_line else sent_tokenize(text, language)

  File "/anaconda3/lib/python3.7/site-packages/nltk/tokenize/__init__.py", line 104, in sent_tokenize
    tokenizer = load('tokenizers/punkt/{0}.pickle'.format(language))

  File "/anaconda3/lib/python3.7/site-packages/nltk/data.py", line 873, in load
    resource_val = pickle.load(opened_resource)

UnpicklingError: invalid load key, 'v'.

Tags: inpytruegetlibdownloadslineusers
1条回答
网友
1楼 · 发布于 2024-04-26 01:21:01

发现了这个问题,我正在处理的pickle文件无效,而且实际上没有正确的数据(它只是在实际文件中有一个指向github的链接)。我找到了一个不同的下载英语.泡菜文件和一切都很好。如果任何人有一个无效的键“v”错误,这很可能与您实际的pickle文件有关。在

相关问题 更多 >