agatha.ml.hypothesis_predictor.predicate_util module¶
-
class
agatha.ml.hypothesis_predictor.predicate_util.
NegativePredicateGenerator
(coded_terms, graph)¶ Bases:
object
-
generate
()¶
-
-
class
agatha.ml.hypothesis_predictor.predicate_util.
PredicateEmbeddings
(subj: numpy.array, obj: numpy.array, subj_neigh: List[numpy.array], obj_neigh: List[numpy.array])¶ Bases:
object
-
obj
: np.array = None¶
-
obj_neigh
: List[np.array] = None¶
-
subj
: np.array = None¶
-
subj_neigh
: List[np.array] = None¶
-
-
class
agatha.ml.hypothesis_predictor.predicate_util.
PredicateObservationGenerator
(graph, embeddings, neighbor_sample_rate)¶ Bases:
object
Converts predicate names to predicate observations
-
class
agatha.ml.hypothesis_predictor.predicate_util.
PredicateScrambleObservationGenerator
(predicates, *args, **kwargs)¶ Bases:
agatha.ml.hypothesis_predictor.predicate_util.PredicateObservationGenerator
Same as above, but the neighborhood comes from randomly selected predicates
-
agatha.ml.hypothesis_predictor.predicate_util.
clean_coded_term
(term)¶ If term is not formatted as an agatha coded term key, produces a coded term key. Otherwise, just returns the term.
- Return type
str
-
agatha.ml.hypothesis_predictor.predicate_util.
collate_predicate_embeddings
(predicate_embeddings)¶
-
agatha.ml.hypothesis_predictor.predicate_util.
collate_predicate_training_examples
(examples)¶ Takes a list of results from PredicateExampleDataset and produces tensors for input into the agatha training model.
- Return type
Dict
[str
,Any
]
-
agatha.ml.hypothesis_predictor.predicate_util.
is_valid_predicate_name
(predicate_name)¶ - Return type
bool
-
agatha.ml.hypothesis_predictor.predicate_util.
parse_predicate_name
(predicate_name)¶ Parses subject and object from predicate name strings.
Predicate names are formatted strings that follow this convention: p:{subj}:{verb}:{obj}. This function extracts the subject and object and returns coded-term names in the form: m:{entity}. Will raise an exception if the predicate name is improperly formatted.
- Parameters
predicate_name (
str
) – Predicate name in form p:{subj}:{verb}:{obj}.- Return type
Tuple
[str
,str
]- Returns
The subject and object formulated as coded-term names.
-
agatha.ml.hypothesis_predictor.predicate_util.
to_predicate_name
(subj, obj, verb='unknown')¶ Converts two names into a predicate of form p:t1:verb:t2
Assumes that terms are correct Agatha graph keys. This means that we expect input terms in the form of m:____. Allows for a custom verb type, but defaults to unknown. Output will always be set to lowercase.
Example usage:
` to_predicate_name(m:c1, m:c2) > p:c1:unknown:c2 to_predicate_name(m:c1, m:c2, "treats") > p:c1:treats:c2 to_predicate_name(m:c1, m:c2, "TREATS") > p:c1:treats:c2 `
- Parameters
subj (
str
) – Subject term. In the form of “m:_____”obj (
str
) – Object term. In the form of “m:_____”verb (
str
) – Optional verb term for resulting predicate.
- Return type
str
- Returns
Properly formatted predicate containing subject and object. Verb type will be set to “UNKNOWN”