aepo.mbr.policy package
Submodules
aepo.mbr.policy.diverse_mbr module
- aepo.mbr.policy.diverse_mbr.compute_dmbr(hyp: list | None = None, score_function: callable | None = None, matrix: array | None = None, weights: list | None = None, src: str | None = None, k: int = 1, div_pen: float = 0.0) array
- Parameters:
hyp (list) – the list of hypotheses.
score_function (callable) – the scoring function.
matrix (np.array) – the similarity matrix.
weights (list) – the weights for the scoring function.
src (str) – the source.
k (int) – the number of elements to select.
div_pen (float) – the diversity penalty.
Compute the diverse MBR.
- aepo.mbr.policy.diverse_mbr.gbfs(func: callable, n: int, k: int) array
- Parameters:
func (callable) – the objective function.
n (int) – the number of elements.
k (int) – the number of elements to select.
- Returns:
the selected elements.
- Return type:
np.array
Greedy Best First Search for the diverse MBR. Greedy search is guaranteed to find a solution with an approximation factor of (1−1/e), provided that λ is small enough to ensure the function is non-decreasing; otherwise, the approximation factor is slightly worse than (1−1/e). Nemhauser, G. L., Wolsey, L. A., & Fisher, M. L. (1978). An analysis of approximations for maximizing submodular set functions—I. Mathematical programming, 14, 265-294.
- aepo.mbr.policy.diverse_mbr.generate_objective(k: int, div_pen: float, matrix: array) callable
- Parameters:
k (int) – the number of elements to select.
div_pen (float) – the diversity penalty.
matrix (np.array) – the similarity matrix.
- Returns:
the objective function of the diverse MBR.
- Return type:
callable
Generate an objective function for the diverse MBR. See https://github.com/CyberAgentAILab/diverse-mbr/tree/master for more details of diverse MBR.
- aepo.mbr.policy.diverse_mbr.local_search(func: callable, init: array, iterations: int = 100, neighbor: int = 2) array
- Parameters:
func (callable) – the objective function.
init (np.array) – the initial solution.
iterations (int) – the number of iterations.
neighbor (int) – the number of neighbors to remove.
- Returns:
the selected elements.
- Return type:
np.array
Local search for the diverse MBR. This is an alternative to the greedy search.
aepo.mbr.policy.mbr module
- aepo.mbr.policy.mbr.compute_mbr(hyp: list | None = None, compute_similarity: callable | None = None, matrix: array | None = None, weights: list | None = None, src: str | None = None, incremental: bool = False)
- Parameters:
hyp (list) – the list of hypotheses.
compute_similarity (callable) – the similarity function.
matrix (np.array) – the similarity matrix.
weights (list) – the weights for the scoring function.
src (str) – the source.
incremental (bool) – the flag for incremental MBR.
- Returns:
the best hypothesis index.
- Return type:
int
Compute the minimum bayes risk decoding.
- aepo.mbr.policy.mbr.compute_score_matrix(samples: list, score_function: callable, src_input: str | None = None) array
- Parameters:
samples (list) – the list of samples.
score_function (callable) – the score function.
src_input (str) – the source input.
- Returns:
the score matrix.
- Return type:
np.array
Compute the score matrix for a list of samples.