【问题标题】:Mallet works in Linux but not WindowsMallet 适用于 Linux,但不适用于 Windows
【发布时间】:2014-03-07 21:47:04
【问题描述】:

好的,我正在尝试使用 Mallet 对 Windows 中的一些文档进行分类

我已经在 Linux 中实现了它。只是无法在 Windows(目标环境)中完成工作

我已将数据导入 .mallet 文件。

然后使用这个输入数据创建一个分类器。

-rw-r--r-- 1 henry henry 15197116 Feb 23 15:56 nntp.classifier

07/03/2014  21:28        15,197,116 nntp.classifier

但是当我在 Linux 中运行时:

bin/mallet 分类目录 --input ./testfolder --output - --classifier nntp.classifier

它迭代测试文件夹中的所有文件并转储出它认为的每个类。

但如果我在 Windows 中运行相同的命令:

bin\mallet classify-dir --input ./testfolder --output - --classifier nntp.classifier

它只是转储了命令列表:

Mallet 2.0 commands:
  import-dir        load the contents of a directory into mallet instances (one per file)
  import-file       load a single file into mallet instances (one per line)
  import-svmlight   load a single SVMLight format data file into mallet instances (one per line)
  train-classifier  train a classifier from Mallet data files
  train-topics      train a topic model from Mallet data files
  infer-topics      use a trained topic model to infer topics for new documents
  estimate-topics   estimate the probability of new documents given a trained model
  hlda              train a topic model using Hierarchical LDA
  prune             remove features based on frequency or information gain
  split             divide data into testing, training, and validation portions
Include --help with any option for more information

我确实注意到了一些事情:我

f 我在 linux 中运行 bin/mallet classify-dir --help 我得到了帮助文件,即每个命令的描述,但在 Windows 中相同的东西 bin\mallet classify-dir --help 不会产生相同的结果 - 只是上面的命令列表......(它确实如果您输入 junk 作为命令,则相同)

而较早的命令之一,例如bin/mallet import-dir --helpbin\mallet import-dir --help 生成相同的完整帮助文件输出。

【问题讨论】:

    标签: linux windows mallet


    【解决方案1】:

    请注意,ignazio 提供的 .bat 文件的第 23 行有一个错字(不幸的是,它包含在 mallet-2.0.7 下载中)导致它寻找“import-smvlight”而不是“import -svmlight”,这是帮助信息中指定的内容。如果您想使用此功能,请务必切换“m”和“v”。

    【讨论】:

      【解决方案2】:

      bin 目录中的 mallet.bat 文件有问题。 你应该修改它:

      @echo off
      
      rem This batch file serves as a wrapper for several
      rem  MALLET command line tools.
      
      if not "%MALLET_HOME%" == "" goto gotMalletHome
      
      echo MALLET requires an environment variable MALLET_HOME.
      goto :eof
      
      :gotMalletHome
      
      set MALLET_CLASSPATH=%MALLET_HOME%\class;%MALLET_HOME%\lib\mallet-deps.jar
      set MALLET_MEMORY=1G
      set MALLET_ENCODING=UTF-8
      
      set CMD=%1
      shift
      
      set CLASS=
      if "%CMD%"=="import-dir" set CLASS=cc.mallet.classify.tui.Text2Vectors
      if "%CMD%"=="import-file" set CLASS=cc.mallet.classify.tui.Csv2Vectors
      if "%CMD%"=="import-smvlight" set CLASS=cc.mallet.classify.tui.SvmLight2Vectors
      if "%CMD%"=="train-classifier" set CLASS=cc.mallet.classify.tui.Vectors2Classify
      if "%CMD%"=="classify-dir" set CLASS=cc.mallet.classify.tui.Text2Classify
      if "%CMD%"=="classify-file" set CLASS=cc.mallet.classify.tui.Csv2Classify
      if "%CMD%"=="train-topics" set CLASS=cc.mallet.topics.tui.Vectors2Topics
      if "%CMD%"=="infer-topics" set CLASS=cc.mallet.topics.tui.InferTopics
      if "%CMD%"=="estimate-topics" set CLASS=cc.mallet.topics.tui.EvaluateTopics
      if "%CMD%"=="hlda" set CLASS=cc.mallet.topics.tui.HierarchicalLDATUI
      if "%CMD%"=="prune" set CLASS=cc.mallet.classify.tui.Vectors2Vectors
      if "%CMD%"=="split" set CLASS=cc.mallet.classify.tui.Vectors2Vectors
      if "%CMD%"=="bulk-load" set CLASS=cc.mallet.util.BulkLoader
      if "%CMD%"=="run" set CLASS=%1 & shift
      
      if not "%CLASS%" == "" goto gotClass
      
      echo Mallet 2.0 commands:
      echo   import-dir        load the contents of a directory into mallet instances (one per file)
      echo   import-file       load a single file into mallet instances (one per line)
      echo   import-svmlight   load a single SVMLight format data file into mallet instances (one per line)
      echo   train-classifier  train a classifier from Mallet data files
      echo   classify-dir      classify the contents of a directory with a saved classifier
      echo   classify-file     classify a file with a saved classifier
      echo   train-topics      train a topic model from Mallet data files
      echo   infer-topics      use a trained topic model to infer topics for new documents
      echo   estimate-topics   estimate the probability of new documents given a trained model
      echo   hlda              train a topic model using Hierarchical LDA
      echo   prune             remove features based on frequency or information gain
      echo   split             divide data into testing, training, and validation portions
      echo Include --help with any option for more information
      
      
      goto :eof
      
      :gotClass
      
      set MALLET_ARGS=
      
      :getArg
      
      if "%1"=="" goto run
      set MALLET_ARGS=%MALLET_ARGS% %1
      shift
      goto getArg
      
      :run
      
      java -Xmx%MALLET_MEMORY% -ea -Dfile.encoding=%MALLET_ENCODING% -classpath %MALLET_CLASSPATH% %CLASS% %MALLET_ARGS%
      
      :eof
      

      能够在 Windows 环境中进行分类。

      我希望这会有所帮助。

      伊格纳齐奥

      【讨论】:

      • 太棒了。效果很好。你注册了SO来告诉我这个!我已经安装了 Cygwin,并用 Ant、Bant、Chant 和 Rant 等名称编译了一个完整的列表。这应该会让下一个 Windows 用户的生活更轻松。
      • /bin 中的其他脚本仍然是 linux-only。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-27
      • 1970-01-01
      • 2016-03-01
      • 2021-05-02
      • 2017-06-14
      • 2011-06-15
      • 2021-10-27
      相关资源
      最近更新 更多