Comments (7)
So to get back to the original question, doc._.trf_data.last_hidden_layer_state
is a Ragged
object where you can use the spacy token index to access the tensor data for that token, without having to do any additional alignment on your side.
The data for each token is also a Ragged
object:
import spacy
nlp = spacy.load("en_core_web_trf")
doc = nlp("DocTransformerOutput.last_hidden_layer_state is a Ragged object")
# for the tensors corresponding to "DocTransformerOutput.last_hidden_layer_state"
# (token index 0), you can access doc._.trf_data.last_hidden_layer_state[0].data
assert doc._.trf_data.last_hidden_layer_state[0].data.shape == (12, 768)
from spacy.
Great! That answers my question, and that's a very intuitive way to access the tensor by token index.
from spacy.
spaCy 3.7 switched to the Curated Transformers library. The DocTransformerOutput
class is documented here:
https://spacy.io/api/curatedtransformer#doctransformeroutput
The last_hidden_layer_state
property provides the per-token hidden representations for every document.
from spacy.
Ah, this probably should have been documented better as part of the release.
At first glance, the DocTransformerOutput
seems to contain quite a bit less information than the spacy-transformers
ModelOutput
, in particular I don't see enough info to align the tensors with anything in the doc, but maybe I am mistaken?
from spacy.
Ah, the Ragged
lengths align to spacy tokens? (I admit that I hadn't looked too closely at the details here before, which is part of why this was missed in the release notes.)
from spacy.
Ah, the
Ragged
lengths align to spacy tokens? (I admit that I hadn't looked too closely at the details here before, which is part of why this was missed in the release notes.)
Yeah, they do. spacy-curated-transformers
applies piecing to tokens, so it doesn't have to do the same alignment as spacy-transformers
(modulo whitespace tokens).
from spacy.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from spacy.
Related Issues (20)
- Install via `requirements.txt` documentation doesn't work HOT 17
- catalogue.RegistryError: [E892] Unknown function registry: 'vectors'. HOT 1
- invalid whitespace entity spans msg but no whitespace is there HOT 2
- Upgrade to spacy 3.7.2 throws Attribute error HOT 9
- Training spacy model stucking in 99% HOT 1
- displaCy: Separating Punctuations in Dependency Visualization HOT 1
- spaCy training stopping automatically in Google Colab
- Spacy-transformers - update transformers compatibility HOT 4
- NER component in en_core_web_trf doesn't depend on transformer HOT 1
- en_core_web_sm/md/lg stopped loading today (02/04/2024) HOT 1
- Custom component to split coordinations
- Fail to train openai-community / gpt2 model for custom NER on SpaCy framework HOT 1
- Summary HOT 1
- Sharding Warning HOT 1
- nlp.pipe() with multiple processes on Windows VSCode HOT 2
- `Spacy` has inconsistency when dividing sentences HOT 5
- Incorrect detection of sentence boundaries, if last sentence missing eos symbol for trf model
- Enable override of existing custom pipe HOT 1
- Check that filter_spans input is a Span HOT 3
- Tokenizer Incorrectly Splitting "M1M" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacy.