- Install OCaml
https://fdopen.github.io/opam-repository-mingw/installation/
Download Graphical Installer depends on your version of Operating System.
The advantage of Graphical Installer is that it includes OCaml, Opam and Cygwin with all libraries.
- Download & compile MEGAM’s source
http://www.umiacs.umd.edu/~hal/megam/index.html
Download source code and put the folder into the path of your Cygwin.
1 2 3 4 5 6 7 8 9 |
tumao@LAPTOP-UGC83CQI ~ $ cd megam_src/ tumao@LAPTOP-UGC83CQI ~/megam_src $ cd megam_0.92/ tumao@LAPTOP-UGC83CQI ~/megam_src/megam_0.92 |
Then you need to modify two things in your makefile
The first one, you should use the “ocamlc -where” to find the right ocmal library: /usr/local/lib/ocaml , and then edit the Makefile
1 2 3 |
#WITHCLIBS =-I /usr/lib/ocaml/caml WITHCLIBS =-I /usr/local/lib/ocaml/caml |
And the Second One
1 2 3 |
#WITHSTR =str.cma -cclib -lstr WITHSTR =str.cma -cclib -lcamlstr |
Then you can run make
to compile a stable version, and make opt
to get a faster version.
- congifigure in Python
movemegam.exe
andmegam.opt
to a easy path, and create a python file to test.
1 2 3 4 5 6 7 8 9 10 11 12 |
def demo(): import nltk try: nltk.config_megam('path/to/megam') trainer = lambda x: nltk.MaxentClassifier.train(x, 'megam') except ValueError: try: trainer = lambda x: nltk.MaxentClassifier.train(x, 'BFGS') except ValueError: trainer = nltk.MaxentClassifier.train nltk.classify.rte_classifier(trainer) |
- Still something wrong for me
For me, I met a strange error while excuting ‘make opt’ as following:
1 2 3 4 5 6 7 8 9 |
ocamlopt -unsafe -ccopt -O4 -ccopt -ffast-math -inline 99999 -o megam.opt str.cmxa -cclib -lcamlstr bigarray.cmxa -cclib -lbigarray unix.cmxa -cclib -lunix -I /home/tumao/.opam/4.06.0+mingw64c/lib/ocaml/caml fastdot_c.c fastdot.cmx intHashtbl.cmx arry.cmx util.cmx data.cmx bitvec.cmx cg.cmx wsemlm.cmx bfgs.cmx pa.cmx perceptron.cmx radapt.cmx kernelmap.cmx abffs.cmx main.cmx flexlink: unknown option '-O4'. FlexDLL version 0.37fdopen1 File "caml_startup", line 1: Error: Error during linking make: *** [Makefile:103:megam.opt] ERROR 2 |
I am trying to solve it, beacuse there are few information online. I will update this article after finding correct method.