Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes max_calls for BranchBound predicate search configurable for training call #1157

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dedupe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import sqlite3
import tempfile
import warnings
from typing import TYPE_CHECKING, cast, overload
from typing import TYPE_CHECKING, Optional, cast, overload

import numpy
import sklearn.linear_model
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def _read_training(self, training_file: TextIO) -> None:
self.mark_pairs(training_pairs)

def train(
self, recall: float = 1.00, index_predicates: bool = True
self, recall: float = 1.00, index_predicates: bool = True, branch_bound_max_calls: Optional[int] = None
) -> None: # pragma: no cover
"""
Learn final pairwise classifier and fingerprinting rules. Requires that
Expand Down Expand Up @@ -1212,7 +1212,7 @@ def train(
examples, y = flatten_training(self.training_pairs)
self.classifier.fit(self.data_model.distances(examples), y)

self.predicates = self.active_learner.learn_predicates(recall, index_predicates)
self.predicates = self.active_learner.learn_predicates(recall, index_predicates, branch_bound_max_calls)
self._fingerprinter = blocking.Fingerprinter(self.predicates)
self.fingerprinter.reset_indices()

Expand Down
9 changes: 5 additions & 4 deletions dedupe/labeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import random
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, overload
from typing import TYPE_CHECKING, Optional, overload
from warnings import warn

import numpy
Expand Down Expand Up @@ -131,13 +131,14 @@ def candidate_scores(self) -> numpy.typing.NDArray[numpy.float_]:
return self._cached_scores

def learn_predicates(
self, dupes: TrainingExamples, recall: float, index_predicates: bool
self, dupes: TrainingExamples, recall: float, index_predicates: bool, branch_bound_max_calls: Optional[int] = None
) -> tuple[Predicate, ...]:
return self.block_learner.learn(
dupes,
recall=recall,
index_predicates=index_predicates,
candidate_types="random forest",
branch_bound_max_calls=branch_bound_max_calls
)

def _predict(self, pairs: TrainingExamples) -> Labels:
Expand Down Expand Up @@ -391,11 +392,11 @@ def mark(self, pairs: TrainingExamples, y: LabelsLike) -> None:
learner.fit(self.pairs, self.y)

def learn_predicates(
self, recall: float, index_predicates: bool
self, recall: float, index_predicates: bool, branch_bound_max_calls: Optional[int] = None
) -> tuple[Predicate, ...]:
dupes = [pair for label, pair in zip(self.y, self.pairs) if label]
return self.blocker.learn_predicates(
dupes, recall=recall, index_predicates=index_predicates
dupes, recall=recall, index_predicates=index_predicates, branch_bound_max_calls=branch_bound_max_calls
)


Expand Down
5 changes: 3 additions & 2 deletions dedupe/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import math
import random
from abc import ABC
from typing import TYPE_CHECKING, overload
from typing import TYPE_CHECKING, Optional, overload
from warnings import warn

from . import blocking
Expand Down Expand Up @@ -40,6 +40,7 @@ def learn(
recall: float,
index_predicates: bool,
candidate_types: Literal["simple", "random forest"] = "simple",
branch_bound_max_calls: Optional[int] = None
) -> tuple[Predicate, ...]:
"""
Takes in a set of training pairs and predicates and tries to find
Expand Down Expand Up @@ -75,7 +76,7 @@ def learn(
else:
raise ValueError("candidate_type is not valid")

searcher = BranchBound(target_cover, 2500)
searcher = BranchBound(target_cover, branch_bound_max_calls or 2500)
final_predicates = searcher.search(candidate_cover)

logger.info("Final predicate set:")
Expand Down