日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python2.7安装使用thulac库时遇到的一些问题

發布時間:2024/9/30 python 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python2.7安装使用thulac库时遇到的一些问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

環境:Windows10、python2.7.14、thulac-0.1.1
提示錯誤:

Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\thulac_init_.py", line 58, in init self.__tagging_decoder.init((self.__prefix+"model_c_model.bin"),(self.__prefix+"model_c_dat.bin"),(self.__prefix+"model_c_label.txt")) File "C:\Python27\lib\site-packages\thulac\character\CBTaggingDecoder.py", line 36, in init self.model = CBModel(modelFile) File "C:\Python27\lib\site-packages\thulac\character\CBModel.py", line 58, in init self.fl_weights = struct.unpack("<"+str(self.f_size * self.l_size)+"i", temp) MemoryError

查閱了資料后,找到了修改方法
編輯CBModel.py,找到__init__方法,找到下面這個代碼:

temp = inputfile.read(4 * self.l_size * self.l_size) self.ll_weights = struct.unpack("<"+str(self.l_size * self.l_size)+"i", temp) self.ll_weights = tuple(self.ll_weights)temp = inputfile.read(4 * self.f_size * self.l_size) self.fl_weights = struct.unpack("<"+str(self.f_size * self.l_size)+"i", temp)

改成

temp = inputfile.read(4 * self.l_size * self.l_size) self.ll_weights = array.array('i') self.ll_weights.fromstring(temp) self.ll_weights = tuple(self.ll_weights)temp = inputfile.read(4 * self.f_size * self.l_size) self.fl_weights = array.array('i') self.fl_weights.fromstring(temp)

再加上import

import array

python2.7適用,3.6有這個API,也能兼任

轉自:https://github.com/thunlp/THULAC-Python/issues/25

總結

以上是生活随笔為你收集整理的python2.7安装使用thulac库时遇到的一些问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。