Consider the following workspace:
import vowpalwabbit
# define our workspace, a contextual epsilon-greedy bandit with interaction terms
model = vowpalwabbit.Workspace("--cb_explore_adf -b 20 -q UA --quiet --epsilon 0.20")
# we learn on two examples
model.learn("shared |User a:1 b:0\n0:-1:0.5 |Action arm_A\n|Action arm_B")
model.learn("shared |User a:0 b:1\n|Action arm_A\n0:-1:0.5 |Action arm_B")
We can now fetch weights using feature_name and namespace combinations:
# User feature weight
model.get_weight_from_name("a", "User")
# -0.1580076813697815
# Action feature weight
model.get_weight_from_name("arm_A", "Action")
# -0.1580076813697815
Given the above is possible, is there a way to use get_weight_from_name to query weights for interaction terms? I have tried the following without success:
model.get_weight_from_name("User^a*Action^arm_A", "User^Action")
# 0.0
model.get_weight_from_name("User^a*Action^arm_A", "UA")
# 0.0
I have also tried using the relatively new json_weights method, but this returns weights by index, and I am unaware of how to map these back into human-readable feature names.
import json
weights_str = model.json_weights()
weights_dict = json.loads(weights_str)
for weight in weights_dict["weights"]:
print(weight)
# {'index': 24567, 'value': -0.15275263786315918}
# {'index': 71687, 'value': -0.15275263786315918}
# {'index': 116060, 'value': -0.2563942074775696}
# {'index': 195964, 'value': -0.1580076813697815}
# {'index': 310189, 'value': -0.1580076813697815}
# {'index': 550027, 'value': -0.1580076813697815}
# {'index': 560370, 'value': -0.15275263786315918}
My current understanding is that 4 of these output weights belong to the interaction terms, assuming that we have 7 from the following indexes:
1. Constant
2. User^a
3. User^b
4. User^a*Action^arm_A
5. User^a*Action^arm_B
6. User^b*Action^arm_A
7. User^b*Action^arm_B
Anyone have any thoughts or insights? Thanks.