hopwise.model.logits_processor¶
Common logits processor in recommender system
Classes¶
Fallback LogitsProcessor if transformers is not available. |
|
Force the last token to be one of the force_tokens if the total length is reached, in the path generation stage |
|
Force the last token to be one of the force_tokens if the total length is reached, in the path generation stage |
|
Module Contents¶
- class hopwise.model.logits_processor.LogitsProcessor[source]¶
Fallback LogitsProcessor if transformers is not available.
- class hopwise.model.logits_processor.ConstrainedLogitsProcessorWordLevel(tokenized_ckg, tokenized_used_ids, max_sequence_length, tokenizer, mask_cache_size=3 * 10**4, pos_candidates_cache_size=1 * 10**5, task=KnowledgeEvaluationType.REC, **kwargs)[source]¶
Bases:
transformers.LogitsProcessor
Force the last token to be one of the force_tokens if the total length is reached, in the path generation stage this means to limit the hop size. This is a word-level constraint, does not work with piece tokenizers. If task is link prediction (LP) logit processor forces last token to reachable ones
- tokenized_ckg¶
- tokenized_used_ids¶
- max_sequence_length¶
- tokenizer¶
- bos_token_id¶
- pos_candidates_cache¶
- mask_cache¶
- task¶
- is_bos_token_in_input(input_ids)[source]¶
Check if the input contains a BOS token. Checking the first sequence is enough.
- process_scores_rec(input_ids, idx)[source]¶
Process each score based on input length and update mask list.
- class hopwise.model.logits_processor.PrefixConstrainedLogitsProcessorWordLevel(tokenized_ckg, tokenized_used_ids, max_sequence_length, tokenizer, **kwargs)[source]¶
Bases:
ConstrainedLogitsProcessorWordLevel
Force the last token to be one of the force_tokens if the total length is reached, in the path generation stage this means to limit the hop size. This is a word-level constraint, does not work with piece tokenizers. If task is link prediction (LP) logit processor forces last token to reachable ones
- mask_cache = None¶
- class hopwise.model.logits_processor.PLMLogitsProcessorWordLevel(tokenized_ckg, tokenized_used_ids, max_sequence_length, tokenizer, pos_candidates_cache_size=1 * 10**5, task=KnowledgeEvaluationType.REC, **kwargs)[source]¶
Bases:
transformers.LogitsProcessor
https://dl.acm.org/doi/pdf/10.1145/3485447.3511937 Constraint decoding strategy for PLM, it forces the model to generate alternatively entities and relations
- tokenized_ckg¶
- tokenized_used_ids¶
- max_sequence_length¶
- tokenizer¶
- bos_token_id¶
- pos_candidates_cache¶
- task¶
- entity_token_ids¶
- relation_token_ids¶