def get_gold_labels(self, cand_lists: List[List[Candidate]], annotator: Optional[str] = None) -> List[np.ndarray]: """Load dense matrix of GoldLabels for each candidate_class. :param cand_lists: The candidates to get gold labels for. :type cand_lists: List of list of candidates. :param annotator: A specific annotator key to get labels for. Default None. :type annotator: str :raises ValueError: If get_gold_labels is called before gold labels are loaded, the result will contain ABSTAIN values. We raise a ValueError to help indicate this potential mistake to the user. :return: A list of MxN dense matrix where M are the candidates and N is the annotators. If annotator is provided, return a list of Mx1 matrix. :rtype: list[np.ndarray] """ gold_labels = [ unshift_label_matrix(m) for m in get_sparse_matrix( self.session, GoldLabelKey, cand_lists, key=annotator) ] for cand_labels in gold_labels: if ABSTAIN in cand_labels: raise ValueError("Gold labels contain ABSTAIN labels. " "Did you load gold labels beforehand?") return gold_labels
def get_feature_matrices( self, cand_lists: List[List[Candidate]]) -> List[csr_matrix]: """Load sparse matrix of Features for each candidate_class. :param cand_lists: The candidates to get features for. :return: A list of MxN sparse matrix where M are the candidates and N is the features. """ return get_sparse_matrix(self.session, FeatureKey, cand_lists)
def get_label_matrices(self, cand_lists): """Load sparse matrix of Labels for each candidate_class. :param cand_lists: The candidates to get labels for. :type cand_lists: List of list of candidates. :return: An MxN sparse matrix where M are the candidates and N is the labeling functions. :rtype: csr_matrix """ return get_sparse_matrix(self.session, LabelKey, cand_lists)
def get_feature_matrices(self, cand_lists): """Load sparse matrix of Features for each candidate_class. :param cand_lists: The candidates to get features for. :type cand_lists: List of list of candidates. :return: An MxN sparse matrix where M are the candidates and N is the features. :rtype: csr_matrix """ return get_sparse_matrix(self.session, FeatureKey, cand_lists)
def get_gold_labels(session, cand_lists, annotator_name="gold"): """Get the sparse matrix for the specified annotator. :param session: The database session. :param cand_lists: The candidates to get gold labels for. :type cand_lists: List of list of candidates. :param annotator: A specific annotator key to get labels for. Default "gold". :type annotator: str """ return get_sparse_matrix(session, GoldLabelKey, cand_lists, key=annotator_name)
def get_label_matrices(self, cand_lists: List[List[Candidate]]) -> List[np.ndarray]: """Load dense matrix of Labels for each candidate_class. :param cand_lists: The candidates to get labels for. :return: A list of MxN dense matrix where M are the candidates and N is the labeling functions. """ return [ unshift_label_matrix(m) for m in get_sparse_matrix(self.session, LabelKey, cand_lists) ]
def get_gold_labels(self, cand_lists, annotator=None): """Load sparse matrix of GoldLabels for each candidate_class. :param cand_lists: The candidates to get gold labels for. :type cand_lists: List of list of candidates. :param annotator: A specific annotator key to get labels for. Default None. :type annotator: str :return: An MxN sparse matrix where M are the candidates and N is the annotators. If annotator is provided, return an Mx1 matrix. :rtype: csr_matrix """ return get_sparse_matrix(self.session, GoldLabelKey, cand_lists, key=annotator)
def get_gold_labels(self, cand_lists: List[List[Candidate]], annotator: Optional[str] = None) -> List[np.ndarray]: """Load dense matrix of GoldLabels for each candidate_class. :param cand_lists: The candidates to get gold labels for. :type cand_lists: List of list of candidates. :param annotator: A specific annotator key to get labels for. Default None. :type annotator: str :return: A list of MxN dense matrix where M are the candidates and N is the annotators. If annotator is provided, return a list of Mx1 matrix. :rtype: list[np.ndarray] """ return [ unshift_label_matrix(m) for m in get_sparse_matrix( self.session, GoldLabelKey, cand_lists, key=annotator) ]
def load_gold_labels(session, cand_lists, annotator_name="gold"): """Load the sparse matrix for the specified annotator.""" return get_sparse_matrix(session, GoldLabelKey, cand_lists, key=annotator_name)
def get_label_matrices(self, cand_lists): """Load sparse matrix of Labels for each candidate_class.""" return get_sparse_matrix(self.session, LabelKey, cand_lists)
def get_gold_labels(self, cand_lists, annotator=None): """Load sparse matrix of GoldLabels for each candidate_class.""" return get_sparse_matrix(self.session, GoldLabelKey, cand_lists, key=annotator)
def get_feature_matrices(self, cand_lists): """Load sparse matrix of Features for each candidate_class.""" return get_sparse_matrix(self.session, FeatureKey, cand_lists)