chaine 3.13.1__cp311-cp311-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chaine might be problematic. Click here for more details.
- chaine/__init__.py +2 -0
- chaine/_core/crf.cpp +19854 -0
- chaine/_core/crf.cpython-311-darwin.so +0 -0
- chaine/_core/crf.pyx +271 -0
- chaine/_core/crfsuite/COPYING +27 -0
- chaine/_core/crfsuite/README +183 -0
- chaine/_core/crfsuite/include/crfsuite.h +1077 -0
- chaine/_core/crfsuite/include/crfsuite.hpp +649 -0
- chaine/_core/crfsuite/include/crfsuite_api.hpp +406 -0
- chaine/_core/crfsuite/include/os.h +65 -0
- chaine/_core/crfsuite/lib/cqdb/COPYING +28 -0
- chaine/_core/crfsuite/lib/cqdb/include/cqdb.h +518 -0
- chaine/_core/crfsuite/lib/cqdb/src/cqdb.c +639 -0
- chaine/_core/crfsuite/lib/cqdb/src/lookup3.c +1271 -0
- chaine/_core/crfsuite/lib/cqdb/src/main.c +184 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d.h +354 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_context.c +788 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_encode.c +1020 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_feature.c +382 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_model.c +1085 -0
- chaine/_core/crfsuite/lib/crf/src/crf1d_tag.c +582 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite.c +500 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite_internal.h +233 -0
- chaine/_core/crfsuite/lib/crf/src/crfsuite_train.c +302 -0
- chaine/_core/crfsuite/lib/crf/src/dataset.c +115 -0
- chaine/_core/crfsuite/lib/crf/src/dictionary.c +127 -0
- chaine/_core/crfsuite/lib/crf/src/holdout.c +83 -0
- chaine/_core/crfsuite/lib/crf/src/json.c +1497 -0
- chaine/_core/crfsuite/lib/crf/src/json.h +120 -0
- chaine/_core/crfsuite/lib/crf/src/logging.c +85 -0
- chaine/_core/crfsuite/lib/crf/src/logging.h +49 -0
- chaine/_core/crfsuite/lib/crf/src/params.c +370 -0
- chaine/_core/crfsuite/lib/crf/src/params.h +84 -0
- chaine/_core/crfsuite/lib/crf/src/quark.c +180 -0
- chaine/_core/crfsuite/lib/crf/src/quark.h +46 -0
- chaine/_core/crfsuite/lib/crf/src/rumavl.c +1178 -0
- chaine/_core/crfsuite/lib/crf/src/rumavl.h +144 -0
- chaine/_core/crfsuite/lib/crf/src/train_arow.c +409 -0
- chaine/_core/crfsuite/lib/crf/src/train_averaged_perceptron.c +237 -0
- chaine/_core/crfsuite/lib/crf/src/train_l2sgd.c +491 -0
- chaine/_core/crfsuite/lib/crf/src/train_lbfgs.c +323 -0
- chaine/_core/crfsuite/lib/crf/src/train_passive_aggressive.c +442 -0
- chaine/_core/crfsuite/lib/crf/src/vecmath.h +360 -0
- chaine/_core/crfsuite/swig/crfsuite.cpp +1 -0
- chaine/_core/crfsuite_api.pxd +67 -0
- chaine/_core/liblbfgs/COPYING +22 -0
- chaine/_core/liblbfgs/README +71 -0
- chaine/_core/liblbfgs/include/lbfgs.h +745 -0
- chaine/_core/liblbfgs/lib/arithmetic_ansi.h +142 -0
- chaine/_core/liblbfgs/lib/arithmetic_sse_double.h +303 -0
- chaine/_core/liblbfgs/lib/arithmetic_sse_float.h +312 -0
- chaine/_core/liblbfgs/lib/lbfgs.c +1531 -0
- chaine/_core/tagger_wrapper.hpp +58 -0
- chaine/_core/trainer_wrapper.cpp +32 -0
- chaine/_core/trainer_wrapper.hpp +26 -0
- chaine/crf.py +505 -0
- chaine/logging.py +214 -0
- chaine/optimization/__init__.py +10 -0
- chaine/optimization/metrics.py +129 -0
- chaine/optimization/spaces.py +394 -0
- chaine/optimization/trial.py +103 -0
- chaine/optimization/utils.py +119 -0
- chaine/training.py +184 -0
- chaine/typing.py +18 -0
- chaine/validation.py +43 -0
- chaine-3.13.1.dist-info/METADATA +348 -0
- chaine-3.13.1.dist-info/RECORD +68 -0
- chaine-3.13.1.dist-info/WHEEL +5 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Implementation of dictionary.
|
|
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
|
+
#include <os.h>
|
|
34
|
+
|
|
35
|
+
#include <stdlib.h>
|
|
36
|
+
#include <string.h>
|
|
37
|
+
|
|
38
|
+
#include <crfsuite.h>
|
|
39
|
+
#include "quark.h"
|
|
40
|
+
|
|
41
|
+
static int dictionary_addref(crfsuite_dictionary_t *dic)
|
|
42
|
+
{
|
|
43
|
+
return crfsuite_interlocked_increment(&dic->nref);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static int dictionary_release(crfsuite_dictionary_t *dic)
|
|
47
|
+
{
|
|
48
|
+
int count = crfsuite_interlocked_decrement(&dic->nref);
|
|
49
|
+
if (count == 0)
|
|
50
|
+
{
|
|
51
|
+
quark_t *qrk = (quark_t *)dic->internal;
|
|
52
|
+
quark_delete(qrk);
|
|
53
|
+
free(dic);
|
|
54
|
+
}
|
|
55
|
+
return count;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static int dictionary_get(crfsuite_dictionary_t *dic, const char *str)
|
|
59
|
+
{
|
|
60
|
+
quark_t *qrk = (quark_t *)dic->internal;
|
|
61
|
+
return quark_get(qrk, str);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static int dictionary_to_id(crfsuite_dictionary_t *dic, const char *str)
|
|
65
|
+
{
|
|
66
|
+
quark_t *qrk = (quark_t *)dic->internal;
|
|
67
|
+
return quark_to_id(qrk, str);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static int dictionary_to_string(crfsuite_dictionary_t *dic, int id, char const **pstr)
|
|
71
|
+
{
|
|
72
|
+
quark_t *qrk = (quark_t *)dic->internal;
|
|
73
|
+
const char *str = quark_to_string(qrk, id);
|
|
74
|
+
if (str != NULL)
|
|
75
|
+
{
|
|
76
|
+
char *dst = (char *)malloc(strlen(str) + 1);
|
|
77
|
+
if (dst)
|
|
78
|
+
{
|
|
79
|
+
strcpy(dst, str);
|
|
80
|
+
*pstr = dst;
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static int dictionary_num(crfsuite_dictionary_t *dic)
|
|
88
|
+
{
|
|
89
|
+
quark_t *qrk = (quark_t *)dic->internal;
|
|
90
|
+
return quark_num(qrk);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static void dictionary_free(crfsuite_dictionary_t *dic, const char *str)
|
|
94
|
+
{
|
|
95
|
+
free((char *)str);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
int crfsuite_dictionary_create_instance(const char *interface, void **ptr)
|
|
99
|
+
{
|
|
100
|
+
if (strcmp(interface, "dictionary") == 0)
|
|
101
|
+
{
|
|
102
|
+
crfsuite_dictionary_t *dic = (crfsuite_dictionary_t *)calloc(1, sizeof(crfsuite_dictionary_t));
|
|
103
|
+
|
|
104
|
+
if (dic != NULL)
|
|
105
|
+
{
|
|
106
|
+
dic->internal = quark_new();
|
|
107
|
+
dic->nref = 1;
|
|
108
|
+
dic->addref = dictionary_addref;
|
|
109
|
+
dic->release = dictionary_release;
|
|
110
|
+
dic->get = dictionary_get;
|
|
111
|
+
dic->to_id = dictionary_to_id;
|
|
112
|
+
dic->to_string = dictionary_to_string;
|
|
113
|
+
dic->num = dictionary_num;
|
|
114
|
+
dic->free = dictionary_free;
|
|
115
|
+
*ptr = dic;
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
{
|
|
120
|
+
return -1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else
|
|
124
|
+
{
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Holdout evaluation.
|
|
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 <stdlib.h>
|
|
40
|
+
#include <crfsuite.h>
|
|
41
|
+
#include "crfsuite_internal.h"
|
|
42
|
+
#include "logging.h"
|
|
43
|
+
|
|
44
|
+
void holdout_evaluation(
|
|
45
|
+
encoder_t *gm,
|
|
46
|
+
dataset_t *ds,
|
|
47
|
+
const floatval_t *w,
|
|
48
|
+
logging_t *lg)
|
|
49
|
+
{
|
|
50
|
+
int i;
|
|
51
|
+
crfsuite_evaluation_t eval;
|
|
52
|
+
const int N = ds->num_instances;
|
|
53
|
+
int *viterbi = NULL;
|
|
54
|
+
int max_length = 0;
|
|
55
|
+
|
|
56
|
+
/* Initialize the evaluation table. */
|
|
57
|
+
crfsuite_evaluation_init(&eval, ds->data->labels->num(ds->data->labels));
|
|
58
|
+
|
|
59
|
+
gm->set_weights(gm, w, 1.);
|
|
60
|
+
|
|
61
|
+
for (i = 0; i < N; ++i)
|
|
62
|
+
{
|
|
63
|
+
floatval_t score;
|
|
64
|
+
const crfsuite_instance_t *inst = dataset_get(ds, i);
|
|
65
|
+
|
|
66
|
+
if (max_length < inst->num_items)
|
|
67
|
+
{
|
|
68
|
+
free(viterbi);
|
|
69
|
+
viterbi = (int *)malloc(sizeof(int) * inst->num_items);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
gm->set_instance(gm, inst);
|
|
73
|
+
gm->viterbi(gm, viterbi, &score);
|
|
74
|
+
|
|
75
|
+
crfsuite_evaluation_accmulate(&eval, inst->labels, viterbi, inst->num_items);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Report the performance. */
|
|
79
|
+
crfsuite_evaluation_finalize(&eval);
|
|
80
|
+
crfsuite_evaluation_output(&eval, ds->data->labels, lg->func, lg->instance);
|
|
81
|
+
if (viterbi)
|
|
82
|
+
free(viterbi);
|
|
83
|
+
}
|