Skip to content

Commit 413044e

Browse files
committed
fix some doctests
1 parent cb5270b commit 413044e

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

autointent/modules/retrieval/_vectordb.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ class VectorDBModule(RetrievalModule):
3232
3333
Examples
3434
--------
35+
.. testsetup::
36+
37+
db_dir = "doctests-db"
38+
3539
.. testcode::
3640
3741
from autointent.modules.retrieval import VectorDBModule
3842
utterances = ["bye", "how are you?", "good morning"]
3943
labels = [0, 1, 1]
40-
vector_db = VectorDBModule(k=2, embedder_name="sergeyzh/rubert-tiny-turbo")
44+
vector_db = VectorDBModule(
45+
k=2,
46+
embedder_name="sergeyzh/rubert-tiny-turbo",
47+
db_dir=db_dir,
48+
)
4149
vector_db.fit(utterances, labels)
4250
predictions = vector_db.predict(["how is the weather today?"])
4351
print(predictions)
@@ -46,6 +54,11 @@ class VectorDBModule(RetrievalModule):
4654
4755
([[1, 1]], [[0.1525942087173462, 0.18616724014282227]], [['good morning', 'how are you?']])
4856
57+
.. testcleanup::
58+
59+
import shutil
60+
shutil.rmtree(db_dir)
61+
4962
"""
5063

5164
vector_index: VectorIndex

autointent/modules/scoring/_description/description.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,6 @@ class DescriptionScorer(ScoringModule):
4040
:ivar db_dir: Directory path where the vector database is stored.
4141
:ivar name: Name of the scorer, defaults to "description".
4242
43-
Examples
44-
--------
45-
.. testsetup::
46-
47-
db_dir = "doctests-db"
48-
49-
.. testcode::
50-
51-
from autointent.modules import DescriptionScorer
52-
utterances = ["what is your name?", "how old are you?"]
53-
labels = [0, 1]
54-
descriptions = ["greeting", "age-related question"]
55-
scorer = DescriptionScorer(
56-
embedder_name="sergeyzh/rubert-tiny-turbo",
57-
db_dir=db_dir
58-
)
59-
scorer.fit(utterances, labels, descriptions)
60-
scores = scorer.predict(["tell me about your age?"])
61-
print(scores) # Outputs similarity scores for the utterance against all descriptions
62-
63-
.. testoutput::
64-
65-
[[0.47210786 0.5278922 ]]
66-
67-
.. testcleanup::
68-
69-
import shutil
70-
shutil.rmtree(db_dir)
71-
7243
"""
7344

7445
weights_file_name: str = "description_vectors.npy"

autointent/modules/scoring/_linear.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ class LinearScorer(ScoringModule):
4848
.. testcode::
4949
5050
from autointent.modules import LinearScorer
51-
from autointent import Dataset
52-
dataset = Dataset.from_datasets("AutoIntent/banking77")
5351
scorer = LinearScorer(
54-
embedder_name="sergeyzh/rubert-tiny-turbo",
52+
embedder_name="sergeyzh/rubert-tiny-turbo", cv=2
5553
)
56-
scorer.fit(dataset["train"]["utterance"], dataset["train"]["label"])
57-
test_utterances = ["Hello!", "What's up?"]
54+
utterances = ["hello", "goodbye", "allo", "sayonara"]
55+
labels = [0, 1, 0, 1]
56+
scorer.fit(utterances, labels)
57+
test_utterances = ["hi", "bye"]
5858
probabilities = scorer.predict(test_utterances)
59+
print(probabilities)
60+
61+
.. testoutput::
62+
63+
[[0.50000032 0.49999968]
64+
[0.50000032 0.49999968]]
5965
6066
"""
6167

0 commit comments

Comments
 (0)