LogLikelihoodAction
dendron.actions.loglikelihood_action.LogLikelihoodAction
Bases: ActionNode
An action node that uses a language model to compute log-likelihoods for a list of completion strings given a prompt.
This node is based on the HFLM library, and will download the model that you specify by name. This can take a long time and/or use a lot of storage, depending on the model you name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The given name of this node. |
required |
cfg
|
HFLMActionConfig
|
The configuration object for this model. |
required |
Source code in src/dendron/actions/loglikelihood_action.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
set_model(new_model)
set_input_processor(f)
Set the input processor to use during tick()
s.
An input processor is applied to the prompt text and completion list stored in the blackboard, and can be used to preprocess them. The processor function should be a map from (str, List[str]) to (str, List[str]).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Callable
|
The input processor function to use. Should be a callable object that maps (self, Any) to (str, List[str]). |
required |
Source code in src/dendron/actions/loglikelihood_action.py
set_output_processor(f)
Set the output processor to use during tick()
s.
An output processor is applied to the log-likelihoods returned by the model, before they are written to the output slot of the blackboard. The function should be a map from List[Tuple[float, bool]] to Any.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f
|
Callable
|
The output processor function. Should be a callable object that maps from (self, List[Tuple[float, bool]]) to Any. |
required |
Source code in src/dendron/actions/loglikelihood_action.py
tick()
Execute a tick, consisting of the following steps:
- Retrieve a prompt and list of completions from the node's blackboard
- Apply the input processor, if one exists
- Compute log-likelihoods for each completion given the prompt
- Apply the output processor, if one exists
- Write the result back to the blackboard
Returns SUCCESS if everything works, FAILURE if there's an exception.
Source code in src/dendron/actions/loglikelihood_action.py
set_tree(tree)
Set the behavior tree for this node, which includes setting up the blackboard and registering the model configuration with the tree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree
|
BehaviorTree
|
The behavior tree this node belongs to. |
required |