“接收”;取消勾选错误:无效的加载键&x27;v'&引用;尝试在Python中运行truecase时
我正在尝试运行一个使用truecase Python包(用于恢复文本大小写)的简短代码片段,我收到一个“接收”;取消勾选错误:无效的加载键&x27;v'&引用;尝试在Python中运行truecase时,python,nltk,pickle,Python,Nltk,Pickle,我正在尝试运行一个使用truecase Python包(用于恢复文本大小写)的简短代码片段,我收到一个UnpicklingError,因为它从nltk加载了一个标记器 由于网络上的服务器限制,我无法使用nltk.download安装丢失的nltk文件,因此我已将nltk_数据目录直接下载到我的计算机上。看起来它能够找到文件,但打开语言pickle文件时遇到了麻烦 import truecase truecase.get_true_case('hey, what is the weather in
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'.
导入truecase
特鲁凯斯。获得特鲁凯斯(‘嘿,纽约的天气怎么样?’)
在[4]中:运行文件('/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py',wdir='/Users/{me}/Downloads/truecase-0.0.4')
重新加载的模块:truecase,truecase.TrueCaser
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
运行文件('/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py',wdir='/Users/{me}/Downloads/truecase-0.0.4')
文件“/anaconda3/lib/python3.7/site packages/spyder_kernels/customize/spyderrcustomize.py”,第704行,在runfile中
execfile(文件名、命名空间)
文件“/anaconda3/lib/python3.7/site packages/spyder_kernels/customize/spyderrcustomize.py”,第108行,在execfile中
exec(编译(f.read(),文件名,'exec'),命名空间)
文件“/Users/{me}/Downloads/truecase-0.0.4/testingtruecase.py”,第10行,在
特鲁凯斯。获得特鲁凯斯(‘嘿,纽约的天气怎么样?’)
文件“/Users/y99b/Downloads/truecase-0.0.4/truecase/_init__.py”,第7行,在get_true_情况下
返回caser.get\u true\u case(句子,out\u of theu词汇表\u token\u选项=out\u of theu词汇表\u token\u选项)
文件“/Users/{me}/Downloads/truecase-0.0.4/truecase/TrueCaser.py”,第80行,在get_true_案例中
tokens=nltk.word\u标记化(句子)
文件“/anaconda3/lib/python3.7/site packages/nltk/tokenize/_init__.py”,第143行,在word_tokenize中
句子=[text]如果保留\u行,则发送\u标记化(文本、语言)
文件“/anaconda3/lib/python3.7/site packages/nltk/tokenize/_init__.py”,第104行,在sent_tokenize中
tokenizer=load('tokenizers/punkt/{0}.pickle'。格式(语言))
文件“/anaconda3/lib/python3.7/site packages/nltk/data.py”,第873行,已加载
resource\u val=pickle.load(打开的\u资源)
取消勾选错误:加载键“v”无效。
发现了问题,我使用的pickle文件无效,实际上没有正确的数据(它只是在实际文件中有一个指向github的链接)。我找到了一个不同的下载,有正确的english.pickle文件,一切正常。如果任何人有无效密钥“v”错误,则可能与实际的pickle文件有关。您的pickle文件可能已损坏。用新文件替换它。它对我有用。也许你需要git lfs-?
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'.