extracting attentions from en_core_web_trf (3.2.0) #9672
-
I have been using spaCy for smaller tasks for a few years now, but am diving in to v3.2 with great gusto for the transformer support. There are a few things I'm learning concurrently, and a little help from someone who knows will be very timely at this point, I think I am trying to figure out how to extract attentions from a model, and have started with en_core_web_trf (v3.2.0). I have looked at #7283, which indicates that this should be possible since explosion/spacy-transformers#268. I have used the example code from the latter discussion:
but it throws an error:
I have also tried loading en_core_web_trf:
...and then modding the config:
I write the model out to disk, and then load it fresh - not sure how best to do this sort of modding, but wanting to be sate. It loads up, and shows the output_attentions to be set in the model's config. So then I look for the attentions:
which yields:
or:
...as suggested in the latter discussion (268), but that yields:
I'm very excited to move my work with transformers into the new spaCy pipeline options, but I've kind of dived into a lot of stuff I'm yet unfamiliar with. My ignorance is I'm sure quite evident. I'm finding the documentation to be scarce, and or out of date, maybe. I'm picking it up quickly, but I learn best by example code, and I cannot find any yet to help me get these attentions back out as I need to. Can you help? I will be most grateful! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This requires a newer version of the architecture The output will be in To modify
This modified setting will be saved with |
Beta Was this translation helpful? Give feedback.
This requires a newer version of the architecture
spacy-transformers.TransformerModel.v3
: https://spacy.io/api/architectures#TransformerModelThe output will be in
trf_data.model_output
once the setting is correct.To modify
en_core_web_trf
, you need to modify the transformer model loaded within the pipeline component directly rather than modifying the config:This modified setting will be saved with
nlp.to_disk
as part of the model data fortransformer
. It's a bit confusing, but the original settings fromconfig.cfg
are only really used when the model is initialized. (If I were starting from scratch, I'd move …