HanLP icon indicating copy to clipboard operation
HanLP copied to clipboard

TextClassifcation 的 temp.data 如何重複使用?

Open yesseecity opened this issue 9 years ago • 4 comments

注意事项

请确认下列注意事项:

  • 我已仔细阅读下列文档,都没有找到答案:
  • 我已经通过Google和issue区检索功能搜索了我的问题,也没有找到答案。
  • 我明白开源社区是出于兴趣爱好聚集起来的自由社区,不承担任何责任或义务。我会礼貌发言,向每一个帮助我的人表示感谢。
  • [x] 我在此括号内输入x打钩,代表上述事项确认完毕。

版本号

当前最新版本号是: master branch https://github.com/hankcs/HanLP/commit/7d35473e4e26631e7362cb861d5a000594f71619 我使用的版本是:master branch https://github.com/hankcs/HanLP/commit/7d35473e4e26631e7362cb861d5a000594f71619

我的问题

DemoTextClassifcationFMeasure.java 裡面 FileDataSet 是以 File.createTempFile 建立 TempFile to cache 如何重複使用 TempFile ?

触发代码

    public FileDataSet() throws IOException
    {
        this(File.createTempFile(String.valueOf(System.currentTimeMillis()), ".dat"));
    }

yesseecity avatar Dec 01 '17 11:12 yesseecity

为什么要重复利用临时文件呢?如果有多个线程同时调用的话,会导致冲突的。

hankcs avatar Dec 02 '17 03:12 hankcs

另外,如果真的要用的话,com.hankcs.hanlp.classification.corpus.FileDataSet#FileDataSet(java.io.File)可以根据给定的File创建FileDataSet

hankcs avatar Dec 02 '17 04:12 hankcs

我的用分類語料包壓縮後有1.4GB 很肥大,讀取讀很久。 _______________ 仔細看了Code之後,我發現我該問的是: 如何保留 train 完的資料,好讓下次使用的時候快速載入。 就像是 dictionary中 txt會變成 .bin 方便下次讀入

_______________ 歡迎取用 分類語料包 (google drive) 他是用爬蟲爬 台灣某個論壇的討論內容

yesseecity avatar Dec 04 '17 07:12 yesseecity

train完之后得到应该是一个AbstractModel,可以序列化到磁盘。

     // 训练后的模型支持持久化,下次就不必训练了
    AbstractModel model = classifier.getModel();
    IOUtil.saveObjectTo(model, "path.ser");

下次读取进来直接构造NaiveBayesClassifier,不必重复训练。See https://github.com/hankcs/HanLP/commit/4240e54e00a403c6c8dfb0ef905fcc21b7e8cf64

也就不存在重复利用temp data的问题了。

hankcs avatar Dec 08 '17 22:12 hankcs