Skip to content

Commit 472ff68

Browse files
authored
Merge branch 'main' into update-pie-rose-charts
2 parents f98c888 + 27d1834 commit 472ff68

File tree

7 files changed

+86
-56
lines changed

7 files changed

+86
-56
lines changed

LICENSE

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-
23-
---
24-
25-
Some of TrueLearn's functionality is derived from externally maintained libraries,
26-
including:
27-
28-
- scikit-learn, licensed as follows:
29-
"""
30-
BSD 3-Clause License
31-
32-
Copyright (c) 2007-2022 The scikit-learn developers.
33-
All rights reserved.
34-
35-
Redistribution and use in source and binary forms, with or without
36-
modification, are permitted provided that the following conditions are met:
37-
38-
* Redistributions of source code must retain the above copyright notice, this
39-
list of conditions and the following disclaimer.
40-
41-
* Redistributions in binary form must reproduce the above copyright notice,
42-
this list of conditions and the following disclaimer in the documentation
43-
and/or other materials provided with the distribution.
44-
45-
* Neither the name of the copyright holder nor the names of its
46-
contributors may be used to endorse or promote products derived from
47-
this software without specific prior written permission.
48-
49-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
50-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
53-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
55-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
57-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59-
"""

LICENSE-3RD-PARTY

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Some of TrueLearn's functionality is derived from externally maintained libraries,
2+
including:
3+
4+
- scikit-learn, licensed as follows:
5+
"""
6+
BSD 3-Clause License
7+
8+
Copyright (c) 2007-2022 The scikit-learn developers.
9+
All rights reserved.
10+
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions are met:
13+
14+
* Redistributions of source code must retain the above copyright notice, this
15+
list of conditions and the following disclaimer.
16+
17+
* Redistributions in binary form must reproduce the above copyright notice,
18+
this list of conditions and the following disclaimer in the documentation
19+
and/or other materials provided with the distribution.
20+
21+
* Neither the name of the copyright holder nor the names of its
22+
contributors may be used to endorse or promote products derived from
23+
this software without specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
"""

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ dependencies = [
5151
'typing-extensions>=4.4.0',
5252
'trueskill>=0.4.5',
5353
'scikit-learn>=1.0.2',
54-
'orjson>=3.8.6',
5554
'mpmath>=1.2.1',
56-
'plotly>=5.14.1',
5755
'matplotlib>=3.5.3',
5856
'circlify>=0.15.0',
59-
"wordcloud>=1.8.2.2; python_version < '3.11'",
57+
58+
# We lock these dependencies because our usage
59+
# might be broken by their updates. We want to
60+
# manually update these dependencies.
61+
'plotly==5.14.1',
62+
"wordcloud==1.9.2",
6063

6164
# This is a temporary fix for kaleido hanging on image generation on Windows
6265
# See: https://github.com/plotly/Kaleido/issues/110
6366
# and: https://github.com/plotly/Kaleido/issues/134
6467
"kaleido==0.1.0.post1; sys_platform == 'win32'",
65-
"kaleido>=0.2.1; sys_platform != 'win32'",
68+
"kaleido==0.2.1; sys_platform != 'win32'",
6669
]
6770
[project.urls]
6871
Homepage = "https://truelearnai.github.io/"

truelearn/learning/_ink_classifier.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from typing import Any, Optional, Dict, Tuple
2+
from typing import Any, Optional, Dict, Tuple, Union
33
from typing_extensions import Self, Final
44

55
import trueskill
@@ -92,8 +92,8 @@ def __init__(
9292
self,
9393
*,
9494
learner_meta_weights: Optional[LearnerMetaWeights] = None,
95-
novelty_classifier: Optional[NoveltyClassifier] = None,
96-
interest_classifier: Optional[InterestClassifier] = None,
95+
novelty_classifier: Optional[Union[NoveltyClassifier, Dict]] = None,
96+
interest_classifier: Optional[Union[InterestClassifier, Dict]] = None,
9797
threshold: float = 0.5,
9898
tau: float = 0.0,
9999
greedy: bool = False,
@@ -106,9 +106,13 @@ def __init__(
106106
learner_meta_weights:
107107
The novelty/interest/bias weights.
108108
novelty_classifier:
109-
The NoveltyClassifier.
109+
The NoveltyClassifier. It can be a NoveltyClassifier object or
110+
a dictionary of parameters that can be used to instantiate a
111+
NoveltyClassifier object.
110112
interest_classifier:
111-
The InterestClassifier.
113+
The InterestClassifier. It can be an InterestClassifier object or
114+
a dictionary of parameters that can be used to instantiate an
115+
InterestClassifier object.
112116
threshold:
113117
A float that determines the classification threshold.
114118
tau:
@@ -125,8 +129,20 @@ def __init__(
125129
TrueLearnValueError:
126130
Values of parameters do not satisfy their constraints.
127131
"""
128-
self._novelty_classifier = novelty_classifier or NoveltyClassifier()
129-
self._interest_classifier = interest_classifier or InterestClassifier()
132+
if novelty_classifier is None:
133+
self._novelty_classifier = NoveltyClassifier()
134+
elif isinstance(novelty_classifier, dict):
135+
self._novelty_classifier = NoveltyClassifier(**novelty_classifier)
136+
else:
137+
self._novelty_classifier = novelty_classifier
138+
139+
if interest_classifier is None:
140+
self._interest_classifier = InterestClassifier()
141+
elif isinstance(interest_classifier, dict):
142+
self._interest_classifier = InterestClassifier(**interest_classifier)
143+
else:
144+
self._interest_classifier = interest_classifier
145+
130146
self._learner_meta_weights = learner_meta_weights or LearnerMetaWeights()
131147
self._threshold = threshold
132148
self._tau = tau

truelearn/preprocessing/_wikifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Optional, Union, Dict, List, Iterable, cast
22
from urllib import parse, request
33

4-
import orjson
4+
import json
55

66
from truelearn.errors import TrueLearnValueError, WikifierError
77

@@ -131,7 +131,7 @@ def __make_wikifier_request(
131131

132132
# nosec because we know `url` is a valid https url
133133
with request.urlopen(url) as r: # nosec
134-
resp = orjson.loads(r.read().decode("utf-8"))
134+
resp = json.loads(r.read().decode("utf-8"))
135135
if "error" in resp:
136136
raise WikifierError(f"error in response : {resp['error']}")
137137
if "status" in resp:

truelearn/tests/test_learning.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,25 @@ def test_ink_classifier_customize(self, train_cases, test_events):
798798

799799
check_farray_close(actual_results, expected_results)
800800

801+
def test_ink_classifier_customize_via_dict(self, train_cases, test_events):
802+
classifier = learning.INKClassifier(
803+
novelty_classifier={"def_var": 0.4},
804+
interest_classifier={"beta": 0.2},
805+
)
806+
807+
train_events, train_labels = train_cases
808+
for event, label in zip(train_events, train_labels):
809+
classifier.fit(event, label)
810+
811+
expected_results = [
812+
0.36741905582712336,
813+
0.3247468970257655,
814+
0.33375911026514554,
815+
]
816+
actual_results = [classifier.predict_proba(event) for event in test_events]
817+
818+
check_farray_close(actual_results, expected_results)
819+
801820
def test_ink_get_set_params(self):
802821
classifier = learning.INKClassifier()
803822

truelearn/tests/test_utils_visualisations.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pathlib
55
import types
66
import os
7-
import sys
87
from typing import Dict, Optional, Callable
98

109
import pytest
@@ -496,10 +495,6 @@ def test_top_n(self, resources):
496495
return plotter
497496

498497

499-
@pytest.mark.skipif(
500-
sys.version_info >= (3, 11),
501-
reason="WordPlotter only supports Python version < 3.11",
502-
)
503498
class TestWordPlotter:
504499
# no way to test this in a cross-platform way
505500
# because wordcloud renders the same font differently on different operating systems

0 commit comments

Comments
 (0)