Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 371af39
Showing
30 changed files
with
8,505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*~ | ||
*.pyc | ||
*.so | ||
*_inner.c | ||
*_bind.cpp | ||
*.o | ||
build/* | ||
\#*\# | ||
*.DS_Store | ||
*.cmat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
GNU LESSER GENERAL PUBLIC LICENSE | ||
Version 3, 29 June 2007 | ||
|
||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | ||
Everyone is permitted to copy and distribute verbatim copies | ||
of this license document, but changing it is not allowed. | ||
|
||
|
||
This version of the GNU Lesser General Public License incorporates | ||
the terms and conditions of version 3 of the GNU General Public | ||
License, supplemented by the additional permissions listed below. | ||
|
||
0. Additional Definitions. | ||
|
||
As used herein, "this License" refers to version 3 of the GNU Lesser | ||
General Public License, and the "GNU GPL" refers to version 3 of the GNU | ||
General Public License. | ||
|
||
"The Library" refers to a covered work governed by this License, | ||
other than an Application or a Combined Work as defined below. | ||
|
||
An "Application" is any work that makes use of an interface provided | ||
by the Library, but which is not otherwise based on the Library. | ||
Defining a subclass of a class defined by the Library is deemed a mode | ||
of using an interface provided by the Library. | ||
|
||
A "Combined Work" is a work produced by combining or linking an | ||
Application with the Library. The particular version of the Library | ||
with which the Combined Work was made is also called the "Linked | ||
Version". | ||
|
||
The "Minimal Corresponding Source" for a Combined Work means the | ||
Corresponding Source for the Combined Work, excluding any source code | ||
for portions of the Combined Work that, considered in isolation, are | ||
based on the Application, and not on the Linked Version. | ||
|
||
The "Corresponding Application Code" for a Combined Work means the | ||
object code and/or source code for the Application, including any data | ||
and utility programs needed for reproducing the Combined Work from the | ||
Application, but excluding the System Libraries of the Combined Work. | ||
|
||
1. Exception to Section 3 of the GNU GPL. | ||
|
||
You may convey a covered work under sections 3 and 4 of this License | ||
without being bound by section 3 of the GNU GPL. | ||
|
||
2. Conveying Modified Versions. | ||
|
||
If you modify a copy of the Library, and, in your modifications, a | ||
facility refers to a function or data to be supplied by an Application | ||
that uses the facility (other than as an argument passed when the | ||
facility is invoked), then you may convey a copy of the modified | ||
version: | ||
|
||
a) under this License, provided that you make a good faith effort to | ||
ensure that, in the event an Application does not supply the | ||
function or data, the facility still operates, and performs | ||
whatever part of its purpose remains meaningful, or | ||
|
||
b) under the GNU GPL, with none of the additional permissions of | ||
this License applicable to that copy. | ||
|
||
3. Object Code Incorporating Material from Library Header Files. | ||
|
||
The object code form of an Application may incorporate material from | ||
a header file that is part of the Library. You may convey such object | ||
code under terms of your choice, provided that, if the incorporated | ||
material is not limited to numerical parameters, data structure | ||
layouts and accessors, or small macros, inline functions and templates | ||
(ten or fewer lines in length), you do both of the following: | ||
|
||
a) Give prominent notice with each copy of the object code that the | ||
Library is used in it and that the Library and its use are | ||
covered by this License. | ||
|
||
b) Accompany the object code with a copy of the GNU GPL and this license | ||
document. | ||
|
||
4. Combined Works. | ||
|
||
You may convey a Combined Work under terms of your choice that, | ||
taken together, effectively do not restrict modification of the | ||
portions of the Library contained in the Combined Work and reverse | ||
engineering for debugging such modifications, if you also do each of | ||
the following: | ||
|
||
a) Give prominent notice with each copy of the Combined Work that | ||
the Library is used in it and that the Library and its use are | ||
covered by this License. | ||
|
||
b) Accompany the Combined Work with a copy of the GNU GPL and this license | ||
document. | ||
|
||
c) For a Combined Work that displays copyright notices during | ||
execution, include the copyright notice for the Library among | ||
these notices, as well as a reference directing the user to the | ||
copies of the GNU GPL and this license document. | ||
|
||
d) Do one of the following: | ||
|
||
0) Convey the Minimal Corresponding Source under the terms of this | ||
License, and the Corresponding Application Code in a form | ||
suitable for, and under terms that permit, the user to | ||
recombine or relink the Application with a modified version of | ||
the Linked Version to produce a modified Combined Work, in the | ||
manner specified by section 6 of the GNU GPL for conveying | ||
Corresponding Source. | ||
|
||
1) Use a suitable shared library mechanism for linking with the | ||
Library. A suitable mechanism is one that (a) uses at run time | ||
a copy of the Library already present on the user's computer | ||
system, and (b) will operate properly with a modified version | ||
of the Library that is interface-compatible with the Linked | ||
Version. | ||
|
||
e) Provide Installation Information, but only if you would otherwise | ||
be required to provide such information under section 6 of the | ||
GNU GPL, and only to the extent that such information is | ||
necessary to install and execute a modified version of the | ||
Combined Work produced by recombining or relinking the | ||
Application with a modified version of the Linked Version. (If | ||
you use option 4d0, the Installation Information must accompany | ||
the Minimal Corresponding Source and Corresponding Application | ||
Code. If you use option 4d1, you must provide the Installation | ||
Information in the manner specified by section 6 of the GNU GPL | ||
for conveying Corresponding Source.) | ||
|
||
5. Combined Libraries. | ||
|
||
You may place library facilities that are a work based on the | ||
Library side by side in a single library together with other library | ||
facilities that are not Applications and are not covered by this | ||
License, and convey such a combined library under terms of your | ||
choice, if you do both of the following: | ||
|
||
a) Accompany the combined library with a copy of the same work based | ||
on the Library, uncombined with any other library facilities, | ||
conveyed under the terms of this License. | ||
|
||
b) Give prominent notice with the combined library that part of it | ||
is a work based on the Library, and explaining where to find the | ||
accompanying uncombined form of the same work. | ||
|
||
6. Revised Versions of the GNU Lesser General Public License. | ||
|
||
The Free Software Foundation may publish revised and/or new versions | ||
of the GNU Lesser General Public License from time to time. Such new | ||
versions will be similar in spirit to the present version, but may | ||
differ in detail to address new problems or concerns. | ||
|
||
Each version is given a distinguishing version number. If the | ||
Library as you received it specifies that a certain numbered version | ||
of the GNU Lesser General Public License "or any later version" | ||
applies to it, you have the option of following the terms and | ||
conditions either of that published version or of any later version | ||
published by the Free Software Foundation. If the Library as you | ||
received it does not specify a version number of the GNU Lesser | ||
General Public License, you may choose any version of the GNU Lesser | ||
General Public License ever published by the Free Software Foundation. | ||
|
||
If the Library as you received it specifies that a proxy can decide | ||
whether future versions of the GNU Lesser General Public License shall | ||
apply, that proxy's public statement of acceptance of any version is | ||
permanent authorization for you to choose that version for the | ||
Library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# build extensions | ||
compile_cmd = python setup.py build_ext --inplace --force | ||
all: word2vec_inner.so cat2vec_bind.so sent2vec_bind.so | ||
|
||
word2vec_inner.so: word2vec_inner.pyx options.h options.c settings.py | ||
$(compile_cmd) | ||
sent2vec_bind.so: sent2vec_bind.pyx sent2vec_calc.h sent2vec_calc.cpp options.h options.c settings.py | ||
$(compile_cmd) | ||
cat2vec_bind.so: cat2vec_bind.pyx cat2vec_calc.h cat2vec_calc.cpp options.h options.c settings.py | ||
$(compile_cmd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# Category2Vec | ||
|
||
## Introduction | ||
Category2Vec is an implementation of the category vector models [Marui and Hagiwara 2015], and the paragraph vector models [Le and Mikolov 2014]. | ||
These programs are based on word2vec [Mikolov et al. 2013a,b] in gensim project (https://radimrehurek.com/gensim/)[Rahurek 2013]. | ||
|
||
After training, you can obtain distributed representations for categories, paragraphs, and words. You can also infer a category from a description. | ||
|
||
## Demo | ||
There are demo programs of category vector models(Category2Vec) and paragraph vector models(Sentence2Vec). | ||
To execute the demo programs, | ||
|
||
``` | ||
make # to build extensions (optional) | ||
python demo_catvec.py # for category vector models | ||
python demo_sentvec.py # for paragraph vector models | ||
``` | ||
|
||
|
||
## Usage | ||
### Download | ||
Clone the git repository as | ||
|
||
``` | ||
git clone https://github.com/rakuten-nlp/category2vec.git | ||
``` | ||
|
||
or download the zip archive from here: https://github.com/rakuten-nlp/category2vec/archive/master.zip | ||
|
||
### Dependency | ||
Category2Vec requires following python modules: | ||
|
||
* numpy | ||
* scipy | ||
* six | ||
* cython | ||
|
||
For Ubuntu, you can install them as follows: | ||
``` | ||
apt-get install python-dev python-pip python-numpy python-scipy | ||
pip install six cython | ||
``` | ||
|
||
To build extensions, it is recommended to get a BLAS library such as: | ||
|
||
* ATLAS | ||
* OpenBLAS | ||
|
||
For Ubuntu, you can use the provided ATLAS package as follows: | ||
``` | ||
apt-get install libatlas-base-dev | ||
``` | ||
|
||
There is limitation in OpenBLAS package included in Ubuntu, we recommend you to install it from the source. | ||
``` | ||
apt-get install gfortran | ||
git clone https://github.com/xianyi/OpenBLAS.git | ||
cd OpenBLAS | ||
#edit Makefile.rule (USE_THREAD=1 is recommended) | ||
make | ||
make install PREFIX=your_installation_directory # for example, PREFIX=/usr/local | ||
``` | ||
|
||
|
||
### Build | ||
You don't have to build the extensions to use Category2Vec, | ||
but to pursue good performance, we recommend to build the extensions. | ||
GCC >= 4.6 is required. | ||
|
||
Before the compilation, edit `settings.py`. | ||
If you use scipy >= 0.15.1, you should use the option `use_blas = True`, and specify your BLAS library in `blas_include` and `blas_libs`. | ||
If you have an Intel CPU (>= Sandy Bridge), you can enable the option `use_avx = True`. | ||
|
||
After you editted the settings, type `make` to build extensions. | ||
|
||
#### Ubuntu | ||
This version has been tested under the following environments: | ||
|
||
* Ubuntu 12.04 / 14.04 | ||
* Python 2.7.3 / 2.7.6 / 2.7.8 (anaconda) | ||
* Numpy 1.8.0 / 1.8.2 / 1.9.0 (anaconda) / 1.10.0 | ||
* Scipy 0.9.0 / 0.13.3 / 0.14.0 (anaconda) / 0.15.0 / 0.16.0 (use_blas=True) | ||
* gcc 4.6.3 / 4.8.1 / 4.8.3 | ||
* OpenBLAS 0.2.12 / ATLAS 3.10.1-4 | ||
|
||
And under the following CPUs: | ||
|
||
* Haswell CPUs | ||
* i7-4770K | ||
* i7-5820K | ||
* Ivy Bridge CPUs | ||
* Xeon E5-26xx v2 series | ||
* AMD CPUs | ||
* Opteron 4100 series (use_avx=False) | ||
|
||
#### Mac OS X | ||
If you use `clang`, edit `settings.py` and specify `use_clang = True`. | ||
``` | ||
easy_install pip | ||
pip install numpy scipy six cython # it's important to build cython using gcc | ||
# you can install OpenBLAS using the instruction above | ||
# or you can install it from Homebrew as follows: | ||
# brew install homebrew/science/openblas | ||
make | ||
``` | ||
|
||
If you want to use gcc, you can edit `settings.py` and specify `force_gcc = True` and `use_clang = False`. | ||
For Homebrew, | ||
``` | ||
brew install gcc49 | ||
brew install python | ||
source ~/.bash_profile # to use brewed python | ||
easy_install pip | ||
pip install numpy scipy six cython # it's important to build cython using gcc | ||
# you can install OpenBLAS using the instruction above | ||
# or you can install it from Homebrew as follows: | ||
# brew install homebrew/science/openblas | ||
make | ||
``` | ||
If you get errors around AVX (e.g. no such instruction error), replace the native OS X assembler (usr/bin/as) by a script below. | ||
|
||
https://gist.github.com/xianyi/2957847 | ||
|
||
Or you can specify `use_avx = False` to avoid this error. | ||
|
||
This version has been tested under Mac OS X 10.9.5, Python 2.7.9 (Numpy 1.9.2, Scipy 0.15.1) and apple llvm 6.0 / gcc 4.8.4 (brew gcc48) / gcc 4.9.2 (brew gcc49) with the above modification on the assembler. | ||
|
||
### Example | ||
|
||
|
||
## Terms and Conditions | ||
Distribution, modification, and academic/commercial use of Category2Vec is permitted, provided that | ||
you conform with GNU Lesser General Public License v3.0 https://www.gnu.org/licenses/lgpl.html | ||
|
||
If you are using Category2Vec for research purposes, please cite our paper on Category2Vec [Marui and Hagiwara 2015] | ||
|
||
Although we are accepting contributions (e.g., issues and pull | ||
requests) to this category2vec projects, | ||
our contribution policy has not been finalized yet. | ||
We will be announcing our official policy in near future, after which | ||
we can fully accept contributions. | ||
|
||
## FAQ (Frequently Asked Questions) | ||
Q. Is commercial use permitted? | ||
- A. Yes, as long as you follow the terms and conditions. See "Terms and Conditions" above for the details. | ||
|
||
## Acknowledgements | ||
The developers would like to thank Masato Hagiwara and Kaoru Yamada for their contribution to this project. | ||
|
||
## References | ||
[Marui and Hagiwara 2015] Junki Marui, and Masato Hagiwara. Category2Vec: 単語・段落・カテゴリに対するベクトル分散表現. 言語処理学会第21回年次大会(NLP2015). | ||
|
||
[Le and Mikolov 2014] Quoc Le, and Tomas Mikolov. Distributed Representations of Sentence and Documents. In Proceedings of ICML 2014. | ||
|
||
[Mikolov et al. 2013a] Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient Estimation of Word Representations | ||
in Vector Space. In Proceedings of Workshop at ICLR, 2013. | ||
|
||
[Mikolov et al. 2013b] Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean. Distributed Representations | ||
of Words and Phrases and their Compositionality. In Proceedings of NIPS, 2013. | ||
|
||
[Rahurek 2013] Radim Rehurek, Optimizing word2vec in gensim, http://radimrehurek.com/2013/09/word2vec-in-python-part-two-optimizing/ | ||
|
||
--- | ||
|
||
© 2015 Rakuten NLP Project. All Rights Reserved. / Sponsored by [Rakuten, Inc.](http://global.rakuten.com/corp/) and [Rakuten Institute of Technology](http://rit.rakuten.co.jp/). |
Oops, something went wrong.