Export to GitHub

word2vec - issue #1

Build for Mac?


Posted on Aug 15, 2013 by Happy Horse

What steps will reproduce the problem? On a Mac: 1. svn checkout http://word2vec.googlecode.com/svn/trunk/ 2. make

What is the expected output? Binary is emitted.

What do you see instead? pindari:word2vec pmonks$ make gcc word2vec.c -o word2vec -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result cc1: error: invalid option argument ‘-Ofast’ cc1: error: unrecognized command line option "-Wno-unused-result" word2vec.c:1: error: bad value (native) for -march= switch word2vec.c:1: error: bad value (native) for -mtune= switch make: * [word2vec] Error 1 pindari:word2vec pmonks$

What version of the product are you using? SVN r32

On what operating system? Mac OSX 10.8.4

Comment #1

Posted on Aug 15, 2013 by Happy Giraffe

Updating gcc will fix this issue: e.g., http://superuser.com/questions/517218/how-do-i-install-gcc-4-7-2-on-os-x-10-8. (You'll probably have other issues after that, though. I still can't get this to work on OS X.)

Comment #2

Posted on Aug 15, 2013 by Happy Giraffe

Got it to work with the following steps:

1) Update gcc to 4.7: http://superuser.com/questions/517218/how-do-i-install-gcc-4-7-2-on-os-x-10-8 2) Change "-march=native" to "-msse4.2" in makefile 3) Add "-I/usr/include/sys" to makefile "CFLAGS = " statement

Comment #3

Posted on Aug 15, 2013 by Massive Kangaroo

It compiles if you remove the -Ofast, -Wno-unused-result and -march gcc options, and replace malloc.h with stdlib.h in the include statements. There might be a better way, though.

Comment #4

Posted on Aug 15, 2013 by Happy Horse

Thanks eaton...@gmail.com - that appears to have worked (binaries run, at least when not provided with arguments).

Comment #5

Posted on Aug 17, 2013 by Swift Bear

This is my modified build for mac. It worked with 8text.zip (I suggest manually downloading/extracting it. since the script uses wget to download and it cannot find it on mac.)

Attachments

Comment #6

Posted on Aug 17, 2013 by Helpful Rabbit

./distance in this mac package works with the bin generated from text8, but not with the freebase bin file. Just me or everyone?

Comment #7

Posted on Aug 18, 2013 by Happy Bear

A slightly better way to go about it. If you replace gcc with clang, which is what osx is sticking to now, then you just switch -Ofast with -O2 and -Who-unused-result with -Wunused-result.

Comment #8

Posted on Aug 22, 2013 by Massive Wombat

I had to do the following to get the demos to work on my 10.8.2 Hackintosh:

  • in the makefile:

    • replace 'gcc' with 'clang'
    • replace '-Ofast' with '-O2'
    • replace '-Who-unused-result' with '-Wunused-result'
  • where needed in the *.c files, replace '#include ' with '#include '

  • intall 'wget' (I used the instructions at http://osxdaily.com/2012/05/22/install-wget-mac-os-x/)

If the files text8 and text8-phrase do not appear after running one of the scripts, you can download them from http://mattmahoney.net/dc/text8.zip.

This looks like really cool technology!

Comment #9

Posted on Aug 27, 2013 by Helpful Giraffe

Instead of getting or building wget, why not use curl. Replace in for example demo-word.sh the wget for: curl -o text8.gz http://mattmahoney.net/dc/text8.zip

Comment #10

Posted on Nov 18, 2013 by Helpful Ox

CFLAGS = -lm -lc -pthread -O2 -msse4.2 -Wall -funroll-loops -Wunused-result

and replaced or removed all (where already present):

include

with:

include

Comment #11

Posted on Nov 20, 2013 by Grumpy Panda

Comment deleted

Comment #12

Posted on Nov 20, 2013 by Grumpy Panda

after having compiled on mavericks (simple malloc.h substitution to stdlib.h and nothing changed in compiler parameters) word2vec works well with demo-word.sh and demo-phrases.sh, but not with demo-word-accuracy. I get a segfault at line 7, sunning only line 7 (as i already have vectors.bin used in demo-word.sh) i get: ./compute-accuracy vectors.bin 30000 < questions-words.txt capital-common-countries: Segmentation fault: 11 Any idea?

Comment #13

Posted on Dec 13, 2013 by Swift Rhino

It could be related to the non-portable call to gzip when unpacking the test data. In fact, if you look at the demo scripts and change the line with gzip to the line with unzip, the demo should run.

#gzip -d text8.gz -f unzip -c -d text8.gz > text8

Regarding the malloc/stdlib error, you can add block of directives to handle whether APPLE has been defined. Something like below should work with distance.c, word-analogy.c, and compute-accuracy.c:

ifdef APPLE

include

include

else

include

endif

Best of luck! Paul

Comment #14

Posted on Mar 28, 2014 by Grumpy Rhino

I had issues on OS X 10.9.2, and my fix was to install gcc 4.7 using macports

  1. "sudo port install gcc47" This will install gcc as gcc-mp-47 so you will need to change the first line in the makefile to refer to that instead of just "gcc".
  2. Some libraries are needed from /usr/include/sys so you have to add to the CFLAGS statement in the makefile "-I/usr/include/sys"
  3. Unfortunately, the header file time.h in /usr/include/sys is not the one you want because it doesn't define clock_t type. So we have to explicitly refer to "#include " in the word2vec.c file and any others that declare variables of clock_t type.

Hopefully this will save other time Eddie

Status: New

Labels:
Type-Defect Priority-Medium