Please take a moment to follow this link to complete a survey about skateboard sizes.

Alternatively, you can navigate to the survey by copying and pasting the following URL to your browser's address bar:

Saturday, August 1, 2015

Off topic: Getting Megam to work in NLTK on Ubuntu

Just a helpful tip for others out there learning NLTK programming using nltk.org's book at http://www.nltk.org/book/ . Chapter 7 has a chunker algorithm called MEGAM that gave me all sorts of trouble. I followed all of the advice I could find on the Internet, most of which was written for OSX unix (like Apple Mac computers), and very little of which helped me with my problem. Specifically, NLTK had trouble finding the megam file. Then, following some of the advice to point NLTK to the megam file using config, NLTK ran into permission issues.

First, I had issues with NLTK not finding MEGAM...

... then I had permission issues. PermissionError: [Errno 13] Permission denied
The config didn't work with the 32-bit version, nltk.config_megam('/home/richard/MEGAM/megam') , either.

The permissions thing got me thinking, though. So I opened up my terminal (Ctrl+Alt+t on my Ubuntu Thinkpad x120e) and made some changes. First, I signed on as root and changed mode of access permissions for all of the files NLTK mentioned:

:~# chmod 777 /usr/lib/python3.4/subprocess.py
:~# chmod 777 /usr/local/lib/python3.4/dist-packages/nltk/classify/megam.py
:~# chmod 777 /usr/local/lib/python3.4/dist-packages/nltk/classify/maxent.py

This didn't make any difference in NLTK. Thinking deeper, I thought about the config pointer command, and decided to locate everything in the same place. I navigated to where I put the megam downloads and moved the megam files to my local binary folder:

:~# cd home/richard/Downloads/megam_0.92
:/home/richard/Downloads/megam_0.92# cp megam /usr/local/bin
:/home/richard/Downloads/megam_0.92# cp megam-64 /usr/local/bin
:/home/richard/Downloads/megam_0.92# cp megam-64.opt /usr/local/bin

I first tried it with just the 32-bit file - megam - but NLTK didn't like it. My system is an AMD 64-bit SOC. Then I moved the 64-bit megam files into the binary folder. After that, all was well with NLTK using megam.

It took both cores on my AMD E350 SOC about 10 minutes to chunk the training set, but my megam location issues were a thing of the past. Thank goodness.
Hope this helps!

My software:
I'm using Python3.4 in the IDLE shell. I got Python3.4 from the Ubuntu Software Center.
I loaded OCAML using sudo apt-get install ocaml .
I loaded nltk using sudo pip3 install nltk .
I loaded megam through the download page at http://www.umiacs.umd.edu/~hal/megam/index.html . This megam didn't work.
I got the 64-bit compilations of megam from http://thinknook.com/nltk-megam-maximum-entropy-library-on-64-bit-linux-2012-11-27/ by loading from the following link:
http://thinknook.com/wp-content/uploads/2012/11/MEGAM.zip

My system:
I'm using a Lenovo ThinkPad x120e with Ubuntu 14.04 LTS Trusty Tahr operating an AMD E-350 1.6 GHz System On Chip and 4 GB of 1333 MHz DDR3 PC3-10600 RAM and 120 GB of SSD storage. (A great combination, by the way. All drivers work, I have absolutely no issues with this computer. The x120e was, at the beginning, a tolerable-because-of-the-price slug with Windows 7 Pro and the 5200rpm spinner drive, then it became slower and slower as Windows updated it to death. It operated Windows 7 reasonably well when I replaced the spinner with the solid state drive. It became a powerhouse when I wiped the drive and installed 64-bit Ubuntu using an ext3/ext4 file system. The computer has been completely reliable ever since.)

Search keywords:
ubuntu linux 64-bit megam nltk python python3.4

Search phrases:
PermissionsError: [Errno 13] Permission denied
NLTK was unable to find the megam file!
megam not working on nltk
nltk book chapter 7
megam chunker algorithm not working
linux "[megam] Error 2"

3 comments:

  1. Hey Richard. Here's my blog with some pictures of the park. And flowers and bees.

    Let me know if the link doesn't work.

    Sudeep

    http://sappynonsense.blogspot.com/

    ReplyDelete
  2. Here's the link to the Brazilian downhill longboard race. 24 minutes 24 seconds.

    https://www.youtube.com/watch?v=L4-aX5LOAXM

    Sudeep

    ReplyDelete
  3. I have a simple question and please don' think me ediot. I just want to know can I use Obunto with an Windows Operating Pc at the same time?

    ReplyDelete