opener-opinion-detector-base 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +101 -0
- data/bin/opinion-detector-base +19 -0
- data/core/annotation.cfg.erb +9 -0
- data/core/packages/KafNafParser-1.4.tar.gz +0 -0
- data/core/packages/VUA_pylib-1.5.tar.gz +0 -0
- data/core/python-scripts/LICENSE +339 -0
- data/core/python-scripts/README.md +226 -0
- data/core/python-scripts/classify_kaf_naf_file.py +499 -0
- data/core/python-scripts/cross_validation.py +634 -0
- data/core/python-scripts/generate_folds.py +134 -0
- data/core/python-scripts/models.cfg +10 -0
- data/core/python-scripts/my_templates/README +33 -0
- data/core/python-scripts/my_templates/templates_exp.only0.txt +6 -0
- data/core/python-scripts/my_templates/templates_exp.pol0.txt +10 -0
- data/core/python-scripts/my_templates/templates_exp.red.txt +7 -0
- data/core/python-scripts/my_templates/templates_exp.txt +10 -0
- data/core/python-scripts/my_templates/templates_holder.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_holder.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_holder.txt +10 -0
- data/core/python-scripts/my_templates/templates_target.only0.txt +11 -0
- data/core/python-scripts/my_templates/templates_target.red.txt +9 -0
- data/core/python-scripts/my_templates/templates_target.txt +10 -0
- data/core/python-scripts/run_all_experiments.sh +49 -0
- data/core/python-scripts/run_basic.py +20 -0
- data/core/python-scripts/run_experiment.sh +42 -0
- data/core/python-scripts/scripts/__init__.py +1 -0
- data/core/python-scripts/scripts/config_manager.py +314 -0
- data/core/python-scripts/scripts/crfutils.py +215 -0
- data/core/python-scripts/scripts/extract_feats_relations.py +295 -0
- data/core/python-scripts/scripts/extract_features.py +376 -0
- data/core/python-scripts/scripts/feats_to_crf.exp.py +105 -0
- data/core/python-scripts/scripts/lexicons.py +44 -0
- data/core/python-scripts/scripts/link_entities_distance.py +77 -0
- data/core/python-scripts/scripts/relation_classifier.py +250 -0
- data/core/python-scripts/train.py +566 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/SOURCES.txt +22 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/installed-files.txt +47 -0
- data/core/site-packages/pre_build/KafNafParser-1.4-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.py +390 -0
- data/core/site-packages/pre_build/KafNafParser/KafNafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.py +14 -0
- data/core/site-packages/pre_build/KafNafParser/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.py +125 -0
- data/core/site-packages/pre_build/KafNafParser/constituency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.py +52 -0
- data/core/site-packages/pre_build/KafNafParser/coreference_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.py +78 -0
- data/core/site-packages/pre_build/KafNafParser/dependency_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.py +59 -0
- data/core/site-packages/pre_build/KafNafParser/entity_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.py +41 -0
- data/core/site-packages/pre_build/KafNafParser/external_references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.py +2 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/__init__.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.py +205 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/constituency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.py +309 -0
- data/core/site-packages/pre_build/KafNafParser/feature_extractor/dependency.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.py +131 -0
- data/core/site-packages/pre_build/KafNafParser/features_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.py +127 -0
- data/core/site-packages/pre_build/KafNafParser/header_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.py +211 -0
- data/core/site-packages/pre_build/KafNafParser/opinion_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.py +23 -0
- data/core/site-packages/pre_build/KafNafParser/references_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.py +63 -0
- data/core/site-packages/pre_build/KafNafParser/span_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.py +111 -0
- data/core/site-packages/pre_build/KafNafParser/term_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.py +42 -0
- data/core/site-packages/pre_build/KafNafParser/term_sentiment_data.pyc +0 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.py +99 -0
- data/core/site-packages/pre_build/KafNafParser/text_data.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/SOURCES.txt +14 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/installed-files.txt +23 -0
- data/core/site-packages/pre_build/VUA_pylib-1.5-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/common/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.py +28 -0
- data/core/site-packages/pre_build/VUA_pylib/common/common.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.py +156 -0
- data/core/site-packages/pre_build/VUA_pylib/corpus_reader/google_web_nl.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.py +121 -0
- data/core/site-packages/pre_build/VUA_pylib/io_utils/feature_file.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.py +1 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/__init__.pyc +0 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.py +72 -0
- data/core/site-packages/pre_build/VUA_pylib/lexicon/lexicon.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/PKG-INFO +10 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/SOURCES.txt +7 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/dependency_links.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/installed-files.txt +11 -0
- data/core/site-packages/pre_build/VUKafParserPy-1.0-py2.7.egg-info/top_level.txt +1 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.py +165 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafDataObjectsMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.py +439 -0
- data/core/site-packages/pre_build/VUKafParserPy/KafParserMod.pyc +0 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.py +7 -0
- data/core/site-packages/pre_build/VUKafParserPy/__init__.pyc +0 -0
- data/core/vendor/src/crfsuite/AUTHORS +1 -0
- data/core/vendor/src/crfsuite/COPYING +27 -0
- data/core/vendor/src/crfsuite/ChangeLog +103 -0
- data/core/vendor/src/crfsuite/INSTALL +236 -0
- data/core/vendor/src/crfsuite/Makefile.am +19 -0
- data/core/vendor/src/crfsuite/Makefile.in +783 -0
- data/core/vendor/src/crfsuite/README +183 -0
- data/core/vendor/src/crfsuite/aclocal.m4 +9018 -0
- data/core/vendor/src/crfsuite/autogen.sh +38 -0
- data/core/vendor/src/crfsuite/compile +143 -0
- data/core/vendor/src/crfsuite/config.guess +1502 -0
- data/core/vendor/src/crfsuite/config.h.in +198 -0
- data/core/vendor/src/crfsuite/config.sub +1714 -0
- data/core/vendor/src/crfsuite/configure +14273 -0
- data/core/vendor/src/crfsuite/configure.in +149 -0
- data/core/vendor/src/crfsuite/crfsuite.sln +42 -0
- data/core/vendor/src/crfsuite/depcomp +630 -0
- data/core/vendor/src/crfsuite/example/chunking.py +49 -0
- data/core/vendor/src/crfsuite/example/crfutils.py +179 -0
- data/core/vendor/src/crfsuite/example/ner.py +270 -0
- data/core/vendor/src/crfsuite/example/pos.py +78 -0
- data/core/vendor/src/crfsuite/example/template.py +88 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.am +29 -0
- data/core/vendor/src/crfsuite/frontend/Makefile.in +640 -0
- data/core/vendor/src/crfsuite/frontend/dump.c +116 -0
- data/core/vendor/src/crfsuite/frontend/frontend.vcxproj +129 -0
- data/core/vendor/src/crfsuite/frontend/iwa.c +273 -0
- data/core/vendor/src/crfsuite/frontend/iwa.h +65 -0
- data/core/vendor/src/crfsuite/frontend/learn.c +439 -0
- data/core/vendor/src/crfsuite/frontend/main.c +137 -0
- data/core/vendor/src/crfsuite/frontend/option.c +93 -0
- data/core/vendor/src/crfsuite/frontend/option.h +86 -0
- data/core/vendor/src/crfsuite/frontend/readdata.h +38 -0
- data/core/vendor/src/crfsuite/frontend/reader.c +136 -0
- data/core/vendor/src/crfsuite/frontend/tag.c +427 -0
- data/core/vendor/src/crfsuite/genbinary.sh.in +15 -0
- data/core/vendor/src/crfsuite/include/Makefile.am +11 -0
- data/core/vendor/src/crfsuite/include/Makefile.in +461 -0
- data/core/vendor/src/crfsuite/include/crfsuite.h +1063 -0
- data/core/vendor/src/crfsuite/include/crfsuite.hpp +555 -0
- data/core/vendor/src/crfsuite/include/crfsuite_api.hpp +400 -0
- data/core/vendor/src/crfsuite/include/os.h +61 -0
- data/core/vendor/src/crfsuite/install-sh +520 -0
- data/core/vendor/src/crfsuite/lib/cqdb/COPYING +28 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.am +21 -0
- data/core/vendor/src/crfsuite/lib/cqdb/Makefile.in +549 -0
- data/core/vendor/src/crfsuite/lib/cqdb/cqdb.vcxproj +86 -0
- data/core/vendor/src/crfsuite/lib/cqdb/include/cqdb.h +524 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/cqdb.c +587 -0
- data/core/vendor/src/crfsuite/lib/cqdb/src/lookup3.c +976 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.am +46 -0
- data/core/vendor/src/crfsuite/lib/crf/Makefile.in +721 -0
- data/core/vendor/src/crfsuite/lib/crf/crf.vcxproj +216 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d.h +353 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_context.c +705 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_encode.c +943 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_feature.c +352 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_model.c +994 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crf1d_tag.c +550 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite.c +492 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_internal.h +236 -0
- data/core/vendor/src/crfsuite/lib/crf/src/crfsuite_train.c +272 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dataset.c +106 -0
- data/core/vendor/src/crfsuite/lib/crf/src/dictionary.c +118 -0
- data/core/vendor/src/crfsuite/lib/crf/src/holdout.c +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.c +91 -0
- data/core/vendor/src/crfsuite/lib/crf/src/logging.h +48 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.c +335 -0
- data/core/vendor/src/crfsuite/lib/crf/src/params.h +80 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.c +172 -0
- data/core/vendor/src/crfsuite/lib/crf/src/quark.h +46 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.c +1107 -0
- data/core/vendor/src/crfsuite/lib/crf/src/rumavl.h +160 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_arow.c +408 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_averaged_perceptron.c +242 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_l2sgd.c +507 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_lbfgs.c +338 -0
- data/core/vendor/src/crfsuite/lib/crf/src/train_passive_aggressive.c +435 -0
- data/core/vendor/src/crfsuite/lib/crf/src/vecmath.h +341 -0
- data/core/vendor/src/crfsuite/ltmain.sh +8413 -0
- data/core/vendor/src/crfsuite/missing +376 -0
- data/core/vendor/src/crfsuite/swig/Makefile.am +13 -0
- data/core/vendor/src/crfsuite/swig/Makefile.in +365 -0
- data/core/vendor/src/crfsuite/swig/crfsuite.cpp +2 -0
- data/core/vendor/src/crfsuite/swig/export.i +32 -0
- data/core/vendor/src/crfsuite/swig/python/README +92 -0
- data/core/vendor/src/crfsuite/swig/python/crfsuite.py +329 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.cpp +14355 -0
- data/core/vendor/src/crfsuite/swig/python/export_wrap.h +63 -0
- data/core/vendor/src/crfsuite/swig/python/prepare.sh +9 -0
- data/core/vendor/src/crfsuite/swig/python/sample_tag.py +52 -0
- data/core/vendor/src/crfsuite/swig/python/sample_train.py +68 -0
- data/core/vendor/src/crfsuite/swig/python/setup.py +44 -0
- data/core/vendor/src/crfsuite/win32/stdint.h +679 -0
- data/core/vendor/src/liblbfgs/AUTHORS +1 -0
- data/core/vendor/src/liblbfgs/COPYING +22 -0
- data/core/vendor/src/liblbfgs/ChangeLog +120 -0
- data/core/vendor/src/liblbfgs/INSTALL +231 -0
- data/core/vendor/src/liblbfgs/Makefile.am +10 -0
- data/core/vendor/src/liblbfgs/Makefile.in +638 -0
- data/core/vendor/src/liblbfgs/NEWS +0 -0
- data/core/vendor/src/liblbfgs/README +71 -0
- data/core/vendor/src/liblbfgs/aclocal.m4 +6985 -0
- data/core/vendor/src/liblbfgs/autogen.sh +38 -0
- data/core/vendor/src/liblbfgs/config.guess +1411 -0
- data/core/vendor/src/liblbfgs/config.h.in +64 -0
- data/core/vendor/src/liblbfgs/config.sub +1500 -0
- data/core/vendor/src/liblbfgs/configure +21146 -0
- data/core/vendor/src/liblbfgs/configure.in +107 -0
- data/core/vendor/src/liblbfgs/depcomp +522 -0
- data/core/vendor/src/liblbfgs/include/lbfgs.h +745 -0
- data/core/vendor/src/liblbfgs/install-sh +322 -0
- data/core/vendor/src/liblbfgs/lbfgs.sln +26 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.am +24 -0
- data/core/vendor/src/liblbfgs/lib/Makefile.in +499 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_ansi.h +133 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_double.h +294 -0
- data/core/vendor/src/liblbfgs/lib/arithmetic_sse_float.h +298 -0
- data/core/vendor/src/liblbfgs/lib/lbfgs.c +1371 -0
- data/core/vendor/src/liblbfgs/lib/lib.vcxproj +95 -0
- data/core/vendor/src/liblbfgs/ltmain.sh +6426 -0
- data/core/vendor/src/liblbfgs/missing +353 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.am +15 -0
- data/core/vendor/src/liblbfgs/sample/Makefile.in +433 -0
- data/core/vendor/src/liblbfgs/sample/sample.c +81 -0
- data/core/vendor/src/liblbfgs/sample/sample.cpp +126 -0
- data/core/vendor/src/liblbfgs/sample/sample.vcxproj +105 -0
- data/core/vendor/src/svm_light/LICENSE.txt +59 -0
- data/core/vendor/src/svm_light/Makefile +105 -0
- data/core/vendor/src/svm_light/kernel.h +40 -0
- data/core/vendor/src/svm_light/svm_classify.c +197 -0
- data/core/vendor/src/svm_light/svm_common.c +985 -0
- data/core/vendor/src/svm_light/svm_common.h +301 -0
- data/core/vendor/src/svm_light/svm_hideo.c +1062 -0
- data/core/vendor/src/svm_light/svm_learn.c +4147 -0
- data/core/vendor/src/svm_light/svm_learn.h +169 -0
- data/core/vendor/src/svm_light/svm_learn_main.c +397 -0
- data/core/vendor/src/svm_light/svm_loqo.c +211 -0
- data/ext/hack/Rakefile +17 -0
- data/ext/hack/support.rb +88 -0
- data/lib/opener/opinion_detectors/base.rb +112 -0
- data/lib/opener/opinion_detectors/base/version.rb +7 -0
- data/lib/opener/opinion_detectors/configuration_creator.rb +86 -0
- data/lib/opener/opinion_detectors/de.rb +7 -0
- data/lib/opener/opinion_detectors/en.rb +7 -0
- data/lib/opener/opinion_detectors/it.rb +7 -0
- data/lib/opener/opinion_detectors/nl.rb +6 -0
- data/opener-opinion-detector-base.gemspec +35 -0
- data/pre_build_requirements.txt +3 -0
- metadata +374 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
/*
|
2
|
+
* RumAVL - Threaded AVL Tree Implementation
|
3
|
+
*
|
4
|
+
* Copyright (c) 2005-2007 Jesse Long <jpl@unknown.za.net>
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
8
|
+
* copy of this software and associated documentation files (the "Software"),
|
9
|
+
* to deal in the Software without restriction, including without limitation
|
10
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
11
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
12
|
+
* Software is furnished to do so, subject to the following conditions:
|
13
|
+
*
|
14
|
+
* 1. The above copyright notice and this permission notice shall be
|
15
|
+
* included in all copies or substantial portions of the Software.
|
16
|
+
* 2. The origin of the Software must not be misrepresented; you must not
|
17
|
+
* claim that you wrote the original Software.
|
18
|
+
* 3. Altered source versions of the Software must be plainly marked as
|
19
|
+
* such, and must not be misrepresented as being the original Software.
|
20
|
+
*
|
21
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
27
|
+
* DEALINGS IN THE SOFTWARE.
|
28
|
+
*/
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Please see the `README' file, the documentation in the `doc' directory and
|
32
|
+
* the `rumavl.c' source file for more information.
|
33
|
+
*/
|
34
|
+
|
35
|
+
#ifndef RUMAVL_H
|
36
|
+
#define RUMAVL_H 1
|
37
|
+
|
38
|
+
#ifdef __cplusplus
|
39
|
+
extern "C" {
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#include <stddef.h> /* size_t */
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
/*----------------------------------------------------------------------------
|
48
|
+
* DATA TYPES
|
49
|
+
*--------------------------------------------------------------------------*/
|
50
|
+
|
51
|
+
/* Opaque context handle for the tree */
|
52
|
+
typedef struct rumavl RUMAVL;
|
53
|
+
|
54
|
+
/* Node type - used for iterating */
|
55
|
+
typedef struct rumavl_node RUMAVL_NODE;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
/*----------------------------------------------------------------------------
|
61
|
+
* FUNDEMENTAL FUNCTIONS
|
62
|
+
*--------------------------------------------------------------------------*/
|
63
|
+
|
64
|
+
/* Create a new RumAVL tree */
|
65
|
+
RUMAVL *rumavl_new (size_t reclen,
|
66
|
+
int (*cmp)(const void *, const void *, size_t, void *),
|
67
|
+
void *(*alloc)(void *, size_t, void *),
|
68
|
+
void *udata);
|
69
|
+
|
70
|
+
/* Destroy a RumAVL tree */
|
71
|
+
void rumavl_destroy (RUMAVL *tree);
|
72
|
+
|
73
|
+
/* This function returns the size of each record in a tree */
|
74
|
+
size_t rumavl_record_size (RUMAVL *tree);
|
75
|
+
|
76
|
+
/* Get a pointer to the udata pointer */
|
77
|
+
void **rumavl_udata (RUMAVL *tree);
|
78
|
+
|
79
|
+
/* Insert a record into a tree, overwriting an existing record necessary */
|
80
|
+
int rumavl_set (RUMAVL *tree, const void *record);
|
81
|
+
/* Insert a record into a tree, never overwrites an existing record */
|
82
|
+
int rumavl_insert (RUMAVL *tree, const void *record);
|
83
|
+
|
84
|
+
/* Retrieve record from tree, or NULL */
|
85
|
+
void *rumavl_find (RUMAVL *tree, const void *find);
|
86
|
+
|
87
|
+
/* Remove record from tree */
|
88
|
+
int rumavl_delete (RUMAVL *tree, const void *record);
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
/*----------------------------------------------------------------------------
|
94
|
+
* ITERATOR FUNCTIONS
|
95
|
+
*--------------------------------------------------------------------------*/
|
96
|
+
|
97
|
+
/* Get a pointer to the node containing a specific record */
|
98
|
+
RUMAVL_NODE *rumavl_node_find (RUMAVL *tree, const void *find, void **record);
|
99
|
+
|
100
|
+
/* Get the next node in sequence after a specific node, in a specific
|
101
|
+
* direction, or get the first node on either end of a tree */
|
102
|
+
RUMAVL_NODE *rumavl_node_next (RUMAVL *tree, RUMAVL_NODE *node, int dir,
|
103
|
+
void **record);
|
104
|
+
/* Possible directions */
|
105
|
+
#define RUMAVL_DESC (-1)
|
106
|
+
#define RUMAVL_ASC (+1)
|
107
|
+
|
108
|
+
/* Get a record held by a specific node */
|
109
|
+
void *rumavl_node_record (RUMAVL_NODE *node);
|
110
|
+
|
111
|
+
/* Pass each record in a tree to a user defined callback function */
|
112
|
+
extern int rumavl_foreach (RUMAVL *tree, int dir,
|
113
|
+
int (*cbfn)(RUMAVL *, void *, void *), void *udata);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
/*----------------------------------------------------------------------------
|
119
|
+
* CALLBACK FUNCTIONS
|
120
|
+
*
|
121
|
+
* Functions giving you more control over the actions of this library.
|
122
|
+
*--------------------------------------------------------------------------*/
|
123
|
+
|
124
|
+
int (**rumavl_owcb(RUMAVL *tree))(RUMAVL *, RUMAVL_NODE *, void *,
|
125
|
+
const void *, void *);
|
126
|
+
int (**rumavl_delcb(RUMAVL *tree))(RUMAVL *, RUMAVL_NODE *, void *, void *);
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
/*----------------------------------------------------------------------------
|
132
|
+
* MEMORY MANAGEMENT
|
133
|
+
*
|
134
|
+
* The rumavl_mem struct is used to define how a RUMAVL object allocates
|
135
|
+
* and frees memory.
|
136
|
+
*--------------------------------------------------------------------------*/
|
137
|
+
void *(**rumavl_alloc(RUMAVL *tree))(void *ptr, size_t size, void *udata);
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
/*----------------------------------------------------------------------------
|
142
|
+
* ERROR CODES
|
143
|
+
*
|
144
|
+
* The functions returning int's will return these errors
|
145
|
+
*--------------------------------------------------------------------------*/
|
146
|
+
|
147
|
+
#define RUMAVL_ERR_INVAL (-1) /* Invalid argument */
|
148
|
+
#define RUMAVL_ERR_NOMEM (-2) /* Insufficient memory */
|
149
|
+
#define RUMAVL_ERR_NOENT (-3) /* Entry does not exist */
|
150
|
+
#define RUMAVL_ERR_EORNG (-5) /* No nodes left in range */
|
151
|
+
#define RUMAVL_ERR_EXIST (-6) /* Entry already exists */
|
152
|
+
|
153
|
+
/* returns static string describing error number */
|
154
|
+
extern const char *rumavl_strerror (int errno);
|
155
|
+
|
156
|
+
#ifdef __cplusplus
|
157
|
+
}
|
158
|
+
#endif
|
159
|
+
|
160
|
+
#endif /* ifndef RUMAVL_H */
|
@@ -0,0 +1,408 @@
|
|
1
|
+
/*
|
2
|
+
* Online training with Adaptive Regularization of Weights (AROW).
|
3
|
+
*
|
4
|
+
* Copyright (c) 2007-2010, Naoaki Okazaki
|
5
|
+
* All rights reserved.
|
6
|
+
*
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
9
|
+
* * Redistributions of source code must retain the above copyright
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
11
|
+
* * Redistributions in binary form must reproduce the above copyright
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
14
|
+
* * Neither the names of the authors nor the names of its contributors
|
15
|
+
* may be used to endorse or promote products derived from this
|
16
|
+
* software without specific prior written permission.
|
17
|
+
*
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
22
|
+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
23
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
24
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
25
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
26
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
27
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
+
*/
|
30
|
+
|
31
|
+
/* $Id$ */
|
32
|
+
|
33
|
+
#ifdef HAVE_CONFIG_H
|
34
|
+
#include <config.h>
|
35
|
+
#endif/*HAVE_CONFIG_H*/
|
36
|
+
|
37
|
+
#include <os.h>
|
38
|
+
|
39
|
+
#include <stdio.h>
|
40
|
+
#include <stdlib.h>
|
41
|
+
#include <time.h>
|
42
|
+
|
43
|
+
#include <crfsuite.h>
|
44
|
+
#include "crfsuite_internal.h"
|
45
|
+
#include "logging.h"
|
46
|
+
#include "params.h"
|
47
|
+
#include "vecmath.h"
|
48
|
+
|
49
|
+
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Training parameters (configurable with crfsuite_params_t interface).
|
53
|
+
*/
|
54
|
+
typedef struct {
|
55
|
+
floatval_t variance;
|
56
|
+
floatval_t gamma;
|
57
|
+
int max_iterations;
|
58
|
+
floatval_t epsilon;
|
59
|
+
} training_option_t;
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Internal data structure for computing the sparse vector F(x, y) - F(x, y').
|
63
|
+
*/
|
64
|
+
typedef struct {
|
65
|
+
/* An array of feature indices relevant to the instance. */
|
66
|
+
int *actives;
|
67
|
+
int num_actives;
|
68
|
+
int cap_actives;
|
69
|
+
char *used;
|
70
|
+
|
71
|
+
/* Coefficient for collecting feature weights. */
|
72
|
+
floatval_t c;
|
73
|
+
/* The difference vector [K]. */
|
74
|
+
floatval_t *delta;
|
75
|
+
/* The number of features. */
|
76
|
+
int K;
|
77
|
+
} delta_t;
|
78
|
+
|
79
|
+
static int delta_init(delta_t *dc, const int K)
|
80
|
+
{
|
81
|
+
memset(dc, 0, sizeof(*dc));
|
82
|
+
dc->used = (char*)calloc(K, sizeof(char));
|
83
|
+
dc->delta = (floatval_t*)calloc(K, sizeof(floatval_t));
|
84
|
+
dc->K = K;
|
85
|
+
if (dc->delta == NULL || dc->used == NULL) {
|
86
|
+
return 1;
|
87
|
+
}
|
88
|
+
return 0;
|
89
|
+
}
|
90
|
+
|
91
|
+
static void delta_finish(delta_t *dc)
|
92
|
+
{
|
93
|
+
free(dc->actives);
|
94
|
+
free(dc->used);
|
95
|
+
free(dc->delta);
|
96
|
+
memset(dc, 0, sizeof(*dc));
|
97
|
+
}
|
98
|
+
|
99
|
+
static void delta_reset(delta_t *dc)
|
100
|
+
{
|
101
|
+
int i;
|
102
|
+
for (i = 0;i < dc->num_actives;++i) {
|
103
|
+
int k = dc->actives[i];
|
104
|
+
dc->delta[k] = 0;
|
105
|
+
}
|
106
|
+
dc->num_actives = 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
static void delta_collect(void *instance, int fid, floatval_t value)
|
110
|
+
{
|
111
|
+
delta_t *dc = (delta_t*)instance;
|
112
|
+
|
113
|
+
/* Expand the active feature list if necessary. */
|
114
|
+
if (dc->cap_actives <= dc->num_actives) {
|
115
|
+
++dc->cap_actives;
|
116
|
+
dc->cap_actives *= 2;
|
117
|
+
dc->actives = (int*)realloc(dc->actives, sizeof(int) * dc->cap_actives);
|
118
|
+
}
|
119
|
+
|
120
|
+
dc->actives[dc->num_actives++] = fid;
|
121
|
+
dc->delta[fid] += dc->c * value;
|
122
|
+
}
|
123
|
+
|
124
|
+
static void delta_finalize(delta_t *dc)
|
125
|
+
{
|
126
|
+
int i, j = 0, k;
|
127
|
+
|
128
|
+
/* Collapse the duplicated indices. */
|
129
|
+
for (i = 0;i < dc->num_actives;++i) {
|
130
|
+
k = dc->actives[i];
|
131
|
+
if (!dc->used[k]) {
|
132
|
+
dc->actives[j++] = k;
|
133
|
+
dc->used[k] = 1;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
dc->num_actives = j; /* This is the distinct number of indices. */
|
137
|
+
|
138
|
+
/* Reset the used flag. */
|
139
|
+
for (i = 0;i < dc->num_actives;++i) {
|
140
|
+
k = dc->actives[i];
|
141
|
+
dc->used[k] = 0;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
static floatval_t delta_norm2(delta_t *dc)
|
146
|
+
{
|
147
|
+
int i;
|
148
|
+
floatval_t norm2 = 0.;
|
149
|
+
|
150
|
+
for (i = 0;i < dc->num_actives;++i) {
|
151
|
+
int k = dc->actives[i];
|
152
|
+
norm2 += dc->delta[k] * dc->delta[k];
|
153
|
+
}
|
154
|
+
return norm2;
|
155
|
+
}
|
156
|
+
|
157
|
+
static void delta_add(delta_t *dc, floatval_t *w, floatval_t *ws, const floatval_t tau, const floatval_t u)
|
158
|
+
{
|
159
|
+
int i;
|
160
|
+
const floatval_t tauu = tau * u;
|
161
|
+
|
162
|
+
for (i = 0;i < dc->num_actives;++i) {
|
163
|
+
int k = dc->actives[i];
|
164
|
+
w[k] += tau * dc->delta[k];
|
165
|
+
ws[k] += tauu * dc->delta[k];
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
static int diff(int *x, int *y, int n)
|
170
|
+
{
|
171
|
+
int i, d = 0;
|
172
|
+
for (i = 0;i < n;++i) {
|
173
|
+
if (x[i] != y[i]) {
|
174
|
+
++d;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
return d;
|
178
|
+
}
|
179
|
+
|
180
|
+
static floatval_t cost_insensitive(floatval_t err, floatval_t d)
|
181
|
+
{
|
182
|
+
return err + 1.;
|
183
|
+
}
|
184
|
+
|
185
|
+
static floatval_t cost_sensitive(floatval_t err, floatval_t d)
|
186
|
+
{
|
187
|
+
return err + sqrt(d);
|
188
|
+
}
|
189
|
+
|
190
|
+
static floatval_t tau0(floatval_t cost, floatval_t norm, floatval_t c)
|
191
|
+
{
|
192
|
+
return cost / norm;
|
193
|
+
}
|
194
|
+
|
195
|
+
static floatval_t tau1(floatval_t cost, floatval_t norm, floatval_t c)
|
196
|
+
{
|
197
|
+
return MIN(c, cost / norm);
|
198
|
+
}
|
199
|
+
|
200
|
+
static floatval_t tau2(floatval_t cost, floatval_t norm, floatval_t c)
|
201
|
+
{
|
202
|
+
return cost / (norm + 0.5 / c);
|
203
|
+
}
|
204
|
+
|
205
|
+
static int exchange_options(crfsuite_params_t* params, training_option_t* opt, int mode)
|
206
|
+
{
|
207
|
+
BEGIN_PARAM_MAP(params, mode)
|
208
|
+
DDX_PARAM_FLOAT(
|
209
|
+
"variance", opt->variance, 1.,
|
210
|
+
"The initial variance of every feature weight."
|
211
|
+
)
|
212
|
+
DDX_PARAM_FLOAT(
|
213
|
+
"gamma", opt->gamma, 1.,
|
214
|
+
"Tradeoff parameter."
|
215
|
+
)
|
216
|
+
DDX_PARAM_INT(
|
217
|
+
"max_iterations", opt->max_iterations, 100,
|
218
|
+
"The maximum number of iterations."
|
219
|
+
)
|
220
|
+
DDX_PARAM_FLOAT(
|
221
|
+
"epsilon", opt->epsilon, 0.,
|
222
|
+
"The stopping criterion (the mean loss)."
|
223
|
+
)
|
224
|
+
END_PARAM_MAP()
|
225
|
+
|
226
|
+
return 0;
|
227
|
+
}
|
228
|
+
|
229
|
+
void crfsuite_train_arow_init(crfsuite_params_t* params)
|
230
|
+
{
|
231
|
+
exchange_options(params, NULL, 0);
|
232
|
+
}
|
233
|
+
|
234
|
+
int crfsuite_train_arow(
|
235
|
+
encoder_t *gm,
|
236
|
+
dataset_t *trainset,
|
237
|
+
dataset_t *testset,
|
238
|
+
crfsuite_params_t *params,
|
239
|
+
logging_t *lg,
|
240
|
+
floatval_t **ptr_w
|
241
|
+
)
|
242
|
+
{
|
243
|
+
int n, i, j, k, ret = 0;
|
244
|
+
int *viterbi = NULL;
|
245
|
+
floatval_t beta;
|
246
|
+
floatval_t *mean = NULL, *cov = NULL, *prod = NULL;
|
247
|
+
const int N = trainset->num_instances;
|
248
|
+
const int K = gm->num_features;
|
249
|
+
const int T = gm->cap_items;
|
250
|
+
training_option_t opt;
|
251
|
+
delta_t dc;
|
252
|
+
clock_t begin = clock();
|
253
|
+
|
254
|
+
/* Initialize the variable. */
|
255
|
+
if (delta_init(&dc, K) != 0) {
|
256
|
+
ret = CRFSUITEERR_OUTOFMEMORY;
|
257
|
+
goto error_exit;
|
258
|
+
}
|
259
|
+
|
260
|
+
/* Obtain parameter values. */
|
261
|
+
exchange_options(params, &opt, -1);
|
262
|
+
|
263
|
+
/* Allocate arrays. */
|
264
|
+
mean = (floatval_t*)calloc(sizeof(floatval_t), K);
|
265
|
+
cov = (floatval_t*)calloc(sizeof(floatval_t), K);
|
266
|
+
prod = (floatval_t*)calloc(sizeof(floatval_t), K);
|
267
|
+
viterbi = (int*)calloc(sizeof(int), T);
|
268
|
+
if (mean == NULL || cov == NULL || prod == NULL || viterbi == NULL) {
|
269
|
+
ret = CRFSUITEERR_OUTOFMEMORY;
|
270
|
+
goto error_exit;
|
271
|
+
}
|
272
|
+
|
273
|
+
/* Initialize the covariance vector (diagnal matrix). */
|
274
|
+
vecset(cov, opt.variance, K);
|
275
|
+
|
276
|
+
/* Show the parameters. */
|
277
|
+
logging(lg, "Adaptive Regularization of Weights (AROW)\n");
|
278
|
+
logging(lg, "variance: %f\n", opt.variance);
|
279
|
+
logging(lg, "gamma: %f\n", opt.gamma);
|
280
|
+
logging(lg, "max_iterations: %d\n", opt.max_iterations);
|
281
|
+
logging(lg, "epsilon: %f\n", opt.epsilon);
|
282
|
+
logging(lg, "\n");
|
283
|
+
|
284
|
+
beta = 1.0 / opt.gamma;
|
285
|
+
|
286
|
+
/* Loop for epoch. */
|
287
|
+
for (i = 0;i < opt.max_iterations;++i) {
|
288
|
+
floatval_t norm = 0., sum_loss = 0.;
|
289
|
+
clock_t iteration_begin = clock();
|
290
|
+
|
291
|
+
/* Shuffle the instances. */
|
292
|
+
dataset_shuffle(trainset);
|
293
|
+
|
294
|
+
/* Loop for each instance. */
|
295
|
+
for (n = 0;n < N;++n) {
|
296
|
+
int d = 0;
|
297
|
+
floatval_t sv;
|
298
|
+
const crfsuite_instance_t *inst = dataset_get(trainset, n);
|
299
|
+
|
300
|
+
/* Set the feature weights to the encoder. */
|
301
|
+
gm->set_weights(gm, mean, 1.);
|
302
|
+
gm->set_instance(gm, inst);
|
303
|
+
|
304
|
+
/* Tag the sequence with the current model. */
|
305
|
+
gm->viterbi(gm, viterbi, &sv);
|
306
|
+
|
307
|
+
/* Compute the number of different labels. */
|
308
|
+
d = diff(inst->labels, viterbi, inst->num_items);
|
309
|
+
if (0 < d) {
|
310
|
+
floatval_t alpha, frac;
|
311
|
+
floatval_t sc, norm2;
|
312
|
+
floatval_t tau, cost;
|
313
|
+
|
314
|
+
/*
|
315
|
+
Compute the cost of this instance.
|
316
|
+
*/
|
317
|
+
gm->score(gm, inst->labels, &sc);
|
318
|
+
cost = sv - sc + (double)d;
|
319
|
+
|
320
|
+
/* Initialize delta[k] = 0. */
|
321
|
+
delta_reset(&dc);
|
322
|
+
|
323
|
+
/*
|
324
|
+
For every feature k on the correct path:
|
325
|
+
delta[k] += 1;
|
326
|
+
*/
|
327
|
+
dc.c = 1;
|
328
|
+
gm->features_on_path(gm, inst, inst->labels, delta_collect, &dc);
|
329
|
+
|
330
|
+
/*
|
331
|
+
For every feature k on the Viterbi path:
|
332
|
+
delta[k] -= 1;
|
333
|
+
*/
|
334
|
+
dc.c = -1;
|
335
|
+
gm->features_on_path(gm, inst, viterbi, delta_collect, &dc);
|
336
|
+
|
337
|
+
delta_finalize(&dc);
|
338
|
+
|
339
|
+
/* Compute prod[k] = delta[k] * delta[k]. */
|
340
|
+
for (j = 0;j < dc.num_actives;++j) {
|
341
|
+
k = dc.actives[j];
|
342
|
+
prod[k] = dc.delta[k] * dc.delta[k];
|
343
|
+
}
|
344
|
+
|
345
|
+
/*
|
346
|
+
Compute alpha.
|
347
|
+
*/
|
348
|
+
frac = opt.gamma;
|
349
|
+
for (j = 0;j < dc.num_actives;++j) {
|
350
|
+
k = dc.actives[j];
|
351
|
+
frac += prod[k] * cov[k];
|
352
|
+
}
|
353
|
+
alpha = cost / frac;
|
354
|
+
|
355
|
+
/*
|
356
|
+
Update.
|
357
|
+
*/
|
358
|
+
for (j = 0;j < dc.num_actives;++j) {
|
359
|
+
k = dc.actives[j];
|
360
|
+
mean[k] += alpha * cov[k] * dc.delta[k];
|
361
|
+
cov[k] = 1.0 / ((1.0 / cov[k]) + prod[k] / opt.gamma);
|
362
|
+
}
|
363
|
+
|
364
|
+
sum_loss += cost;
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
/* Output the progress. */
|
369
|
+
logging(lg, "***** Iteration #%d *****\n", i+1);
|
370
|
+
logging(lg, "Loss: %f\n", sum_loss);
|
371
|
+
logging(lg, "Feature norm: %f\n", sqrt(vecdot(mean, mean, K)));
|
372
|
+
logging(lg, "Seconds required for this iteration: %.3f\n", (clock() - iteration_begin) / (double)CLOCKS_PER_SEC);
|
373
|
+
|
374
|
+
/* Holdout evaluation if necessary. */
|
375
|
+
if (testset != NULL) {
|
376
|
+
holdout_evaluation(gm, testset, mean, lg);
|
377
|
+
}
|
378
|
+
|
379
|
+
logging(lg, "\n");
|
380
|
+
|
381
|
+
/* Convergence test. */
|
382
|
+
if (sum_loss / N <= opt.epsilon) {
|
383
|
+
logging(lg, "Terminated with the stopping criterion\n");
|
384
|
+
logging(lg, "\n");
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
|
389
|
+
logging(lg, "Total seconds required for training: %.3f\n", (clock() - begin) / (double)CLOCKS_PER_SEC);
|
390
|
+
logging(lg, "\n");
|
391
|
+
|
392
|
+
free(viterbi);
|
393
|
+
free(prod);
|
394
|
+
free(cov);
|
395
|
+
*ptr_w = mean;
|
396
|
+
delta_finish(&dc);
|
397
|
+
return ret;
|
398
|
+
|
399
|
+
error_exit:
|
400
|
+
free(viterbi);
|
401
|
+
free(prod);
|
402
|
+
free(cov);
|
403
|
+
free(mean);
|
404
|
+
*ptr_w = NULL;
|
405
|
+
delta_finish(&dc);
|
406
|
+
|
407
|
+
return ret;
|
408
|
+
}
|